d3.js 484 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856
  1. /*!
  2. * Copyright 2010-2017 Mike Bostock
  3. * All rights reserved.
  4. * d3(https://github.com/d3/d3)
  5. * license: BSD-3-Clause
  6. * version: v5.5.0
  7. */
  8. // https://d3js.org Version 5.5.0. Copyright 2018 Mike Bostock.
  9. (function (global, factory) {
  10. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  11. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  12. (factory((global.d3 = global.d3 || {})));
  13. }(this, (function (exports) { 'use strict';
  14. var version = "5.5.0";
  15. function ascending(a, b) {
  16. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  17. }
  18. function bisector(compare) {
  19. if (compare.length === 1) compare = ascendingComparator(compare);
  20. return {
  21. left: function(a, x, lo, hi) {
  22. if (lo == null) lo = 0;
  23. if (hi == null) hi = a.length;
  24. while (lo < hi) {
  25. var mid = lo + hi >>> 1;
  26. if (compare(a[mid], x) < 0) lo = mid + 1;
  27. else hi = mid;
  28. }
  29. return lo;
  30. },
  31. right: function(a, x, lo, hi) {
  32. if (lo == null) lo = 0;
  33. if (hi == null) hi = a.length;
  34. while (lo < hi) {
  35. var mid = lo + hi >>> 1;
  36. if (compare(a[mid], x) > 0) hi = mid;
  37. else lo = mid + 1;
  38. }
  39. return lo;
  40. }
  41. };
  42. }
  43. function ascendingComparator(f) {
  44. return function(d, x) {
  45. return ascending(f(d), x);
  46. };
  47. }
  48. var ascendingBisect = bisector(ascending);
  49. var bisectRight = ascendingBisect.right;
  50. var bisectLeft = ascendingBisect.left;
  51. function pairs(array, f) {
  52. if (f == null) f = pair;
  53. var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
  54. while (i < n) pairs[i] = f(p, p = array[++i]);
  55. return pairs;
  56. }
  57. function pair(a, b) {
  58. return [a, b];
  59. }
  60. function cross(values0, values1, reduce) {
  61. var n0 = values0.length,
  62. n1 = values1.length,
  63. values = new Array(n0 * n1),
  64. i0,
  65. i1,
  66. i,
  67. value0;
  68. if (reduce == null) reduce = pair;
  69. for (i0 = i = 0; i0 < n0; ++i0) {
  70. for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
  71. values[i] = reduce(value0, values1[i1]);
  72. }
  73. }
  74. return values;
  75. }
  76. function descending(a, b) {
  77. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  78. }
  79. function number(x) {
  80. return x === null ? NaN : +x;
  81. }
  82. function variance(values, valueof) {
  83. var n = values.length,
  84. m = 0,
  85. i = -1,
  86. mean = 0,
  87. value,
  88. delta,
  89. sum = 0;
  90. if (valueof == null) {
  91. while (++i < n) {
  92. if (!isNaN(value = number(values[i]))) {
  93. delta = value - mean;
  94. mean += delta / ++m;
  95. sum += delta * (value - mean);
  96. }
  97. }
  98. }
  99. else {
  100. while (++i < n) {
  101. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  102. delta = value - mean;
  103. mean += delta / ++m;
  104. sum += delta * (value - mean);
  105. }
  106. }
  107. }
  108. if (m > 1) return sum / (m - 1);
  109. }
  110. function deviation(array, f) {
  111. var v = variance(array, f);
  112. return v ? Math.sqrt(v) : v;
  113. }
  114. function extent(values, valueof) {
  115. var n = values.length,
  116. i = -1,
  117. value,
  118. min,
  119. max;
  120. if (valueof == null) {
  121. while (++i < n) { // Find the first comparable value.
  122. if ((value = values[i]) != null && value >= value) {
  123. min = max = value;
  124. while (++i < n) { // Compare the remaining values.
  125. if ((value = values[i]) != null) {
  126. if (min > value) min = value;
  127. if (max < value) max = value;
  128. }
  129. }
  130. }
  131. }
  132. }
  133. else {
  134. while (++i < n) { // Find the first comparable value.
  135. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  136. min = max = value;
  137. while (++i < n) { // Compare the remaining values.
  138. if ((value = valueof(values[i], i, values)) != null) {
  139. if (min > value) min = value;
  140. if (max < value) max = value;
  141. }
  142. }
  143. }
  144. }
  145. }
  146. return [min, max];
  147. }
  148. var array = Array.prototype;
  149. var slice = array.slice;
  150. var map = array.map;
  151. function constant(x) {
  152. return function() {
  153. return x;
  154. };
  155. }
  156. function identity(x) {
  157. return x;
  158. }
  159. function sequence(start, stop, step) {
  160. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  161. var i = -1,
  162. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  163. range = new Array(n);
  164. while (++i < n) {
  165. range[i] = start + i * step;
  166. }
  167. return range;
  168. }
  169. var e10 = Math.sqrt(50),
  170. e5 = Math.sqrt(10),
  171. e2 = Math.sqrt(2);
  172. function ticks(start, stop, count) {
  173. var reverse,
  174. i = -1,
  175. n,
  176. ticks,
  177. step;
  178. stop = +stop, start = +start, count = +count;
  179. if (start === stop && count > 0) return [start];
  180. if (reverse = stop < start) n = start, start = stop, stop = n;
  181. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  182. if (step > 0) {
  183. start = Math.ceil(start / step);
  184. stop = Math.floor(stop / step);
  185. ticks = new Array(n = Math.ceil(stop - start + 1));
  186. while (++i < n) ticks[i] = (start + i) * step;
  187. } else {
  188. start = Math.floor(start * step);
  189. stop = Math.ceil(stop * step);
  190. ticks = new Array(n = Math.ceil(start - stop + 1));
  191. while (++i < n) ticks[i] = (start - i) / step;
  192. }
  193. if (reverse) ticks.reverse();
  194. return ticks;
  195. }
  196. function tickIncrement(start, stop, count) {
  197. var step = (stop - start) / Math.max(0, count),
  198. power = Math.floor(Math.log(step) / Math.LN10),
  199. error = step / Math.pow(10, power);
  200. return power >= 0
  201. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  202. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  203. }
  204. function tickStep(start, stop, count) {
  205. var step0 = Math.abs(stop - start) / Math.max(0, count),
  206. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  207. error = step0 / step1;
  208. if (error >= e10) step1 *= 10;
  209. else if (error >= e5) step1 *= 5;
  210. else if (error >= e2) step1 *= 2;
  211. return stop < start ? -step1 : step1;
  212. }
  213. function thresholdSturges(values) {
  214. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  215. }
  216. function histogram() {
  217. var value = identity,
  218. domain = extent,
  219. threshold = thresholdSturges;
  220. function histogram(data) {
  221. var i,
  222. n = data.length,
  223. x,
  224. values = new Array(n);
  225. for (i = 0; i < n; ++i) {
  226. values[i] = value(data[i], i, data);
  227. }
  228. var xz = domain(values),
  229. x0 = xz[0],
  230. x1 = xz[1],
  231. tz = threshold(values, x0, x1);
  232. // Convert number of thresholds into uniform thresholds.
  233. if (!Array.isArray(tz)) {
  234. tz = tickStep(x0, x1, tz);
  235. tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
  236. }
  237. // Remove any thresholds outside the domain.
  238. var m = tz.length;
  239. while (tz[0] <= x0) tz.shift(), --m;
  240. while (tz[m - 1] > x1) tz.pop(), --m;
  241. var bins = new Array(m + 1),
  242. bin;
  243. // Initialize bins.
  244. for (i = 0; i <= m; ++i) {
  245. bin = bins[i] = [];
  246. bin.x0 = i > 0 ? tz[i - 1] : x0;
  247. bin.x1 = i < m ? tz[i] : x1;
  248. }
  249. // Assign data to bins by value, ignoring any outside the domain.
  250. for (i = 0; i < n; ++i) {
  251. x = values[i];
  252. if (x0 <= x && x <= x1) {
  253. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  254. }
  255. }
  256. return bins;
  257. }
  258. histogram.value = function(_) {
  259. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  260. };
  261. histogram.domain = function(_) {
  262. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  263. };
  264. histogram.thresholds = function(_) {
  265. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  266. };
  267. return histogram;
  268. }
  269. function threshold(values, p, valueof) {
  270. if (valueof == null) valueof = number;
  271. if (!(n = values.length)) return;
  272. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  273. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  274. var n,
  275. i = (n - 1) * p,
  276. i0 = Math.floor(i),
  277. value0 = +valueof(values[i0], i0, values),
  278. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  279. return value0 + (value1 - value0) * (i - i0);
  280. }
  281. function freedmanDiaconis(values, min, max) {
  282. values = map.call(values, number).sort(ascending);
  283. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  284. }
  285. function scott(values, min, max) {
  286. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  287. }
  288. function max(values, valueof) {
  289. var n = values.length,
  290. i = -1,
  291. value,
  292. max;
  293. if (valueof == null) {
  294. while (++i < n) { // Find the first comparable value.
  295. if ((value = values[i]) != null && value >= value) {
  296. max = value;
  297. while (++i < n) { // Compare the remaining values.
  298. if ((value = values[i]) != null && value > max) {
  299. max = value;
  300. }
  301. }
  302. }
  303. }
  304. }
  305. else {
  306. while (++i < n) { // Find the first comparable value.
  307. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  308. max = value;
  309. while (++i < n) { // Compare the remaining values.
  310. if ((value = valueof(values[i], i, values)) != null && value > max) {
  311. max = value;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. return max;
  318. }
  319. function mean(values, valueof) {
  320. var n = values.length,
  321. m = n,
  322. i = -1,
  323. value,
  324. sum = 0;
  325. if (valueof == null) {
  326. while (++i < n) {
  327. if (!isNaN(value = number(values[i]))) sum += value;
  328. else --m;
  329. }
  330. }
  331. else {
  332. while (++i < n) {
  333. if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
  334. else --m;
  335. }
  336. }
  337. if (m) return sum / m;
  338. }
  339. function median(values, valueof) {
  340. var n = values.length,
  341. i = -1,
  342. value,
  343. numbers = [];
  344. if (valueof == null) {
  345. while (++i < n) {
  346. if (!isNaN(value = number(values[i]))) {
  347. numbers.push(value);
  348. }
  349. }
  350. }
  351. else {
  352. while (++i < n) {
  353. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  354. numbers.push(value);
  355. }
  356. }
  357. }
  358. return threshold(numbers.sort(ascending), 0.5);
  359. }
  360. function merge(arrays) {
  361. var n = arrays.length,
  362. m,
  363. i = -1,
  364. j = 0,
  365. merged,
  366. array;
  367. while (++i < n) j += arrays[i].length;
  368. merged = new Array(j);
  369. while (--n >= 0) {
  370. array = arrays[n];
  371. m = array.length;
  372. while (--m >= 0) {
  373. merged[--j] = array[m];
  374. }
  375. }
  376. return merged;
  377. }
  378. function min(values, valueof) {
  379. var n = values.length,
  380. i = -1,
  381. value,
  382. min;
  383. if (valueof == null) {
  384. while (++i < n) { // Find the first comparable value.
  385. if ((value = values[i]) != null && value >= value) {
  386. min = value;
  387. while (++i < n) { // Compare the remaining values.
  388. if ((value = values[i]) != null && min > value) {
  389. min = value;
  390. }
  391. }
  392. }
  393. }
  394. }
  395. else {
  396. while (++i < n) { // Find the first comparable value.
  397. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  398. min = value;
  399. while (++i < n) { // Compare the remaining values.
  400. if ((value = valueof(values[i], i, values)) != null && min > value) {
  401. min = value;
  402. }
  403. }
  404. }
  405. }
  406. }
  407. return min;
  408. }
  409. function permute(array, indexes) {
  410. var i = indexes.length, permutes = new Array(i);
  411. while (i--) permutes[i] = array[indexes[i]];
  412. return permutes;
  413. }
  414. function scan(values, compare) {
  415. if (!(n = values.length)) return;
  416. var n,
  417. i = 0,
  418. j = 0,
  419. xi,
  420. xj = values[j];
  421. if (compare == null) compare = ascending;
  422. while (++i < n) {
  423. if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
  424. xj = xi, j = i;
  425. }
  426. }
  427. if (compare(xj, xj) === 0) return j;
  428. }
  429. function shuffle(array, i0, i1) {
  430. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  431. t,
  432. i;
  433. while (m) {
  434. i = Math.random() * m-- | 0;
  435. t = array[m + i0];
  436. array[m + i0] = array[i + i0];
  437. array[i + i0] = t;
  438. }
  439. return array;
  440. }
  441. function sum(values, valueof) {
  442. var n = values.length,
  443. i = -1,
  444. value,
  445. sum = 0;
  446. if (valueof == null) {
  447. while (++i < n) {
  448. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  449. }
  450. }
  451. else {
  452. while (++i < n) {
  453. if (value = +valueof(values[i], i, values)) sum += value;
  454. }
  455. }
  456. return sum;
  457. }
  458. function transpose(matrix) {
  459. if (!(n = matrix.length)) return [];
  460. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  461. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  462. row[j] = matrix[j][i];
  463. }
  464. }
  465. return transpose;
  466. }
  467. function length(d) {
  468. return d.length;
  469. }
  470. function zip() {
  471. return transpose(arguments);
  472. }
  473. var slice$1 = Array.prototype.slice;
  474. function identity$1(x) {
  475. return x;
  476. }
  477. var top = 1,
  478. right = 2,
  479. bottom = 3,
  480. left = 4,
  481. epsilon = 1e-6;
  482. function translateX(x) {
  483. return "translate(" + (x + 0.5) + ",0)";
  484. }
  485. function translateY(y) {
  486. return "translate(0," + (y + 0.5) + ")";
  487. }
  488. function number$1(scale) {
  489. return function(d) {
  490. return +scale(d);
  491. };
  492. }
  493. function center(scale) {
  494. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  495. if (scale.round()) offset = Math.round(offset);
  496. return function(d) {
  497. return +scale(d) + offset;
  498. };
  499. }
  500. function entering() {
  501. return !this.__axis;
  502. }
  503. function axis(orient, scale) {
  504. var tickArguments = [],
  505. tickValues = null,
  506. tickFormat = null,
  507. tickSizeInner = 6,
  508. tickSizeOuter = 6,
  509. tickPadding = 3,
  510. k = orient === top || orient === left ? -1 : 1,
  511. x = orient === left || orient === right ? "x" : "y",
  512. transform = orient === top || orient === bottom ? translateX : translateY;
  513. function axis(context) {
  514. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  515. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  516. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  517. range = scale.range(),
  518. range0 = +range[0] + 0.5,
  519. range1 = +range[range.length - 1] + 0.5,
  520. position = (scale.bandwidth ? center : number$1)(scale.copy()),
  521. selection = context.selection ? context.selection() : context,
  522. path = selection.selectAll(".domain").data([null]),
  523. tick = selection.selectAll(".tick").data(values, scale).order(),
  524. tickExit = tick.exit(),
  525. tickEnter = tick.enter().append("g").attr("class", "tick"),
  526. line = tick.select("line"),
  527. text = tick.select("text");
  528. path = path.merge(path.enter().insert("path", ".tick")
  529. .attr("class", "domain")
  530. .attr("stroke", "#000"));
  531. tick = tick.merge(tickEnter);
  532. line = line.merge(tickEnter.append("line")
  533. .attr("stroke", "#000")
  534. .attr(x + "2", k * tickSizeInner));
  535. text = text.merge(tickEnter.append("text")
  536. .attr("fill", "#000")
  537. .attr(x, k * spacing)
  538. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  539. if (context !== selection) {
  540. path = path.transition(context);
  541. tick = tick.transition(context);
  542. line = line.transition(context);
  543. text = text.transition(context);
  544. tickExit = tickExit.transition(context)
  545. .attr("opacity", epsilon)
  546. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  547. tickEnter
  548. .attr("opacity", epsilon)
  549. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  550. }
  551. tickExit.remove();
  552. path
  553. .attr("d", orient === left || orient == right
  554. ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
  555. : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
  556. tick
  557. .attr("opacity", 1)
  558. .attr("transform", function(d) { return transform(position(d)); });
  559. line
  560. .attr(x + "2", k * tickSizeInner);
  561. text
  562. .attr(x, k * spacing)
  563. .text(format);
  564. selection.filter(entering)
  565. .attr("fill", "none")
  566. .attr("font-size", 10)
  567. .attr("font-family", "sans-serif")
  568. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  569. selection
  570. .each(function() { this.__axis = position; });
  571. }
  572. axis.scale = function(_) {
  573. return arguments.length ? (scale = _, axis) : scale;
  574. };
  575. axis.ticks = function() {
  576. return tickArguments = slice$1.call(arguments), axis;
  577. };
  578. axis.tickArguments = function(_) {
  579. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  580. };
  581. axis.tickValues = function(_) {
  582. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  583. };
  584. axis.tickFormat = function(_) {
  585. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  586. };
  587. axis.tickSize = function(_) {
  588. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  589. };
  590. axis.tickSizeInner = function(_) {
  591. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  592. };
  593. axis.tickSizeOuter = function(_) {
  594. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  595. };
  596. axis.tickPadding = function(_) {
  597. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  598. };
  599. return axis;
  600. }
  601. function axisTop(scale) {
  602. return axis(top, scale);
  603. }
  604. function axisRight(scale) {
  605. return axis(right, scale);
  606. }
  607. function axisBottom(scale) {
  608. return axis(bottom, scale);
  609. }
  610. function axisLeft(scale) {
  611. return axis(left, scale);
  612. }
  613. var noop = {value: function() {}};
  614. function dispatch() {
  615. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  616. if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
  617. _[t] = [];
  618. }
  619. return new Dispatch(_);
  620. }
  621. function Dispatch(_) {
  622. this._ = _;
  623. }
  624. function parseTypenames(typenames, types) {
  625. return typenames.trim().split(/^|\s+/).map(function(t) {
  626. var name = "", i = t.indexOf(".");
  627. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  628. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  629. return {type: t, name: name};
  630. });
  631. }
  632. Dispatch.prototype = dispatch.prototype = {
  633. constructor: Dispatch,
  634. on: function(typename, callback) {
  635. var _ = this._,
  636. T = parseTypenames(typename + "", _),
  637. t,
  638. i = -1,
  639. n = T.length;
  640. // If no callback was specified, return the callback of the given type and name.
  641. if (arguments.length < 2) {
  642. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  643. return;
  644. }
  645. // If a type was specified, set the callback for the given type and name.
  646. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  647. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  648. while (++i < n) {
  649. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  650. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  651. }
  652. return this;
  653. },
  654. copy: function() {
  655. var copy = {}, _ = this._;
  656. for (var t in _) copy[t] = _[t].slice();
  657. return new Dispatch(copy);
  658. },
  659. call: function(type, that) {
  660. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  661. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  662. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  663. },
  664. apply: function(type, that, args) {
  665. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  666. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  667. }
  668. };
  669. function get(type, name) {
  670. for (var i = 0, n = type.length, c; i < n; ++i) {
  671. if ((c = type[i]).name === name) {
  672. return c.value;
  673. }
  674. }
  675. }
  676. function set(type, name, callback) {
  677. for (var i = 0, n = type.length; i < n; ++i) {
  678. if (type[i].name === name) {
  679. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  680. break;
  681. }
  682. }
  683. if (callback != null) type.push({name: name, value: callback});
  684. return type;
  685. }
  686. var xhtml = "http://www.w3.org/1999/xhtml";
  687. var namespaces = {
  688. svg: "http://www.w3.org/2000/svg",
  689. xhtml: xhtml,
  690. xlink: "http://www.w3.org/1999/xlink",
  691. xml: "http://www.w3.org/XML/1998/namespace",
  692. xmlns: "http://www.w3.org/2000/xmlns/"
  693. };
  694. function namespace(name) {
  695. var prefix = name += "", i = prefix.indexOf(":");
  696. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  697. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  698. }
  699. function creatorInherit(name) {
  700. return function() {
  701. var document = this.ownerDocument,
  702. uri = this.namespaceURI;
  703. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  704. ? document.createElement(name)
  705. : document.createElementNS(uri, name);
  706. };
  707. }
  708. function creatorFixed(fullname) {
  709. return function() {
  710. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  711. };
  712. }
  713. function creator(name) {
  714. var fullname = namespace(name);
  715. return (fullname.local
  716. ? creatorFixed
  717. : creatorInherit)(fullname);
  718. }
  719. function none() {}
  720. function selector(selector) {
  721. return selector == null ? none : function() {
  722. return this.querySelector(selector);
  723. };
  724. }
  725. function selection_select(select) {
  726. if (typeof select !== "function") select = selector(select);
  727. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  728. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  729. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  730. if ("__data__" in node) subnode.__data__ = node.__data__;
  731. subgroup[i] = subnode;
  732. }
  733. }
  734. }
  735. return new Selection(subgroups, this._parents);
  736. }
  737. function empty() {
  738. return [];
  739. }
  740. function selectorAll(selector) {
  741. return selector == null ? empty : function() {
  742. return this.querySelectorAll(selector);
  743. };
  744. }
  745. function selection_selectAll(select) {
  746. if (typeof select !== "function") select = selectorAll(select);
  747. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  748. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  749. if (node = group[i]) {
  750. subgroups.push(select.call(node, node.__data__, i, group));
  751. parents.push(node);
  752. }
  753. }
  754. }
  755. return new Selection(subgroups, parents);
  756. }
  757. var matcher = function(selector) {
  758. return function() {
  759. return this.matches(selector);
  760. };
  761. };
  762. if (typeof document !== "undefined") {
  763. var element = document.documentElement;
  764. if (!element.matches) {
  765. var vendorMatches = element.webkitMatchesSelector
  766. || element.msMatchesSelector
  767. || element.mozMatchesSelector
  768. || element.oMatchesSelector;
  769. matcher = function(selector) {
  770. return function() {
  771. return vendorMatches.call(this, selector);
  772. };
  773. };
  774. }
  775. }
  776. var matcher$1 = matcher;
  777. function selection_filter(match) {
  778. if (typeof match !== "function") match = matcher$1(match);
  779. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  780. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  781. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  782. subgroup.push(node);
  783. }
  784. }
  785. }
  786. return new Selection(subgroups, this._parents);
  787. }
  788. function sparse(update) {
  789. return new Array(update.length);
  790. }
  791. function selection_enter() {
  792. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  793. }
  794. function EnterNode(parent, datum) {
  795. this.ownerDocument = parent.ownerDocument;
  796. this.namespaceURI = parent.namespaceURI;
  797. this._next = null;
  798. this._parent = parent;
  799. this.__data__ = datum;
  800. }
  801. EnterNode.prototype = {
  802. constructor: EnterNode,
  803. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  804. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  805. querySelector: function(selector) { return this._parent.querySelector(selector); },
  806. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  807. };
  808. function constant$1(x) {
  809. return function() {
  810. return x;
  811. };
  812. }
  813. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  814. function bindIndex(parent, group, enter, update, exit, data) {
  815. var i = 0,
  816. node,
  817. groupLength = group.length,
  818. dataLength = data.length;
  819. // Put any non-null nodes that fit into update.
  820. // Put any null nodes into enter.
  821. // Put any remaining data into enter.
  822. for (; i < dataLength; ++i) {
  823. if (node = group[i]) {
  824. node.__data__ = data[i];
  825. update[i] = node;
  826. } else {
  827. enter[i] = new EnterNode(parent, data[i]);
  828. }
  829. }
  830. // Put any non-null nodes that don’t fit into exit.
  831. for (; i < groupLength; ++i) {
  832. if (node = group[i]) {
  833. exit[i] = node;
  834. }
  835. }
  836. }
  837. function bindKey(parent, group, enter, update, exit, data, key) {
  838. var i,
  839. node,
  840. nodeByKeyValue = {},
  841. groupLength = group.length,
  842. dataLength = data.length,
  843. keyValues = new Array(groupLength),
  844. keyValue;
  845. // Compute the key for each node.
  846. // If multiple nodes have the same key, the duplicates are added to exit.
  847. for (i = 0; i < groupLength; ++i) {
  848. if (node = group[i]) {
  849. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  850. if (keyValue in nodeByKeyValue) {
  851. exit[i] = node;
  852. } else {
  853. nodeByKeyValue[keyValue] = node;
  854. }
  855. }
  856. }
  857. // Compute the key for each datum.
  858. // If there a node associated with this key, join and add it to update.
  859. // If there is not (or the key is a duplicate), add it to enter.
  860. for (i = 0; i < dataLength; ++i) {
  861. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  862. if (node = nodeByKeyValue[keyValue]) {
  863. update[i] = node;
  864. node.__data__ = data[i];
  865. nodeByKeyValue[keyValue] = null;
  866. } else {
  867. enter[i] = new EnterNode(parent, data[i]);
  868. }
  869. }
  870. // Add any remaining nodes that were not bound to data to exit.
  871. for (i = 0; i < groupLength; ++i) {
  872. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  873. exit[i] = node;
  874. }
  875. }
  876. }
  877. function selection_data(value, key) {
  878. if (!value) {
  879. data = new Array(this.size()), j = -1;
  880. this.each(function(d) { data[++j] = d; });
  881. return data;
  882. }
  883. var bind = key ? bindKey : bindIndex,
  884. parents = this._parents,
  885. groups = this._groups;
  886. if (typeof value !== "function") value = constant$1(value);
  887. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  888. var parent = parents[j],
  889. group = groups[j],
  890. groupLength = group.length,
  891. data = value.call(parent, parent && parent.__data__, j, parents),
  892. dataLength = data.length,
  893. enterGroup = enter[j] = new Array(dataLength),
  894. updateGroup = update[j] = new Array(dataLength),
  895. exitGroup = exit[j] = new Array(groupLength);
  896. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  897. // Now connect the enter nodes to their following update node, such that
  898. // appendChild can insert the materialized enter node before this node,
  899. // rather than at the end of the parent node.
  900. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  901. if (previous = enterGroup[i0]) {
  902. if (i0 >= i1) i1 = i0 + 1;
  903. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  904. previous._next = next || null;
  905. }
  906. }
  907. }
  908. update = new Selection(update, parents);
  909. update._enter = enter;
  910. update._exit = exit;
  911. return update;
  912. }
  913. function selection_exit() {
  914. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  915. }
  916. function selection_merge(selection$$1) {
  917. for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  918. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  919. if (node = group0[i] || group1[i]) {
  920. merge[i] = node;
  921. }
  922. }
  923. }
  924. for (; j < m0; ++j) {
  925. merges[j] = groups0[j];
  926. }
  927. return new Selection(merges, this._parents);
  928. }
  929. function selection_order() {
  930. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  931. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  932. if (node = group[i]) {
  933. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  934. next = node;
  935. }
  936. }
  937. }
  938. return this;
  939. }
  940. function selection_sort(compare) {
  941. if (!compare) compare = ascending$1;
  942. function compareNode(a, b) {
  943. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  944. }
  945. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  946. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  947. if (node = group[i]) {
  948. sortgroup[i] = node;
  949. }
  950. }
  951. sortgroup.sort(compareNode);
  952. }
  953. return new Selection(sortgroups, this._parents).order();
  954. }
  955. function ascending$1(a, b) {
  956. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  957. }
  958. function selection_call() {
  959. var callback = arguments[0];
  960. arguments[0] = this;
  961. callback.apply(null, arguments);
  962. return this;
  963. }
  964. function selection_nodes() {
  965. var nodes = new Array(this.size()), i = -1;
  966. this.each(function() { nodes[++i] = this; });
  967. return nodes;
  968. }
  969. function selection_node() {
  970. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  971. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  972. var node = group[i];
  973. if (node) return node;
  974. }
  975. }
  976. return null;
  977. }
  978. function selection_size() {
  979. var size = 0;
  980. this.each(function() { ++size; });
  981. return size;
  982. }
  983. function selection_empty() {
  984. return !this.node();
  985. }
  986. function selection_each(callback) {
  987. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  988. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  989. if (node = group[i]) callback.call(node, node.__data__, i, group);
  990. }
  991. }
  992. return this;
  993. }
  994. function attrRemove(name) {
  995. return function() {
  996. this.removeAttribute(name);
  997. };
  998. }
  999. function attrRemoveNS(fullname) {
  1000. return function() {
  1001. this.removeAttributeNS(fullname.space, fullname.local);
  1002. };
  1003. }
  1004. function attrConstant(name, value) {
  1005. return function() {
  1006. this.setAttribute(name, value);
  1007. };
  1008. }
  1009. function attrConstantNS(fullname, value) {
  1010. return function() {
  1011. this.setAttributeNS(fullname.space, fullname.local, value);
  1012. };
  1013. }
  1014. function attrFunction(name, value) {
  1015. return function() {
  1016. var v = value.apply(this, arguments);
  1017. if (v == null) this.removeAttribute(name);
  1018. else this.setAttribute(name, v);
  1019. };
  1020. }
  1021. function attrFunctionNS(fullname, value) {
  1022. return function() {
  1023. var v = value.apply(this, arguments);
  1024. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1025. else this.setAttributeNS(fullname.space, fullname.local, v);
  1026. };
  1027. }
  1028. function selection_attr(name, value) {
  1029. var fullname = namespace(name);
  1030. if (arguments.length < 2) {
  1031. var node = this.node();
  1032. return fullname.local
  1033. ? node.getAttributeNS(fullname.space, fullname.local)
  1034. : node.getAttribute(fullname);
  1035. }
  1036. return this.each((value == null
  1037. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1038. ? (fullname.local ? attrFunctionNS : attrFunction)
  1039. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1040. }
  1041. function defaultView(node) {
  1042. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1043. || (node.document && node) // node is a Window
  1044. || node.defaultView; // node is a Document
  1045. }
  1046. function styleRemove(name) {
  1047. return function() {
  1048. this.style.removeProperty(name);
  1049. };
  1050. }
  1051. function styleConstant(name, value, priority) {
  1052. return function() {
  1053. this.style.setProperty(name, value, priority);
  1054. };
  1055. }
  1056. function styleFunction(name, value, priority) {
  1057. return function() {
  1058. var v = value.apply(this, arguments);
  1059. if (v == null) this.style.removeProperty(name);
  1060. else this.style.setProperty(name, v, priority);
  1061. };
  1062. }
  1063. function selection_style(name, value, priority) {
  1064. return arguments.length > 1
  1065. ? this.each((value == null
  1066. ? styleRemove : typeof value === "function"
  1067. ? styleFunction
  1068. : styleConstant)(name, value, priority == null ? "" : priority))
  1069. : styleValue(this.node(), name);
  1070. }
  1071. function styleValue(node, name) {
  1072. return node.style.getPropertyValue(name)
  1073. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1074. }
  1075. function propertyRemove(name) {
  1076. return function() {
  1077. delete this[name];
  1078. };
  1079. }
  1080. function propertyConstant(name, value) {
  1081. return function() {
  1082. this[name] = value;
  1083. };
  1084. }
  1085. function propertyFunction(name, value) {
  1086. return function() {
  1087. var v = value.apply(this, arguments);
  1088. if (v == null) delete this[name];
  1089. else this[name] = v;
  1090. };
  1091. }
  1092. function selection_property(name, value) {
  1093. return arguments.length > 1
  1094. ? this.each((value == null
  1095. ? propertyRemove : typeof value === "function"
  1096. ? propertyFunction
  1097. : propertyConstant)(name, value))
  1098. : this.node()[name];
  1099. }
  1100. function classArray(string) {
  1101. return string.trim().split(/^|\s+/);
  1102. }
  1103. function classList(node) {
  1104. return node.classList || new ClassList(node);
  1105. }
  1106. function ClassList(node) {
  1107. this._node = node;
  1108. this._names = classArray(node.getAttribute("class") || "");
  1109. }
  1110. ClassList.prototype = {
  1111. add: function(name) {
  1112. var i = this._names.indexOf(name);
  1113. if (i < 0) {
  1114. this._names.push(name);
  1115. this._node.setAttribute("class", this._names.join(" "));
  1116. }
  1117. },
  1118. remove: function(name) {
  1119. var i = this._names.indexOf(name);
  1120. if (i >= 0) {
  1121. this._names.splice(i, 1);
  1122. this._node.setAttribute("class", this._names.join(" "));
  1123. }
  1124. },
  1125. contains: function(name) {
  1126. return this._names.indexOf(name) >= 0;
  1127. }
  1128. };
  1129. function classedAdd(node, names) {
  1130. var list = classList(node), i = -1, n = names.length;
  1131. while (++i < n) list.add(names[i]);
  1132. }
  1133. function classedRemove(node, names) {
  1134. var list = classList(node), i = -1, n = names.length;
  1135. while (++i < n) list.remove(names[i]);
  1136. }
  1137. function classedTrue(names) {
  1138. return function() {
  1139. classedAdd(this, names);
  1140. };
  1141. }
  1142. function classedFalse(names) {
  1143. return function() {
  1144. classedRemove(this, names);
  1145. };
  1146. }
  1147. function classedFunction(names, value) {
  1148. return function() {
  1149. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1150. };
  1151. }
  1152. function selection_classed(name, value) {
  1153. var names = classArray(name + "");
  1154. if (arguments.length < 2) {
  1155. var list = classList(this.node()), i = -1, n = names.length;
  1156. while (++i < n) if (!list.contains(names[i])) return false;
  1157. return true;
  1158. }
  1159. return this.each((typeof value === "function"
  1160. ? classedFunction : value
  1161. ? classedTrue
  1162. : classedFalse)(names, value));
  1163. }
  1164. function textRemove() {
  1165. this.textContent = "";
  1166. }
  1167. function textConstant(value) {
  1168. return function() {
  1169. this.textContent = value;
  1170. };
  1171. }
  1172. function textFunction(value) {
  1173. return function() {
  1174. var v = value.apply(this, arguments);
  1175. this.textContent = v == null ? "" : v;
  1176. };
  1177. }
  1178. function selection_text(value) {
  1179. return arguments.length
  1180. ? this.each(value == null
  1181. ? textRemove : (typeof value === "function"
  1182. ? textFunction
  1183. : textConstant)(value))
  1184. : this.node().textContent;
  1185. }
  1186. function htmlRemove() {
  1187. this.innerHTML = "";
  1188. }
  1189. function htmlConstant(value) {
  1190. return function() {
  1191. this.innerHTML = value;
  1192. };
  1193. }
  1194. function htmlFunction(value) {
  1195. return function() {
  1196. var v = value.apply(this, arguments);
  1197. this.innerHTML = v == null ? "" : v;
  1198. };
  1199. }
  1200. function selection_html(value) {
  1201. return arguments.length
  1202. ? this.each(value == null
  1203. ? htmlRemove : (typeof value === "function"
  1204. ? htmlFunction
  1205. : htmlConstant)(value))
  1206. : this.node().innerHTML;
  1207. }
  1208. function raise() {
  1209. if (this.nextSibling) this.parentNode.appendChild(this);
  1210. }
  1211. function selection_raise() {
  1212. return this.each(raise);
  1213. }
  1214. function lower() {
  1215. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1216. }
  1217. function selection_lower() {
  1218. return this.each(lower);
  1219. }
  1220. function selection_append(name) {
  1221. var create = typeof name === "function" ? name : creator(name);
  1222. return this.select(function() {
  1223. return this.appendChild(create.apply(this, arguments));
  1224. });
  1225. }
  1226. function constantNull() {
  1227. return null;
  1228. }
  1229. function selection_insert(name, before) {
  1230. var create = typeof name === "function" ? name : creator(name),
  1231. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1232. return this.select(function() {
  1233. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1234. });
  1235. }
  1236. function remove() {
  1237. var parent = this.parentNode;
  1238. if (parent) parent.removeChild(this);
  1239. }
  1240. function selection_remove() {
  1241. return this.each(remove);
  1242. }
  1243. function selection_cloneShallow() {
  1244. return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
  1245. }
  1246. function selection_cloneDeep() {
  1247. return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
  1248. }
  1249. function selection_clone(deep) {
  1250. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  1251. }
  1252. function selection_datum(value) {
  1253. return arguments.length
  1254. ? this.property("__data__", value)
  1255. : this.node().__data__;
  1256. }
  1257. var filterEvents = {};
  1258. exports.event = null;
  1259. if (typeof document !== "undefined") {
  1260. var element$1 = document.documentElement;
  1261. if (!("onmouseenter" in element$1)) {
  1262. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  1263. }
  1264. }
  1265. function filterContextListener(listener, index, group) {
  1266. listener = contextListener(listener, index, group);
  1267. return function(event) {
  1268. var related = event.relatedTarget;
  1269. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  1270. listener.call(this, event);
  1271. }
  1272. };
  1273. }
  1274. function contextListener(listener, index, group) {
  1275. return function(event1) {
  1276. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  1277. exports.event = event1;
  1278. try {
  1279. listener.call(this, this.__data__, index, group);
  1280. } finally {
  1281. exports.event = event0;
  1282. }
  1283. };
  1284. }
  1285. function parseTypenames$1(typenames) {
  1286. return typenames.trim().split(/^|\s+/).map(function(t) {
  1287. var name = "", i = t.indexOf(".");
  1288. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1289. return {type: t, name: name};
  1290. });
  1291. }
  1292. function onRemove(typename) {
  1293. return function() {
  1294. var on = this.__on;
  1295. if (!on) return;
  1296. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  1297. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  1298. this.removeEventListener(o.type, o.listener, o.capture);
  1299. } else {
  1300. on[++i] = o;
  1301. }
  1302. }
  1303. if (++i) on.length = i;
  1304. else delete this.__on;
  1305. };
  1306. }
  1307. function onAdd(typename, value, capture) {
  1308. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  1309. return function(d, i, group) {
  1310. var on = this.__on, o, listener = wrap(value, i, group);
  1311. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  1312. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  1313. this.removeEventListener(o.type, o.listener, o.capture);
  1314. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  1315. o.value = value;
  1316. return;
  1317. }
  1318. }
  1319. this.addEventListener(typename.type, listener, capture);
  1320. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  1321. if (!on) this.__on = [o];
  1322. else on.push(o);
  1323. };
  1324. }
  1325. function selection_on(typename, value, capture) {
  1326. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  1327. if (arguments.length < 2) {
  1328. var on = this.node().__on;
  1329. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  1330. for (i = 0, o = on[j]; i < n; ++i) {
  1331. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  1332. return o.value;
  1333. }
  1334. }
  1335. }
  1336. return;
  1337. }
  1338. on = value ? onAdd : onRemove;
  1339. if (capture == null) capture = false;
  1340. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  1341. return this;
  1342. }
  1343. function customEvent(event1, listener, that, args) {
  1344. var event0 = exports.event;
  1345. event1.sourceEvent = exports.event;
  1346. exports.event = event1;
  1347. try {
  1348. return listener.apply(that, args);
  1349. } finally {
  1350. exports.event = event0;
  1351. }
  1352. }
  1353. function dispatchEvent(node, type, params) {
  1354. var window = defaultView(node),
  1355. event = window.CustomEvent;
  1356. if (typeof event === "function") {
  1357. event = new event(type, params);
  1358. } else {
  1359. event = window.document.createEvent("Event");
  1360. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1361. else event.initEvent(type, false, false);
  1362. }
  1363. node.dispatchEvent(event);
  1364. }
  1365. function dispatchConstant(type, params) {
  1366. return function() {
  1367. return dispatchEvent(this, type, params);
  1368. };
  1369. }
  1370. function dispatchFunction(type, params) {
  1371. return function() {
  1372. return dispatchEvent(this, type, params.apply(this, arguments));
  1373. };
  1374. }
  1375. function selection_dispatch(type, params) {
  1376. return this.each((typeof params === "function"
  1377. ? dispatchFunction
  1378. : dispatchConstant)(type, params));
  1379. }
  1380. var root = [null];
  1381. function Selection(groups, parents) {
  1382. this._groups = groups;
  1383. this._parents = parents;
  1384. }
  1385. function selection() {
  1386. return new Selection([[document.documentElement]], root);
  1387. }
  1388. Selection.prototype = selection.prototype = {
  1389. constructor: Selection,
  1390. select: selection_select,
  1391. selectAll: selection_selectAll,
  1392. filter: selection_filter,
  1393. data: selection_data,
  1394. enter: selection_enter,
  1395. exit: selection_exit,
  1396. merge: selection_merge,
  1397. order: selection_order,
  1398. sort: selection_sort,
  1399. call: selection_call,
  1400. nodes: selection_nodes,
  1401. node: selection_node,
  1402. size: selection_size,
  1403. empty: selection_empty,
  1404. each: selection_each,
  1405. attr: selection_attr,
  1406. style: selection_style,
  1407. property: selection_property,
  1408. classed: selection_classed,
  1409. text: selection_text,
  1410. html: selection_html,
  1411. raise: selection_raise,
  1412. lower: selection_lower,
  1413. append: selection_append,
  1414. insert: selection_insert,
  1415. remove: selection_remove,
  1416. clone: selection_clone,
  1417. datum: selection_datum,
  1418. on: selection_on,
  1419. dispatch: selection_dispatch
  1420. };
  1421. function select(selector) {
  1422. return typeof selector === "string"
  1423. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1424. : new Selection([[selector]], root);
  1425. }
  1426. function create(name) {
  1427. return select(creator(name).call(document.documentElement));
  1428. }
  1429. var nextId = 0;
  1430. function local() {
  1431. return new Local;
  1432. }
  1433. function Local() {
  1434. this._ = "@" + (++nextId).toString(36);
  1435. }
  1436. Local.prototype = local.prototype = {
  1437. constructor: Local,
  1438. get: function(node) {
  1439. var id = this._;
  1440. while (!(id in node)) if (!(node = node.parentNode)) return;
  1441. return node[id];
  1442. },
  1443. set: function(node, value) {
  1444. return node[this._] = value;
  1445. },
  1446. remove: function(node) {
  1447. return this._ in node && delete node[this._];
  1448. },
  1449. toString: function() {
  1450. return this._;
  1451. }
  1452. };
  1453. function sourceEvent() {
  1454. var current = exports.event, source;
  1455. while (source = current.sourceEvent) current = source;
  1456. return current;
  1457. }
  1458. function point(node, event) {
  1459. var svg = node.ownerSVGElement || node;
  1460. if (svg.createSVGPoint) {
  1461. var point = svg.createSVGPoint();
  1462. point.x = event.clientX, point.y = event.clientY;
  1463. point = point.matrixTransform(node.getScreenCTM().inverse());
  1464. return [point.x, point.y];
  1465. }
  1466. var rect = node.getBoundingClientRect();
  1467. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  1468. }
  1469. function mouse(node) {
  1470. var event = sourceEvent();
  1471. if (event.changedTouches) event = event.changedTouches[0];
  1472. return point(node, event);
  1473. }
  1474. function selectAll(selector) {
  1475. return typeof selector === "string"
  1476. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1477. : new Selection([selector == null ? [] : selector], root);
  1478. }
  1479. function touch(node, touches, identifier) {
  1480. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1481. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1482. if ((touch = touches[i]).identifier === identifier) {
  1483. return point(node, touch);
  1484. }
  1485. }
  1486. return null;
  1487. }
  1488. function touches(node, touches) {
  1489. if (touches == null) touches = sourceEvent().touches;
  1490. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1491. points[i] = point(node, touches[i]);
  1492. }
  1493. return points;
  1494. }
  1495. function nopropagation() {
  1496. exports.event.stopImmediatePropagation();
  1497. }
  1498. function noevent() {
  1499. exports.event.preventDefault();
  1500. exports.event.stopImmediatePropagation();
  1501. }
  1502. function dragDisable(view) {
  1503. var root = view.document.documentElement,
  1504. selection$$1 = select(view).on("dragstart.drag", noevent, true);
  1505. if ("onselectstart" in root) {
  1506. selection$$1.on("selectstart.drag", noevent, true);
  1507. } else {
  1508. root.__noselect = root.style.MozUserSelect;
  1509. root.style.MozUserSelect = "none";
  1510. }
  1511. }
  1512. function yesdrag(view, noclick) {
  1513. var root = view.document.documentElement,
  1514. selection$$1 = select(view).on("dragstart.drag", null);
  1515. if (noclick) {
  1516. selection$$1.on("click.drag", noevent, true);
  1517. setTimeout(function() { selection$$1.on("click.drag", null); }, 0);
  1518. }
  1519. if ("onselectstart" in root) {
  1520. selection$$1.on("selectstart.drag", null);
  1521. } else {
  1522. root.style.MozUserSelect = root.__noselect;
  1523. delete root.__noselect;
  1524. }
  1525. }
  1526. function constant$2(x) {
  1527. return function() {
  1528. return x;
  1529. };
  1530. }
  1531. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1532. this.target = target;
  1533. this.type = type;
  1534. this.subject = subject;
  1535. this.identifier = id;
  1536. this.active = active;
  1537. this.x = x;
  1538. this.y = y;
  1539. this.dx = dx;
  1540. this.dy = dy;
  1541. this._ = dispatch;
  1542. }
  1543. DragEvent.prototype.on = function() {
  1544. var value = this._.on.apply(this._, arguments);
  1545. return value === this._ ? this : value;
  1546. };
  1547. // Ignore right-click, since that should open the context menu.
  1548. function defaultFilter() {
  1549. return !exports.event.button;
  1550. }
  1551. function defaultContainer() {
  1552. return this.parentNode;
  1553. }
  1554. function defaultSubject(d) {
  1555. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1556. }
  1557. function defaultTouchable() {
  1558. return "ontouchstart" in this;
  1559. }
  1560. function drag() {
  1561. var filter = defaultFilter,
  1562. container = defaultContainer,
  1563. subject = defaultSubject,
  1564. touchable = defaultTouchable,
  1565. gestures = {},
  1566. listeners = dispatch("start", "drag", "end"),
  1567. active = 0,
  1568. mousedownx,
  1569. mousedowny,
  1570. mousemoving,
  1571. touchending,
  1572. clickDistance2 = 0;
  1573. function drag(selection$$1) {
  1574. selection$$1
  1575. .on("mousedown.drag", mousedowned)
  1576. .filter(touchable)
  1577. .on("touchstart.drag", touchstarted)
  1578. .on("touchmove.drag", touchmoved)
  1579. .on("touchend.drag touchcancel.drag", touchended)
  1580. .style("touch-action", "none")
  1581. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1582. }
  1583. function mousedowned() {
  1584. if (touchending || !filter.apply(this, arguments)) return;
  1585. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1586. if (!gesture) return;
  1587. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1588. dragDisable(exports.event.view);
  1589. nopropagation();
  1590. mousemoving = false;
  1591. mousedownx = exports.event.clientX;
  1592. mousedowny = exports.event.clientY;
  1593. gesture("start");
  1594. }
  1595. function mousemoved() {
  1596. noevent();
  1597. if (!mousemoving) {
  1598. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1599. mousemoving = dx * dx + dy * dy > clickDistance2;
  1600. }
  1601. gestures.mouse("drag");
  1602. }
  1603. function mouseupped() {
  1604. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1605. yesdrag(exports.event.view, mousemoving);
  1606. noevent();
  1607. gestures.mouse("end");
  1608. }
  1609. function touchstarted() {
  1610. if (!filter.apply(this, arguments)) return;
  1611. var touches$$1 = exports.event.changedTouches,
  1612. c = container.apply(this, arguments),
  1613. n = touches$$1.length, i, gesture;
  1614. for (i = 0; i < n; ++i) {
  1615. if (gesture = beforestart(touches$$1[i].identifier, c, touch, this, arguments)) {
  1616. nopropagation();
  1617. gesture("start");
  1618. }
  1619. }
  1620. }
  1621. function touchmoved() {
  1622. var touches$$1 = exports.event.changedTouches,
  1623. n = touches$$1.length, i, gesture;
  1624. for (i = 0; i < n; ++i) {
  1625. if (gesture = gestures[touches$$1[i].identifier]) {
  1626. noevent();
  1627. gesture("drag");
  1628. }
  1629. }
  1630. }
  1631. function touchended() {
  1632. var touches$$1 = exports.event.changedTouches,
  1633. n = touches$$1.length, i, gesture;
  1634. if (touchending) clearTimeout(touchending);
  1635. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1636. for (i = 0; i < n; ++i) {
  1637. if (gesture = gestures[touches$$1[i].identifier]) {
  1638. nopropagation();
  1639. gesture("end");
  1640. }
  1641. }
  1642. }
  1643. function beforestart(id, container, point$$1, that, args) {
  1644. var p = point$$1(container, id), s, dx, dy,
  1645. sublisteners = listeners.copy();
  1646. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1647. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1648. dx = s.x - p[0] || 0;
  1649. dy = s.y - p[1] || 0;
  1650. return true;
  1651. })) return;
  1652. return function gesture(type) {
  1653. var p0 = p, n;
  1654. switch (type) {
  1655. case "start": gestures[id] = gesture, n = active++; break;
  1656. case "end": delete gestures[id], --active; // nobreak
  1657. case "drag": p = point$$1(container, id), n = active; break;
  1658. }
  1659. 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]);
  1660. };
  1661. }
  1662. drag.filter = function(_) {
  1663. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1664. };
  1665. drag.container = function(_) {
  1666. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1667. };
  1668. drag.subject = function(_) {
  1669. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1670. };
  1671. drag.touchable = function(_) {
  1672. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
  1673. };
  1674. drag.on = function() {
  1675. var value = listeners.on.apply(listeners, arguments);
  1676. return value === listeners ? drag : value;
  1677. };
  1678. drag.clickDistance = function(_) {
  1679. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1680. };
  1681. return drag;
  1682. }
  1683. function define(constructor, factory, prototype) {
  1684. constructor.prototype = factory.prototype = prototype;
  1685. prototype.constructor = constructor;
  1686. }
  1687. function extend(parent, definition) {
  1688. var prototype = Object.create(parent.prototype);
  1689. for (var key in definition) prototype[key] = definition[key];
  1690. return prototype;
  1691. }
  1692. function Color() {}
  1693. var darker = 0.7;
  1694. var brighter = 1 / darker;
  1695. var reI = "\\s*([+-]?\\d+)\\s*",
  1696. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  1697. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  1698. reHex3 = /^#([0-9a-f]{3})$/,
  1699. reHex6 = /^#([0-9a-f]{6})$/,
  1700. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  1701. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  1702. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  1703. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  1704. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  1705. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1706. var named = {
  1707. aliceblue: 0xf0f8ff,
  1708. antiquewhite: 0xfaebd7,
  1709. aqua: 0x00ffff,
  1710. aquamarine: 0x7fffd4,
  1711. azure: 0xf0ffff,
  1712. beige: 0xf5f5dc,
  1713. bisque: 0xffe4c4,
  1714. black: 0x000000,
  1715. blanchedalmond: 0xffebcd,
  1716. blue: 0x0000ff,
  1717. blueviolet: 0x8a2be2,
  1718. brown: 0xa52a2a,
  1719. burlywood: 0xdeb887,
  1720. cadetblue: 0x5f9ea0,
  1721. chartreuse: 0x7fff00,
  1722. chocolate: 0xd2691e,
  1723. coral: 0xff7f50,
  1724. cornflowerblue: 0x6495ed,
  1725. cornsilk: 0xfff8dc,
  1726. crimson: 0xdc143c,
  1727. cyan: 0x00ffff,
  1728. darkblue: 0x00008b,
  1729. darkcyan: 0x008b8b,
  1730. darkgoldenrod: 0xb8860b,
  1731. darkgray: 0xa9a9a9,
  1732. darkgreen: 0x006400,
  1733. darkgrey: 0xa9a9a9,
  1734. darkkhaki: 0xbdb76b,
  1735. darkmagenta: 0x8b008b,
  1736. darkolivegreen: 0x556b2f,
  1737. darkorange: 0xff8c00,
  1738. darkorchid: 0x9932cc,
  1739. darkred: 0x8b0000,
  1740. darksalmon: 0xe9967a,
  1741. darkseagreen: 0x8fbc8f,
  1742. darkslateblue: 0x483d8b,
  1743. darkslategray: 0x2f4f4f,
  1744. darkslategrey: 0x2f4f4f,
  1745. darkturquoise: 0x00ced1,
  1746. darkviolet: 0x9400d3,
  1747. deeppink: 0xff1493,
  1748. deepskyblue: 0x00bfff,
  1749. dimgray: 0x696969,
  1750. dimgrey: 0x696969,
  1751. dodgerblue: 0x1e90ff,
  1752. firebrick: 0xb22222,
  1753. floralwhite: 0xfffaf0,
  1754. forestgreen: 0x228b22,
  1755. fuchsia: 0xff00ff,
  1756. gainsboro: 0xdcdcdc,
  1757. ghostwhite: 0xf8f8ff,
  1758. gold: 0xffd700,
  1759. goldenrod: 0xdaa520,
  1760. gray: 0x808080,
  1761. green: 0x008000,
  1762. greenyellow: 0xadff2f,
  1763. grey: 0x808080,
  1764. honeydew: 0xf0fff0,
  1765. hotpink: 0xff69b4,
  1766. indianred: 0xcd5c5c,
  1767. indigo: 0x4b0082,
  1768. ivory: 0xfffff0,
  1769. khaki: 0xf0e68c,
  1770. lavender: 0xe6e6fa,
  1771. lavenderblush: 0xfff0f5,
  1772. lawngreen: 0x7cfc00,
  1773. lemonchiffon: 0xfffacd,
  1774. lightblue: 0xadd8e6,
  1775. lightcoral: 0xf08080,
  1776. lightcyan: 0xe0ffff,
  1777. lightgoldenrodyellow: 0xfafad2,
  1778. lightgray: 0xd3d3d3,
  1779. lightgreen: 0x90ee90,
  1780. lightgrey: 0xd3d3d3,
  1781. lightpink: 0xffb6c1,
  1782. lightsalmon: 0xffa07a,
  1783. lightseagreen: 0x20b2aa,
  1784. lightskyblue: 0x87cefa,
  1785. lightslategray: 0x778899,
  1786. lightslategrey: 0x778899,
  1787. lightsteelblue: 0xb0c4de,
  1788. lightyellow: 0xffffe0,
  1789. lime: 0x00ff00,
  1790. limegreen: 0x32cd32,
  1791. linen: 0xfaf0e6,
  1792. magenta: 0xff00ff,
  1793. maroon: 0x800000,
  1794. mediumaquamarine: 0x66cdaa,
  1795. mediumblue: 0x0000cd,
  1796. mediumorchid: 0xba55d3,
  1797. mediumpurple: 0x9370db,
  1798. mediumseagreen: 0x3cb371,
  1799. mediumslateblue: 0x7b68ee,
  1800. mediumspringgreen: 0x00fa9a,
  1801. mediumturquoise: 0x48d1cc,
  1802. mediumvioletred: 0xc71585,
  1803. midnightblue: 0x191970,
  1804. mintcream: 0xf5fffa,
  1805. mistyrose: 0xffe4e1,
  1806. moccasin: 0xffe4b5,
  1807. navajowhite: 0xffdead,
  1808. navy: 0x000080,
  1809. oldlace: 0xfdf5e6,
  1810. olive: 0x808000,
  1811. olivedrab: 0x6b8e23,
  1812. orange: 0xffa500,
  1813. orangered: 0xff4500,
  1814. orchid: 0xda70d6,
  1815. palegoldenrod: 0xeee8aa,
  1816. palegreen: 0x98fb98,
  1817. paleturquoise: 0xafeeee,
  1818. palevioletred: 0xdb7093,
  1819. papayawhip: 0xffefd5,
  1820. peachpuff: 0xffdab9,
  1821. peru: 0xcd853f,
  1822. pink: 0xffc0cb,
  1823. plum: 0xdda0dd,
  1824. powderblue: 0xb0e0e6,
  1825. purple: 0x800080,
  1826. rebeccapurple: 0x663399,
  1827. red: 0xff0000,
  1828. rosybrown: 0xbc8f8f,
  1829. royalblue: 0x4169e1,
  1830. saddlebrown: 0x8b4513,
  1831. salmon: 0xfa8072,
  1832. sandybrown: 0xf4a460,
  1833. seagreen: 0x2e8b57,
  1834. seashell: 0xfff5ee,
  1835. sienna: 0xa0522d,
  1836. silver: 0xc0c0c0,
  1837. skyblue: 0x87ceeb,
  1838. slateblue: 0x6a5acd,
  1839. slategray: 0x708090,
  1840. slategrey: 0x708090,
  1841. snow: 0xfffafa,
  1842. springgreen: 0x00ff7f,
  1843. steelblue: 0x4682b4,
  1844. tan: 0xd2b48c,
  1845. teal: 0x008080,
  1846. thistle: 0xd8bfd8,
  1847. tomato: 0xff6347,
  1848. turquoise: 0x40e0d0,
  1849. violet: 0xee82ee,
  1850. wheat: 0xf5deb3,
  1851. white: 0xffffff,
  1852. whitesmoke: 0xf5f5f5,
  1853. yellow: 0xffff00,
  1854. yellowgreen: 0x9acd32
  1855. };
  1856. define(Color, color, {
  1857. displayable: function() {
  1858. return this.rgb().displayable();
  1859. },
  1860. hex: function() {
  1861. return this.rgb().hex();
  1862. },
  1863. toString: function() {
  1864. return this.rgb() + "";
  1865. }
  1866. });
  1867. function color(format) {
  1868. var m;
  1869. format = (format + "").trim().toLowerCase();
  1870. return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
  1871. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  1872. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1873. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1874. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1875. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1876. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1877. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1878. : named.hasOwnProperty(format) ? rgbn(named[format])
  1879. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1880. : null;
  1881. }
  1882. function rgbn(n) {
  1883. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1884. }
  1885. function rgba(r, g, b, a) {
  1886. if (a <= 0) r = g = b = NaN;
  1887. return new Rgb(r, g, b, a);
  1888. }
  1889. function rgbConvert(o) {
  1890. if (!(o instanceof Color)) o = color(o);
  1891. if (!o) return new Rgb;
  1892. o = o.rgb();
  1893. return new Rgb(o.r, o.g, o.b, o.opacity);
  1894. }
  1895. function rgb(r, g, b, opacity) {
  1896. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1897. }
  1898. function Rgb(r, g, b, opacity) {
  1899. this.r = +r;
  1900. this.g = +g;
  1901. this.b = +b;
  1902. this.opacity = +opacity;
  1903. }
  1904. define(Rgb, rgb, extend(Color, {
  1905. brighter: function(k) {
  1906. k = k == null ? brighter : Math.pow(brighter, k);
  1907. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1908. },
  1909. darker: function(k) {
  1910. k = k == null ? darker : Math.pow(darker, k);
  1911. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1912. },
  1913. rgb: function() {
  1914. return this;
  1915. },
  1916. displayable: function() {
  1917. return (0 <= this.r && this.r <= 255)
  1918. && (0 <= this.g && this.g <= 255)
  1919. && (0 <= this.b && this.b <= 255)
  1920. && (0 <= this.opacity && this.opacity <= 1);
  1921. },
  1922. hex: function() {
  1923. return "#" + hex(this.r) + hex(this.g) + hex(this.b);
  1924. },
  1925. toString: function() {
  1926. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1927. return (a === 1 ? "rgb(" : "rgba(")
  1928. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1929. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1930. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1931. + (a === 1 ? ")" : ", " + a + ")");
  1932. }
  1933. }));
  1934. function hex(value) {
  1935. value = Math.max(0, Math.min(255, Math.round(value) || 0));
  1936. return (value < 16 ? "0" : "") + value.toString(16);
  1937. }
  1938. function hsla(h, s, l, a) {
  1939. if (a <= 0) h = s = l = NaN;
  1940. else if (l <= 0 || l >= 1) h = s = NaN;
  1941. else if (s <= 0) h = NaN;
  1942. return new Hsl(h, s, l, a);
  1943. }
  1944. function hslConvert(o) {
  1945. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1946. if (!(o instanceof Color)) o = color(o);
  1947. if (!o) return new Hsl;
  1948. if (o instanceof Hsl) return o;
  1949. o = o.rgb();
  1950. var r = o.r / 255,
  1951. g = o.g / 255,
  1952. b = o.b / 255,
  1953. min = Math.min(r, g, b),
  1954. max = Math.max(r, g, b),
  1955. h = NaN,
  1956. s = max - min,
  1957. l = (max + min) / 2;
  1958. if (s) {
  1959. if (r === max) h = (g - b) / s + (g < b) * 6;
  1960. else if (g === max) h = (b - r) / s + 2;
  1961. else h = (r - g) / s + 4;
  1962. s /= l < 0.5 ? max + min : 2 - max - min;
  1963. h *= 60;
  1964. } else {
  1965. s = l > 0 && l < 1 ? 0 : h;
  1966. }
  1967. return new Hsl(h, s, l, o.opacity);
  1968. }
  1969. function hsl(h, s, l, opacity) {
  1970. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1971. }
  1972. function Hsl(h, s, l, opacity) {
  1973. this.h = +h;
  1974. this.s = +s;
  1975. this.l = +l;
  1976. this.opacity = +opacity;
  1977. }
  1978. define(Hsl, hsl, extend(Color, {
  1979. brighter: function(k) {
  1980. k = k == null ? brighter : Math.pow(brighter, k);
  1981. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1982. },
  1983. darker: function(k) {
  1984. k = k == null ? darker : Math.pow(darker, k);
  1985. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1986. },
  1987. rgb: function() {
  1988. var h = this.h % 360 + (this.h < 0) * 360,
  1989. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1990. l = this.l,
  1991. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1992. m1 = 2 * l - m2;
  1993. return new Rgb(
  1994. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  1995. hsl2rgb(h, m1, m2),
  1996. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  1997. this.opacity
  1998. );
  1999. },
  2000. displayable: function() {
  2001. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  2002. && (0 <= this.l && this.l <= 1)
  2003. && (0 <= this.opacity && this.opacity <= 1);
  2004. }
  2005. }));
  2006. /* From FvD 13.37, CSS Color Module Level 3 */
  2007. function hsl2rgb(h, m1, m2) {
  2008. return (h < 60 ? m1 + (m2 - m1) * h / 60
  2009. : h < 180 ? m2
  2010. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  2011. : m1) * 255;
  2012. }
  2013. var deg2rad = Math.PI / 180;
  2014. var rad2deg = 180 / Math.PI;
  2015. // https://beta.observablehq.com/@mbostock/lab-and-rgb
  2016. var K = 18,
  2017. Xn = 0.96422,
  2018. Yn = 1,
  2019. Zn = 0.82521,
  2020. t0 = 4 / 29,
  2021. t1 = 6 / 29,
  2022. t2 = 3 * t1 * t1,
  2023. t3 = t1 * t1 * t1;
  2024. function labConvert(o) {
  2025. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2026. if (o instanceof Hcl) {
  2027. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2028. var h = o.h * deg2rad;
  2029. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2030. }
  2031. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2032. var r = rgb2lrgb(o.r),
  2033. g = rgb2lrgb(o.g),
  2034. b = rgb2lrgb(o.b),
  2035. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2036. if (r === g && g === b) x = z = y; else {
  2037. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2038. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2039. }
  2040. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2041. }
  2042. function gray(l, opacity) {
  2043. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2044. }
  2045. function lab(l, a, b, opacity) {
  2046. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2047. }
  2048. function Lab(l, a, b, opacity) {
  2049. this.l = +l;
  2050. this.a = +a;
  2051. this.b = +b;
  2052. this.opacity = +opacity;
  2053. }
  2054. define(Lab, lab, extend(Color, {
  2055. brighter: function(k) {
  2056. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2057. },
  2058. darker: function(k) {
  2059. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2060. },
  2061. rgb: function() {
  2062. var y = (this.l + 16) / 116,
  2063. x = isNaN(this.a) ? y : y + this.a / 500,
  2064. z = isNaN(this.b) ? y : y - this.b / 200;
  2065. x = Xn * lab2xyz(x);
  2066. y = Yn * lab2xyz(y);
  2067. z = Zn * lab2xyz(z);
  2068. return new Rgb(
  2069. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2070. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2071. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2072. this.opacity
  2073. );
  2074. }
  2075. }));
  2076. function xyz2lab(t) {
  2077. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2078. }
  2079. function lab2xyz(t) {
  2080. return t > t1 ? t * t * t : t2 * (t - t0);
  2081. }
  2082. function lrgb2rgb(x) {
  2083. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2084. }
  2085. function rgb2lrgb(x) {
  2086. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2087. }
  2088. function hclConvert(o) {
  2089. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2090. if (!(o instanceof Lab)) o = labConvert(o);
  2091. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0, o.l, o.opacity);
  2092. var h = Math.atan2(o.b, o.a) * rad2deg;
  2093. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2094. }
  2095. function lch(l, c, h, opacity) {
  2096. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2097. }
  2098. function hcl(h, c, l, opacity) {
  2099. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2100. }
  2101. function Hcl(h, c, l, opacity) {
  2102. this.h = +h;
  2103. this.c = +c;
  2104. this.l = +l;
  2105. this.opacity = +opacity;
  2106. }
  2107. define(Hcl, hcl, extend(Color, {
  2108. brighter: function(k) {
  2109. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2110. },
  2111. darker: function(k) {
  2112. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2113. },
  2114. rgb: function() {
  2115. return labConvert(this).rgb();
  2116. }
  2117. }));
  2118. var A = -0.14861,
  2119. B = +1.78277,
  2120. C = -0.29227,
  2121. D = -0.90649,
  2122. E = +1.97294,
  2123. ED = E * D,
  2124. EB = E * B,
  2125. BC_DA = B * C - D * A;
  2126. function cubehelixConvert(o) {
  2127. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2128. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2129. var r = o.r / 255,
  2130. g = o.g / 255,
  2131. b = o.b / 255,
  2132. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2133. bl = b - l,
  2134. k = (E * (g - l) - C * bl) / D,
  2135. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2136. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2137. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2138. }
  2139. function cubehelix(h, s, l, opacity) {
  2140. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2141. }
  2142. function Cubehelix(h, s, l, opacity) {
  2143. this.h = +h;
  2144. this.s = +s;
  2145. this.l = +l;
  2146. this.opacity = +opacity;
  2147. }
  2148. define(Cubehelix, cubehelix, extend(Color, {
  2149. brighter: function(k) {
  2150. k = k == null ? brighter : Math.pow(brighter, k);
  2151. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2152. },
  2153. darker: function(k) {
  2154. k = k == null ? darker : Math.pow(darker, k);
  2155. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2156. },
  2157. rgb: function() {
  2158. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2159. l = +this.l,
  2160. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2161. cosh = Math.cos(h),
  2162. sinh = Math.sin(h);
  2163. return new Rgb(
  2164. 255 * (l + a * (A * cosh + B * sinh)),
  2165. 255 * (l + a * (C * cosh + D * sinh)),
  2166. 255 * (l + a * (E * cosh)),
  2167. this.opacity
  2168. );
  2169. }
  2170. }));
  2171. function basis(t1, v0, v1, v2, v3) {
  2172. var t2 = t1 * t1, t3 = t2 * t1;
  2173. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2174. + (4 - 6 * t2 + 3 * t3) * v1
  2175. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2176. + t3 * v3) / 6;
  2177. }
  2178. function basis$1(values) {
  2179. var n = values.length - 1;
  2180. return function(t) {
  2181. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2182. v1 = values[i],
  2183. v2 = values[i + 1],
  2184. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2185. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2186. return basis((t - i / n) * n, v0, v1, v2, v3);
  2187. };
  2188. }
  2189. function basisClosed(values) {
  2190. var n = values.length;
  2191. return function(t) {
  2192. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2193. v0 = values[(i + n - 1) % n],
  2194. v1 = values[i % n],
  2195. v2 = values[(i + 1) % n],
  2196. v3 = values[(i + 2) % n];
  2197. return basis((t - i / n) * n, v0, v1, v2, v3);
  2198. };
  2199. }
  2200. function constant$3(x) {
  2201. return function() {
  2202. return x;
  2203. };
  2204. }
  2205. function linear(a, d) {
  2206. return function(t) {
  2207. return a + t * d;
  2208. };
  2209. }
  2210. function exponential(a, b, y) {
  2211. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2212. return Math.pow(a + t * b, y);
  2213. };
  2214. }
  2215. function hue(a, b) {
  2216. var d = b - a;
  2217. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2218. }
  2219. function gamma(y) {
  2220. return (y = +y) === 1 ? nogamma : function(a, b) {
  2221. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2222. };
  2223. }
  2224. function nogamma(a, b) {
  2225. var d = b - a;
  2226. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2227. }
  2228. var interpolateRgb = (function rgbGamma(y) {
  2229. var color$$1 = gamma(y);
  2230. function rgb$$1(start, end) {
  2231. var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
  2232. g = color$$1(start.g, end.g),
  2233. b = color$$1(start.b, end.b),
  2234. opacity = nogamma(start.opacity, end.opacity);
  2235. return function(t) {
  2236. start.r = r(t);
  2237. start.g = g(t);
  2238. start.b = b(t);
  2239. start.opacity = opacity(t);
  2240. return start + "";
  2241. };
  2242. }
  2243. rgb$$1.gamma = rgbGamma;
  2244. return rgb$$1;
  2245. })(1);
  2246. function rgbSpline(spline) {
  2247. return function(colors) {
  2248. var n = colors.length,
  2249. r = new Array(n),
  2250. g = new Array(n),
  2251. b = new Array(n),
  2252. i, color$$1;
  2253. for (i = 0; i < n; ++i) {
  2254. color$$1 = rgb(colors[i]);
  2255. r[i] = color$$1.r || 0;
  2256. g[i] = color$$1.g || 0;
  2257. b[i] = color$$1.b || 0;
  2258. }
  2259. r = spline(r);
  2260. g = spline(g);
  2261. b = spline(b);
  2262. color$$1.opacity = 1;
  2263. return function(t) {
  2264. color$$1.r = r(t);
  2265. color$$1.g = g(t);
  2266. color$$1.b = b(t);
  2267. return color$$1 + "";
  2268. };
  2269. };
  2270. }
  2271. var rgbBasis = rgbSpline(basis$1);
  2272. var rgbBasisClosed = rgbSpline(basisClosed);
  2273. function array$1(a, b) {
  2274. var nb = b ? b.length : 0,
  2275. na = a ? Math.min(nb, a.length) : 0,
  2276. x = new Array(na),
  2277. c = new Array(nb),
  2278. i;
  2279. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2280. for (; i < nb; ++i) c[i] = b[i];
  2281. return function(t) {
  2282. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2283. return c;
  2284. };
  2285. }
  2286. function date(a, b) {
  2287. var d = new Date;
  2288. return a = +a, b -= a, function(t) {
  2289. return d.setTime(a + b * t), d;
  2290. };
  2291. }
  2292. function reinterpolate(a, b) {
  2293. return a = +a, b -= a, function(t) {
  2294. return a + b * t;
  2295. };
  2296. }
  2297. function object(a, b) {
  2298. var i = {},
  2299. c = {},
  2300. k;
  2301. if (a === null || typeof a !== "object") a = {};
  2302. if (b === null || typeof b !== "object") b = {};
  2303. for (k in b) {
  2304. if (k in a) {
  2305. i[k] = interpolateValue(a[k], b[k]);
  2306. } else {
  2307. c[k] = b[k];
  2308. }
  2309. }
  2310. return function(t) {
  2311. for (k in i) c[k] = i[k](t);
  2312. return c;
  2313. };
  2314. }
  2315. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  2316. reB = new RegExp(reA.source, "g");
  2317. function zero(b) {
  2318. return function() {
  2319. return b;
  2320. };
  2321. }
  2322. function one(b) {
  2323. return function(t) {
  2324. return b(t) + "";
  2325. };
  2326. }
  2327. function interpolateString(a, b) {
  2328. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2329. am, // current match in a
  2330. bm, // current match in b
  2331. bs, // string preceding current number in b, if any
  2332. i = -1, // index in s
  2333. s = [], // string constants and placeholders
  2334. q = []; // number interpolators
  2335. // Coerce inputs to strings.
  2336. a = a + "", b = b + "";
  2337. // Interpolate pairs of numbers in a & b.
  2338. while ((am = reA.exec(a))
  2339. && (bm = reB.exec(b))) {
  2340. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2341. bs = b.slice(bi, bs);
  2342. if (s[i]) s[i] += bs; // coalesce with previous string
  2343. else s[++i] = bs;
  2344. }
  2345. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2346. if (s[i]) s[i] += bm; // coalesce with previous string
  2347. else s[++i] = bm;
  2348. } else { // interpolate non-matching numbers
  2349. s[++i] = null;
  2350. q.push({i: i, x: reinterpolate(am, bm)});
  2351. }
  2352. bi = reB.lastIndex;
  2353. }
  2354. // Add remains of b.
  2355. if (bi < b.length) {
  2356. bs = b.slice(bi);
  2357. if (s[i]) s[i] += bs; // coalesce with previous string
  2358. else s[++i] = bs;
  2359. }
  2360. // Special optimization for only a single match.
  2361. // Otherwise, interpolate each of the numbers and rejoin the string.
  2362. return s.length < 2 ? (q[0]
  2363. ? one(q[0].x)
  2364. : zero(b))
  2365. : (b = q.length, function(t) {
  2366. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2367. return s.join("");
  2368. });
  2369. }
  2370. function interpolateValue(a, b) {
  2371. var t = typeof b, c;
  2372. return b == null || t === "boolean" ? constant$3(b)
  2373. : (t === "number" ? reinterpolate
  2374. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2375. : b instanceof color ? interpolateRgb
  2376. : b instanceof Date ? date
  2377. : Array.isArray(b) ? array$1
  2378. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2379. : reinterpolate)(a, b);
  2380. }
  2381. function interpolateRound(a, b) {
  2382. return a = +a, b -= a, function(t) {
  2383. return Math.round(a + b * t);
  2384. };
  2385. }
  2386. var degrees = 180 / Math.PI;
  2387. var identity$2 = {
  2388. translateX: 0,
  2389. translateY: 0,
  2390. rotate: 0,
  2391. skewX: 0,
  2392. scaleX: 1,
  2393. scaleY: 1
  2394. };
  2395. function decompose(a, b, c, d, e, f) {
  2396. var scaleX, scaleY, skewX;
  2397. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2398. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2399. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2400. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2401. return {
  2402. translateX: e,
  2403. translateY: f,
  2404. rotate: Math.atan2(b, a) * degrees,
  2405. skewX: Math.atan(skewX) * degrees,
  2406. scaleX: scaleX,
  2407. scaleY: scaleY
  2408. };
  2409. }
  2410. var cssNode,
  2411. cssRoot,
  2412. cssView,
  2413. svgNode;
  2414. function parseCss(value) {
  2415. if (value === "none") return identity$2;
  2416. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2417. cssNode.style.transform = value;
  2418. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2419. cssRoot.removeChild(cssNode);
  2420. value = value.slice(7, -1).split(",");
  2421. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2422. }
  2423. function parseSvg(value) {
  2424. if (value == null) return identity$2;
  2425. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2426. svgNode.setAttribute("transform", value);
  2427. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2428. value = value.matrix;
  2429. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2430. }
  2431. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2432. function pop(s) {
  2433. return s.length ? s.pop() + " " : "";
  2434. }
  2435. function translate(xa, ya, xb, yb, s, q) {
  2436. if (xa !== xb || ya !== yb) {
  2437. var i = s.push("translate(", null, pxComma, null, pxParen);
  2438. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2439. } else if (xb || yb) {
  2440. s.push("translate(" + xb + pxComma + yb + pxParen);
  2441. }
  2442. }
  2443. function rotate(a, b, s, q) {
  2444. if (a !== b) {
  2445. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2446. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
  2447. } else if (b) {
  2448. s.push(pop(s) + "rotate(" + b + degParen);
  2449. }
  2450. }
  2451. function skewX(a, b, s, q) {
  2452. if (a !== b) {
  2453. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
  2454. } else if (b) {
  2455. s.push(pop(s) + "skewX(" + b + degParen);
  2456. }
  2457. }
  2458. function scale(xa, ya, xb, yb, s, q) {
  2459. if (xa !== xb || ya !== yb) {
  2460. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2461. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2462. } else if (xb !== 1 || yb !== 1) {
  2463. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2464. }
  2465. }
  2466. return function(a, b) {
  2467. var s = [], // string constants and placeholders
  2468. q = []; // number interpolators
  2469. a = parse(a), b = parse(b);
  2470. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2471. rotate(a.rotate, b.rotate, s, q);
  2472. skewX(a.skewX, b.skewX, s, q);
  2473. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2474. a = b = null; // gc
  2475. return function(t) {
  2476. var i = -1, n = q.length, o;
  2477. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2478. return s.join("");
  2479. };
  2480. };
  2481. }
  2482. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2483. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2484. var rho = Math.SQRT2,
  2485. rho2 = 2,
  2486. rho4 = 4,
  2487. epsilon2 = 1e-12;
  2488. function cosh(x) {
  2489. return ((x = Math.exp(x)) + 1 / x) / 2;
  2490. }
  2491. function sinh(x) {
  2492. return ((x = Math.exp(x)) - 1 / x) / 2;
  2493. }
  2494. function tanh(x) {
  2495. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2496. }
  2497. // p0 = [ux0, uy0, w0]
  2498. // p1 = [ux1, uy1, w1]
  2499. function interpolateZoom(p0, p1) {
  2500. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2501. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2502. dx = ux1 - ux0,
  2503. dy = uy1 - uy0,
  2504. d2 = dx * dx + dy * dy,
  2505. i,
  2506. S;
  2507. // Special case for u0 ≅ u1.
  2508. if (d2 < epsilon2) {
  2509. S = Math.log(w1 / w0) / rho;
  2510. i = function(t) {
  2511. return [
  2512. ux0 + t * dx,
  2513. uy0 + t * dy,
  2514. w0 * Math.exp(rho * t * S)
  2515. ];
  2516. };
  2517. }
  2518. // General case.
  2519. else {
  2520. var d1 = Math.sqrt(d2),
  2521. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2522. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2523. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2524. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2525. S = (r1 - r0) / rho;
  2526. i = function(t) {
  2527. var s = t * S,
  2528. coshr0 = cosh(r0),
  2529. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2530. return [
  2531. ux0 + u * dx,
  2532. uy0 + u * dy,
  2533. w0 * coshr0 / cosh(rho * s + r0)
  2534. ];
  2535. };
  2536. }
  2537. i.duration = S * 1000;
  2538. return i;
  2539. }
  2540. function hsl$1(hue$$1) {
  2541. return function(start, end) {
  2542. var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
  2543. s = nogamma(start.s, end.s),
  2544. l = nogamma(start.l, end.l),
  2545. opacity = nogamma(start.opacity, end.opacity);
  2546. return function(t) {
  2547. start.h = h(t);
  2548. start.s = s(t);
  2549. start.l = l(t);
  2550. start.opacity = opacity(t);
  2551. return start + "";
  2552. };
  2553. }
  2554. }
  2555. var hsl$2 = hsl$1(hue);
  2556. var hslLong = hsl$1(nogamma);
  2557. function lab$1(start, end) {
  2558. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2559. a = nogamma(start.a, end.a),
  2560. b = nogamma(start.b, end.b),
  2561. opacity = nogamma(start.opacity, end.opacity);
  2562. return function(t) {
  2563. start.l = l(t);
  2564. start.a = a(t);
  2565. start.b = b(t);
  2566. start.opacity = opacity(t);
  2567. return start + "";
  2568. };
  2569. }
  2570. function hcl$1(hue$$1) {
  2571. return function(start, end) {
  2572. var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
  2573. c = nogamma(start.c, end.c),
  2574. l = nogamma(start.l, end.l),
  2575. opacity = nogamma(start.opacity, end.opacity);
  2576. return function(t) {
  2577. start.h = h(t);
  2578. start.c = c(t);
  2579. start.l = l(t);
  2580. start.opacity = opacity(t);
  2581. return start + "";
  2582. };
  2583. }
  2584. }
  2585. var hcl$2 = hcl$1(hue);
  2586. var hclLong = hcl$1(nogamma);
  2587. function cubehelix$1(hue$$1) {
  2588. return (function cubehelixGamma(y) {
  2589. y = +y;
  2590. function cubehelix$$1(start, end) {
  2591. var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2592. s = nogamma(start.s, end.s),
  2593. l = nogamma(start.l, end.l),
  2594. opacity = nogamma(start.opacity, end.opacity);
  2595. return function(t) {
  2596. start.h = h(t);
  2597. start.s = s(t);
  2598. start.l = l(Math.pow(t, y));
  2599. start.opacity = opacity(t);
  2600. return start + "";
  2601. };
  2602. }
  2603. cubehelix$$1.gamma = cubehelixGamma;
  2604. return cubehelix$$1;
  2605. })(1);
  2606. }
  2607. var cubehelix$2 = cubehelix$1(hue);
  2608. var cubehelixLong = cubehelix$1(nogamma);
  2609. function piecewise(interpolate, values) {
  2610. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  2611. while (i < n) I[i] = interpolate(v, v = values[++i]);
  2612. return function(t) {
  2613. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  2614. return I[i](t - i);
  2615. };
  2616. }
  2617. function quantize(interpolator, n) {
  2618. var samples = new Array(n);
  2619. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2620. return samples;
  2621. }
  2622. var frame = 0, // is an animation frame pending?
  2623. timeout = 0, // is a timeout pending?
  2624. interval = 0, // are any timers active?
  2625. pokeDelay = 1000, // how frequently we check for clock skew
  2626. taskHead,
  2627. taskTail,
  2628. clockLast = 0,
  2629. clockNow = 0,
  2630. clockSkew = 0,
  2631. clock = typeof performance === "object" && performance.now ? performance : Date,
  2632. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2633. function now() {
  2634. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2635. }
  2636. function clearNow() {
  2637. clockNow = 0;
  2638. }
  2639. function Timer() {
  2640. this._call =
  2641. this._time =
  2642. this._next = null;
  2643. }
  2644. Timer.prototype = timer.prototype = {
  2645. constructor: Timer,
  2646. restart: function(callback, delay, time) {
  2647. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2648. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2649. if (!this._next && taskTail !== this) {
  2650. if (taskTail) taskTail._next = this;
  2651. else taskHead = this;
  2652. taskTail = this;
  2653. }
  2654. this._call = callback;
  2655. this._time = time;
  2656. sleep();
  2657. },
  2658. stop: function() {
  2659. if (this._call) {
  2660. this._call = null;
  2661. this._time = Infinity;
  2662. sleep();
  2663. }
  2664. }
  2665. };
  2666. function timer(callback, delay, time) {
  2667. var t = new Timer;
  2668. t.restart(callback, delay, time);
  2669. return t;
  2670. }
  2671. function timerFlush() {
  2672. now(); // Get the current time, if not already set.
  2673. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2674. var t = taskHead, e;
  2675. while (t) {
  2676. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2677. t = t._next;
  2678. }
  2679. --frame;
  2680. }
  2681. function wake() {
  2682. clockNow = (clockLast = clock.now()) + clockSkew;
  2683. frame = timeout = 0;
  2684. try {
  2685. timerFlush();
  2686. } finally {
  2687. frame = 0;
  2688. nap();
  2689. clockNow = 0;
  2690. }
  2691. }
  2692. function poke() {
  2693. var now = clock.now(), delay = now - clockLast;
  2694. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2695. }
  2696. function nap() {
  2697. var t0, t1 = taskHead, t2, time = Infinity;
  2698. while (t1) {
  2699. if (t1._call) {
  2700. if (time > t1._time) time = t1._time;
  2701. t0 = t1, t1 = t1._next;
  2702. } else {
  2703. t2 = t1._next, t1._next = null;
  2704. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2705. }
  2706. }
  2707. taskTail = t0;
  2708. sleep(time);
  2709. }
  2710. function sleep(time) {
  2711. if (frame) return; // Soonest alarm already set, or will be.
  2712. if (timeout) timeout = clearTimeout(timeout);
  2713. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2714. if (delay > 24) {
  2715. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2716. if (interval) interval = clearInterval(interval);
  2717. } else {
  2718. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2719. frame = 1, setFrame(wake);
  2720. }
  2721. }
  2722. function timeout$1(callback, delay, time) {
  2723. var t = new Timer;
  2724. delay = delay == null ? 0 : +delay;
  2725. t.restart(function(elapsed) {
  2726. t.stop();
  2727. callback(elapsed + delay);
  2728. }, delay, time);
  2729. return t;
  2730. }
  2731. function interval$1(callback, delay, time) {
  2732. var t = new Timer, total = delay;
  2733. if (delay == null) return t.restart(callback, delay, time), t;
  2734. delay = +delay, time = time == null ? now() : +time;
  2735. t.restart(function tick(elapsed) {
  2736. elapsed += total;
  2737. t.restart(tick, total += delay, time);
  2738. callback(elapsed);
  2739. }, delay, time);
  2740. return t;
  2741. }
  2742. var emptyOn = dispatch("start", "end", "interrupt");
  2743. var emptyTween = [];
  2744. var CREATED = 0;
  2745. var SCHEDULED = 1;
  2746. var STARTING = 2;
  2747. var STARTED = 3;
  2748. var RUNNING = 4;
  2749. var ENDING = 5;
  2750. var ENDED = 6;
  2751. function schedule(node, name, id, index, group, timing) {
  2752. var schedules = node.__transition;
  2753. if (!schedules) node.__transition = {};
  2754. else if (id in schedules) return;
  2755. create$1(node, id, {
  2756. name: name,
  2757. index: index, // For context during callback.
  2758. group: group, // For context during callback.
  2759. on: emptyOn,
  2760. tween: emptyTween,
  2761. time: timing.time,
  2762. delay: timing.delay,
  2763. duration: timing.duration,
  2764. ease: timing.ease,
  2765. timer: null,
  2766. state: CREATED
  2767. });
  2768. }
  2769. function init(node, id) {
  2770. var schedule = get$1(node, id);
  2771. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  2772. return schedule;
  2773. }
  2774. function set$1(node, id) {
  2775. var schedule = get$1(node, id);
  2776. if (schedule.state > STARTING) throw new Error("too late; already started");
  2777. return schedule;
  2778. }
  2779. function get$1(node, id) {
  2780. var schedule = node.__transition;
  2781. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  2782. return schedule;
  2783. }
  2784. function create$1(node, id, self) {
  2785. var schedules = node.__transition,
  2786. tween;
  2787. // Initialize the self timer when the transition is created.
  2788. // Note the actual delay is not known until the first callback!
  2789. schedules[id] = self;
  2790. self.timer = timer(schedule, 0, self.time);
  2791. function schedule(elapsed) {
  2792. self.state = SCHEDULED;
  2793. self.timer.restart(start, self.delay, self.time);
  2794. // If the elapsed delay is less than our first sleep, start immediately.
  2795. if (self.delay <= elapsed) start(elapsed - self.delay);
  2796. }
  2797. function start(elapsed) {
  2798. var i, j, n, o;
  2799. // If the state is not SCHEDULED, then we previously errored on start.
  2800. if (self.state !== SCHEDULED) return stop();
  2801. for (i in schedules) {
  2802. o = schedules[i];
  2803. if (o.name !== self.name) continue;
  2804. // While this element already has a starting transition during this frame,
  2805. // defer starting an interrupting transition until that transition has a
  2806. // chance to tick (and possibly end); see d3/d3-transition#54!
  2807. if (o.state === STARTED) return timeout$1(start);
  2808. // Interrupt the active transition, if any.
  2809. // Dispatch the interrupt event.
  2810. if (o.state === RUNNING) {
  2811. o.state = ENDED;
  2812. o.timer.stop();
  2813. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2814. delete schedules[i];
  2815. }
  2816. // Cancel any pre-empted transitions. No interrupt event is dispatched
  2817. // because the cancelled transitions never started. Note that this also
  2818. // removes this transition from the pending list!
  2819. else if (+i < id) {
  2820. o.state = ENDED;
  2821. o.timer.stop();
  2822. delete schedules[i];
  2823. }
  2824. }
  2825. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2826. // Note the transition may be canceled after start and before the first tick!
  2827. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2828. // Assuming this is successful, subsequent callbacks go straight to tick.
  2829. timeout$1(function() {
  2830. if (self.state === STARTED) {
  2831. self.state = RUNNING;
  2832. self.timer.restart(tick, self.delay, self.time);
  2833. tick(elapsed);
  2834. }
  2835. });
  2836. // Dispatch the start event.
  2837. // Note this must be done before the tween are initialized.
  2838. self.state = STARTING;
  2839. self.on.call("start", node, node.__data__, self.index, self.group);
  2840. if (self.state !== STARTING) return; // interrupted
  2841. self.state = STARTED;
  2842. // Initialize the tween, deleting null tween.
  2843. tween = new Array(n = self.tween.length);
  2844. for (i = 0, j = -1; i < n; ++i) {
  2845. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2846. tween[++j] = o;
  2847. }
  2848. }
  2849. tween.length = j + 1;
  2850. }
  2851. function tick(elapsed) {
  2852. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2853. i = -1,
  2854. n = tween.length;
  2855. while (++i < n) {
  2856. tween[i].call(null, t);
  2857. }
  2858. // Dispatch the end event.
  2859. if (self.state === ENDING) {
  2860. self.on.call("end", node, node.__data__, self.index, self.group);
  2861. stop();
  2862. }
  2863. }
  2864. function stop() {
  2865. self.state = ENDED;
  2866. self.timer.stop();
  2867. delete schedules[id];
  2868. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2869. delete node.__transition;
  2870. }
  2871. }
  2872. function interrupt(node, name) {
  2873. var schedules = node.__transition,
  2874. schedule$$1,
  2875. active,
  2876. empty = true,
  2877. i;
  2878. if (!schedules) return;
  2879. name = name == null ? null : name + "";
  2880. for (i in schedules) {
  2881. if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
  2882. active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
  2883. schedule$$1.state = ENDED;
  2884. schedule$$1.timer.stop();
  2885. if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
  2886. delete schedules[i];
  2887. }
  2888. if (empty) delete node.__transition;
  2889. }
  2890. function selection_interrupt(name) {
  2891. return this.each(function() {
  2892. interrupt(this, name);
  2893. });
  2894. }
  2895. function tweenRemove(id, name) {
  2896. var tween0, tween1;
  2897. return function() {
  2898. var schedule$$1 = set$1(this, id),
  2899. tween = schedule$$1.tween;
  2900. // If this node shared tween with the previous node,
  2901. // just assign the updated shared tween and we’re done!
  2902. // Otherwise, copy-on-write.
  2903. if (tween !== tween0) {
  2904. tween1 = tween0 = tween;
  2905. for (var i = 0, n = tween1.length; i < n; ++i) {
  2906. if (tween1[i].name === name) {
  2907. tween1 = tween1.slice();
  2908. tween1.splice(i, 1);
  2909. break;
  2910. }
  2911. }
  2912. }
  2913. schedule$$1.tween = tween1;
  2914. };
  2915. }
  2916. function tweenFunction(id, name, value) {
  2917. var tween0, tween1;
  2918. if (typeof value !== "function") throw new Error;
  2919. return function() {
  2920. var schedule$$1 = set$1(this, id),
  2921. tween = schedule$$1.tween;
  2922. // If this node shared tween with the previous node,
  2923. // just assign the updated shared tween and we’re done!
  2924. // Otherwise, copy-on-write.
  2925. if (tween !== tween0) {
  2926. tween1 = (tween0 = tween).slice();
  2927. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2928. if (tween1[i].name === name) {
  2929. tween1[i] = t;
  2930. break;
  2931. }
  2932. }
  2933. if (i === n) tween1.push(t);
  2934. }
  2935. schedule$$1.tween = tween1;
  2936. };
  2937. }
  2938. function transition_tween(name, value) {
  2939. var id = this._id;
  2940. name += "";
  2941. if (arguments.length < 2) {
  2942. var tween = get$1(this.node(), id).tween;
  2943. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2944. if ((t = tween[i]).name === name) {
  2945. return t.value;
  2946. }
  2947. }
  2948. return null;
  2949. }
  2950. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2951. }
  2952. function tweenValue(transition, name, value) {
  2953. var id = transition._id;
  2954. transition.each(function() {
  2955. var schedule$$1 = set$1(this, id);
  2956. (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
  2957. });
  2958. return function(node) {
  2959. return get$1(node, id).value[name];
  2960. };
  2961. }
  2962. function interpolate(a, b) {
  2963. var c;
  2964. return (typeof b === "number" ? reinterpolate
  2965. : b instanceof color ? interpolateRgb
  2966. : (c = color(b)) ? (b = c, interpolateRgb)
  2967. : interpolateString)(a, b);
  2968. }
  2969. function attrRemove$1(name) {
  2970. return function() {
  2971. this.removeAttribute(name);
  2972. };
  2973. }
  2974. function attrRemoveNS$1(fullname) {
  2975. return function() {
  2976. this.removeAttributeNS(fullname.space, fullname.local);
  2977. };
  2978. }
  2979. function attrConstant$1(name, interpolate$$1, value1) {
  2980. var value00,
  2981. interpolate0;
  2982. return function() {
  2983. var value0 = this.getAttribute(name);
  2984. return value0 === value1 ? null
  2985. : value0 === value00 ? interpolate0
  2986. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2987. };
  2988. }
  2989. function attrConstantNS$1(fullname, interpolate$$1, value1) {
  2990. var value00,
  2991. interpolate0;
  2992. return function() {
  2993. var value0 = this.getAttributeNS(fullname.space, fullname.local);
  2994. return value0 === value1 ? null
  2995. : value0 === value00 ? interpolate0
  2996. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2997. };
  2998. }
  2999. function attrFunction$1(name, interpolate$$1, value) {
  3000. var value00,
  3001. value10,
  3002. interpolate0;
  3003. return function() {
  3004. var value0, value1 = value(this);
  3005. if (value1 == null) return void this.removeAttribute(name);
  3006. value0 = this.getAttribute(name);
  3007. return value0 === value1 ? null
  3008. : value0 === value00 && value1 === value10 ? interpolate0
  3009. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3010. };
  3011. }
  3012. function attrFunctionNS$1(fullname, interpolate$$1, value) {
  3013. var value00,
  3014. value10,
  3015. interpolate0;
  3016. return function() {
  3017. var value0, value1 = value(this);
  3018. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3019. value0 = this.getAttributeNS(fullname.space, fullname.local);
  3020. return value0 === value1 ? null
  3021. : value0 === value00 && value1 === value10 ? interpolate0
  3022. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3023. };
  3024. }
  3025. function transition_attr(name, value) {
  3026. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  3027. return this.attrTween(name, typeof value === "function"
  3028. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  3029. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  3030. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
  3031. }
  3032. function attrTweenNS(fullname, value) {
  3033. function tween() {
  3034. var node = this, i = value.apply(node, arguments);
  3035. return i && function(t) {
  3036. node.setAttributeNS(fullname.space, fullname.local, i(t));
  3037. };
  3038. }
  3039. tween._value = value;
  3040. return tween;
  3041. }
  3042. function attrTween(name, value) {
  3043. function tween() {
  3044. var node = this, i = value.apply(node, arguments);
  3045. return i && function(t) {
  3046. node.setAttribute(name, i(t));
  3047. };
  3048. }
  3049. tween._value = value;
  3050. return tween;
  3051. }
  3052. function transition_attrTween(name, value) {
  3053. var key = "attr." + name;
  3054. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3055. if (value == null) return this.tween(key, null);
  3056. if (typeof value !== "function") throw new Error;
  3057. var fullname = namespace(name);
  3058. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3059. }
  3060. function delayFunction(id, value) {
  3061. return function() {
  3062. init(this, id).delay = +value.apply(this, arguments);
  3063. };
  3064. }
  3065. function delayConstant(id, value) {
  3066. return value = +value, function() {
  3067. init(this, id).delay = value;
  3068. };
  3069. }
  3070. function transition_delay(value) {
  3071. var id = this._id;
  3072. return arguments.length
  3073. ? this.each((typeof value === "function"
  3074. ? delayFunction
  3075. : delayConstant)(id, value))
  3076. : get$1(this.node(), id).delay;
  3077. }
  3078. function durationFunction(id, value) {
  3079. return function() {
  3080. set$1(this, id).duration = +value.apply(this, arguments);
  3081. };
  3082. }
  3083. function durationConstant(id, value) {
  3084. return value = +value, function() {
  3085. set$1(this, id).duration = value;
  3086. };
  3087. }
  3088. function transition_duration(value) {
  3089. var id = this._id;
  3090. return arguments.length
  3091. ? this.each((typeof value === "function"
  3092. ? durationFunction
  3093. : durationConstant)(id, value))
  3094. : get$1(this.node(), id).duration;
  3095. }
  3096. function easeConstant(id, value) {
  3097. if (typeof value !== "function") throw new Error;
  3098. return function() {
  3099. set$1(this, id).ease = value;
  3100. };
  3101. }
  3102. function transition_ease(value) {
  3103. var id = this._id;
  3104. return arguments.length
  3105. ? this.each(easeConstant(id, value))
  3106. : get$1(this.node(), id).ease;
  3107. }
  3108. function transition_filter(match) {
  3109. if (typeof match !== "function") match = matcher$1(match);
  3110. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3111. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3112. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3113. subgroup.push(node);
  3114. }
  3115. }
  3116. }
  3117. return new Transition(subgroups, this._parents, this._name, this._id);
  3118. }
  3119. function transition_merge(transition$$1) {
  3120. if (transition$$1._id !== this._id) throw new Error;
  3121. for (var groups0 = this._groups, groups1 = transition$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  3122. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3123. if (node = group0[i] || group1[i]) {
  3124. merge[i] = node;
  3125. }
  3126. }
  3127. }
  3128. for (; j < m0; ++j) {
  3129. merges[j] = groups0[j];
  3130. }
  3131. return new Transition(merges, this._parents, this._name, this._id);
  3132. }
  3133. function start(name) {
  3134. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3135. var i = t.indexOf(".");
  3136. if (i >= 0) t = t.slice(0, i);
  3137. return !t || t === "start";
  3138. });
  3139. }
  3140. function onFunction(id, name, listener) {
  3141. var on0, on1, sit = start(name) ? init : set$1;
  3142. return function() {
  3143. var schedule$$1 = sit(this, id),
  3144. on = schedule$$1.on;
  3145. // If this node shared a dispatch with the previous node,
  3146. // just assign the updated shared dispatch and we’re done!
  3147. // Otherwise, copy-on-write.
  3148. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3149. schedule$$1.on = on1;
  3150. };
  3151. }
  3152. function transition_on(name, listener) {
  3153. var id = this._id;
  3154. return arguments.length < 2
  3155. ? get$1(this.node(), id).on.on(name)
  3156. : this.each(onFunction(id, name, listener));
  3157. }
  3158. function removeFunction(id) {
  3159. return function() {
  3160. var parent = this.parentNode;
  3161. for (var i in this.__transition) if (+i !== id) return;
  3162. if (parent) parent.removeChild(this);
  3163. };
  3164. }
  3165. function transition_remove() {
  3166. return this.on("end.remove", removeFunction(this._id));
  3167. }
  3168. function transition_select(select$$1) {
  3169. var name = this._name,
  3170. id = this._id;
  3171. if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
  3172. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3173. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3174. if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
  3175. if ("__data__" in node) subnode.__data__ = node.__data__;
  3176. subgroup[i] = subnode;
  3177. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3178. }
  3179. }
  3180. }
  3181. return new Transition(subgroups, this._parents, name, id);
  3182. }
  3183. function transition_selectAll(select$$1) {
  3184. var name = this._name,
  3185. id = this._id;
  3186. if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
  3187. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3188. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3189. if (node = group[i]) {
  3190. for (var children = select$$1.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3191. if (child = children[k]) {
  3192. schedule(child, name, id, k, children, inherit);
  3193. }
  3194. }
  3195. subgroups.push(children);
  3196. parents.push(node);
  3197. }
  3198. }
  3199. }
  3200. return new Transition(subgroups, parents, name, id);
  3201. }
  3202. var Selection$1 = selection.prototype.constructor;
  3203. function transition_selection() {
  3204. return new Selection$1(this._groups, this._parents);
  3205. }
  3206. function styleRemove$1(name, interpolate$$1) {
  3207. var value00,
  3208. value10,
  3209. interpolate0;
  3210. return function() {
  3211. var value0 = styleValue(this, name),
  3212. value1 = (this.style.removeProperty(name), styleValue(this, name));
  3213. return value0 === value1 ? null
  3214. : value0 === value00 && value1 === value10 ? interpolate0
  3215. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3216. };
  3217. }
  3218. function styleRemoveEnd(name) {
  3219. return function() {
  3220. this.style.removeProperty(name);
  3221. };
  3222. }
  3223. function styleConstant$1(name, interpolate$$1, value1) {
  3224. var value00,
  3225. interpolate0;
  3226. return function() {
  3227. var value0 = styleValue(this, name);
  3228. return value0 === value1 ? null
  3229. : value0 === value00 ? interpolate0
  3230. : interpolate0 = interpolate$$1(value00 = value0, value1);
  3231. };
  3232. }
  3233. function styleFunction$1(name, interpolate$$1, value) {
  3234. var value00,
  3235. value10,
  3236. interpolate0;
  3237. return function() {
  3238. var value0 = styleValue(this, name),
  3239. value1 = value(this);
  3240. if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
  3241. return value0 === value1 ? null
  3242. : value0 === value00 && value1 === value10 ? interpolate0
  3243. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3244. };
  3245. }
  3246. function transition_style(name, value, priority) {
  3247. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3248. return value == null ? this
  3249. .styleTween(name, styleRemove$1(name, i))
  3250. .on("end.style." + name, styleRemoveEnd(name))
  3251. : this.styleTween(name, typeof value === "function"
  3252. ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
  3253. : styleConstant$1(name, i, value + ""), priority);
  3254. }
  3255. function styleTween(name, value, priority) {
  3256. function tween() {
  3257. var node = this, i = value.apply(node, arguments);
  3258. return i && function(t) {
  3259. node.style.setProperty(name, i(t), priority);
  3260. };
  3261. }
  3262. tween._value = value;
  3263. return tween;
  3264. }
  3265. function transition_styleTween(name, value, priority) {
  3266. var key = "style." + (name += "");
  3267. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3268. if (value == null) return this.tween(key, null);
  3269. if (typeof value !== "function") throw new Error;
  3270. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3271. }
  3272. function textConstant$1(value) {
  3273. return function() {
  3274. this.textContent = value;
  3275. };
  3276. }
  3277. function textFunction$1(value) {
  3278. return function() {
  3279. var value1 = value(this);
  3280. this.textContent = value1 == null ? "" : value1;
  3281. };
  3282. }
  3283. function transition_text(value) {
  3284. return this.tween("text", typeof value === "function"
  3285. ? textFunction$1(tweenValue(this, "text", value))
  3286. : textConstant$1(value == null ? "" : value + ""));
  3287. }
  3288. function transition_transition() {
  3289. var name = this._name,
  3290. id0 = this._id,
  3291. id1 = newId();
  3292. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3293. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3294. if (node = group[i]) {
  3295. var inherit = get$1(node, id0);
  3296. schedule(node, name, id1, i, group, {
  3297. time: inherit.time + inherit.delay + inherit.duration,
  3298. delay: 0,
  3299. duration: inherit.duration,
  3300. ease: inherit.ease
  3301. });
  3302. }
  3303. }
  3304. }
  3305. return new Transition(groups, this._parents, name, id1);
  3306. }
  3307. var id = 0;
  3308. function Transition(groups, parents, name, id) {
  3309. this._groups = groups;
  3310. this._parents = parents;
  3311. this._name = name;
  3312. this._id = id;
  3313. }
  3314. function transition(name) {
  3315. return selection().transition(name);
  3316. }
  3317. function newId() {
  3318. return ++id;
  3319. }
  3320. var selection_prototype = selection.prototype;
  3321. Transition.prototype = transition.prototype = {
  3322. constructor: Transition,
  3323. select: transition_select,
  3324. selectAll: transition_selectAll,
  3325. filter: transition_filter,
  3326. merge: transition_merge,
  3327. selection: transition_selection,
  3328. transition: transition_transition,
  3329. call: selection_prototype.call,
  3330. nodes: selection_prototype.nodes,
  3331. node: selection_prototype.node,
  3332. size: selection_prototype.size,
  3333. empty: selection_prototype.empty,
  3334. each: selection_prototype.each,
  3335. on: transition_on,
  3336. attr: transition_attr,
  3337. attrTween: transition_attrTween,
  3338. style: transition_style,
  3339. styleTween: transition_styleTween,
  3340. text: transition_text,
  3341. remove: transition_remove,
  3342. tween: transition_tween,
  3343. delay: transition_delay,
  3344. duration: transition_duration,
  3345. ease: transition_ease
  3346. };
  3347. function linear$1(t) {
  3348. return +t;
  3349. }
  3350. function quadIn(t) {
  3351. return t * t;
  3352. }
  3353. function quadOut(t) {
  3354. return t * (2 - t);
  3355. }
  3356. function quadInOut(t) {
  3357. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3358. }
  3359. function cubicIn(t) {
  3360. return t * t * t;
  3361. }
  3362. function cubicOut(t) {
  3363. return --t * t * t + 1;
  3364. }
  3365. function cubicInOut(t) {
  3366. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3367. }
  3368. var exponent = 3;
  3369. var polyIn = (function custom(e) {
  3370. e = +e;
  3371. function polyIn(t) {
  3372. return Math.pow(t, e);
  3373. }
  3374. polyIn.exponent = custom;
  3375. return polyIn;
  3376. })(exponent);
  3377. var polyOut = (function custom(e) {
  3378. e = +e;
  3379. function polyOut(t) {
  3380. return 1 - Math.pow(1 - t, e);
  3381. }
  3382. polyOut.exponent = custom;
  3383. return polyOut;
  3384. })(exponent);
  3385. var polyInOut = (function custom(e) {
  3386. e = +e;
  3387. function polyInOut(t) {
  3388. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3389. }
  3390. polyInOut.exponent = custom;
  3391. return polyInOut;
  3392. })(exponent);
  3393. var pi = Math.PI,
  3394. halfPi = pi / 2;
  3395. function sinIn(t) {
  3396. return 1 - Math.cos(t * halfPi);
  3397. }
  3398. function sinOut(t) {
  3399. return Math.sin(t * halfPi);
  3400. }
  3401. function sinInOut(t) {
  3402. return (1 - Math.cos(pi * t)) / 2;
  3403. }
  3404. function expIn(t) {
  3405. return Math.pow(2, 10 * t - 10);
  3406. }
  3407. function expOut(t) {
  3408. return 1 - Math.pow(2, -10 * t);
  3409. }
  3410. function expInOut(t) {
  3411. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3412. }
  3413. function circleIn(t) {
  3414. return 1 - Math.sqrt(1 - t * t);
  3415. }
  3416. function circleOut(t) {
  3417. return Math.sqrt(1 - --t * t);
  3418. }
  3419. function circleInOut(t) {
  3420. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3421. }
  3422. var b1 = 4 / 11,
  3423. b2 = 6 / 11,
  3424. b3 = 8 / 11,
  3425. b4 = 3 / 4,
  3426. b5 = 9 / 11,
  3427. b6 = 10 / 11,
  3428. b7 = 15 / 16,
  3429. b8 = 21 / 22,
  3430. b9 = 63 / 64,
  3431. b0 = 1 / b1 / b1;
  3432. function bounceIn(t) {
  3433. return 1 - bounceOut(1 - t);
  3434. }
  3435. function bounceOut(t) {
  3436. 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;
  3437. }
  3438. function bounceInOut(t) {
  3439. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3440. }
  3441. var overshoot = 1.70158;
  3442. var backIn = (function custom(s) {
  3443. s = +s;
  3444. function backIn(t) {
  3445. return t * t * ((s + 1) * t - s);
  3446. }
  3447. backIn.overshoot = custom;
  3448. return backIn;
  3449. })(overshoot);
  3450. var backOut = (function custom(s) {
  3451. s = +s;
  3452. function backOut(t) {
  3453. return --t * t * ((s + 1) * t + s) + 1;
  3454. }
  3455. backOut.overshoot = custom;
  3456. return backOut;
  3457. })(overshoot);
  3458. var backInOut = (function custom(s) {
  3459. s = +s;
  3460. function backInOut(t) {
  3461. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3462. }
  3463. backInOut.overshoot = custom;
  3464. return backInOut;
  3465. })(overshoot);
  3466. var tau = 2 * Math.PI,
  3467. amplitude = 1,
  3468. period = 0.3;
  3469. var elasticIn = (function custom(a, p) {
  3470. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3471. function elasticIn(t) {
  3472. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3473. }
  3474. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3475. elasticIn.period = function(p) { return custom(a, p); };
  3476. return elasticIn;
  3477. })(amplitude, period);
  3478. var elasticOut = (function custom(a, p) {
  3479. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3480. function elasticOut(t) {
  3481. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3482. }
  3483. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3484. elasticOut.period = function(p) { return custom(a, p); };
  3485. return elasticOut;
  3486. })(amplitude, period);
  3487. var elasticInOut = (function custom(a, p) {
  3488. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3489. function elasticInOut(t) {
  3490. return ((t = t * 2 - 1) < 0
  3491. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3492. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3493. }
  3494. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3495. elasticInOut.period = function(p) { return custom(a, p); };
  3496. return elasticInOut;
  3497. })(amplitude, period);
  3498. var defaultTiming = {
  3499. time: null, // Set on use.
  3500. delay: 0,
  3501. duration: 250,
  3502. ease: cubicInOut
  3503. };
  3504. function inherit(node, id) {
  3505. var timing;
  3506. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3507. if (!(node = node.parentNode)) {
  3508. return defaultTiming.time = now(), defaultTiming;
  3509. }
  3510. }
  3511. return timing;
  3512. }
  3513. function selection_transition(name) {
  3514. var id,
  3515. timing;
  3516. if (name instanceof Transition) {
  3517. id = name._id, name = name._name;
  3518. } else {
  3519. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3520. }
  3521. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3522. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3523. if (node = group[i]) {
  3524. schedule(node, name, id, i, group, timing || inherit(node, id));
  3525. }
  3526. }
  3527. }
  3528. return new Transition(groups, this._parents, name, id);
  3529. }
  3530. selection.prototype.interrupt = selection_interrupt;
  3531. selection.prototype.transition = selection_transition;
  3532. var root$1 = [null];
  3533. function active(node, name) {
  3534. var schedules = node.__transition,
  3535. schedule$$1,
  3536. i;
  3537. if (schedules) {
  3538. name = name == null ? null : name + "";
  3539. for (i in schedules) {
  3540. if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
  3541. return new Transition([[node]], root$1, name, +i);
  3542. }
  3543. }
  3544. }
  3545. return null;
  3546. }
  3547. function constant$4(x) {
  3548. return function() {
  3549. return x;
  3550. };
  3551. }
  3552. function BrushEvent(target, type, selection) {
  3553. this.target = target;
  3554. this.type = type;
  3555. this.selection = selection;
  3556. }
  3557. function nopropagation$1() {
  3558. exports.event.stopImmediatePropagation();
  3559. }
  3560. function noevent$1() {
  3561. exports.event.preventDefault();
  3562. exports.event.stopImmediatePropagation();
  3563. }
  3564. var MODE_DRAG = {name: "drag"},
  3565. MODE_SPACE = {name: "space"},
  3566. MODE_HANDLE = {name: "handle"},
  3567. MODE_CENTER = {name: "center"};
  3568. var X = {
  3569. name: "x",
  3570. handles: ["e", "w"].map(type),
  3571. input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
  3572. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3573. };
  3574. var Y = {
  3575. name: "y",
  3576. handles: ["n", "s"].map(type),
  3577. input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
  3578. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3579. };
  3580. var XY = {
  3581. name: "xy",
  3582. handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
  3583. input: function(xy) { return xy; },
  3584. output: function(xy) { return xy; }
  3585. };
  3586. var cursors = {
  3587. overlay: "crosshair",
  3588. selection: "move",
  3589. n: "ns-resize",
  3590. e: "ew-resize",
  3591. s: "ns-resize",
  3592. w: "ew-resize",
  3593. nw: "nwse-resize",
  3594. ne: "nesw-resize",
  3595. se: "nwse-resize",
  3596. sw: "nesw-resize"
  3597. };
  3598. var flipX = {
  3599. e: "w",
  3600. w: "e",
  3601. nw: "ne",
  3602. ne: "nw",
  3603. se: "sw",
  3604. sw: "se"
  3605. };
  3606. var flipY = {
  3607. n: "s",
  3608. s: "n",
  3609. nw: "sw",
  3610. ne: "se",
  3611. se: "ne",
  3612. sw: "nw"
  3613. };
  3614. var signsX = {
  3615. overlay: +1,
  3616. selection: +1,
  3617. n: null,
  3618. e: +1,
  3619. s: null,
  3620. w: -1,
  3621. nw: -1,
  3622. ne: +1,
  3623. se: +1,
  3624. sw: -1
  3625. };
  3626. var signsY = {
  3627. overlay: +1,
  3628. selection: +1,
  3629. n: -1,
  3630. e: null,
  3631. s: +1,
  3632. w: null,
  3633. nw: -1,
  3634. ne: -1,
  3635. se: +1,
  3636. sw: +1
  3637. };
  3638. function type(t) {
  3639. return {type: t};
  3640. }
  3641. // Ignore right-click, since that should open the context menu.
  3642. function defaultFilter$1() {
  3643. return !exports.event.button;
  3644. }
  3645. function defaultExtent() {
  3646. var svg = this.ownerSVGElement || this;
  3647. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3648. }
  3649. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3650. function local$1(node) {
  3651. while (!node.__brush) if (!(node = node.parentNode)) return;
  3652. return node.__brush;
  3653. }
  3654. function empty$1(extent) {
  3655. return extent[0][0] === extent[1][0]
  3656. || extent[0][1] === extent[1][1];
  3657. }
  3658. function brushSelection(node) {
  3659. var state = node.__brush;
  3660. return state ? state.dim.output(state.selection) : null;
  3661. }
  3662. function brushX() {
  3663. return brush$1(X);
  3664. }
  3665. function brushY() {
  3666. return brush$1(Y);
  3667. }
  3668. function brush() {
  3669. return brush$1(XY);
  3670. }
  3671. function brush$1(dim) {
  3672. var extent = defaultExtent,
  3673. filter = defaultFilter$1,
  3674. listeners = dispatch(brush, "start", "brush", "end"),
  3675. handleSize = 6,
  3676. touchending;
  3677. function brush(group) {
  3678. var overlay = group
  3679. .property("__brush", initialize)
  3680. .selectAll(".overlay")
  3681. .data([type("overlay")]);
  3682. overlay.enter().append("rect")
  3683. .attr("class", "overlay")
  3684. .attr("pointer-events", "all")
  3685. .attr("cursor", cursors.overlay)
  3686. .merge(overlay)
  3687. .each(function() {
  3688. var extent = local$1(this).extent;
  3689. select(this)
  3690. .attr("x", extent[0][0])
  3691. .attr("y", extent[0][1])
  3692. .attr("width", extent[1][0] - extent[0][0])
  3693. .attr("height", extent[1][1] - extent[0][1]);
  3694. });
  3695. group.selectAll(".selection")
  3696. .data([type("selection")])
  3697. .enter().append("rect")
  3698. .attr("class", "selection")
  3699. .attr("cursor", cursors.selection)
  3700. .attr("fill", "#777")
  3701. .attr("fill-opacity", 0.3)
  3702. .attr("stroke", "#fff")
  3703. .attr("shape-rendering", "crispEdges");
  3704. var handle = group.selectAll(".handle")
  3705. .data(dim.handles, function(d) { return d.type; });
  3706. handle.exit().remove();
  3707. handle.enter().append("rect")
  3708. .attr("class", function(d) { return "handle handle--" + d.type; })
  3709. .attr("cursor", function(d) { return cursors[d.type]; });
  3710. group
  3711. .each(redraw)
  3712. .attr("fill", "none")
  3713. .attr("pointer-events", "all")
  3714. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  3715. .on("mousedown.brush touchstart.brush", started);
  3716. }
  3717. brush.move = function(group, selection$$1) {
  3718. if (group.selection) {
  3719. group
  3720. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3721. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3722. .tween("brush", function() {
  3723. var that = this,
  3724. state = that.__brush,
  3725. emit = emitter(that, arguments),
  3726. selection0 = state.selection,
  3727. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
  3728. i = interpolateValue(selection0, selection1);
  3729. function tween(t) {
  3730. state.selection = t === 1 && empty$1(selection1) ? null : i(t);
  3731. redraw.call(that);
  3732. emit.brush();
  3733. }
  3734. return selection0 && selection1 ? tween : tween(1);
  3735. });
  3736. } else {
  3737. group
  3738. .each(function() {
  3739. var that = this,
  3740. args = arguments,
  3741. state = that.__brush,
  3742. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
  3743. emit = emitter(that, args).beforestart();
  3744. interrupt(that);
  3745. state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
  3746. redraw.call(that);
  3747. emit.start().brush().end();
  3748. });
  3749. }
  3750. };
  3751. function redraw() {
  3752. var group = select(this),
  3753. selection$$1 = local$1(this).selection;
  3754. if (selection$$1) {
  3755. group.selectAll(".selection")
  3756. .style("display", null)
  3757. .attr("x", selection$$1[0][0])
  3758. .attr("y", selection$$1[0][1])
  3759. .attr("width", selection$$1[1][0] - selection$$1[0][0])
  3760. .attr("height", selection$$1[1][1] - selection$$1[0][1]);
  3761. group.selectAll(".handle")
  3762. .style("display", null)
  3763. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2; })
  3764. .attr("y", function(d) { return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2; })
  3765. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize; })
  3766. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize; });
  3767. }
  3768. else {
  3769. group.selectAll(".selection,.handle")
  3770. .style("display", "none")
  3771. .attr("x", null)
  3772. .attr("y", null)
  3773. .attr("width", null)
  3774. .attr("height", null);
  3775. }
  3776. }
  3777. function emitter(that, args) {
  3778. return that.__brush.emitter || new Emitter(that, args);
  3779. }
  3780. function Emitter(that, args) {
  3781. this.that = that;
  3782. this.args = args;
  3783. this.state = that.__brush;
  3784. this.active = 0;
  3785. }
  3786. Emitter.prototype = {
  3787. beforestart: function() {
  3788. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3789. return this;
  3790. },
  3791. start: function() {
  3792. if (this.starting) this.starting = false, this.emit("start");
  3793. return this;
  3794. },
  3795. brush: function() {
  3796. this.emit("brush");
  3797. return this;
  3798. },
  3799. end: function() {
  3800. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3801. return this;
  3802. },
  3803. emit: function(type) {
  3804. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3805. }
  3806. };
  3807. function started() {
  3808. if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
  3809. else if (touchending) return;
  3810. if (!filter.apply(this, arguments)) return;
  3811. var that = this,
  3812. type = exports.event.target.__data__.type,
  3813. mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3814. signX = dim === Y ? null : signsX[type],
  3815. signY = dim === X ? null : signsY[type],
  3816. state = local$1(that),
  3817. extent = state.extent,
  3818. selection$$1 = state.selection,
  3819. W = extent[0][0], w0, w1,
  3820. N = extent[0][1], n0, n1,
  3821. E = extent[1][0], e0, e1,
  3822. S = extent[1][1], s0, s1,
  3823. dx,
  3824. dy,
  3825. moving,
  3826. shifting = signX && signY && exports.event.shiftKey,
  3827. lockX,
  3828. lockY,
  3829. point0 = mouse(that),
  3830. point$$1 = point0,
  3831. emit = emitter(that, arguments).beforestart();
  3832. if (type === "overlay") {
  3833. state.selection = selection$$1 = [
  3834. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3835. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3836. ];
  3837. } else {
  3838. w0 = selection$$1[0][0];
  3839. n0 = selection$$1[0][1];
  3840. e0 = selection$$1[1][0];
  3841. s0 = selection$$1[1][1];
  3842. }
  3843. w1 = w0;
  3844. n1 = n0;
  3845. e1 = e0;
  3846. s1 = s0;
  3847. var group = select(that)
  3848. .attr("pointer-events", "none");
  3849. var overlay = group.selectAll(".overlay")
  3850. .attr("cursor", cursors[type]);
  3851. if (exports.event.touches) {
  3852. group
  3853. .on("touchmove.brush", moved, true)
  3854. .on("touchend.brush touchcancel.brush", ended, true);
  3855. } else {
  3856. var view = select(exports.event.view)
  3857. .on("keydown.brush", keydowned, true)
  3858. .on("keyup.brush", keyupped, true)
  3859. .on("mousemove.brush", moved, true)
  3860. .on("mouseup.brush", ended, true);
  3861. dragDisable(exports.event.view);
  3862. }
  3863. nopropagation$1();
  3864. interrupt(that);
  3865. redraw.call(that);
  3866. emit.start();
  3867. function moved() {
  3868. var point1 = mouse(that);
  3869. if (shifting && !lockX && !lockY) {
  3870. if (Math.abs(point1[0] - point$$1[0]) > Math.abs(point1[1] - point$$1[1])) lockY = true;
  3871. else lockX = true;
  3872. }
  3873. point$$1 = point1;
  3874. moving = true;
  3875. noevent$1();
  3876. move();
  3877. }
  3878. function move() {
  3879. var t;
  3880. dx = point$$1[0] - point0[0];
  3881. dy = point$$1[1] - point0[1];
  3882. switch (mode) {
  3883. case MODE_SPACE:
  3884. case MODE_DRAG: {
  3885. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  3886. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  3887. break;
  3888. }
  3889. case MODE_HANDLE: {
  3890. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  3891. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  3892. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  3893. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  3894. break;
  3895. }
  3896. case MODE_CENTER: {
  3897. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  3898. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  3899. break;
  3900. }
  3901. }
  3902. if (e1 < w1) {
  3903. signX *= -1;
  3904. t = w0, w0 = e0, e0 = t;
  3905. t = w1, w1 = e1, e1 = t;
  3906. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  3907. }
  3908. if (s1 < n1) {
  3909. signY *= -1;
  3910. t = n0, n0 = s0, s0 = t;
  3911. t = n1, n1 = s1, s1 = t;
  3912. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  3913. }
  3914. if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
  3915. if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
  3916. if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
  3917. if (selection$$1[0][0] !== w1
  3918. || selection$$1[0][1] !== n1
  3919. || selection$$1[1][0] !== e1
  3920. || selection$$1[1][1] !== s1) {
  3921. state.selection = [[w1, n1], [e1, s1]];
  3922. redraw.call(that);
  3923. emit.brush();
  3924. }
  3925. }
  3926. function ended() {
  3927. nopropagation$1();
  3928. if (exports.event.touches) {
  3929. if (exports.event.touches.length) return;
  3930. if (touchending) clearTimeout(touchending);
  3931. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  3932. group.on("touchmove.brush touchend.brush touchcancel.brush", null);
  3933. } else {
  3934. yesdrag(exports.event.view, moving);
  3935. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  3936. }
  3937. group.attr("pointer-events", "all");
  3938. overlay.attr("cursor", cursors.overlay);
  3939. if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
  3940. if (empty$1(selection$$1)) state.selection = null, redraw.call(that);
  3941. emit.end();
  3942. }
  3943. function keydowned() {
  3944. switch (exports.event.keyCode) {
  3945. case 16: { // SHIFT
  3946. shifting = signX && signY;
  3947. break;
  3948. }
  3949. case 18: { // ALT
  3950. if (mode === MODE_HANDLE) {
  3951. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3952. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3953. mode = MODE_CENTER;
  3954. move();
  3955. }
  3956. break;
  3957. }
  3958. case 32: { // SPACE; takes priority over ALT
  3959. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  3960. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  3961. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  3962. mode = MODE_SPACE;
  3963. overlay.attr("cursor", cursors.selection);
  3964. move();
  3965. }
  3966. break;
  3967. }
  3968. default: return;
  3969. }
  3970. noevent$1();
  3971. }
  3972. function keyupped() {
  3973. switch (exports.event.keyCode) {
  3974. case 16: { // SHIFT
  3975. if (shifting) {
  3976. lockX = lockY = shifting = false;
  3977. move();
  3978. }
  3979. break;
  3980. }
  3981. case 18: { // ALT
  3982. if (mode === MODE_CENTER) {
  3983. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3984. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3985. mode = MODE_HANDLE;
  3986. move();
  3987. }
  3988. break;
  3989. }
  3990. case 32: { // SPACE
  3991. if (mode === MODE_SPACE) {
  3992. if (exports.event.altKey) {
  3993. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3994. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3995. mode = MODE_CENTER;
  3996. } else {
  3997. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3998. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3999. mode = MODE_HANDLE;
  4000. }
  4001. overlay.attr("cursor", cursors[type]);
  4002. move();
  4003. }
  4004. break;
  4005. }
  4006. default: return;
  4007. }
  4008. noevent$1();
  4009. }
  4010. }
  4011. function initialize() {
  4012. var state = this.__brush || {selection: null};
  4013. state.extent = extent.apply(this, arguments);
  4014. state.dim = dim;
  4015. return state;
  4016. }
  4017. brush.extent = function(_) {
  4018. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
  4019. };
  4020. brush.filter = function(_) {
  4021. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  4022. };
  4023. brush.handleSize = function(_) {
  4024. return arguments.length ? (handleSize = +_, brush) : handleSize;
  4025. };
  4026. brush.on = function() {
  4027. var value = listeners.on.apply(listeners, arguments);
  4028. return value === listeners ? brush : value;
  4029. };
  4030. return brush;
  4031. }
  4032. var cos = Math.cos;
  4033. var sin = Math.sin;
  4034. var pi$1 = Math.PI;
  4035. var halfPi$1 = pi$1 / 2;
  4036. var tau$1 = pi$1 * 2;
  4037. var max$1 = Math.max;
  4038. function compareValue(compare) {
  4039. return function(a, b) {
  4040. return compare(
  4041. a.source.value + a.target.value,
  4042. b.source.value + b.target.value
  4043. );
  4044. };
  4045. }
  4046. function chord() {
  4047. var padAngle = 0,
  4048. sortGroups = null,
  4049. sortSubgroups = null,
  4050. sortChords = null;
  4051. function chord(matrix) {
  4052. var n = matrix.length,
  4053. groupSums = [],
  4054. groupIndex = sequence(n),
  4055. subgroupIndex = [],
  4056. chords = [],
  4057. groups = chords.groups = new Array(n),
  4058. subgroups = new Array(n * n),
  4059. k,
  4060. x,
  4061. x0,
  4062. dx,
  4063. i,
  4064. j;
  4065. // Compute the sum.
  4066. k = 0, i = -1; while (++i < n) {
  4067. x = 0, j = -1; while (++j < n) {
  4068. x += matrix[i][j];
  4069. }
  4070. groupSums.push(x);
  4071. subgroupIndex.push(sequence(n));
  4072. k += x;
  4073. }
  4074. // Sort groups…
  4075. if (sortGroups) groupIndex.sort(function(a, b) {
  4076. return sortGroups(groupSums[a], groupSums[b]);
  4077. });
  4078. // Sort subgroups…
  4079. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4080. d.sort(function(a, b) {
  4081. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4082. });
  4083. });
  4084. // Convert the sum to scaling factor for [0, 2pi].
  4085. // TODO Allow start and end angle to be specified?
  4086. // TODO Allow padding to be specified as percentage?
  4087. k = max$1(0, tau$1 - padAngle * n) / k;
  4088. dx = k ? padAngle : tau$1 / n;
  4089. // Compute the start and end angle for each group and subgroup.
  4090. // Note: Opera has a bug reordering object literal properties!
  4091. x = 0, i = -1; while (++i < n) {
  4092. x0 = x, j = -1; while (++j < n) {
  4093. var di = groupIndex[i],
  4094. dj = subgroupIndex[di][j],
  4095. v = matrix[di][dj],
  4096. a0 = x,
  4097. a1 = x += v * k;
  4098. subgroups[dj * n + di] = {
  4099. index: di,
  4100. subindex: dj,
  4101. startAngle: a0,
  4102. endAngle: a1,
  4103. value: v
  4104. };
  4105. }
  4106. groups[di] = {
  4107. index: di,
  4108. startAngle: x0,
  4109. endAngle: x,
  4110. value: groupSums[di]
  4111. };
  4112. x += dx;
  4113. }
  4114. // Generate chords for each (non-empty) subgroup-subgroup link.
  4115. i = -1; while (++i < n) {
  4116. j = i - 1; while (++j < n) {
  4117. var source = subgroups[j * n + i],
  4118. target = subgroups[i * n + j];
  4119. if (source.value || target.value) {
  4120. chords.push(source.value < target.value
  4121. ? {source: target, target: source}
  4122. : {source: source, target: target});
  4123. }
  4124. }
  4125. }
  4126. return sortChords ? chords.sort(sortChords) : chords;
  4127. }
  4128. chord.padAngle = function(_) {
  4129. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4130. };
  4131. chord.sortGroups = function(_) {
  4132. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4133. };
  4134. chord.sortSubgroups = function(_) {
  4135. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4136. };
  4137. chord.sortChords = function(_) {
  4138. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4139. };
  4140. return chord;
  4141. }
  4142. var slice$2 = Array.prototype.slice;
  4143. function constant$5(x) {
  4144. return function() {
  4145. return x;
  4146. };
  4147. }
  4148. var pi$2 = Math.PI,
  4149. tau$2 = 2 * pi$2,
  4150. epsilon$1 = 1e-6,
  4151. tauEpsilon = tau$2 - epsilon$1;
  4152. function Path() {
  4153. this._x0 = this._y0 = // start of current subpath
  4154. this._x1 = this._y1 = null; // end of current subpath
  4155. this._ = "";
  4156. }
  4157. function path() {
  4158. return new Path;
  4159. }
  4160. Path.prototype = path.prototype = {
  4161. constructor: Path,
  4162. moveTo: function(x, y) {
  4163. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4164. },
  4165. closePath: function() {
  4166. if (this._x1 !== null) {
  4167. this._x1 = this._x0, this._y1 = this._y0;
  4168. this._ += "Z";
  4169. }
  4170. },
  4171. lineTo: function(x, y) {
  4172. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4173. },
  4174. quadraticCurveTo: function(x1, y1, x, y) {
  4175. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4176. },
  4177. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4178. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4179. },
  4180. arcTo: function(x1, y1, x2, y2, r) {
  4181. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4182. var x0 = this._x1,
  4183. y0 = this._y1,
  4184. x21 = x2 - x1,
  4185. y21 = y2 - y1,
  4186. x01 = x0 - x1,
  4187. y01 = y0 - y1,
  4188. l01_2 = x01 * x01 + y01 * y01;
  4189. // Is the radius negative? Error.
  4190. if (r < 0) throw new Error("negative radius: " + r);
  4191. // Is this path empty? Move to (x1,y1).
  4192. if (this._x1 === null) {
  4193. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4194. }
  4195. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4196. else if (!(l01_2 > epsilon$1)) {}
  4197. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4198. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4199. // Or, is the radius zero? Line to (x1,y1).
  4200. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4201. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4202. }
  4203. // Otherwise, draw an arc!
  4204. else {
  4205. var x20 = x2 - x0,
  4206. y20 = y2 - y0,
  4207. l21_2 = x21 * x21 + y21 * y21,
  4208. l20_2 = x20 * x20 + y20 * y20,
  4209. l21 = Math.sqrt(l21_2),
  4210. l01 = Math.sqrt(l01_2),
  4211. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4212. t01 = l / l01,
  4213. t21 = l / l21;
  4214. // If the start tangent is not coincident with (x0,y0), line to.
  4215. if (Math.abs(t01 - 1) > epsilon$1) {
  4216. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4217. }
  4218. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4219. }
  4220. },
  4221. arc: function(x, y, r, a0, a1, ccw) {
  4222. x = +x, y = +y, r = +r;
  4223. var dx = r * Math.cos(a0),
  4224. dy = r * Math.sin(a0),
  4225. x0 = x + dx,
  4226. y0 = y + dy,
  4227. cw = 1 ^ ccw,
  4228. da = ccw ? a0 - a1 : a1 - a0;
  4229. // Is the radius negative? Error.
  4230. if (r < 0) throw new Error("negative radius: " + r);
  4231. // Is this path empty? Move to (x0,y0).
  4232. if (this._x1 === null) {
  4233. this._ += "M" + x0 + "," + y0;
  4234. }
  4235. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4236. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4237. this._ += "L" + x0 + "," + y0;
  4238. }
  4239. // Is this arc empty? We’re done.
  4240. if (!r) return;
  4241. // Does the angle go the wrong way? Flip the direction.
  4242. if (da < 0) da = da % tau$2 + tau$2;
  4243. // Is this a complete circle? Draw two arcs to complete the circle.
  4244. if (da > tauEpsilon) {
  4245. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4246. }
  4247. // Is this arc non-empty? Draw an arc!
  4248. else if (da > epsilon$1) {
  4249. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4250. }
  4251. },
  4252. rect: function(x, y, w, h) {
  4253. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4254. },
  4255. toString: function() {
  4256. return this._;
  4257. }
  4258. };
  4259. function defaultSource(d) {
  4260. return d.source;
  4261. }
  4262. function defaultTarget(d) {
  4263. return d.target;
  4264. }
  4265. function defaultRadius(d) {
  4266. return d.radius;
  4267. }
  4268. function defaultStartAngle(d) {
  4269. return d.startAngle;
  4270. }
  4271. function defaultEndAngle(d) {
  4272. return d.endAngle;
  4273. }
  4274. function ribbon() {
  4275. var source = defaultSource,
  4276. target = defaultTarget,
  4277. radius = defaultRadius,
  4278. startAngle = defaultStartAngle,
  4279. endAngle = defaultEndAngle,
  4280. context = null;
  4281. function ribbon() {
  4282. var buffer,
  4283. argv = slice$2.call(arguments),
  4284. s = source.apply(this, argv),
  4285. t = target.apply(this, argv),
  4286. sr = +radius.apply(this, (argv[0] = s, argv)),
  4287. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4288. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4289. sx0 = sr * cos(sa0),
  4290. sy0 = sr * sin(sa0),
  4291. tr = +radius.apply(this, (argv[0] = t, argv)),
  4292. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4293. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4294. if (!context) context = buffer = path();
  4295. context.moveTo(sx0, sy0);
  4296. context.arc(0, 0, sr, sa0, sa1);
  4297. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4298. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4299. context.arc(0, 0, tr, ta0, ta1);
  4300. }
  4301. context.quadraticCurveTo(0, 0, sx0, sy0);
  4302. context.closePath();
  4303. if (buffer) return context = null, buffer + "" || null;
  4304. }
  4305. ribbon.radius = function(_) {
  4306. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4307. };
  4308. ribbon.startAngle = function(_) {
  4309. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4310. };
  4311. ribbon.endAngle = function(_) {
  4312. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4313. };
  4314. ribbon.source = function(_) {
  4315. return arguments.length ? (source = _, ribbon) : source;
  4316. };
  4317. ribbon.target = function(_) {
  4318. return arguments.length ? (target = _, ribbon) : target;
  4319. };
  4320. ribbon.context = function(_) {
  4321. return arguments.length ? (context = _ == null ? null : _, ribbon) : context;
  4322. };
  4323. return ribbon;
  4324. }
  4325. var prefix = "$";
  4326. function Map() {}
  4327. Map.prototype = map$1.prototype = {
  4328. constructor: Map,
  4329. has: function(key) {
  4330. return (prefix + key) in this;
  4331. },
  4332. get: function(key) {
  4333. return this[prefix + key];
  4334. },
  4335. set: function(key, value) {
  4336. this[prefix + key] = value;
  4337. return this;
  4338. },
  4339. remove: function(key) {
  4340. var property = prefix + key;
  4341. return property in this && delete this[property];
  4342. },
  4343. clear: function() {
  4344. for (var property in this) if (property[0] === prefix) delete this[property];
  4345. },
  4346. keys: function() {
  4347. var keys = [];
  4348. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4349. return keys;
  4350. },
  4351. values: function() {
  4352. var values = [];
  4353. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4354. return values;
  4355. },
  4356. entries: function() {
  4357. var entries = [];
  4358. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4359. return entries;
  4360. },
  4361. size: function() {
  4362. var size = 0;
  4363. for (var property in this) if (property[0] === prefix) ++size;
  4364. return size;
  4365. },
  4366. empty: function() {
  4367. for (var property in this) if (property[0] === prefix) return false;
  4368. return true;
  4369. },
  4370. each: function(f) {
  4371. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4372. }
  4373. };
  4374. function map$1(object, f) {
  4375. var map = new Map;
  4376. // Copy constructor.
  4377. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4378. // Index array by numeric index or specified key function.
  4379. else if (Array.isArray(object)) {
  4380. var i = -1,
  4381. n = object.length,
  4382. o;
  4383. if (f == null) while (++i < n) map.set(i, object[i]);
  4384. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4385. }
  4386. // Convert object to map.
  4387. else if (object) for (var key in object) map.set(key, object[key]);
  4388. return map;
  4389. }
  4390. function nest() {
  4391. var keys = [],
  4392. sortKeys = [],
  4393. sortValues,
  4394. rollup,
  4395. nest;
  4396. function apply(array, depth, createResult, setResult) {
  4397. if (depth >= keys.length) {
  4398. if (sortValues != null) array.sort(sortValues);
  4399. return rollup != null ? rollup(array) : array;
  4400. }
  4401. var i = -1,
  4402. n = array.length,
  4403. key = keys[depth++],
  4404. keyValue,
  4405. value,
  4406. valuesByKey = map$1(),
  4407. values,
  4408. result = createResult();
  4409. while (++i < n) {
  4410. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4411. values.push(value);
  4412. } else {
  4413. valuesByKey.set(keyValue, [value]);
  4414. }
  4415. }
  4416. valuesByKey.each(function(values, key) {
  4417. setResult(result, key, apply(values, depth, createResult, setResult));
  4418. });
  4419. return result;
  4420. }
  4421. function entries(map, depth) {
  4422. if (++depth > keys.length) return map;
  4423. var array, sortKey = sortKeys[depth - 1];
  4424. if (rollup != null && depth >= keys.length) array = map.entries();
  4425. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4426. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4427. }
  4428. return nest = {
  4429. object: function(array) { return apply(array, 0, createObject, setObject); },
  4430. map: function(array) { return apply(array, 0, createMap, setMap); },
  4431. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4432. key: function(d) { keys.push(d); return nest; },
  4433. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4434. sortValues: function(order) { sortValues = order; return nest; },
  4435. rollup: function(f) { rollup = f; return nest; }
  4436. };
  4437. }
  4438. function createObject() {
  4439. return {};
  4440. }
  4441. function setObject(object, key, value) {
  4442. object[key] = value;
  4443. }
  4444. function createMap() {
  4445. return map$1();
  4446. }
  4447. function setMap(map, key, value) {
  4448. map.set(key, value);
  4449. }
  4450. function Set() {}
  4451. var proto = map$1.prototype;
  4452. Set.prototype = set$2.prototype = {
  4453. constructor: Set,
  4454. has: proto.has,
  4455. add: function(value) {
  4456. value += "";
  4457. this[prefix + value] = value;
  4458. return this;
  4459. },
  4460. remove: proto.remove,
  4461. clear: proto.clear,
  4462. values: proto.keys,
  4463. size: proto.size,
  4464. empty: proto.empty,
  4465. each: proto.each
  4466. };
  4467. function set$2(object, f) {
  4468. var set = new Set;
  4469. // Copy constructor.
  4470. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4471. // Otherwise, assume it’s an array.
  4472. else if (object) {
  4473. var i = -1, n = object.length;
  4474. if (f == null) while (++i < n) set.add(object[i]);
  4475. else while (++i < n) set.add(f(object[i], i, object));
  4476. }
  4477. return set;
  4478. }
  4479. function keys(map) {
  4480. var keys = [];
  4481. for (var key in map) keys.push(key);
  4482. return keys;
  4483. }
  4484. function values(map) {
  4485. var values = [];
  4486. for (var key in map) values.push(map[key]);
  4487. return values;
  4488. }
  4489. function entries(map) {
  4490. var entries = [];
  4491. for (var key in map) entries.push({key: key, value: map[key]});
  4492. return entries;
  4493. }
  4494. var array$2 = Array.prototype;
  4495. var slice$3 = array$2.slice;
  4496. function ascending$2(a, b) {
  4497. return a - b;
  4498. }
  4499. function area(ring) {
  4500. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  4501. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  4502. return area;
  4503. }
  4504. function constant$6(x) {
  4505. return function() {
  4506. return x;
  4507. };
  4508. }
  4509. function contains(ring, hole) {
  4510. var i = -1, n = hole.length, c;
  4511. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  4512. return 0;
  4513. }
  4514. function ringContains(ring, point) {
  4515. var x = point[0], y = point[1], contains = -1;
  4516. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  4517. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  4518. if (segmentContains(pi, pj, point)) return 0;
  4519. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  4520. }
  4521. return contains;
  4522. }
  4523. function segmentContains(a, b, c) {
  4524. var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  4525. }
  4526. function collinear(a, b, c) {
  4527. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  4528. }
  4529. function within(p, q, r) {
  4530. return p <= q && q <= r || r <= q && q <= p;
  4531. }
  4532. function noop$1() {}
  4533. var cases = [
  4534. [],
  4535. [[[1.0, 1.5], [0.5, 1.0]]],
  4536. [[[1.5, 1.0], [1.0, 1.5]]],
  4537. [[[1.5, 1.0], [0.5, 1.0]]],
  4538. [[[1.0, 0.5], [1.5, 1.0]]],
  4539. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  4540. [[[1.0, 0.5], [1.0, 1.5]]],
  4541. [[[1.0, 0.5], [0.5, 1.0]]],
  4542. [[[0.5, 1.0], [1.0, 0.5]]],
  4543. [[[1.0, 1.5], [1.0, 0.5]]],
  4544. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  4545. [[[1.5, 1.0], [1.0, 0.5]]],
  4546. [[[0.5, 1.0], [1.5, 1.0]]],
  4547. [[[1.0, 1.5], [1.5, 1.0]]],
  4548. [[[0.5, 1.0], [1.0, 1.5]]],
  4549. []
  4550. ];
  4551. function contours() {
  4552. var dx = 1,
  4553. dy = 1,
  4554. threshold$$1 = thresholdSturges,
  4555. smooth = smoothLinear;
  4556. function contours(values) {
  4557. var tz = threshold$$1(values);
  4558. // Convert number of thresholds into uniform thresholds.
  4559. if (!Array.isArray(tz)) {
  4560. var domain = extent(values), start = domain[0], stop = domain[1];
  4561. tz = tickStep(start, stop, tz);
  4562. tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
  4563. } else {
  4564. tz = tz.slice().sort(ascending$2);
  4565. }
  4566. return tz.map(function(value) {
  4567. return contour(values, value);
  4568. });
  4569. }
  4570. // Accumulate, smooth contour rings, assign holes to exterior rings.
  4571. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  4572. function contour(values, value) {
  4573. var polygons = [],
  4574. holes = [];
  4575. isorings(values, value, function(ring) {
  4576. smooth(ring, values, value);
  4577. if (area(ring) > 0) polygons.push([ring]);
  4578. else holes.push(ring);
  4579. });
  4580. holes.forEach(function(hole) {
  4581. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  4582. if (contains((polygon = polygons[i])[0], hole) !== -1) {
  4583. polygon.push(hole);
  4584. return;
  4585. }
  4586. }
  4587. });
  4588. return {
  4589. type: "MultiPolygon",
  4590. value: value,
  4591. coordinates: polygons
  4592. };
  4593. }
  4594. // Marching squares with isolines stitched into rings.
  4595. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  4596. function isorings(values, value, callback) {
  4597. var fragmentByStart = new Array,
  4598. fragmentByEnd = new Array,
  4599. x, y, t0, t1, t2, t3;
  4600. // Special case for the first row (y = -1, t2 = t3 = 0).
  4601. x = y = -1;
  4602. t1 = values[0] >= value;
  4603. cases[t1 << 1].forEach(stitch);
  4604. while (++x < dx - 1) {
  4605. t0 = t1, t1 = values[x + 1] >= value;
  4606. cases[t0 | t1 << 1].forEach(stitch);
  4607. }
  4608. cases[t1 << 0].forEach(stitch);
  4609. // General case for the intermediate rows.
  4610. while (++y < dy - 1) {
  4611. x = -1;
  4612. t1 = values[y * dx + dx] >= value;
  4613. t2 = values[y * dx] >= value;
  4614. cases[t1 << 1 | t2 << 2].forEach(stitch);
  4615. while (++x < dx - 1) {
  4616. t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
  4617. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4618. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  4619. }
  4620. cases[t1 | t2 << 3].forEach(stitch);
  4621. }
  4622. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  4623. x = -1;
  4624. t2 = values[y * dx] >= value;
  4625. cases[t2 << 2].forEach(stitch);
  4626. while (++x < dx - 1) {
  4627. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4628. cases[t2 << 2 | t3 << 3].forEach(stitch);
  4629. }
  4630. cases[t2 << 3].forEach(stitch);
  4631. function stitch(line) {
  4632. var start = [line[0][0] + x, line[0][1] + y],
  4633. end = [line[1][0] + x, line[1][1] + y],
  4634. startIndex = index(start),
  4635. endIndex = index(end),
  4636. f, g;
  4637. if (f = fragmentByEnd[startIndex]) {
  4638. if (g = fragmentByStart[endIndex]) {
  4639. delete fragmentByEnd[f.end];
  4640. delete fragmentByStart[g.start];
  4641. if (f === g) {
  4642. f.ring.push(end);
  4643. callback(f.ring);
  4644. } else {
  4645. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  4646. }
  4647. } else {
  4648. delete fragmentByEnd[f.end];
  4649. f.ring.push(end);
  4650. fragmentByEnd[f.end = endIndex] = f;
  4651. }
  4652. } else if (f = fragmentByStart[endIndex]) {
  4653. if (g = fragmentByEnd[startIndex]) {
  4654. delete fragmentByStart[f.start];
  4655. delete fragmentByEnd[g.end];
  4656. if (f === g) {
  4657. f.ring.push(end);
  4658. callback(f.ring);
  4659. } else {
  4660. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  4661. }
  4662. } else {
  4663. delete fragmentByStart[f.start];
  4664. f.ring.unshift(start);
  4665. fragmentByStart[f.start = startIndex] = f;
  4666. }
  4667. } else {
  4668. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  4669. }
  4670. }
  4671. }
  4672. function index(point) {
  4673. return point[0] * 2 + point[1] * (dx + 1) * 4;
  4674. }
  4675. function smoothLinear(ring, values, value) {
  4676. ring.forEach(function(point) {
  4677. var x = point[0],
  4678. y = point[1],
  4679. xt = x | 0,
  4680. yt = y | 0,
  4681. v0,
  4682. v1 = values[yt * dx + xt];
  4683. if (x > 0 && x < dx && xt === x) {
  4684. v0 = values[yt * dx + xt - 1];
  4685. point[0] = x + (value - v0) / (v1 - v0) - 0.5;
  4686. }
  4687. if (y > 0 && y < dy && yt === y) {
  4688. v0 = values[(yt - 1) * dx + xt];
  4689. point[1] = y + (value - v0) / (v1 - v0) - 0.5;
  4690. }
  4691. });
  4692. }
  4693. contours.contour = contour;
  4694. contours.size = function(_) {
  4695. if (!arguments.length) return [dx, dy];
  4696. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4697. if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
  4698. return dx = _0, dy = _1, contours;
  4699. };
  4700. contours.thresholds = function(_) {
  4701. return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold$$1;
  4702. };
  4703. contours.smooth = function(_) {
  4704. return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
  4705. };
  4706. return contours;
  4707. }
  4708. // TODO Optimize edge cases.
  4709. // TODO Optimize index calculation.
  4710. // TODO Optimize arguments.
  4711. function blurX(source, target, r) {
  4712. var n = source.width,
  4713. m = source.height,
  4714. w = (r << 1) + 1;
  4715. for (var j = 0; j < m; ++j) {
  4716. for (var i = 0, sr = 0; i < n + r; ++i) {
  4717. if (i < n) {
  4718. sr += source.data[i + j * n];
  4719. }
  4720. if (i >= r) {
  4721. if (i >= w) {
  4722. sr -= source.data[i - w + j * n];
  4723. }
  4724. target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
  4725. }
  4726. }
  4727. }
  4728. }
  4729. // TODO Optimize edge cases.
  4730. // TODO Optimize index calculation.
  4731. // TODO Optimize arguments.
  4732. function blurY(source, target, r) {
  4733. var n = source.width,
  4734. m = source.height,
  4735. w = (r << 1) + 1;
  4736. for (var i = 0; i < n; ++i) {
  4737. for (var j = 0, sr = 0; j < m + r; ++j) {
  4738. if (j < m) {
  4739. sr += source.data[i + j * n];
  4740. }
  4741. if (j >= r) {
  4742. if (j >= w) {
  4743. sr -= source.data[i + (j - w) * n];
  4744. }
  4745. target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
  4746. }
  4747. }
  4748. }
  4749. }
  4750. function defaultX(d) {
  4751. return d[0];
  4752. }
  4753. function defaultY(d) {
  4754. return d[1];
  4755. }
  4756. function density() {
  4757. var x = defaultX,
  4758. y = defaultY,
  4759. dx = 960,
  4760. dy = 500,
  4761. r = 20, // blur radius
  4762. k = 2, // log2(grid cell size)
  4763. o = r * 3, // grid offset, to pad for blur
  4764. n = (dx + o * 2) >> k, // grid width
  4765. m = (dy + o * 2) >> k, // grid height
  4766. threshold$$1 = constant$6(20);
  4767. function density(data) {
  4768. var values0 = new Float32Array(n * m),
  4769. values1 = new Float32Array(n * m);
  4770. data.forEach(function(d, i, data) {
  4771. var xi = (x(d, i, data) + o) >> k,
  4772. yi = (y(d, i, data) + o) >> k;
  4773. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  4774. ++values0[xi + yi * n];
  4775. }
  4776. });
  4777. // TODO Optimize.
  4778. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4779. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4780. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4781. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4782. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4783. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4784. var tz = threshold$$1(values0);
  4785. // Convert number of thresholds into uniform thresholds.
  4786. if (!Array.isArray(tz)) {
  4787. var stop = max(values0);
  4788. tz = tickStep(0, stop, tz);
  4789. tz = sequence(0, Math.floor(stop / tz) * tz, tz);
  4790. tz.shift();
  4791. }
  4792. return contours()
  4793. .thresholds(tz)
  4794. .size([n, m])
  4795. (values0)
  4796. .map(transform);
  4797. }
  4798. function transform(geometry) {
  4799. geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
  4800. geometry.coordinates.forEach(transformPolygon);
  4801. return geometry;
  4802. }
  4803. function transformPolygon(coordinates) {
  4804. coordinates.forEach(transformRing);
  4805. }
  4806. function transformRing(coordinates) {
  4807. coordinates.forEach(transformPoint);
  4808. }
  4809. // TODO Optimize.
  4810. function transformPoint(coordinates) {
  4811. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  4812. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  4813. }
  4814. function resize() {
  4815. o = r * 3;
  4816. n = (dx + o * 2) >> k;
  4817. m = (dy + o * 2) >> k;
  4818. return density;
  4819. }
  4820. density.x = function(_) {
  4821. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
  4822. };
  4823. density.y = function(_) {
  4824. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
  4825. };
  4826. density.size = function(_) {
  4827. if (!arguments.length) return [dx, dy];
  4828. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4829. if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
  4830. return dx = _0, dy = _1, resize();
  4831. };
  4832. density.cellSize = function(_) {
  4833. if (!arguments.length) return 1 << k;
  4834. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  4835. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  4836. };
  4837. density.thresholds = function(_) {
  4838. return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold$$1;
  4839. };
  4840. density.bandwidth = function(_) {
  4841. if (!arguments.length) return Math.sqrt(r * (r + 1));
  4842. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  4843. return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
  4844. };
  4845. return density;
  4846. }
  4847. var EOL = {},
  4848. EOF = {},
  4849. QUOTE = 34,
  4850. NEWLINE = 10,
  4851. RETURN = 13;
  4852. function objectConverter(columns) {
  4853. return new Function("d", "return {" + columns.map(function(name, i) {
  4854. return JSON.stringify(name) + ": d[" + i + "]";
  4855. }).join(",") + "}");
  4856. }
  4857. function customConverter(columns, f) {
  4858. var object = objectConverter(columns);
  4859. return function(row, i) {
  4860. return f(object(row), i, columns);
  4861. };
  4862. }
  4863. // Compute unique columns in order of discovery.
  4864. function inferColumns(rows) {
  4865. var columnSet = Object.create(null),
  4866. columns = [];
  4867. rows.forEach(function(row) {
  4868. for (var column in row) {
  4869. if (!(column in columnSet)) {
  4870. columns.push(columnSet[column] = column);
  4871. }
  4872. }
  4873. });
  4874. return columns;
  4875. }
  4876. function dsvFormat(delimiter) {
  4877. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  4878. DELIMITER = delimiter.charCodeAt(0);
  4879. function parse(text, f) {
  4880. var convert, columns, rows = parseRows(text, function(row, i) {
  4881. if (convert) return convert(row, i - 1);
  4882. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  4883. });
  4884. rows.columns = columns || [];
  4885. return rows;
  4886. }
  4887. function parseRows(text, f) {
  4888. var rows = [], // output rows
  4889. N = text.length,
  4890. I = 0, // current character index
  4891. n = 0, // current line number
  4892. t, // current token
  4893. eof = N <= 0, // current token followed by EOF?
  4894. eol = false; // current token followed by EOL?
  4895. // Strip the trailing newline.
  4896. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  4897. if (text.charCodeAt(N - 1) === RETURN) --N;
  4898. function token() {
  4899. if (eof) return EOF;
  4900. if (eol) return eol = false, EOL;
  4901. // Unescape quotes.
  4902. var i, j = I, c;
  4903. if (text.charCodeAt(j) === QUOTE) {
  4904. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  4905. if ((i = I) >= N) eof = true;
  4906. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  4907. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4908. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  4909. }
  4910. // Find next delimiter or newline.
  4911. while (I < N) {
  4912. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  4913. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4914. else if (c !== DELIMITER) continue;
  4915. return text.slice(j, i);
  4916. }
  4917. // Return last token before EOF.
  4918. return eof = true, text.slice(j, N);
  4919. }
  4920. while ((t = token()) !== EOF) {
  4921. var row = [];
  4922. while (t !== EOL && t !== EOF) row.push(t), t = token();
  4923. if (f && (row = f(row, n++)) == null) continue;
  4924. rows.push(row);
  4925. }
  4926. return rows;
  4927. }
  4928. function format(rows, columns) {
  4929. if (columns == null) columns = inferColumns(rows);
  4930. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  4931. return columns.map(function(column) {
  4932. return formatValue(row[column]);
  4933. }).join(delimiter);
  4934. })).join("\n");
  4935. }
  4936. function formatRows(rows) {
  4937. return rows.map(formatRow).join("\n");
  4938. }
  4939. function formatRow(row) {
  4940. return row.map(formatValue).join(delimiter);
  4941. }
  4942. function formatValue(text) {
  4943. return text == null ? ""
  4944. : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
  4945. : text;
  4946. }
  4947. return {
  4948. parse: parse,
  4949. parseRows: parseRows,
  4950. format: format,
  4951. formatRows: formatRows
  4952. };
  4953. }
  4954. var csv = dsvFormat(",");
  4955. var csvParse = csv.parse;
  4956. var csvParseRows = csv.parseRows;
  4957. var csvFormat = csv.format;
  4958. var csvFormatRows = csv.formatRows;
  4959. var tsv = dsvFormat("\t");
  4960. var tsvParse = tsv.parse;
  4961. var tsvParseRows = tsv.parseRows;
  4962. var tsvFormat = tsv.format;
  4963. var tsvFormatRows = tsv.formatRows;
  4964. function responseBlob(response) {
  4965. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4966. return response.blob();
  4967. }
  4968. function blob(input, init) {
  4969. return fetch(input, init).then(responseBlob);
  4970. }
  4971. function responseArrayBuffer(response) {
  4972. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4973. return response.arrayBuffer();
  4974. }
  4975. function buffer(input, init) {
  4976. return fetch(input, init).then(responseArrayBuffer);
  4977. }
  4978. function responseText(response) {
  4979. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4980. return response.text();
  4981. }
  4982. function text(input, init) {
  4983. return fetch(input, init).then(responseText);
  4984. }
  4985. function dsvParse(parse) {
  4986. return function(input, init, row) {
  4987. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  4988. return text(input, init).then(function(response) {
  4989. return parse(response, row);
  4990. });
  4991. };
  4992. }
  4993. function dsv(delimiter, input, init, row) {
  4994. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  4995. var format = dsvFormat(delimiter);
  4996. return text(input, init).then(function(response) {
  4997. return format.parse(response, row);
  4998. });
  4999. }
  5000. var csv$1 = dsvParse(csvParse);
  5001. var tsv$1 = dsvParse(tsvParse);
  5002. function image(input, init) {
  5003. return new Promise(function(resolve, reject) {
  5004. var image = new Image;
  5005. for (var key in init) image[key] = init[key];
  5006. image.onerror = reject;
  5007. image.onload = function() { resolve(image); };
  5008. image.src = input;
  5009. });
  5010. }
  5011. function responseJson(response) {
  5012. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5013. return response.json();
  5014. }
  5015. function json(input, init) {
  5016. return fetch(input, init).then(responseJson);
  5017. }
  5018. function parser(type) {
  5019. return function(input, init) {
  5020. return text(input, init).then(function(text$$1) {
  5021. return (new DOMParser).parseFromString(text$$1, type);
  5022. });
  5023. };
  5024. }
  5025. var xml = parser("application/xml");
  5026. var html = parser("text/html");
  5027. var svg = parser("image/svg+xml");
  5028. function center$1(x, y) {
  5029. var nodes;
  5030. if (x == null) x = 0;
  5031. if (y == null) y = 0;
  5032. function force() {
  5033. var i,
  5034. n = nodes.length,
  5035. node,
  5036. sx = 0,
  5037. sy = 0;
  5038. for (i = 0; i < n; ++i) {
  5039. node = nodes[i], sx += node.x, sy += node.y;
  5040. }
  5041. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  5042. node = nodes[i], node.x -= sx, node.y -= sy;
  5043. }
  5044. }
  5045. force.initialize = function(_) {
  5046. nodes = _;
  5047. };
  5048. force.x = function(_) {
  5049. return arguments.length ? (x = +_, force) : x;
  5050. };
  5051. force.y = function(_) {
  5052. return arguments.length ? (y = +_, force) : y;
  5053. };
  5054. return force;
  5055. }
  5056. function constant$7(x) {
  5057. return function() {
  5058. return x;
  5059. };
  5060. }
  5061. function jiggle() {
  5062. return (Math.random() - 0.5) * 1e-6;
  5063. }
  5064. function tree_add(d) {
  5065. var x = +this._x.call(null, d),
  5066. y = +this._y.call(null, d);
  5067. return add(this.cover(x, y), x, y, d);
  5068. }
  5069. function add(tree, x, y, d) {
  5070. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  5071. var parent,
  5072. node = tree._root,
  5073. leaf = {data: d},
  5074. x0 = tree._x0,
  5075. y0 = tree._y0,
  5076. x1 = tree._x1,
  5077. y1 = tree._y1,
  5078. xm,
  5079. ym,
  5080. xp,
  5081. yp,
  5082. right,
  5083. bottom,
  5084. i,
  5085. j;
  5086. // If the tree is empty, initialize the root as a leaf.
  5087. if (!node) return tree._root = leaf, tree;
  5088. // Find the existing leaf for the new point, or add it.
  5089. while (node.length) {
  5090. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5091. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5092. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  5093. }
  5094. // Is the new point is exactly coincident with the existing point?
  5095. xp = +tree._x.call(null, node.data);
  5096. yp = +tree._y.call(null, node.data);
  5097. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  5098. // Otherwise, split the leaf node until the old and new point are separated.
  5099. do {
  5100. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  5101. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5102. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5103. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  5104. return parent[j] = node, parent[i] = leaf, tree;
  5105. }
  5106. function addAll(data) {
  5107. var d, i, n = data.length,
  5108. x,
  5109. y,
  5110. xz = new Array(n),
  5111. yz = new Array(n),
  5112. x0 = Infinity,
  5113. y0 = Infinity,
  5114. x1 = -Infinity,
  5115. y1 = -Infinity;
  5116. // Compute the points and their extent.
  5117. for (i = 0; i < n; ++i) {
  5118. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  5119. xz[i] = x;
  5120. yz[i] = y;
  5121. if (x < x0) x0 = x;
  5122. if (x > x1) x1 = x;
  5123. if (y < y0) y0 = y;
  5124. if (y > y1) y1 = y;
  5125. }
  5126. // If there were no (valid) points, inherit the existing extent.
  5127. if (x1 < x0) x0 = this._x0, x1 = this._x1;
  5128. if (y1 < y0) y0 = this._y0, y1 = this._y1;
  5129. // Expand the tree to cover the new points.
  5130. this.cover(x0, y0).cover(x1, y1);
  5131. // Add the new points.
  5132. for (i = 0; i < n; ++i) {
  5133. add(this, xz[i], yz[i], data[i]);
  5134. }
  5135. return this;
  5136. }
  5137. function tree_cover(x, y) {
  5138. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  5139. var x0 = this._x0,
  5140. y0 = this._y0,
  5141. x1 = this._x1,
  5142. y1 = this._y1;
  5143. // If the quadtree has no extent, initialize them.
  5144. // Integer extent are necessary so that if we later double the extent,
  5145. // the existing quadrant boundaries don’t change due to floating point error!
  5146. if (isNaN(x0)) {
  5147. x1 = (x0 = Math.floor(x)) + 1;
  5148. y1 = (y0 = Math.floor(y)) + 1;
  5149. }
  5150. // Otherwise, double repeatedly to cover.
  5151. else if (x0 > x || x > x1 || y0 > y || y > y1) {
  5152. var z = x1 - x0,
  5153. node = this._root,
  5154. parent,
  5155. i;
  5156. switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
  5157. case 0: {
  5158. do parent = new Array(4), parent[i] = node, node = parent;
  5159. while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
  5160. break;
  5161. }
  5162. case 1: {
  5163. do parent = new Array(4), parent[i] = node, node = parent;
  5164. while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
  5165. break;
  5166. }
  5167. case 2: {
  5168. do parent = new Array(4), parent[i] = node, node = parent;
  5169. while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
  5170. break;
  5171. }
  5172. case 3: {
  5173. do parent = new Array(4), parent[i] = node, node = parent;
  5174. while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
  5175. break;
  5176. }
  5177. }
  5178. if (this._root && this._root.length) this._root = node;
  5179. }
  5180. // If the quadtree covers the point already, just return.
  5181. else return this;
  5182. this._x0 = x0;
  5183. this._y0 = y0;
  5184. this._x1 = x1;
  5185. this._y1 = y1;
  5186. return this;
  5187. }
  5188. function tree_data() {
  5189. var data = [];
  5190. this.visit(function(node) {
  5191. if (!node.length) do data.push(node.data); while (node = node.next)
  5192. });
  5193. return data;
  5194. }
  5195. function tree_extent(_) {
  5196. return arguments.length
  5197. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  5198. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  5199. }
  5200. function Quad(node, x0, y0, x1, y1) {
  5201. this.node = node;
  5202. this.x0 = x0;
  5203. this.y0 = y0;
  5204. this.x1 = x1;
  5205. this.y1 = y1;
  5206. }
  5207. function tree_find(x, y, radius) {
  5208. var data,
  5209. x0 = this._x0,
  5210. y0 = this._y0,
  5211. x1,
  5212. y1,
  5213. x2,
  5214. y2,
  5215. x3 = this._x1,
  5216. y3 = this._y1,
  5217. quads = [],
  5218. node = this._root,
  5219. q,
  5220. i;
  5221. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  5222. if (radius == null) radius = Infinity;
  5223. else {
  5224. x0 = x - radius, y0 = y - radius;
  5225. x3 = x + radius, y3 = y + radius;
  5226. radius *= radius;
  5227. }
  5228. while (q = quads.pop()) {
  5229. // Stop searching if this quadrant can’t contain a closer node.
  5230. if (!(node = q.node)
  5231. || (x1 = q.x0) > x3
  5232. || (y1 = q.y0) > y3
  5233. || (x2 = q.x1) < x0
  5234. || (y2 = q.y1) < y0) continue;
  5235. // Bisect the current quadrant.
  5236. if (node.length) {
  5237. var xm = (x1 + x2) / 2,
  5238. ym = (y1 + y2) / 2;
  5239. quads.push(
  5240. new Quad(node[3], xm, ym, x2, y2),
  5241. new Quad(node[2], x1, ym, xm, y2),
  5242. new Quad(node[1], xm, y1, x2, ym),
  5243. new Quad(node[0], x1, y1, xm, ym)
  5244. );
  5245. // Visit the closest quadrant first.
  5246. if (i = (y >= ym) << 1 | (x >= xm)) {
  5247. q = quads[quads.length - 1];
  5248. quads[quads.length - 1] = quads[quads.length - 1 - i];
  5249. quads[quads.length - 1 - i] = q;
  5250. }
  5251. }
  5252. // Visit this point. (Visiting coincident points isn’t necessary!)
  5253. else {
  5254. var dx = x - +this._x.call(null, node.data),
  5255. dy = y - +this._y.call(null, node.data),
  5256. d2 = dx * dx + dy * dy;
  5257. if (d2 < radius) {
  5258. var d = Math.sqrt(radius = d2);
  5259. x0 = x - d, y0 = y - d;
  5260. x3 = x + d, y3 = y + d;
  5261. data = node.data;
  5262. }
  5263. }
  5264. }
  5265. return data;
  5266. }
  5267. function tree_remove(d) {
  5268. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  5269. var parent,
  5270. node = this._root,
  5271. retainer,
  5272. previous,
  5273. next,
  5274. x0 = this._x0,
  5275. y0 = this._y0,
  5276. x1 = this._x1,
  5277. y1 = this._y1,
  5278. x,
  5279. y,
  5280. xm,
  5281. ym,
  5282. right,
  5283. bottom,
  5284. i,
  5285. j;
  5286. // If the tree is empty, initialize the root as a leaf.
  5287. if (!node) return this;
  5288. // Find the leaf node for the point.
  5289. // While descending, also retain the deepest parent with a non-removed sibling.
  5290. if (node.length) while (true) {
  5291. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5292. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5293. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  5294. if (!node.length) break;
  5295. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  5296. }
  5297. // Find the point to remove.
  5298. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  5299. if (next = node.next) delete node.next;
  5300. // If there are multiple coincident points, remove just the point.
  5301. if (previous) return next ? previous.next = next : delete previous.next, this;
  5302. // If this is the root point, remove it.
  5303. if (!parent) return this._root = next, this;
  5304. // Remove this leaf.
  5305. next ? parent[i] = next : delete parent[i];
  5306. // If the parent now contains exactly one leaf, collapse superfluous parents.
  5307. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  5308. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  5309. && !node.length) {
  5310. if (retainer) retainer[j] = node;
  5311. else this._root = node;
  5312. }
  5313. return this;
  5314. }
  5315. function removeAll(data) {
  5316. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  5317. return this;
  5318. }
  5319. function tree_root() {
  5320. return this._root;
  5321. }
  5322. function tree_size() {
  5323. var size = 0;
  5324. this.visit(function(node) {
  5325. if (!node.length) do ++size; while (node = node.next)
  5326. });
  5327. return size;
  5328. }
  5329. function tree_visit(callback) {
  5330. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  5331. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  5332. while (q = quads.pop()) {
  5333. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  5334. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5335. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5336. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5337. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5338. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5339. }
  5340. }
  5341. return this;
  5342. }
  5343. function tree_visitAfter(callback) {
  5344. var quads = [], next = [], q;
  5345. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  5346. while (q = quads.pop()) {
  5347. var node = q.node;
  5348. if (node.length) {
  5349. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5350. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5351. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5352. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5353. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5354. }
  5355. next.push(q);
  5356. }
  5357. while (q = next.pop()) {
  5358. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  5359. }
  5360. return this;
  5361. }
  5362. function defaultX$1(d) {
  5363. return d[0];
  5364. }
  5365. function tree_x(_) {
  5366. return arguments.length ? (this._x = _, this) : this._x;
  5367. }
  5368. function defaultY$1(d) {
  5369. return d[1];
  5370. }
  5371. function tree_y(_) {
  5372. return arguments.length ? (this._y = _, this) : this._y;
  5373. }
  5374. function quadtree(nodes, x, y) {
  5375. var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
  5376. return nodes == null ? tree : tree.addAll(nodes);
  5377. }
  5378. function Quadtree(x, y, x0, y0, x1, y1) {
  5379. this._x = x;
  5380. this._y = y;
  5381. this._x0 = x0;
  5382. this._y0 = y0;
  5383. this._x1 = x1;
  5384. this._y1 = y1;
  5385. this._root = undefined;
  5386. }
  5387. function leaf_copy(leaf) {
  5388. var copy = {data: leaf.data}, next = copy;
  5389. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  5390. return copy;
  5391. }
  5392. var treeProto = quadtree.prototype = Quadtree.prototype;
  5393. treeProto.copy = function() {
  5394. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  5395. node = this._root,
  5396. nodes,
  5397. child;
  5398. if (!node) return copy;
  5399. if (!node.length) return copy._root = leaf_copy(node), copy;
  5400. nodes = [{source: node, target: copy._root = new Array(4)}];
  5401. while (node = nodes.pop()) {
  5402. for (var i = 0; i < 4; ++i) {
  5403. if (child = node.source[i]) {
  5404. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  5405. else node.target[i] = leaf_copy(child);
  5406. }
  5407. }
  5408. }
  5409. return copy;
  5410. };
  5411. treeProto.add = tree_add;
  5412. treeProto.addAll = addAll;
  5413. treeProto.cover = tree_cover;
  5414. treeProto.data = tree_data;
  5415. treeProto.extent = tree_extent;
  5416. treeProto.find = tree_find;
  5417. treeProto.remove = tree_remove;
  5418. treeProto.removeAll = removeAll;
  5419. treeProto.root = tree_root;
  5420. treeProto.size = tree_size;
  5421. treeProto.visit = tree_visit;
  5422. treeProto.visitAfter = tree_visitAfter;
  5423. treeProto.x = tree_x;
  5424. treeProto.y = tree_y;
  5425. function x(d) {
  5426. return d.x + d.vx;
  5427. }
  5428. function y(d) {
  5429. return d.y + d.vy;
  5430. }
  5431. function collide(radius) {
  5432. var nodes,
  5433. radii,
  5434. strength = 1,
  5435. iterations = 1;
  5436. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  5437. function force() {
  5438. var i, n = nodes.length,
  5439. tree,
  5440. node,
  5441. xi,
  5442. yi,
  5443. ri,
  5444. ri2;
  5445. for (var k = 0; k < iterations; ++k) {
  5446. tree = quadtree(nodes, x, y).visitAfter(prepare);
  5447. for (i = 0; i < n; ++i) {
  5448. node = nodes[i];
  5449. ri = radii[node.index], ri2 = ri * ri;
  5450. xi = node.x + node.vx;
  5451. yi = node.y + node.vy;
  5452. tree.visit(apply);
  5453. }
  5454. }
  5455. function apply(quad, x0, y0, x1, y1) {
  5456. var data = quad.data, rj = quad.r, r = ri + rj;
  5457. if (data) {
  5458. if (data.index > node.index) {
  5459. var x = xi - data.x - data.vx,
  5460. y = yi - data.y - data.vy,
  5461. l = x * x + y * y;
  5462. if (l < r * r) {
  5463. if (x === 0) x = jiggle(), l += x * x;
  5464. if (y === 0) y = jiggle(), l += y * y;
  5465. l = (r - (l = Math.sqrt(l))) / l * strength;
  5466. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5467. node.vy += (y *= l) * r;
  5468. data.vx -= x * (r = 1 - r);
  5469. data.vy -= y * r;
  5470. }
  5471. }
  5472. return;
  5473. }
  5474. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5475. }
  5476. }
  5477. function prepare(quad) {
  5478. if (quad.data) return quad.r = radii[quad.data.index];
  5479. for (var i = quad.r = 0; i < 4; ++i) {
  5480. if (quad[i] && quad[i].r > quad.r) {
  5481. quad.r = quad[i].r;
  5482. }
  5483. }
  5484. }
  5485. function initialize() {
  5486. if (!nodes) return;
  5487. var i, n = nodes.length, node;
  5488. radii = new Array(n);
  5489. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5490. }
  5491. force.initialize = function(_) {
  5492. nodes = _;
  5493. initialize();
  5494. };
  5495. force.iterations = function(_) {
  5496. return arguments.length ? (iterations = +_, force) : iterations;
  5497. };
  5498. force.strength = function(_) {
  5499. return arguments.length ? (strength = +_, force) : strength;
  5500. };
  5501. force.radius = function(_) {
  5502. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5503. };
  5504. return force;
  5505. }
  5506. function index(d) {
  5507. return d.index;
  5508. }
  5509. function find(nodeById, nodeId) {
  5510. var node = nodeById.get(nodeId);
  5511. if (!node) throw new Error("missing: " + nodeId);
  5512. return node;
  5513. }
  5514. function link(links) {
  5515. var id = index,
  5516. strength = defaultStrength,
  5517. strengths,
  5518. distance = constant$7(30),
  5519. distances,
  5520. nodes,
  5521. count,
  5522. bias,
  5523. iterations = 1;
  5524. if (links == null) links = [];
  5525. function defaultStrength(link) {
  5526. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5527. }
  5528. function force(alpha) {
  5529. for (var k = 0, n = links.length; k < iterations; ++k) {
  5530. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5531. link = links[i], source = link.source, target = link.target;
  5532. x = target.x + target.vx - source.x - source.vx || jiggle();
  5533. y = target.y + target.vy - source.y - source.vy || jiggle();
  5534. l = Math.sqrt(x * x + y * y);
  5535. l = (l - distances[i]) / l * alpha * strengths[i];
  5536. x *= l, y *= l;
  5537. target.vx -= x * (b = bias[i]);
  5538. target.vy -= y * b;
  5539. source.vx += x * (b = 1 - b);
  5540. source.vy += y * b;
  5541. }
  5542. }
  5543. }
  5544. function initialize() {
  5545. if (!nodes) return;
  5546. var i,
  5547. n = nodes.length,
  5548. m = links.length,
  5549. nodeById = map$1(nodes, id),
  5550. link;
  5551. for (i = 0, count = new Array(n); i < m; ++i) {
  5552. link = links[i], link.index = i;
  5553. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5554. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5555. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5556. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5557. }
  5558. for (i = 0, bias = new Array(m); i < m; ++i) {
  5559. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5560. }
  5561. strengths = new Array(m), initializeStrength();
  5562. distances = new Array(m), initializeDistance();
  5563. }
  5564. function initializeStrength() {
  5565. if (!nodes) return;
  5566. for (var i = 0, n = links.length; i < n; ++i) {
  5567. strengths[i] = +strength(links[i], i, links);
  5568. }
  5569. }
  5570. function initializeDistance() {
  5571. if (!nodes) return;
  5572. for (var i = 0, n = links.length; i < n; ++i) {
  5573. distances[i] = +distance(links[i], i, links);
  5574. }
  5575. }
  5576. force.initialize = function(_) {
  5577. nodes = _;
  5578. initialize();
  5579. };
  5580. force.links = function(_) {
  5581. return arguments.length ? (links = _, initialize(), force) : links;
  5582. };
  5583. force.id = function(_) {
  5584. return arguments.length ? (id = _, force) : id;
  5585. };
  5586. force.iterations = function(_) {
  5587. return arguments.length ? (iterations = +_, force) : iterations;
  5588. };
  5589. force.strength = function(_) {
  5590. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  5591. };
  5592. force.distance = function(_) {
  5593. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  5594. };
  5595. return force;
  5596. }
  5597. function x$1(d) {
  5598. return d.x;
  5599. }
  5600. function y$1(d) {
  5601. return d.y;
  5602. }
  5603. var initialRadius = 10,
  5604. initialAngle = Math.PI * (3 - Math.sqrt(5));
  5605. function simulation(nodes) {
  5606. var simulation,
  5607. alpha = 1,
  5608. alphaMin = 0.001,
  5609. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5610. alphaTarget = 0,
  5611. velocityDecay = 0.6,
  5612. forces = map$1(),
  5613. stepper = timer(step),
  5614. event = dispatch("tick", "end");
  5615. if (nodes == null) nodes = [];
  5616. function step() {
  5617. tick();
  5618. event.call("tick", simulation);
  5619. if (alpha < alphaMin) {
  5620. stepper.stop();
  5621. event.call("end", simulation);
  5622. }
  5623. }
  5624. function tick() {
  5625. var i, n = nodes.length, node;
  5626. alpha += (alphaTarget - alpha) * alphaDecay;
  5627. forces.each(function(force) {
  5628. force(alpha);
  5629. });
  5630. for (i = 0; i < n; ++i) {
  5631. node = nodes[i];
  5632. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5633. else node.x = node.fx, node.vx = 0;
  5634. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5635. else node.y = node.fy, node.vy = 0;
  5636. }
  5637. }
  5638. function initializeNodes() {
  5639. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5640. node = nodes[i], node.index = i;
  5641. if (isNaN(node.x) || isNaN(node.y)) {
  5642. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5643. node.x = radius * Math.cos(angle);
  5644. node.y = radius * Math.sin(angle);
  5645. }
  5646. if (isNaN(node.vx) || isNaN(node.vy)) {
  5647. node.vx = node.vy = 0;
  5648. }
  5649. }
  5650. }
  5651. function initializeForce(force) {
  5652. if (force.initialize) force.initialize(nodes);
  5653. return force;
  5654. }
  5655. initializeNodes();
  5656. return simulation = {
  5657. tick: tick,
  5658. restart: function() {
  5659. return stepper.restart(step), simulation;
  5660. },
  5661. stop: function() {
  5662. return stepper.stop(), simulation;
  5663. },
  5664. nodes: function(_) {
  5665. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5666. },
  5667. alpha: function(_) {
  5668. return arguments.length ? (alpha = +_, simulation) : alpha;
  5669. },
  5670. alphaMin: function(_) {
  5671. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5672. },
  5673. alphaDecay: function(_) {
  5674. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5675. },
  5676. alphaTarget: function(_) {
  5677. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5678. },
  5679. velocityDecay: function(_) {
  5680. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5681. },
  5682. force: function(name, _) {
  5683. return arguments.length > 1 ? (_ == null ? forces.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
  5684. },
  5685. find: function(x, y, radius) {
  5686. var i = 0,
  5687. n = nodes.length,
  5688. dx,
  5689. dy,
  5690. d2,
  5691. node,
  5692. closest;
  5693. if (radius == null) radius = Infinity;
  5694. else radius *= radius;
  5695. for (i = 0; i < n; ++i) {
  5696. node = nodes[i];
  5697. dx = x - node.x;
  5698. dy = y - node.y;
  5699. d2 = dx * dx + dy * dy;
  5700. if (d2 < radius) closest = node, radius = d2;
  5701. }
  5702. return closest;
  5703. },
  5704. on: function(name, _) {
  5705. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5706. }
  5707. };
  5708. }
  5709. function manyBody() {
  5710. var nodes,
  5711. node,
  5712. alpha,
  5713. strength = constant$7(-30),
  5714. strengths,
  5715. distanceMin2 = 1,
  5716. distanceMax2 = Infinity,
  5717. theta2 = 0.81;
  5718. function force(_) {
  5719. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5720. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5721. }
  5722. function initialize() {
  5723. if (!nodes) return;
  5724. var i, n = nodes.length, node;
  5725. strengths = new Array(n);
  5726. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5727. }
  5728. function accumulate(quad) {
  5729. var strength = 0, q, c, weight = 0, x, y, i;
  5730. // For internal nodes, accumulate forces from child quadrants.
  5731. if (quad.length) {
  5732. for (x = y = i = 0; i < 4; ++i) {
  5733. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5734. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5735. }
  5736. }
  5737. quad.x = x / weight;
  5738. quad.y = y / weight;
  5739. }
  5740. // For leaf nodes, accumulate forces from coincident quadrants.
  5741. else {
  5742. q = quad;
  5743. q.x = q.data.x;
  5744. q.y = q.data.y;
  5745. do strength += strengths[q.data.index];
  5746. while (q = q.next);
  5747. }
  5748. quad.value = strength;
  5749. }
  5750. function apply(quad, x1, _, x2) {
  5751. if (!quad.value) return true;
  5752. var x = quad.x - node.x,
  5753. y = quad.y - node.y,
  5754. w = x2 - x1,
  5755. l = x * x + y * y;
  5756. // Apply the Barnes-Hut approximation if possible.
  5757. // Limit forces for very close nodes; randomize direction if coincident.
  5758. if (w * w / theta2 < l) {
  5759. if (l < distanceMax2) {
  5760. if (x === 0) x = jiggle(), l += x * x;
  5761. if (y === 0) y = jiggle(), l += y * y;
  5762. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5763. node.vx += x * quad.value * alpha / l;
  5764. node.vy += y * quad.value * alpha / l;
  5765. }
  5766. return true;
  5767. }
  5768. // Otherwise, process points directly.
  5769. else if (quad.length || l >= distanceMax2) return;
  5770. // Limit forces for very close nodes; randomize direction if coincident.
  5771. if (quad.data !== node || quad.next) {
  5772. if (x === 0) x = jiggle(), l += x * x;
  5773. if (y === 0) y = jiggle(), l += y * y;
  5774. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5775. }
  5776. do if (quad.data !== node) {
  5777. w = strengths[quad.data.index] * alpha / l;
  5778. node.vx += x * w;
  5779. node.vy += y * w;
  5780. } while (quad = quad.next);
  5781. }
  5782. force.initialize = function(_) {
  5783. nodes = _;
  5784. initialize();
  5785. };
  5786. force.strength = function(_) {
  5787. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5788. };
  5789. force.distanceMin = function(_) {
  5790. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5791. };
  5792. force.distanceMax = function(_) {
  5793. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5794. };
  5795. force.theta = function(_) {
  5796. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  5797. };
  5798. return force;
  5799. }
  5800. function radial(radius, x, y) {
  5801. var nodes,
  5802. strength = constant$7(0.1),
  5803. strengths,
  5804. radiuses;
  5805. if (typeof radius !== "function") radius = constant$7(+radius);
  5806. if (x == null) x = 0;
  5807. if (y == null) y = 0;
  5808. function force(alpha) {
  5809. for (var i = 0, n = nodes.length; i < n; ++i) {
  5810. var node = nodes[i],
  5811. dx = node.x - x || 1e-6,
  5812. dy = node.y - y || 1e-6,
  5813. r = Math.sqrt(dx * dx + dy * dy),
  5814. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  5815. node.vx += dx * k;
  5816. node.vy += dy * k;
  5817. }
  5818. }
  5819. function initialize() {
  5820. if (!nodes) return;
  5821. var i, n = nodes.length;
  5822. strengths = new Array(n);
  5823. radiuses = new Array(n);
  5824. for (i = 0; i < n; ++i) {
  5825. radiuses[i] = +radius(nodes[i], i, nodes);
  5826. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  5827. }
  5828. }
  5829. force.initialize = function(_) {
  5830. nodes = _, initialize();
  5831. };
  5832. force.strength = function(_) {
  5833. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5834. };
  5835. force.radius = function(_) {
  5836. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5837. };
  5838. force.x = function(_) {
  5839. return arguments.length ? (x = +_, force) : x;
  5840. };
  5841. force.y = function(_) {
  5842. return arguments.length ? (y = +_, force) : y;
  5843. };
  5844. return force;
  5845. }
  5846. function x$2(x) {
  5847. var strength = constant$7(0.1),
  5848. nodes,
  5849. strengths,
  5850. xz;
  5851. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  5852. function force(alpha) {
  5853. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5854. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  5855. }
  5856. }
  5857. function initialize() {
  5858. if (!nodes) return;
  5859. var i, n = nodes.length;
  5860. strengths = new Array(n);
  5861. xz = new Array(n);
  5862. for (i = 0; i < n; ++i) {
  5863. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5864. }
  5865. }
  5866. force.initialize = function(_) {
  5867. nodes = _;
  5868. initialize();
  5869. };
  5870. force.strength = function(_) {
  5871. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5872. };
  5873. force.x = function(_) {
  5874. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  5875. };
  5876. return force;
  5877. }
  5878. function y$2(y) {
  5879. var strength = constant$7(0.1),
  5880. nodes,
  5881. strengths,
  5882. yz;
  5883. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  5884. function force(alpha) {
  5885. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5886. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  5887. }
  5888. }
  5889. function initialize() {
  5890. if (!nodes) return;
  5891. var i, n = nodes.length;
  5892. strengths = new Array(n);
  5893. yz = new Array(n);
  5894. for (i = 0; i < n; ++i) {
  5895. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5896. }
  5897. }
  5898. force.initialize = function(_) {
  5899. nodes = _;
  5900. initialize();
  5901. };
  5902. force.strength = function(_) {
  5903. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5904. };
  5905. force.y = function(_) {
  5906. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  5907. };
  5908. return force;
  5909. }
  5910. // Computes the decimal coefficient and exponent of the specified number x with
  5911. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  5912. // For example, formatDecimal(1.23) returns ["123", 0].
  5913. function formatDecimal(x, p) {
  5914. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  5915. var i, coefficient = x.slice(0, i);
  5916. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  5917. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  5918. return [
  5919. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  5920. +x.slice(i + 1)
  5921. ];
  5922. }
  5923. function exponent$1(x) {
  5924. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  5925. }
  5926. function formatGroup(grouping, thousands) {
  5927. return function(value, width) {
  5928. var i = value.length,
  5929. t = [],
  5930. j = 0,
  5931. g = grouping[0],
  5932. length = 0;
  5933. while (i > 0 && g > 0) {
  5934. if (length + g + 1 > width) g = Math.max(1, width - length);
  5935. t.push(value.substring(i -= g, i + g));
  5936. if ((length += g + 1) > width) break;
  5937. g = grouping[j = (j + 1) % grouping.length];
  5938. }
  5939. return t.reverse().join(thousands);
  5940. };
  5941. }
  5942. function formatNumerals(numerals) {
  5943. return function(value) {
  5944. return value.replace(/[0-9]/g, function(i) {
  5945. return numerals[+i];
  5946. });
  5947. };
  5948. }
  5949. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  5950. var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  5951. function formatSpecifier(specifier) {
  5952. return new FormatSpecifier(specifier);
  5953. }
  5954. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  5955. function FormatSpecifier(specifier) {
  5956. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  5957. var match;
  5958. this.fill = match[1] || " ";
  5959. this.align = match[2] || ">";
  5960. this.sign = match[3] || "-";
  5961. this.symbol = match[4] || "";
  5962. this.zero = !!match[5];
  5963. this.width = match[6] && +match[6];
  5964. this.comma = !!match[7];
  5965. this.precision = match[8] && +match[8].slice(1);
  5966. this.trim = !!match[9];
  5967. this.type = match[10] || "";
  5968. }
  5969. FormatSpecifier.prototype.toString = function() {
  5970. return this.fill
  5971. + this.align
  5972. + this.sign
  5973. + this.symbol
  5974. + (this.zero ? "0" : "")
  5975. + (this.width == null ? "" : Math.max(1, this.width | 0))
  5976. + (this.comma ? "," : "")
  5977. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  5978. + (this.trim ? "~" : "")
  5979. + this.type;
  5980. };
  5981. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  5982. function formatTrim(s) {
  5983. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  5984. switch (s[i]) {
  5985. case ".": i0 = i1 = i; break;
  5986. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  5987. default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
  5988. }
  5989. }
  5990. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  5991. }
  5992. var prefixExponent;
  5993. function formatPrefixAuto(x, p) {
  5994. var d = formatDecimal(x, p);
  5995. if (!d) return x + "";
  5996. var coefficient = d[0],
  5997. exponent = d[1],
  5998. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  5999. n = coefficient.length;
  6000. return i === n ? coefficient
  6001. : i > n ? coefficient + new Array(i - n + 1).join("0")
  6002. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  6003. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  6004. }
  6005. function formatRounded(x, p) {
  6006. var d = formatDecimal(x, p);
  6007. if (!d) return x + "";
  6008. var coefficient = d[0],
  6009. exponent = d[1];
  6010. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  6011. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  6012. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  6013. }
  6014. var formatTypes = {
  6015. "%": function(x, p) { return (x * 100).toFixed(p); },
  6016. "b": function(x) { return Math.round(x).toString(2); },
  6017. "c": function(x) { return x + ""; },
  6018. "d": function(x) { return Math.round(x).toString(10); },
  6019. "e": function(x, p) { return x.toExponential(p); },
  6020. "f": function(x, p) { return x.toFixed(p); },
  6021. "g": function(x, p) { return x.toPrecision(p); },
  6022. "o": function(x) { return Math.round(x).toString(8); },
  6023. "p": function(x, p) { return formatRounded(x * 100, p); },
  6024. "r": formatRounded,
  6025. "s": formatPrefixAuto,
  6026. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  6027. "x": function(x) { return Math.round(x).toString(16); }
  6028. };
  6029. function identity$3(x) {
  6030. return x;
  6031. }
  6032. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  6033. function formatLocale(locale) {
  6034. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  6035. currency = locale.currency,
  6036. decimal = locale.decimal,
  6037. numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
  6038. percent = locale.percent || "%";
  6039. function newFormat(specifier) {
  6040. specifier = formatSpecifier(specifier);
  6041. var fill = specifier.fill,
  6042. align = specifier.align,
  6043. sign = specifier.sign,
  6044. symbol = specifier.symbol,
  6045. zero = specifier.zero,
  6046. width = specifier.width,
  6047. comma = specifier.comma,
  6048. precision = specifier.precision,
  6049. trim = specifier.trim,
  6050. type = specifier.type;
  6051. // The "n" type is an alias for ",g".
  6052. if (type === "n") comma = true, type = "g";
  6053. // The "" type, and any invalid type, is an alias for ".12~g".
  6054. else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
  6055. // If zero fill is specified, padding goes after sign and before digits.
  6056. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  6057. // Compute the prefix and suffix.
  6058. // For SI-prefix, the suffix is lazily computed.
  6059. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  6060. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
  6061. // What format function should we use?
  6062. // Is this an integer type?
  6063. // Can this type generate exponential notation?
  6064. var formatType = formatTypes[type],
  6065. maybeSuffix = /[defgprs%]/.test(type);
  6066. // Set the default precision if not specified,
  6067. // or clamp the specified precision to the supported range.
  6068. // For significant precision, it must be in [1, 21].
  6069. // For fixed precision, it must be in [0, 20].
  6070. precision = precision == null ? 6
  6071. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  6072. : Math.max(0, Math.min(20, precision));
  6073. function format(value) {
  6074. var valuePrefix = prefix,
  6075. valueSuffix = suffix,
  6076. i, n, c;
  6077. if (type === "c") {
  6078. valueSuffix = formatType(value) + valueSuffix;
  6079. value = "";
  6080. } else {
  6081. value = +value;
  6082. // Perform the initial formatting.
  6083. var valueNegative = value < 0;
  6084. value = formatType(Math.abs(value), precision);
  6085. // Trim insignificant zeros.
  6086. if (trim) value = formatTrim(value);
  6087. // If a negative value rounds to zero during formatting, treat as positive.
  6088. if (valueNegative && +value === 0) valueNegative = false;
  6089. // Compute the prefix and suffix.
  6090. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  6091. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  6092. // Break the formatted value into the integer “value” part that can be
  6093. // grouped, and fractional or exponential “suffix” part that is not.
  6094. if (maybeSuffix) {
  6095. i = -1, n = value.length;
  6096. while (++i < n) {
  6097. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  6098. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  6099. value = value.slice(0, i);
  6100. break;
  6101. }
  6102. }
  6103. }
  6104. }
  6105. // If the fill character is not "0", grouping is applied before padding.
  6106. if (comma && !zero) value = group(value, Infinity);
  6107. // Compute the padding.
  6108. var length = valuePrefix.length + value.length + valueSuffix.length,
  6109. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  6110. // If the fill character is "0", grouping is applied after padding.
  6111. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  6112. // Reconstruct the final output based on the desired alignment.
  6113. switch (align) {
  6114. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  6115. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  6116. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  6117. default: value = padding + valuePrefix + value + valueSuffix; break;
  6118. }
  6119. return numerals(value);
  6120. }
  6121. format.toString = function() {
  6122. return specifier + "";
  6123. };
  6124. return format;
  6125. }
  6126. function formatPrefix(specifier, value) {
  6127. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  6128. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  6129. k = Math.pow(10, -e),
  6130. prefix = prefixes[8 + e / 3];
  6131. return function(value) {
  6132. return f(k * value) + prefix;
  6133. };
  6134. }
  6135. return {
  6136. format: newFormat,
  6137. formatPrefix: formatPrefix
  6138. };
  6139. }
  6140. var locale;
  6141. defaultLocale({
  6142. decimal: ".",
  6143. thousands: ",",
  6144. grouping: [3],
  6145. currency: ["$", ""]
  6146. });
  6147. function defaultLocale(definition) {
  6148. locale = formatLocale(definition);
  6149. exports.format = locale.format;
  6150. exports.formatPrefix = locale.formatPrefix;
  6151. return locale;
  6152. }
  6153. function precisionFixed(step) {
  6154. return Math.max(0, -exponent$1(Math.abs(step)));
  6155. }
  6156. function precisionPrefix(step, value) {
  6157. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  6158. }
  6159. function precisionRound(step, max) {
  6160. step = Math.abs(step), max = Math.abs(max) - step;
  6161. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  6162. }
  6163. // Adds floating point numbers with twice the normal precision.
  6164. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  6165. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  6166. // 305–363 (1997).
  6167. // Code adapted from GeographicLib by Charles F. F. Karney,
  6168. // http://geographiclib.sourceforge.net/
  6169. function adder() {
  6170. return new Adder;
  6171. }
  6172. function Adder() {
  6173. this.reset();
  6174. }
  6175. Adder.prototype = {
  6176. constructor: Adder,
  6177. reset: function() {
  6178. this.s = // rounded value
  6179. this.t = 0; // exact error
  6180. },
  6181. add: function(y) {
  6182. add$1(temp, y, this.t);
  6183. add$1(this, temp.s, this.s);
  6184. if (this.s) this.t += temp.t;
  6185. else this.s = temp.t;
  6186. },
  6187. valueOf: function() {
  6188. return this.s;
  6189. }
  6190. };
  6191. var temp = new Adder;
  6192. function add$1(adder, a, b) {
  6193. var x = adder.s = a + b,
  6194. bv = x - a,
  6195. av = x - bv;
  6196. adder.t = (a - av) + (b - bv);
  6197. }
  6198. var epsilon$2 = 1e-6;
  6199. var epsilon2$1 = 1e-12;
  6200. var pi$3 = Math.PI;
  6201. var halfPi$2 = pi$3 / 2;
  6202. var quarterPi = pi$3 / 4;
  6203. var tau$3 = pi$3 * 2;
  6204. var degrees$1 = 180 / pi$3;
  6205. var radians = pi$3 / 180;
  6206. var abs = Math.abs;
  6207. var atan = Math.atan;
  6208. var atan2 = Math.atan2;
  6209. var cos$1 = Math.cos;
  6210. var ceil = Math.ceil;
  6211. var exp = Math.exp;
  6212. var log = Math.log;
  6213. var pow = Math.pow;
  6214. var sin$1 = Math.sin;
  6215. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  6216. var sqrt = Math.sqrt;
  6217. var tan = Math.tan;
  6218. function acos(x) {
  6219. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  6220. }
  6221. function asin(x) {
  6222. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  6223. }
  6224. function haversin(x) {
  6225. return (x = sin$1(x / 2)) * x;
  6226. }
  6227. function noop$2() {}
  6228. function streamGeometry(geometry, stream) {
  6229. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  6230. streamGeometryType[geometry.type](geometry, stream);
  6231. }
  6232. }
  6233. var streamObjectType = {
  6234. Feature: function(object, stream) {
  6235. streamGeometry(object.geometry, stream);
  6236. },
  6237. FeatureCollection: function(object, stream) {
  6238. var features = object.features, i = -1, n = features.length;
  6239. while (++i < n) streamGeometry(features[i].geometry, stream);
  6240. }
  6241. };
  6242. var streamGeometryType = {
  6243. Sphere: function(object, stream) {
  6244. stream.sphere();
  6245. },
  6246. Point: function(object, stream) {
  6247. object = object.coordinates;
  6248. stream.point(object[0], object[1], object[2]);
  6249. },
  6250. MultiPoint: function(object, stream) {
  6251. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6252. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  6253. },
  6254. LineString: function(object, stream) {
  6255. streamLine(object.coordinates, stream, 0);
  6256. },
  6257. MultiLineString: function(object, stream) {
  6258. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6259. while (++i < n) streamLine(coordinates[i], stream, 0);
  6260. },
  6261. Polygon: function(object, stream) {
  6262. streamPolygon(object.coordinates, stream);
  6263. },
  6264. MultiPolygon: function(object, stream) {
  6265. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6266. while (++i < n) streamPolygon(coordinates[i], stream);
  6267. },
  6268. GeometryCollection: function(object, stream) {
  6269. var geometries = object.geometries, i = -1, n = geometries.length;
  6270. while (++i < n) streamGeometry(geometries[i], stream);
  6271. }
  6272. };
  6273. function streamLine(coordinates, stream, closed) {
  6274. var i = -1, n = coordinates.length - closed, coordinate;
  6275. stream.lineStart();
  6276. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  6277. stream.lineEnd();
  6278. }
  6279. function streamPolygon(coordinates, stream) {
  6280. var i = -1, n = coordinates.length;
  6281. stream.polygonStart();
  6282. while (++i < n) streamLine(coordinates[i], stream, 1);
  6283. stream.polygonEnd();
  6284. }
  6285. function geoStream(object, stream) {
  6286. if (object && streamObjectType.hasOwnProperty(object.type)) {
  6287. streamObjectType[object.type](object, stream);
  6288. } else {
  6289. streamGeometry(object, stream);
  6290. }
  6291. }
  6292. var areaRingSum = adder();
  6293. var areaSum = adder(),
  6294. lambda00,
  6295. phi00,
  6296. lambda0,
  6297. cosPhi0,
  6298. sinPhi0;
  6299. var areaStream = {
  6300. point: noop$2,
  6301. lineStart: noop$2,
  6302. lineEnd: noop$2,
  6303. polygonStart: function() {
  6304. areaRingSum.reset();
  6305. areaStream.lineStart = areaRingStart;
  6306. areaStream.lineEnd = areaRingEnd;
  6307. },
  6308. polygonEnd: function() {
  6309. var areaRing = +areaRingSum;
  6310. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  6311. this.lineStart = this.lineEnd = this.point = noop$2;
  6312. },
  6313. sphere: function() {
  6314. areaSum.add(tau$3);
  6315. }
  6316. };
  6317. function areaRingStart() {
  6318. areaStream.point = areaPointFirst;
  6319. }
  6320. function areaRingEnd() {
  6321. areaPoint(lambda00, phi00);
  6322. }
  6323. function areaPointFirst(lambda, phi) {
  6324. areaStream.point = areaPoint;
  6325. lambda00 = lambda, phi00 = phi;
  6326. lambda *= radians, phi *= radians;
  6327. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  6328. }
  6329. function areaPoint(lambda, phi) {
  6330. lambda *= radians, phi *= radians;
  6331. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  6332. // Spherical excess E for a spherical triangle with vertices: south pole,
  6333. // previous point, current point. Uses a formula derived from Cagnoli’s
  6334. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  6335. var dLambda = lambda - lambda0,
  6336. sdLambda = dLambda >= 0 ? 1 : -1,
  6337. adLambda = sdLambda * dLambda,
  6338. cosPhi = cos$1(phi),
  6339. sinPhi = sin$1(phi),
  6340. k = sinPhi0 * sinPhi,
  6341. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  6342. v = k * sdLambda * sin$1(adLambda);
  6343. areaRingSum.add(atan2(v, u));
  6344. // Advance the previous points.
  6345. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  6346. }
  6347. function area$1(object) {
  6348. areaSum.reset();
  6349. geoStream(object, areaStream);
  6350. return areaSum * 2;
  6351. }
  6352. function spherical(cartesian) {
  6353. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  6354. }
  6355. function cartesian(spherical) {
  6356. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  6357. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  6358. }
  6359. function cartesianDot(a, b) {
  6360. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6361. }
  6362. function cartesianCross(a, b) {
  6363. 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]];
  6364. }
  6365. // TODO return a
  6366. function cartesianAddInPlace(a, b) {
  6367. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  6368. }
  6369. function cartesianScale(vector, k) {
  6370. return [vector[0] * k, vector[1] * k, vector[2] * k];
  6371. }
  6372. // TODO return d
  6373. function cartesianNormalizeInPlace(d) {
  6374. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  6375. d[0] /= l, d[1] /= l, d[2] /= l;
  6376. }
  6377. var lambda0$1, phi0, lambda1, phi1, // bounds
  6378. lambda2, // previous lambda-coordinate
  6379. lambda00$1, phi00$1, // first point
  6380. p0, // previous 3D point
  6381. deltaSum = adder(),
  6382. ranges,
  6383. range;
  6384. var boundsStream = {
  6385. point: boundsPoint,
  6386. lineStart: boundsLineStart,
  6387. lineEnd: boundsLineEnd,
  6388. polygonStart: function() {
  6389. boundsStream.point = boundsRingPoint;
  6390. boundsStream.lineStart = boundsRingStart;
  6391. boundsStream.lineEnd = boundsRingEnd;
  6392. deltaSum.reset();
  6393. areaStream.polygonStart();
  6394. },
  6395. polygonEnd: function() {
  6396. areaStream.polygonEnd();
  6397. boundsStream.point = boundsPoint;
  6398. boundsStream.lineStart = boundsLineStart;
  6399. boundsStream.lineEnd = boundsLineEnd;
  6400. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6401. else if (deltaSum > epsilon$2) phi1 = 90;
  6402. else if (deltaSum < -epsilon$2) phi0 = -90;
  6403. range[0] = lambda0$1, range[1] = lambda1;
  6404. }
  6405. };
  6406. function boundsPoint(lambda, phi) {
  6407. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6408. if (phi < phi0) phi0 = phi;
  6409. if (phi > phi1) phi1 = phi;
  6410. }
  6411. function linePoint(lambda, phi) {
  6412. var p = cartesian([lambda * radians, phi * radians]);
  6413. if (p0) {
  6414. var normal = cartesianCross(p0, p),
  6415. equatorial = [normal[1], -normal[0], 0],
  6416. inflection = cartesianCross(equatorial, normal);
  6417. cartesianNormalizeInPlace(inflection);
  6418. inflection = spherical(inflection);
  6419. var delta = lambda - lambda2,
  6420. sign$$1 = delta > 0 ? 1 : -1,
  6421. lambdai = inflection[0] * degrees$1 * sign$$1,
  6422. phii,
  6423. antimeridian = abs(delta) > 180;
  6424. if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  6425. phii = inflection[1] * degrees$1;
  6426. if (phii > phi1) phi1 = phii;
  6427. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  6428. phii = -inflection[1] * degrees$1;
  6429. if (phii < phi0) phi0 = phii;
  6430. } else {
  6431. if (phi < phi0) phi0 = phi;
  6432. if (phi > phi1) phi1 = phi;
  6433. }
  6434. if (antimeridian) {
  6435. if (lambda < lambda2) {
  6436. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6437. } else {
  6438. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6439. }
  6440. } else {
  6441. if (lambda1 >= lambda0$1) {
  6442. if (lambda < lambda0$1) lambda0$1 = lambda;
  6443. if (lambda > lambda1) lambda1 = lambda;
  6444. } else {
  6445. if (lambda > lambda2) {
  6446. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6447. } else {
  6448. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6449. }
  6450. }
  6451. }
  6452. } else {
  6453. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6454. }
  6455. if (phi < phi0) phi0 = phi;
  6456. if (phi > phi1) phi1 = phi;
  6457. p0 = p, lambda2 = lambda;
  6458. }
  6459. function boundsLineStart() {
  6460. boundsStream.point = linePoint;
  6461. }
  6462. function boundsLineEnd() {
  6463. range[0] = lambda0$1, range[1] = lambda1;
  6464. boundsStream.point = boundsPoint;
  6465. p0 = null;
  6466. }
  6467. function boundsRingPoint(lambda, phi) {
  6468. if (p0) {
  6469. var delta = lambda - lambda2;
  6470. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6471. } else {
  6472. lambda00$1 = lambda, phi00$1 = phi;
  6473. }
  6474. areaStream.point(lambda, phi);
  6475. linePoint(lambda, phi);
  6476. }
  6477. function boundsRingStart() {
  6478. areaStream.lineStart();
  6479. }
  6480. function boundsRingEnd() {
  6481. boundsRingPoint(lambda00$1, phi00$1);
  6482. areaStream.lineEnd();
  6483. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6484. range[0] = lambda0$1, range[1] = lambda1;
  6485. p0 = null;
  6486. }
  6487. // Finds the left-right distance between two longitudes.
  6488. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6489. // the distance between ±180° to be 360°.
  6490. function angle(lambda0, lambda1) {
  6491. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6492. }
  6493. function rangeCompare(a, b) {
  6494. return a[0] - b[0];
  6495. }
  6496. function rangeContains(range, x) {
  6497. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6498. }
  6499. function bounds(feature) {
  6500. var i, n, a, b, merged, deltaMax, delta;
  6501. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6502. ranges = [];
  6503. geoStream(feature, boundsStream);
  6504. // First, sort ranges by their minimum longitudes.
  6505. if (n = ranges.length) {
  6506. ranges.sort(rangeCompare);
  6507. // Then, merge any ranges that overlap.
  6508. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6509. b = ranges[i];
  6510. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6511. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6512. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6513. } else {
  6514. merged.push(a = b);
  6515. }
  6516. }
  6517. // Finally, find the largest gap between the merged ranges.
  6518. // The final bounding box will be the inverse of this gap.
  6519. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6520. b = merged[i];
  6521. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6522. }
  6523. }
  6524. ranges = range = null;
  6525. return lambda0$1 === Infinity || phi0 === Infinity
  6526. ? [[NaN, NaN], [NaN, NaN]]
  6527. : [[lambda0$1, phi0], [lambda1, phi1]];
  6528. }
  6529. var W0, W1,
  6530. X0, Y0, Z0,
  6531. X1, Y1, Z1,
  6532. X2, Y2, Z2,
  6533. lambda00$2, phi00$2, // first point
  6534. x0, y0, z0; // previous point
  6535. var centroidStream = {
  6536. sphere: noop$2,
  6537. point: centroidPoint,
  6538. lineStart: centroidLineStart,
  6539. lineEnd: centroidLineEnd,
  6540. polygonStart: function() {
  6541. centroidStream.lineStart = centroidRingStart;
  6542. centroidStream.lineEnd = centroidRingEnd;
  6543. },
  6544. polygonEnd: function() {
  6545. centroidStream.lineStart = centroidLineStart;
  6546. centroidStream.lineEnd = centroidLineEnd;
  6547. }
  6548. };
  6549. // Arithmetic mean of Cartesian vectors.
  6550. function centroidPoint(lambda, phi) {
  6551. lambda *= radians, phi *= radians;
  6552. var cosPhi = cos$1(phi);
  6553. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6554. }
  6555. function centroidPointCartesian(x, y, z) {
  6556. ++W0;
  6557. X0 += (x - X0) / W0;
  6558. Y0 += (y - Y0) / W0;
  6559. Z0 += (z - Z0) / W0;
  6560. }
  6561. function centroidLineStart() {
  6562. centroidStream.point = centroidLinePointFirst;
  6563. }
  6564. function centroidLinePointFirst(lambda, phi) {
  6565. lambda *= radians, phi *= radians;
  6566. var cosPhi = cos$1(phi);
  6567. x0 = cosPhi * cos$1(lambda);
  6568. y0 = cosPhi * sin$1(lambda);
  6569. z0 = sin$1(phi);
  6570. centroidStream.point = centroidLinePoint;
  6571. centroidPointCartesian(x0, y0, z0);
  6572. }
  6573. function centroidLinePoint(lambda, phi) {
  6574. lambda *= radians, phi *= radians;
  6575. var cosPhi = cos$1(phi),
  6576. x = cosPhi * cos$1(lambda),
  6577. y = cosPhi * sin$1(lambda),
  6578. z = sin$1(phi),
  6579. 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);
  6580. W1 += w;
  6581. X1 += w * (x0 + (x0 = x));
  6582. Y1 += w * (y0 + (y0 = y));
  6583. Z1 += w * (z0 + (z0 = z));
  6584. centroidPointCartesian(x0, y0, z0);
  6585. }
  6586. function centroidLineEnd() {
  6587. centroidStream.point = centroidPoint;
  6588. }
  6589. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6590. // J. Applied Mechanics 42, 239 (1975).
  6591. function centroidRingStart() {
  6592. centroidStream.point = centroidRingPointFirst;
  6593. }
  6594. function centroidRingEnd() {
  6595. centroidRingPoint(lambda00$2, phi00$2);
  6596. centroidStream.point = centroidPoint;
  6597. }
  6598. function centroidRingPointFirst(lambda, phi) {
  6599. lambda00$2 = lambda, phi00$2 = phi;
  6600. lambda *= radians, phi *= radians;
  6601. centroidStream.point = centroidRingPoint;
  6602. var cosPhi = cos$1(phi);
  6603. x0 = cosPhi * cos$1(lambda);
  6604. y0 = cosPhi * sin$1(lambda);
  6605. z0 = sin$1(phi);
  6606. centroidPointCartesian(x0, y0, z0);
  6607. }
  6608. function centroidRingPoint(lambda, phi) {
  6609. lambda *= radians, phi *= radians;
  6610. var cosPhi = cos$1(phi),
  6611. x = cosPhi * cos$1(lambda),
  6612. y = cosPhi * sin$1(lambda),
  6613. z = sin$1(phi),
  6614. cx = y0 * z - z0 * y,
  6615. cy = z0 * x - x0 * z,
  6616. cz = x0 * y - y0 * x,
  6617. m = sqrt(cx * cx + cy * cy + cz * cz),
  6618. w = asin(m), // line weight = angle
  6619. v = m && -w / m; // area weight multiplier
  6620. X2 += v * cx;
  6621. Y2 += v * cy;
  6622. Z2 += v * cz;
  6623. W1 += w;
  6624. X1 += w * (x0 + (x0 = x));
  6625. Y1 += w * (y0 + (y0 = y));
  6626. Z1 += w * (z0 + (z0 = z));
  6627. centroidPointCartesian(x0, y0, z0);
  6628. }
  6629. function centroid(object) {
  6630. W0 = W1 =
  6631. X0 = Y0 = Z0 =
  6632. X1 = Y1 = Z1 =
  6633. X2 = Y2 = Z2 = 0;
  6634. geoStream(object, centroidStream);
  6635. var x = X2,
  6636. y = Y2,
  6637. z = Z2,
  6638. m = x * x + y * y + z * z;
  6639. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6640. if (m < epsilon2$1) {
  6641. x = X1, y = Y1, z = Z1;
  6642. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6643. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6644. m = x * x + y * y + z * z;
  6645. // If the feature still has an undefined ccentroid, then return.
  6646. if (m < epsilon2$1) return [NaN, NaN];
  6647. }
  6648. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6649. }
  6650. function constant$8(x) {
  6651. return function() {
  6652. return x;
  6653. };
  6654. }
  6655. function compose(a, b) {
  6656. function compose(x, y) {
  6657. return x = a(x, y), b(x[0], x[1]);
  6658. }
  6659. if (a.invert && b.invert) compose.invert = function(x, y) {
  6660. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6661. };
  6662. return compose;
  6663. }
  6664. function rotationIdentity(lambda, phi) {
  6665. return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6666. }
  6667. rotationIdentity.invert = rotationIdentity;
  6668. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6669. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6670. : rotationLambda(deltaLambda))
  6671. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6672. : rotationIdentity);
  6673. }
  6674. function forwardRotationLambda(deltaLambda) {
  6675. return function(lambda, phi) {
  6676. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6677. };
  6678. }
  6679. function rotationLambda(deltaLambda) {
  6680. var rotation = forwardRotationLambda(deltaLambda);
  6681. rotation.invert = forwardRotationLambda(-deltaLambda);
  6682. return rotation;
  6683. }
  6684. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6685. var cosDeltaPhi = cos$1(deltaPhi),
  6686. sinDeltaPhi = sin$1(deltaPhi),
  6687. cosDeltaGamma = cos$1(deltaGamma),
  6688. sinDeltaGamma = sin$1(deltaGamma);
  6689. function rotation(lambda, phi) {
  6690. var cosPhi = cos$1(phi),
  6691. x = cos$1(lambda) * cosPhi,
  6692. y = sin$1(lambda) * cosPhi,
  6693. z = sin$1(phi),
  6694. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6695. return [
  6696. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6697. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6698. ];
  6699. }
  6700. rotation.invert = function(lambda, phi) {
  6701. var cosPhi = cos$1(phi),
  6702. x = cos$1(lambda) * cosPhi,
  6703. y = sin$1(lambda) * cosPhi,
  6704. z = sin$1(phi),
  6705. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6706. return [
  6707. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6708. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6709. ];
  6710. };
  6711. return rotation;
  6712. }
  6713. function rotation(rotate) {
  6714. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6715. function forward(coordinates) {
  6716. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6717. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6718. }
  6719. forward.invert = function(coordinates) {
  6720. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6721. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6722. };
  6723. return forward;
  6724. }
  6725. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6726. function circleStream(stream, radius, delta, direction, t0, t1) {
  6727. if (!delta) return;
  6728. var cosRadius = cos$1(radius),
  6729. sinRadius = sin$1(radius),
  6730. step = direction * delta;
  6731. if (t0 == null) {
  6732. t0 = radius + direction * tau$3;
  6733. t1 = radius - step / 2;
  6734. } else {
  6735. t0 = circleRadius(cosRadius, t0);
  6736. t1 = circleRadius(cosRadius, t1);
  6737. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6738. }
  6739. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6740. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6741. stream.point(point[0], point[1]);
  6742. }
  6743. }
  6744. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6745. function circleRadius(cosRadius, point) {
  6746. point = cartesian(point), point[0] -= cosRadius;
  6747. cartesianNormalizeInPlace(point);
  6748. var radius = acos(-point[1]);
  6749. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6750. }
  6751. function circle() {
  6752. var center = constant$8([0, 0]),
  6753. radius = constant$8(90),
  6754. precision = constant$8(6),
  6755. ring,
  6756. rotate,
  6757. stream = {point: point};
  6758. function point(x, y) {
  6759. ring.push(x = rotate(x, y));
  6760. x[0] *= degrees$1, x[1] *= degrees$1;
  6761. }
  6762. function circle() {
  6763. var c = center.apply(this, arguments),
  6764. r = radius.apply(this, arguments) * radians,
  6765. p = precision.apply(this, arguments) * radians;
  6766. ring = [];
  6767. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6768. circleStream(stream, r, p, 1);
  6769. c = {type: "Polygon", coordinates: [ring]};
  6770. ring = rotate = null;
  6771. return c;
  6772. }
  6773. circle.center = function(_) {
  6774. return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
  6775. };
  6776. circle.radius = function(_) {
  6777. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
  6778. };
  6779. circle.precision = function(_) {
  6780. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
  6781. };
  6782. return circle;
  6783. }
  6784. function clipBuffer() {
  6785. var lines = [],
  6786. line;
  6787. return {
  6788. point: function(x, y) {
  6789. line.push([x, y]);
  6790. },
  6791. lineStart: function() {
  6792. lines.push(line = []);
  6793. },
  6794. lineEnd: noop$2,
  6795. rejoin: function() {
  6796. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  6797. },
  6798. result: function() {
  6799. var result = lines;
  6800. lines = [];
  6801. line = null;
  6802. return result;
  6803. }
  6804. };
  6805. }
  6806. function pointEqual(a, b) {
  6807. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  6808. }
  6809. function Intersection(point, points, other, entry) {
  6810. this.x = point;
  6811. this.z = points;
  6812. this.o = other; // another intersection
  6813. this.e = entry; // is an entry?
  6814. this.v = false; // visited
  6815. this.n = this.p = null; // next & previous
  6816. }
  6817. // A generalized polygon clipping algorithm: given a polygon that has been cut
  6818. // into its visible line segments, and rejoins the segments by interpolating
  6819. // along the clip edge.
  6820. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  6821. var subject = [],
  6822. clip = [],
  6823. i,
  6824. n;
  6825. segments.forEach(function(segment) {
  6826. if ((n = segment.length - 1) <= 0) return;
  6827. var n, p0 = segment[0], p1 = segment[n], x;
  6828. // If the first and last points of a segment are coincident, then treat as a
  6829. // closed ring. TODO if all rings are closed, then the winding order of the
  6830. // exterior ring should be checked.
  6831. if (pointEqual(p0, p1)) {
  6832. stream.lineStart();
  6833. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  6834. stream.lineEnd();
  6835. return;
  6836. }
  6837. subject.push(x = new Intersection(p0, segment, null, true));
  6838. clip.push(x.o = new Intersection(p0, null, x, false));
  6839. subject.push(x = new Intersection(p1, segment, null, false));
  6840. clip.push(x.o = new Intersection(p1, null, x, true));
  6841. });
  6842. if (!subject.length) return;
  6843. clip.sort(compareIntersection);
  6844. link$1(subject);
  6845. link$1(clip);
  6846. for (i = 0, n = clip.length; i < n; ++i) {
  6847. clip[i].e = startInside = !startInside;
  6848. }
  6849. var start = subject[0],
  6850. points,
  6851. point;
  6852. while (1) {
  6853. // Find first unvisited intersection.
  6854. var current = start,
  6855. isSubject = true;
  6856. while (current.v) if ((current = current.n) === start) return;
  6857. points = current.z;
  6858. stream.lineStart();
  6859. do {
  6860. current.v = current.o.v = true;
  6861. if (current.e) {
  6862. if (isSubject) {
  6863. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  6864. } else {
  6865. interpolate(current.x, current.n.x, 1, stream);
  6866. }
  6867. current = current.n;
  6868. } else {
  6869. if (isSubject) {
  6870. points = current.p.z;
  6871. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  6872. } else {
  6873. interpolate(current.x, current.p.x, -1, stream);
  6874. }
  6875. current = current.p;
  6876. }
  6877. current = current.o;
  6878. points = current.z;
  6879. isSubject = !isSubject;
  6880. } while (!current.v);
  6881. stream.lineEnd();
  6882. }
  6883. }
  6884. function link$1(array) {
  6885. if (!(n = array.length)) return;
  6886. var n,
  6887. i = 0,
  6888. a = array[0],
  6889. b;
  6890. while (++i < n) {
  6891. a.n = b = array[i];
  6892. b.p = a;
  6893. a = b;
  6894. }
  6895. a.n = b = array[0];
  6896. b.p = a;
  6897. }
  6898. var sum$1 = adder();
  6899. function polygonContains(polygon, point) {
  6900. var lambda = point[0],
  6901. phi = point[1],
  6902. sinPhi = sin$1(phi),
  6903. normal = [sin$1(lambda), -cos$1(lambda), 0],
  6904. angle = 0,
  6905. winding = 0;
  6906. sum$1.reset();
  6907. if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
  6908. else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
  6909. for (var i = 0, n = polygon.length; i < n; ++i) {
  6910. if (!(m = (ring = polygon[i]).length)) continue;
  6911. var ring,
  6912. m,
  6913. point0 = ring[m - 1],
  6914. lambda0 = point0[0],
  6915. phi0 = point0[1] / 2 + quarterPi,
  6916. sinPhi0 = sin$1(phi0),
  6917. cosPhi0 = cos$1(phi0);
  6918. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  6919. var point1 = ring[j],
  6920. lambda1 = point1[0],
  6921. phi1 = point1[1] / 2 + quarterPi,
  6922. sinPhi1 = sin$1(phi1),
  6923. cosPhi1 = cos$1(phi1),
  6924. delta = lambda1 - lambda0,
  6925. sign$$1 = delta >= 0 ? 1 : -1,
  6926. absDelta = sign$$1 * delta,
  6927. antimeridian = absDelta > pi$3,
  6928. k = sinPhi0 * sinPhi1;
  6929. sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  6930. angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
  6931. // Are the longitudes either side of the point’s meridian (lambda),
  6932. // and are the latitudes smaller than the parallel (phi)?
  6933. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  6934. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  6935. cartesianNormalizeInPlace(arc);
  6936. var intersection = cartesianCross(normal, arc);
  6937. cartesianNormalizeInPlace(intersection);
  6938. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  6939. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  6940. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  6941. }
  6942. }
  6943. }
  6944. }
  6945. // First, determine whether the South pole is inside or outside:
  6946. //
  6947. // It is inside if:
  6948. // * the polygon winds around it in a clockwise direction.
  6949. // * the polygon does not (cumulatively) wind around it, but has a negative
  6950. // (counter-clockwise) area.
  6951. //
  6952. // Second, count the (signed) number of times a segment crosses a lambda
  6953. // from the point to the South pole. If it is zero, then the point is the
  6954. // same side as the South pole.
  6955. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  6956. }
  6957. function clip(pointVisible, clipLine, interpolate, start) {
  6958. return function(sink) {
  6959. var line = clipLine(sink),
  6960. ringBuffer = clipBuffer(),
  6961. ringSink = clipLine(ringBuffer),
  6962. polygonStarted = false,
  6963. polygon,
  6964. segments,
  6965. ring;
  6966. var clip = {
  6967. point: point,
  6968. lineStart: lineStart,
  6969. lineEnd: lineEnd,
  6970. polygonStart: function() {
  6971. clip.point = pointRing;
  6972. clip.lineStart = ringStart;
  6973. clip.lineEnd = ringEnd;
  6974. segments = [];
  6975. polygon = [];
  6976. },
  6977. polygonEnd: function() {
  6978. clip.point = point;
  6979. clip.lineStart = lineStart;
  6980. clip.lineEnd = lineEnd;
  6981. segments = merge(segments);
  6982. var startInside = polygonContains(polygon, start);
  6983. if (segments.length) {
  6984. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6985. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  6986. } else if (startInside) {
  6987. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6988. sink.lineStart();
  6989. interpolate(null, null, 1, sink);
  6990. sink.lineEnd();
  6991. }
  6992. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  6993. segments = polygon = null;
  6994. },
  6995. sphere: function() {
  6996. sink.polygonStart();
  6997. sink.lineStart();
  6998. interpolate(null, null, 1, sink);
  6999. sink.lineEnd();
  7000. sink.polygonEnd();
  7001. }
  7002. };
  7003. function point(lambda, phi) {
  7004. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  7005. }
  7006. function pointLine(lambda, phi) {
  7007. line.point(lambda, phi);
  7008. }
  7009. function lineStart() {
  7010. clip.point = pointLine;
  7011. line.lineStart();
  7012. }
  7013. function lineEnd() {
  7014. clip.point = point;
  7015. line.lineEnd();
  7016. }
  7017. function pointRing(lambda, phi) {
  7018. ring.push([lambda, phi]);
  7019. ringSink.point(lambda, phi);
  7020. }
  7021. function ringStart() {
  7022. ringSink.lineStart();
  7023. ring = [];
  7024. }
  7025. function ringEnd() {
  7026. pointRing(ring[0][0], ring[0][1]);
  7027. ringSink.lineEnd();
  7028. var clean = ringSink.clean(),
  7029. ringSegments = ringBuffer.result(),
  7030. i, n = ringSegments.length, m,
  7031. segment,
  7032. point;
  7033. ring.pop();
  7034. polygon.push(ring);
  7035. ring = null;
  7036. if (!n) return;
  7037. // No intersections.
  7038. if (clean & 1) {
  7039. segment = ringSegments[0];
  7040. if ((m = segment.length - 1) > 0) {
  7041. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7042. sink.lineStart();
  7043. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7044. sink.lineEnd();
  7045. }
  7046. return;
  7047. }
  7048. // Rejoin connected segments.
  7049. // TODO reuse ringBuffer.rejoin()?
  7050. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7051. segments.push(ringSegments.filter(validSegment));
  7052. }
  7053. return clip;
  7054. };
  7055. }
  7056. function validSegment(segment) {
  7057. return segment.length > 1;
  7058. }
  7059. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7060. // and circle clipping, the same comparison is used.
  7061. function compareIntersection(a, b) {
  7062. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7063. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7064. }
  7065. var clipAntimeridian = clip(
  7066. function() { return true; },
  7067. clipAntimeridianLine,
  7068. clipAntimeridianInterpolate,
  7069. [-pi$3, -halfPi$2]
  7070. );
  7071. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7072. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7073. // intersections, and the first and last segments should be rejoined.
  7074. function clipAntimeridianLine(stream) {
  7075. var lambda0 = NaN,
  7076. phi0 = NaN,
  7077. sign0 = NaN,
  7078. clean; // no intersections
  7079. return {
  7080. lineStart: function() {
  7081. stream.lineStart();
  7082. clean = 1;
  7083. },
  7084. point: function(lambda1, phi1) {
  7085. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7086. delta = abs(lambda1 - lambda0);
  7087. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7088. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7089. stream.point(sign0, phi0);
  7090. stream.lineEnd();
  7091. stream.lineStart();
  7092. stream.point(sign1, phi0);
  7093. stream.point(lambda1, phi0);
  7094. clean = 0;
  7095. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7096. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7097. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7098. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7099. stream.point(sign0, phi0);
  7100. stream.lineEnd();
  7101. stream.lineStart();
  7102. stream.point(sign1, phi0);
  7103. clean = 0;
  7104. }
  7105. stream.point(lambda0 = lambda1, phi0 = phi1);
  7106. sign0 = sign1;
  7107. },
  7108. lineEnd: function() {
  7109. stream.lineEnd();
  7110. lambda0 = phi0 = NaN;
  7111. },
  7112. clean: function() {
  7113. return 2 - clean; // if intersections, rejoin first and last segments
  7114. }
  7115. };
  7116. }
  7117. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7118. var cosPhi0,
  7119. cosPhi1,
  7120. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7121. return abs(sinLambda0Lambda1) > epsilon$2
  7122. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7123. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7124. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7125. : (phi0 + phi1) / 2;
  7126. }
  7127. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7128. var phi;
  7129. if (from == null) {
  7130. phi = direction * halfPi$2;
  7131. stream.point(-pi$3, phi);
  7132. stream.point(0, phi);
  7133. stream.point(pi$3, phi);
  7134. stream.point(pi$3, 0);
  7135. stream.point(pi$3, -phi);
  7136. stream.point(0, -phi);
  7137. stream.point(-pi$3, -phi);
  7138. stream.point(-pi$3, 0);
  7139. stream.point(-pi$3, phi);
  7140. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7141. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7142. phi = direction * lambda / 2;
  7143. stream.point(-lambda, phi);
  7144. stream.point(0, phi);
  7145. stream.point(lambda, phi);
  7146. } else {
  7147. stream.point(to[0], to[1]);
  7148. }
  7149. }
  7150. function clipCircle(radius) {
  7151. var cr = cos$1(radius),
  7152. delta = 6 * radians,
  7153. smallRadius = cr > 0,
  7154. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7155. function interpolate(from, to, direction, stream) {
  7156. circleStream(stream, radius, delta, direction, from, to);
  7157. }
  7158. function visible(lambda, phi) {
  7159. return cos$1(lambda) * cos$1(phi) > cr;
  7160. }
  7161. // Takes a line and cuts into visible segments. Return values used for polygon
  7162. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7163. // intersections 2 - there were intersections, and the first and last segments
  7164. // should be rejoined.
  7165. function clipLine(stream) {
  7166. var point0, // previous point
  7167. c0, // code for previous point
  7168. v0, // visibility of previous point
  7169. v00, // visibility of first point
  7170. clean; // no intersections
  7171. return {
  7172. lineStart: function() {
  7173. v00 = v0 = false;
  7174. clean = 1;
  7175. },
  7176. point: function(lambda, phi) {
  7177. var point1 = [lambda, phi],
  7178. point2,
  7179. v = visible(lambda, phi),
  7180. c = smallRadius
  7181. ? v ? 0 : code(lambda, phi)
  7182. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7183. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7184. // Handle degeneracies.
  7185. // TODO ignore if not clipping polygons.
  7186. if (v !== v0) {
  7187. point2 = intersect(point0, point1);
  7188. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7189. point1[0] += epsilon$2;
  7190. point1[1] += epsilon$2;
  7191. v = visible(point1[0], point1[1]);
  7192. }
  7193. }
  7194. if (v !== v0) {
  7195. clean = 0;
  7196. if (v) {
  7197. // outside going in
  7198. stream.lineStart();
  7199. point2 = intersect(point1, point0);
  7200. stream.point(point2[0], point2[1]);
  7201. } else {
  7202. // inside going out
  7203. point2 = intersect(point0, point1);
  7204. stream.point(point2[0], point2[1]);
  7205. stream.lineEnd();
  7206. }
  7207. point0 = point2;
  7208. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7209. var t;
  7210. // If the codes for two points are different, or are both zero,
  7211. // and there this segment intersects with the small circle.
  7212. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7213. clean = 0;
  7214. if (smallRadius) {
  7215. stream.lineStart();
  7216. stream.point(t[0][0], t[0][1]);
  7217. stream.point(t[1][0], t[1][1]);
  7218. stream.lineEnd();
  7219. } else {
  7220. stream.point(t[1][0], t[1][1]);
  7221. stream.lineEnd();
  7222. stream.lineStart();
  7223. stream.point(t[0][0], t[0][1]);
  7224. }
  7225. }
  7226. }
  7227. if (v && (!point0 || !pointEqual(point0, point1))) {
  7228. stream.point(point1[0], point1[1]);
  7229. }
  7230. point0 = point1, v0 = v, c0 = c;
  7231. },
  7232. lineEnd: function() {
  7233. if (v0) stream.lineEnd();
  7234. point0 = null;
  7235. },
  7236. // Rejoin first and last segments if there were intersections and the first
  7237. // and last points were visible.
  7238. clean: function() {
  7239. return clean | ((v00 && v0) << 1);
  7240. }
  7241. };
  7242. }
  7243. // Intersects the great circle between a and b with the clip circle.
  7244. function intersect(a, b, two) {
  7245. var pa = cartesian(a),
  7246. pb = cartesian(b);
  7247. // We have two planes, n1.p = d1 and n2.p = d2.
  7248. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7249. var n1 = [1, 0, 0], // normal
  7250. n2 = cartesianCross(pa, pb),
  7251. n2n2 = cartesianDot(n2, n2),
  7252. n1n2 = n2[0], // cartesianDot(n1, n2),
  7253. determinant = n2n2 - n1n2 * n1n2;
  7254. // Two polar points.
  7255. if (!determinant) return !two && a;
  7256. var c1 = cr * n2n2 / determinant,
  7257. c2 = -cr * n1n2 / determinant,
  7258. n1xn2 = cartesianCross(n1, n2),
  7259. A = cartesianScale(n1, c1),
  7260. B = cartesianScale(n2, c2);
  7261. cartesianAddInPlace(A, B);
  7262. // Solve |p(t)|^2 = 1.
  7263. var u = n1xn2,
  7264. w = cartesianDot(A, u),
  7265. uu = cartesianDot(u, u),
  7266. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7267. if (t2 < 0) return;
  7268. var t = sqrt(t2),
  7269. q = cartesianScale(u, (-w - t) / uu);
  7270. cartesianAddInPlace(q, A);
  7271. q = spherical(q);
  7272. if (!two) return q;
  7273. // Two intersection points.
  7274. var lambda0 = a[0],
  7275. lambda1 = b[0],
  7276. phi0 = a[1],
  7277. phi1 = b[1],
  7278. z;
  7279. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7280. var delta = lambda1 - lambda0,
  7281. polar = abs(delta - pi$3) < epsilon$2,
  7282. meridian = polar || delta < epsilon$2;
  7283. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7284. // Check that the first point is between a and b.
  7285. if (meridian
  7286. ? polar
  7287. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7288. : phi0 <= q[1] && q[1] <= phi1
  7289. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7290. var q1 = cartesianScale(u, (-w + t) / uu);
  7291. cartesianAddInPlace(q1, A);
  7292. return [q, spherical(q1)];
  7293. }
  7294. }
  7295. // Generates a 4-bit vector representing the location of a point relative to
  7296. // the small circle's bounding box.
  7297. function code(lambda, phi) {
  7298. var r = smallRadius ? radius : pi$3 - radius,
  7299. code = 0;
  7300. if (lambda < -r) code |= 1; // left
  7301. else if (lambda > r) code |= 2; // right
  7302. if (phi < -r) code |= 4; // below
  7303. else if (phi > r) code |= 8; // above
  7304. return code;
  7305. }
  7306. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7307. }
  7308. function clipLine(a, b, x0, y0, x1, y1) {
  7309. var ax = a[0],
  7310. ay = a[1],
  7311. bx = b[0],
  7312. by = b[1],
  7313. t0 = 0,
  7314. t1 = 1,
  7315. dx = bx - ax,
  7316. dy = by - ay,
  7317. r;
  7318. r = x0 - ax;
  7319. if (!dx && r > 0) return;
  7320. r /= dx;
  7321. if (dx < 0) {
  7322. if (r < t0) return;
  7323. if (r < t1) t1 = r;
  7324. } else if (dx > 0) {
  7325. if (r > t1) return;
  7326. if (r > t0) t0 = r;
  7327. }
  7328. r = x1 - ax;
  7329. if (!dx && r < 0) return;
  7330. r /= dx;
  7331. if (dx < 0) {
  7332. if (r > t1) return;
  7333. if (r > t0) t0 = r;
  7334. } else if (dx > 0) {
  7335. if (r < t0) return;
  7336. if (r < t1) t1 = r;
  7337. }
  7338. r = y0 - ay;
  7339. if (!dy && r > 0) return;
  7340. r /= dy;
  7341. if (dy < 0) {
  7342. if (r < t0) return;
  7343. if (r < t1) t1 = r;
  7344. } else if (dy > 0) {
  7345. if (r > t1) return;
  7346. if (r > t0) t0 = r;
  7347. }
  7348. r = y1 - ay;
  7349. if (!dy && r < 0) return;
  7350. r /= dy;
  7351. if (dy < 0) {
  7352. if (r > t1) return;
  7353. if (r > t0) t0 = r;
  7354. } else if (dy > 0) {
  7355. if (r < t0) return;
  7356. if (r < t1) t1 = r;
  7357. }
  7358. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  7359. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  7360. return true;
  7361. }
  7362. var clipMax = 1e9, clipMin = -clipMax;
  7363. // TODO Use d3-polygon’s polygonContains here for the ring check?
  7364. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  7365. function clipRectangle(x0, y0, x1, y1) {
  7366. function visible(x, y) {
  7367. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  7368. }
  7369. function interpolate(from, to, direction, stream) {
  7370. var a = 0, a1 = 0;
  7371. if (from == null
  7372. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  7373. || comparePoint(from, to) < 0 ^ direction > 0) {
  7374. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  7375. while ((a = (a + direction + 4) % 4) !== a1);
  7376. } else {
  7377. stream.point(to[0], to[1]);
  7378. }
  7379. }
  7380. function corner(p, direction) {
  7381. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  7382. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  7383. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  7384. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  7385. }
  7386. function compareIntersection(a, b) {
  7387. return comparePoint(a.x, b.x);
  7388. }
  7389. function comparePoint(a, b) {
  7390. var ca = corner(a, 1),
  7391. cb = corner(b, 1);
  7392. return ca !== cb ? ca - cb
  7393. : ca === 0 ? b[1] - a[1]
  7394. : ca === 1 ? a[0] - b[0]
  7395. : ca === 2 ? a[1] - b[1]
  7396. : b[0] - a[0];
  7397. }
  7398. return function(stream) {
  7399. var activeStream = stream,
  7400. bufferStream = clipBuffer(),
  7401. segments,
  7402. polygon,
  7403. ring,
  7404. x__, y__, v__, // first point
  7405. x_, y_, v_, // previous point
  7406. first,
  7407. clean;
  7408. var clipStream = {
  7409. point: point,
  7410. lineStart: lineStart,
  7411. lineEnd: lineEnd,
  7412. polygonStart: polygonStart,
  7413. polygonEnd: polygonEnd
  7414. };
  7415. function point(x, y) {
  7416. if (visible(x, y)) activeStream.point(x, y);
  7417. }
  7418. function polygonInside() {
  7419. var winding = 0;
  7420. for (var i = 0, n = polygon.length; i < n; ++i) {
  7421. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  7422. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  7423. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  7424. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  7425. }
  7426. }
  7427. return winding;
  7428. }
  7429. // Buffer geometry within a polygon and then clip it en masse.
  7430. function polygonStart() {
  7431. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  7432. }
  7433. function polygonEnd() {
  7434. var startInside = polygonInside(),
  7435. cleanInside = clean && startInside,
  7436. visible = (segments = merge(segments)).length;
  7437. if (cleanInside || visible) {
  7438. stream.polygonStart();
  7439. if (cleanInside) {
  7440. stream.lineStart();
  7441. interpolate(null, null, 1, stream);
  7442. stream.lineEnd();
  7443. }
  7444. if (visible) {
  7445. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  7446. }
  7447. stream.polygonEnd();
  7448. }
  7449. activeStream = stream, segments = polygon = ring = null;
  7450. }
  7451. function lineStart() {
  7452. clipStream.point = linePoint;
  7453. if (polygon) polygon.push(ring = []);
  7454. first = true;
  7455. v_ = false;
  7456. x_ = y_ = NaN;
  7457. }
  7458. // TODO rather than special-case polygons, simply handle them separately.
  7459. // Ideally, coincident intersection points should be jittered to avoid
  7460. // clipping issues.
  7461. function lineEnd() {
  7462. if (segments) {
  7463. linePoint(x__, y__);
  7464. if (v__ && v_) bufferStream.rejoin();
  7465. segments.push(bufferStream.result());
  7466. }
  7467. clipStream.point = point;
  7468. if (v_) activeStream.lineEnd();
  7469. }
  7470. function linePoint(x, y) {
  7471. var v = visible(x, y);
  7472. if (polygon) ring.push([x, y]);
  7473. if (first) {
  7474. x__ = x, y__ = y, v__ = v;
  7475. first = false;
  7476. if (v) {
  7477. activeStream.lineStart();
  7478. activeStream.point(x, y);
  7479. }
  7480. } else {
  7481. if (v && v_) activeStream.point(x, y);
  7482. else {
  7483. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7484. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7485. if (clipLine(a, b, x0, y0, x1, y1)) {
  7486. if (!v_) {
  7487. activeStream.lineStart();
  7488. activeStream.point(a[0], a[1]);
  7489. }
  7490. activeStream.point(b[0], b[1]);
  7491. if (!v) activeStream.lineEnd();
  7492. clean = false;
  7493. } else if (v) {
  7494. activeStream.lineStart();
  7495. activeStream.point(x, y);
  7496. clean = false;
  7497. }
  7498. }
  7499. }
  7500. x_ = x, y_ = y, v_ = v;
  7501. }
  7502. return clipStream;
  7503. };
  7504. }
  7505. function extent$1() {
  7506. var x0 = 0,
  7507. y0 = 0,
  7508. x1 = 960,
  7509. y1 = 500,
  7510. cache,
  7511. cacheStream,
  7512. clip;
  7513. return clip = {
  7514. stream: function(stream) {
  7515. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7516. },
  7517. extent: function(_) {
  7518. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7519. }
  7520. };
  7521. }
  7522. var lengthSum = adder(),
  7523. lambda0$2,
  7524. sinPhi0$1,
  7525. cosPhi0$1;
  7526. var lengthStream = {
  7527. sphere: noop$2,
  7528. point: noop$2,
  7529. lineStart: lengthLineStart,
  7530. lineEnd: noop$2,
  7531. polygonStart: noop$2,
  7532. polygonEnd: noop$2
  7533. };
  7534. function lengthLineStart() {
  7535. lengthStream.point = lengthPointFirst;
  7536. lengthStream.lineEnd = lengthLineEnd;
  7537. }
  7538. function lengthLineEnd() {
  7539. lengthStream.point = lengthStream.lineEnd = noop$2;
  7540. }
  7541. function lengthPointFirst(lambda, phi) {
  7542. lambda *= radians, phi *= radians;
  7543. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7544. lengthStream.point = lengthPoint;
  7545. }
  7546. function lengthPoint(lambda, phi) {
  7547. lambda *= radians, phi *= radians;
  7548. var sinPhi = sin$1(phi),
  7549. cosPhi = cos$1(phi),
  7550. delta = abs(lambda - lambda0$2),
  7551. cosDelta = cos$1(delta),
  7552. sinDelta = sin$1(delta),
  7553. x = cosPhi * sinDelta,
  7554. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7555. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7556. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7557. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7558. }
  7559. function length$1(object) {
  7560. lengthSum.reset();
  7561. geoStream(object, lengthStream);
  7562. return +lengthSum;
  7563. }
  7564. var coordinates = [null, null],
  7565. object$1 = {type: "LineString", coordinates: coordinates};
  7566. function distance(a, b) {
  7567. coordinates[0] = a;
  7568. coordinates[1] = b;
  7569. return length$1(object$1);
  7570. }
  7571. var containsObjectType = {
  7572. Feature: function(object, point) {
  7573. return containsGeometry(object.geometry, point);
  7574. },
  7575. FeatureCollection: function(object, point) {
  7576. var features = object.features, i = -1, n = features.length;
  7577. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7578. return false;
  7579. }
  7580. };
  7581. var containsGeometryType = {
  7582. Sphere: function() {
  7583. return true;
  7584. },
  7585. Point: function(object, point) {
  7586. return containsPoint(object.coordinates, point);
  7587. },
  7588. MultiPoint: function(object, point) {
  7589. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7590. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7591. return false;
  7592. },
  7593. LineString: function(object, point) {
  7594. return containsLine(object.coordinates, point);
  7595. },
  7596. MultiLineString: function(object, point) {
  7597. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7598. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7599. return false;
  7600. },
  7601. Polygon: function(object, point) {
  7602. return containsPolygon(object.coordinates, point);
  7603. },
  7604. MultiPolygon: function(object, point) {
  7605. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7606. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7607. return false;
  7608. },
  7609. GeometryCollection: function(object, point) {
  7610. var geometries = object.geometries, i = -1, n = geometries.length;
  7611. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7612. return false;
  7613. }
  7614. };
  7615. function containsGeometry(geometry, point) {
  7616. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7617. ? containsGeometryType[geometry.type](geometry, point)
  7618. : false;
  7619. }
  7620. function containsPoint(coordinates, point) {
  7621. return distance(coordinates, point) === 0;
  7622. }
  7623. function containsLine(coordinates, point) {
  7624. var ab = distance(coordinates[0], coordinates[1]),
  7625. ao = distance(coordinates[0], point),
  7626. ob = distance(point, coordinates[1]);
  7627. return ao + ob <= ab + epsilon$2;
  7628. }
  7629. function containsPolygon(coordinates, point) {
  7630. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7631. }
  7632. function ringRadians(ring) {
  7633. return ring = ring.map(pointRadians), ring.pop(), ring;
  7634. }
  7635. function pointRadians(point) {
  7636. return [point[0] * radians, point[1] * radians];
  7637. }
  7638. function contains$1(object, point) {
  7639. return (object && containsObjectType.hasOwnProperty(object.type)
  7640. ? containsObjectType[object.type]
  7641. : containsGeometry)(object, point);
  7642. }
  7643. function graticuleX(y0, y1, dy) {
  7644. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7645. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7646. }
  7647. function graticuleY(x0, x1, dx) {
  7648. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7649. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7650. }
  7651. function graticule() {
  7652. var x1, x0, X1, X0,
  7653. y1, y0, Y1, Y0,
  7654. dx = 10, dy = dx, DX = 90, DY = 360,
  7655. x, y, X, Y,
  7656. precision = 2.5;
  7657. function graticule() {
  7658. return {type: "MultiLineString", coordinates: lines()};
  7659. }
  7660. function lines() {
  7661. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7662. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7663. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7664. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7665. }
  7666. graticule.lines = function() {
  7667. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7668. };
  7669. graticule.outline = function() {
  7670. return {
  7671. type: "Polygon",
  7672. coordinates: [
  7673. X(X0).concat(
  7674. Y(Y1).slice(1),
  7675. X(X1).reverse().slice(1),
  7676. Y(Y0).reverse().slice(1))
  7677. ]
  7678. };
  7679. };
  7680. graticule.extent = function(_) {
  7681. if (!arguments.length) return graticule.extentMinor();
  7682. return graticule.extentMajor(_).extentMinor(_);
  7683. };
  7684. graticule.extentMajor = function(_) {
  7685. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7686. X0 = +_[0][0], X1 = +_[1][0];
  7687. Y0 = +_[0][1], Y1 = +_[1][1];
  7688. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7689. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7690. return graticule.precision(precision);
  7691. };
  7692. graticule.extentMinor = function(_) {
  7693. if (!arguments.length) return [[x0, y0], [x1, y1]];
  7694. x0 = +_[0][0], x1 = +_[1][0];
  7695. y0 = +_[0][1], y1 = +_[1][1];
  7696. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  7697. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  7698. return graticule.precision(precision);
  7699. };
  7700. graticule.step = function(_) {
  7701. if (!arguments.length) return graticule.stepMinor();
  7702. return graticule.stepMajor(_).stepMinor(_);
  7703. };
  7704. graticule.stepMajor = function(_) {
  7705. if (!arguments.length) return [DX, DY];
  7706. DX = +_[0], DY = +_[1];
  7707. return graticule;
  7708. };
  7709. graticule.stepMinor = function(_) {
  7710. if (!arguments.length) return [dx, dy];
  7711. dx = +_[0], dy = +_[1];
  7712. return graticule;
  7713. };
  7714. graticule.precision = function(_) {
  7715. if (!arguments.length) return precision;
  7716. precision = +_;
  7717. x = graticuleX(y0, y1, 90);
  7718. y = graticuleY(x0, x1, precision);
  7719. X = graticuleX(Y0, Y1, 90);
  7720. Y = graticuleY(X0, X1, precision);
  7721. return graticule;
  7722. };
  7723. return graticule
  7724. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7725. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7726. }
  7727. function graticule10() {
  7728. return graticule()();
  7729. }
  7730. function interpolate$1(a, b) {
  7731. var x0 = a[0] * radians,
  7732. y0 = a[1] * radians,
  7733. x1 = b[0] * radians,
  7734. y1 = b[1] * radians,
  7735. cy0 = cos$1(y0),
  7736. sy0 = sin$1(y0),
  7737. cy1 = cos$1(y1),
  7738. sy1 = sin$1(y1),
  7739. kx0 = cy0 * cos$1(x0),
  7740. ky0 = cy0 * sin$1(x0),
  7741. kx1 = cy1 * cos$1(x1),
  7742. ky1 = cy1 * sin$1(x1),
  7743. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  7744. k = sin$1(d);
  7745. var interpolate = d ? function(t) {
  7746. var B = sin$1(t *= d) / k,
  7747. A = sin$1(d - t) / k,
  7748. x = A * kx0 + B * kx1,
  7749. y = A * ky0 + B * ky1,
  7750. z = A * sy0 + B * sy1;
  7751. return [
  7752. atan2(y, x) * degrees$1,
  7753. atan2(z, sqrt(x * x + y * y)) * degrees$1
  7754. ];
  7755. } : function() {
  7756. return [x0 * degrees$1, y0 * degrees$1];
  7757. };
  7758. interpolate.distance = d;
  7759. return interpolate;
  7760. }
  7761. function identity$4(x) {
  7762. return x;
  7763. }
  7764. var areaSum$1 = adder(),
  7765. areaRingSum$1 = adder(),
  7766. x00,
  7767. y00,
  7768. x0$1,
  7769. y0$1;
  7770. var areaStream$1 = {
  7771. point: noop$2,
  7772. lineStart: noop$2,
  7773. lineEnd: noop$2,
  7774. polygonStart: function() {
  7775. areaStream$1.lineStart = areaRingStart$1;
  7776. areaStream$1.lineEnd = areaRingEnd$1;
  7777. },
  7778. polygonEnd: function() {
  7779. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  7780. areaSum$1.add(abs(areaRingSum$1));
  7781. areaRingSum$1.reset();
  7782. },
  7783. result: function() {
  7784. var area = areaSum$1 / 2;
  7785. areaSum$1.reset();
  7786. return area;
  7787. }
  7788. };
  7789. function areaRingStart$1() {
  7790. areaStream$1.point = areaPointFirst$1;
  7791. }
  7792. function areaPointFirst$1(x, y) {
  7793. areaStream$1.point = areaPoint$1;
  7794. x00 = x0$1 = x, y00 = y0$1 = y;
  7795. }
  7796. function areaPoint$1(x, y) {
  7797. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  7798. x0$1 = x, y0$1 = y;
  7799. }
  7800. function areaRingEnd$1() {
  7801. areaPoint$1(x00, y00);
  7802. }
  7803. var x0$2 = Infinity,
  7804. y0$2 = x0$2,
  7805. x1 = -x0$2,
  7806. y1 = x1;
  7807. var boundsStream$1 = {
  7808. point: boundsPoint$1,
  7809. lineStart: noop$2,
  7810. lineEnd: noop$2,
  7811. polygonStart: noop$2,
  7812. polygonEnd: noop$2,
  7813. result: function() {
  7814. var bounds = [[x0$2, y0$2], [x1, y1]];
  7815. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  7816. return bounds;
  7817. }
  7818. };
  7819. function boundsPoint$1(x, y) {
  7820. if (x < x0$2) x0$2 = x;
  7821. if (x > x1) x1 = x;
  7822. if (y < y0$2) y0$2 = y;
  7823. if (y > y1) y1 = y;
  7824. }
  7825. // TODO Enforce positive area for exterior, negative area for interior?
  7826. var X0$1 = 0,
  7827. Y0$1 = 0,
  7828. Z0$1 = 0,
  7829. X1$1 = 0,
  7830. Y1$1 = 0,
  7831. Z1$1 = 0,
  7832. X2$1 = 0,
  7833. Y2$1 = 0,
  7834. Z2$1 = 0,
  7835. x00$1,
  7836. y00$1,
  7837. x0$3,
  7838. y0$3;
  7839. var centroidStream$1 = {
  7840. point: centroidPoint$1,
  7841. lineStart: centroidLineStart$1,
  7842. lineEnd: centroidLineEnd$1,
  7843. polygonStart: function() {
  7844. centroidStream$1.lineStart = centroidRingStart$1;
  7845. centroidStream$1.lineEnd = centroidRingEnd$1;
  7846. },
  7847. polygonEnd: function() {
  7848. centroidStream$1.point = centroidPoint$1;
  7849. centroidStream$1.lineStart = centroidLineStart$1;
  7850. centroidStream$1.lineEnd = centroidLineEnd$1;
  7851. },
  7852. result: function() {
  7853. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  7854. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  7855. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  7856. : [NaN, NaN];
  7857. X0$1 = Y0$1 = Z0$1 =
  7858. X1$1 = Y1$1 = Z1$1 =
  7859. X2$1 = Y2$1 = Z2$1 = 0;
  7860. return centroid;
  7861. }
  7862. };
  7863. function centroidPoint$1(x, y) {
  7864. X0$1 += x;
  7865. Y0$1 += y;
  7866. ++Z0$1;
  7867. }
  7868. function centroidLineStart$1() {
  7869. centroidStream$1.point = centroidPointFirstLine;
  7870. }
  7871. function centroidPointFirstLine(x, y) {
  7872. centroidStream$1.point = centroidPointLine;
  7873. centroidPoint$1(x0$3 = x, y0$3 = y);
  7874. }
  7875. function centroidPointLine(x, y) {
  7876. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  7877. X1$1 += z * (x0$3 + x) / 2;
  7878. Y1$1 += z * (y0$3 + y) / 2;
  7879. Z1$1 += z;
  7880. centroidPoint$1(x0$3 = x, y0$3 = y);
  7881. }
  7882. function centroidLineEnd$1() {
  7883. centroidStream$1.point = centroidPoint$1;
  7884. }
  7885. function centroidRingStart$1() {
  7886. centroidStream$1.point = centroidPointFirstRing;
  7887. }
  7888. function centroidRingEnd$1() {
  7889. centroidPointRing(x00$1, y00$1);
  7890. }
  7891. function centroidPointFirstRing(x, y) {
  7892. centroidStream$1.point = centroidPointRing;
  7893. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  7894. }
  7895. function centroidPointRing(x, y) {
  7896. var dx = x - x0$3,
  7897. dy = y - y0$3,
  7898. z = sqrt(dx * dx + dy * dy);
  7899. X1$1 += z * (x0$3 + x) / 2;
  7900. Y1$1 += z * (y0$3 + y) / 2;
  7901. Z1$1 += z;
  7902. z = y0$3 * x - x0$3 * y;
  7903. X2$1 += z * (x0$3 + x);
  7904. Y2$1 += z * (y0$3 + y);
  7905. Z2$1 += z * 3;
  7906. centroidPoint$1(x0$3 = x, y0$3 = y);
  7907. }
  7908. function PathContext(context) {
  7909. this._context = context;
  7910. }
  7911. PathContext.prototype = {
  7912. _radius: 4.5,
  7913. pointRadius: function(_) {
  7914. return this._radius = _, this;
  7915. },
  7916. polygonStart: function() {
  7917. this._line = 0;
  7918. },
  7919. polygonEnd: function() {
  7920. this._line = NaN;
  7921. },
  7922. lineStart: function() {
  7923. this._point = 0;
  7924. },
  7925. lineEnd: function() {
  7926. if (this._line === 0) this._context.closePath();
  7927. this._point = NaN;
  7928. },
  7929. point: function(x, y) {
  7930. switch (this._point) {
  7931. case 0: {
  7932. this._context.moveTo(x, y);
  7933. this._point = 1;
  7934. break;
  7935. }
  7936. case 1: {
  7937. this._context.lineTo(x, y);
  7938. break;
  7939. }
  7940. default: {
  7941. this._context.moveTo(x + this._radius, y);
  7942. this._context.arc(x, y, this._radius, 0, tau$3);
  7943. break;
  7944. }
  7945. }
  7946. },
  7947. result: noop$2
  7948. };
  7949. var lengthSum$1 = adder(),
  7950. lengthRing,
  7951. x00$2,
  7952. y00$2,
  7953. x0$4,
  7954. y0$4;
  7955. var lengthStream$1 = {
  7956. point: noop$2,
  7957. lineStart: function() {
  7958. lengthStream$1.point = lengthPointFirst$1;
  7959. },
  7960. lineEnd: function() {
  7961. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  7962. lengthStream$1.point = noop$2;
  7963. },
  7964. polygonStart: function() {
  7965. lengthRing = true;
  7966. },
  7967. polygonEnd: function() {
  7968. lengthRing = null;
  7969. },
  7970. result: function() {
  7971. var length = +lengthSum$1;
  7972. lengthSum$1.reset();
  7973. return length;
  7974. }
  7975. };
  7976. function lengthPointFirst$1(x, y) {
  7977. lengthStream$1.point = lengthPoint$1;
  7978. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  7979. }
  7980. function lengthPoint$1(x, y) {
  7981. x0$4 -= x, y0$4 -= y;
  7982. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  7983. x0$4 = x, y0$4 = y;
  7984. }
  7985. function PathString() {
  7986. this._string = [];
  7987. }
  7988. PathString.prototype = {
  7989. _radius: 4.5,
  7990. _circle: circle$1(4.5),
  7991. pointRadius: function(_) {
  7992. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  7993. return this;
  7994. },
  7995. polygonStart: function() {
  7996. this._line = 0;
  7997. },
  7998. polygonEnd: function() {
  7999. this._line = NaN;
  8000. },
  8001. lineStart: function() {
  8002. this._point = 0;
  8003. },
  8004. lineEnd: function() {
  8005. if (this._line === 0) this._string.push("Z");
  8006. this._point = NaN;
  8007. },
  8008. point: function(x, y) {
  8009. switch (this._point) {
  8010. case 0: {
  8011. this._string.push("M", x, ",", y);
  8012. this._point = 1;
  8013. break;
  8014. }
  8015. case 1: {
  8016. this._string.push("L", x, ",", y);
  8017. break;
  8018. }
  8019. default: {
  8020. if (this._circle == null) this._circle = circle$1(this._radius);
  8021. this._string.push("M", x, ",", y, this._circle);
  8022. break;
  8023. }
  8024. }
  8025. },
  8026. result: function() {
  8027. if (this._string.length) {
  8028. var result = this._string.join("");
  8029. this._string = [];
  8030. return result;
  8031. } else {
  8032. return null;
  8033. }
  8034. }
  8035. };
  8036. function circle$1(radius) {
  8037. return "m0," + radius
  8038. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  8039. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  8040. + "z";
  8041. }
  8042. function index$1(projection, context) {
  8043. var pointRadius = 4.5,
  8044. projectionStream,
  8045. contextStream;
  8046. function path(object) {
  8047. if (object) {
  8048. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  8049. geoStream(object, projectionStream(contextStream));
  8050. }
  8051. return contextStream.result();
  8052. }
  8053. path.area = function(object) {
  8054. geoStream(object, projectionStream(areaStream$1));
  8055. return areaStream$1.result();
  8056. };
  8057. path.measure = function(object) {
  8058. geoStream(object, projectionStream(lengthStream$1));
  8059. return lengthStream$1.result();
  8060. };
  8061. path.bounds = function(object) {
  8062. geoStream(object, projectionStream(boundsStream$1));
  8063. return boundsStream$1.result();
  8064. };
  8065. path.centroid = function(object) {
  8066. geoStream(object, projectionStream(centroidStream$1));
  8067. return centroidStream$1.result();
  8068. };
  8069. path.projection = function(_) {
  8070. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  8071. };
  8072. path.context = function(_) {
  8073. if (!arguments.length) return context;
  8074. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  8075. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  8076. return path;
  8077. };
  8078. path.pointRadius = function(_) {
  8079. if (!arguments.length) return pointRadius;
  8080. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  8081. return path;
  8082. };
  8083. return path.projection(projection).context(context);
  8084. }
  8085. function transform(methods) {
  8086. return {
  8087. stream: transformer(methods)
  8088. };
  8089. }
  8090. function transformer(methods) {
  8091. return function(stream) {
  8092. var s = new TransformStream;
  8093. for (var key in methods) s[key] = methods[key];
  8094. s.stream = stream;
  8095. return s;
  8096. };
  8097. }
  8098. function TransformStream() {}
  8099. TransformStream.prototype = {
  8100. constructor: TransformStream,
  8101. point: function(x, y) { this.stream.point(x, y); },
  8102. sphere: function() { this.stream.sphere(); },
  8103. lineStart: function() { this.stream.lineStart(); },
  8104. lineEnd: function() { this.stream.lineEnd(); },
  8105. polygonStart: function() { this.stream.polygonStart(); },
  8106. polygonEnd: function() { this.stream.polygonEnd(); }
  8107. };
  8108. function fit(projection, fitBounds, object) {
  8109. var clip = projection.clipExtent && projection.clipExtent();
  8110. projection.scale(150).translate([0, 0]);
  8111. if (clip != null) projection.clipExtent(null);
  8112. geoStream(object, projection.stream(boundsStream$1));
  8113. fitBounds(boundsStream$1.result());
  8114. if (clip != null) projection.clipExtent(clip);
  8115. return projection;
  8116. }
  8117. function fitExtent(projection, extent, object) {
  8118. return fit(projection, function(b) {
  8119. var w = extent[1][0] - extent[0][0],
  8120. h = extent[1][1] - extent[0][1],
  8121. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  8122. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  8123. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  8124. projection.scale(150 * k).translate([x, y]);
  8125. }, object);
  8126. }
  8127. function fitSize(projection, size, object) {
  8128. return fitExtent(projection, [[0, 0], size], object);
  8129. }
  8130. function fitWidth(projection, width, object) {
  8131. return fit(projection, function(b) {
  8132. var w = +width,
  8133. k = w / (b[1][0] - b[0][0]),
  8134. x = (w - k * (b[1][0] + b[0][0])) / 2,
  8135. y = -k * b[0][1];
  8136. projection.scale(150 * k).translate([x, y]);
  8137. }, object);
  8138. }
  8139. function fitHeight(projection, height, object) {
  8140. return fit(projection, function(b) {
  8141. var h = +height,
  8142. k = h / (b[1][1] - b[0][1]),
  8143. x = -k * b[0][0],
  8144. y = (h - k * (b[1][1] + b[0][1])) / 2;
  8145. projection.scale(150 * k).translate([x, y]);
  8146. }, object);
  8147. }
  8148. var maxDepth = 16, // maximum depth of subdivision
  8149. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  8150. function resample(project, delta2) {
  8151. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  8152. }
  8153. function resampleNone(project) {
  8154. return transformer({
  8155. point: function(x, y) {
  8156. x = project(x, y);
  8157. this.stream.point(x[0], x[1]);
  8158. }
  8159. });
  8160. }
  8161. function resample$1(project, delta2) {
  8162. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  8163. var dx = x1 - x0,
  8164. dy = y1 - y0,
  8165. d2 = dx * dx + dy * dy;
  8166. if (d2 > 4 * delta2 && depth--) {
  8167. var a = a0 + a1,
  8168. b = b0 + b1,
  8169. c = c0 + c1,
  8170. m = sqrt(a * a + b * b + c * c),
  8171. phi2 = asin(c /= m),
  8172. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  8173. p = project(lambda2, phi2),
  8174. x2 = p[0],
  8175. y2 = p[1],
  8176. dx2 = x2 - x0,
  8177. dy2 = y2 - y0,
  8178. dz = dy * dx2 - dx * dy2;
  8179. if (dz * dz / d2 > delta2 // perpendicular projected distance
  8180. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  8181. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  8182. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  8183. stream.point(x2, y2);
  8184. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  8185. }
  8186. }
  8187. }
  8188. return function(stream) {
  8189. var lambda00, x00, y00, a00, b00, c00, // first point
  8190. lambda0, x0, y0, a0, b0, c0; // previous point
  8191. var resampleStream = {
  8192. point: point,
  8193. lineStart: lineStart,
  8194. lineEnd: lineEnd,
  8195. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  8196. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  8197. };
  8198. function point(x, y) {
  8199. x = project(x, y);
  8200. stream.point(x[0], x[1]);
  8201. }
  8202. function lineStart() {
  8203. x0 = NaN;
  8204. resampleStream.point = linePoint;
  8205. stream.lineStart();
  8206. }
  8207. function linePoint(lambda, phi) {
  8208. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  8209. 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);
  8210. stream.point(x0, y0);
  8211. }
  8212. function lineEnd() {
  8213. resampleStream.point = point;
  8214. stream.lineEnd();
  8215. }
  8216. function ringStart() {
  8217. lineStart();
  8218. resampleStream.point = ringPoint;
  8219. resampleStream.lineEnd = ringEnd;
  8220. }
  8221. function ringPoint(lambda, phi) {
  8222. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  8223. resampleStream.point = linePoint;
  8224. }
  8225. function ringEnd() {
  8226. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  8227. resampleStream.lineEnd = lineEnd;
  8228. lineEnd();
  8229. }
  8230. return resampleStream;
  8231. };
  8232. }
  8233. var transformRadians = transformer({
  8234. point: function(x, y) {
  8235. this.stream.point(x * radians, y * radians);
  8236. }
  8237. });
  8238. function transformRotate(rotate) {
  8239. return transformer({
  8240. point: function(x, y) {
  8241. var r = rotate(x, y);
  8242. return this.stream.point(r[0], r[1]);
  8243. }
  8244. });
  8245. }
  8246. function scaleTranslate(k, dx, dy) {
  8247. function transform$$1(x, y) {
  8248. return [dx + k * x, dy - k * y];
  8249. }
  8250. transform$$1.invert = function(x, y) {
  8251. return [(x - dx) / k, (dy - y) / k];
  8252. };
  8253. return transform$$1;
  8254. }
  8255. function scaleTranslateRotate(k, dx, dy, alpha) {
  8256. var cosAlpha = cos$1(alpha),
  8257. sinAlpha = sin$1(alpha),
  8258. a = cosAlpha * k,
  8259. b = sinAlpha * k,
  8260. ai = cosAlpha / k,
  8261. bi = sinAlpha / k,
  8262. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  8263. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  8264. function transform$$1(x, y) {
  8265. return [a * x - b * y + dx, dy - b * x - a * y];
  8266. }
  8267. transform$$1.invert = function(x, y) {
  8268. return [ai * x - bi * y + ci, fi - bi * x - ai * y];
  8269. };
  8270. return transform$$1;
  8271. }
  8272. function projection(project) {
  8273. return projectionMutator(function() { return project; })();
  8274. }
  8275. function projectionMutator(projectAt) {
  8276. var project,
  8277. k = 150, // scale
  8278. x = 480, y = 250, // translate
  8279. lambda = 0, phi = 0, // center
  8280. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  8281. alpha = 0, // post-rotate
  8282. theta = null, preclip = clipAntimeridian, // pre-clip angle
  8283. x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
  8284. delta2 = 0.5, // precision
  8285. projectResample,
  8286. projectTransform,
  8287. projectRotateTransform,
  8288. cache,
  8289. cacheStream;
  8290. function projection(point) {
  8291. return projectRotateTransform(point[0] * radians, point[1] * radians);
  8292. }
  8293. function invert(point) {
  8294. point = projectRotateTransform.invert(point[0], point[1]);
  8295. return point && [point[0] * degrees$1, point[1] * degrees$1];
  8296. }
  8297. projection.stream = function(stream) {
  8298. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  8299. };
  8300. projection.preclip = function(_) {
  8301. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  8302. };
  8303. projection.postclip = function(_) {
  8304. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8305. };
  8306. projection.clipAngle = function(_) {
  8307. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  8308. };
  8309. projection.clipExtent = function(_) {
  8310. 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]];
  8311. };
  8312. projection.scale = function(_) {
  8313. return arguments.length ? (k = +_, recenter()) : k;
  8314. };
  8315. projection.translate = function(_) {
  8316. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  8317. };
  8318. projection.center = function(_) {
  8319. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  8320. };
  8321. projection.rotate = function(_) {
  8322. 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];
  8323. };
  8324. projection.angle = function(_) {
  8325. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
  8326. };
  8327. projection.precision = function(_) {
  8328. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  8329. };
  8330. projection.fitExtent = function(extent, object) {
  8331. return fitExtent(projection, extent, object);
  8332. };
  8333. projection.fitSize = function(size, object) {
  8334. return fitSize(projection, size, object);
  8335. };
  8336. projection.fitWidth = function(width, object) {
  8337. return fitWidth(projection, width, object);
  8338. };
  8339. projection.fitHeight = function(height, object) {
  8340. return fitHeight(projection, height, object);
  8341. };
  8342. function recenter() {
  8343. var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
  8344. transform$$1 = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
  8345. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  8346. projectTransform = compose(project, transform$$1);
  8347. projectRotateTransform = compose(rotate, projectTransform);
  8348. projectResample = resample(projectTransform, delta2);
  8349. return reset();
  8350. }
  8351. function reset() {
  8352. cache = cacheStream = null;
  8353. return projection;
  8354. }
  8355. return function() {
  8356. project = projectAt.apply(this, arguments);
  8357. projection.invert = project.invert && invert;
  8358. return recenter();
  8359. };
  8360. }
  8361. function conicProjection(projectAt) {
  8362. var phi0 = 0,
  8363. phi1 = pi$3 / 3,
  8364. m = projectionMutator(projectAt),
  8365. p = m(phi0, phi1);
  8366. p.parallels = function(_) {
  8367. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  8368. };
  8369. return p;
  8370. }
  8371. function cylindricalEqualAreaRaw(phi0) {
  8372. var cosPhi0 = cos$1(phi0);
  8373. function forward(lambda, phi) {
  8374. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  8375. }
  8376. forward.invert = function(x, y) {
  8377. return [x / cosPhi0, asin(y * cosPhi0)];
  8378. };
  8379. return forward;
  8380. }
  8381. function conicEqualAreaRaw(y0, y1) {
  8382. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  8383. // Are the parallels symmetrical around the Equator?
  8384. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  8385. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  8386. function project(x, y) {
  8387. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  8388. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  8389. }
  8390. project.invert = function(x, y) {
  8391. var r0y = r0 - y;
  8392. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  8393. };
  8394. return project;
  8395. }
  8396. function conicEqualArea() {
  8397. return conicProjection(conicEqualAreaRaw)
  8398. .scale(155.424)
  8399. .center([0, 33.6442]);
  8400. }
  8401. function albers() {
  8402. return conicEqualArea()
  8403. .parallels([29.5, 45.5])
  8404. .scale(1070)
  8405. .translate([480, 250])
  8406. .rotate([96, 0])
  8407. .center([-0.6, 38.7]);
  8408. }
  8409. // The projections must have mutually exclusive clip regions on the sphere,
  8410. // as this will avoid emitting interleaving lines and polygons.
  8411. function multiplex(streams) {
  8412. var n = streams.length;
  8413. return {
  8414. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  8415. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  8416. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  8417. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  8418. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  8419. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  8420. };
  8421. }
  8422. // A composite projection for the United States, configured by default for
  8423. // 960×500. The projection also works quite well at 960×600 if you change the
  8424. // scale to 1285 and adjust the translate accordingly. The set of standard
  8425. // parallels for each region comes from USGS, which is published here:
  8426. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  8427. function albersUsa() {
  8428. var cache,
  8429. cacheStream,
  8430. lower48 = albers(), lower48Point,
  8431. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  8432. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  8433. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  8434. function albersUsa(coordinates) {
  8435. var x = coordinates[0], y = coordinates[1];
  8436. return point = null, (lower48Point.point(x, y), point)
  8437. || (alaskaPoint.point(x, y), point)
  8438. || (hawaiiPoint.point(x, y), point);
  8439. }
  8440. albersUsa.invert = function(coordinates) {
  8441. var k = lower48.scale(),
  8442. t = lower48.translate(),
  8443. x = (coordinates[0] - t[0]) / k,
  8444. y = (coordinates[1] - t[1]) / k;
  8445. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  8446. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  8447. : lower48).invert(coordinates);
  8448. };
  8449. albersUsa.stream = function(stream) {
  8450. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  8451. };
  8452. albersUsa.precision = function(_) {
  8453. if (!arguments.length) return lower48.precision();
  8454. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  8455. return reset();
  8456. };
  8457. albersUsa.scale = function(_) {
  8458. if (!arguments.length) return lower48.scale();
  8459. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  8460. return albersUsa.translate(lower48.translate());
  8461. };
  8462. albersUsa.translate = function(_) {
  8463. if (!arguments.length) return lower48.translate();
  8464. var k = lower48.scale(), x = +_[0], y = +_[1];
  8465. lower48Point = lower48
  8466. .translate(_)
  8467. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  8468. .stream(pointStream);
  8469. alaskaPoint = alaska
  8470. .translate([x - 0.307 * k, y + 0.201 * k])
  8471. .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]])
  8472. .stream(pointStream);
  8473. hawaiiPoint = hawaii
  8474. .translate([x - 0.205 * k, y + 0.212 * k])
  8475. .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]])
  8476. .stream(pointStream);
  8477. return reset();
  8478. };
  8479. albersUsa.fitExtent = function(extent, object) {
  8480. return fitExtent(albersUsa, extent, object);
  8481. };
  8482. albersUsa.fitSize = function(size, object) {
  8483. return fitSize(albersUsa, size, object);
  8484. };
  8485. albersUsa.fitWidth = function(width, object) {
  8486. return fitWidth(albersUsa, width, object);
  8487. };
  8488. albersUsa.fitHeight = function(height, object) {
  8489. return fitHeight(albersUsa, height, object);
  8490. };
  8491. function reset() {
  8492. cache = cacheStream = null;
  8493. return albersUsa;
  8494. }
  8495. return albersUsa.scale(1070);
  8496. }
  8497. function azimuthalRaw(scale) {
  8498. return function(x, y) {
  8499. var cx = cos$1(x),
  8500. cy = cos$1(y),
  8501. k = scale(cx * cy);
  8502. return [
  8503. k * cy * sin$1(x),
  8504. k * sin$1(y)
  8505. ];
  8506. }
  8507. }
  8508. function azimuthalInvert(angle) {
  8509. return function(x, y) {
  8510. var z = sqrt(x * x + y * y),
  8511. c = angle(z),
  8512. sc = sin$1(c),
  8513. cc = cos$1(c);
  8514. return [
  8515. atan2(x * sc, z * cc),
  8516. asin(z && y * sc / z)
  8517. ];
  8518. }
  8519. }
  8520. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8521. return sqrt(2 / (1 + cxcy));
  8522. });
  8523. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8524. return 2 * asin(z / 2);
  8525. });
  8526. function azimuthalEqualArea() {
  8527. return projection(azimuthalEqualAreaRaw)
  8528. .scale(124.75)
  8529. .clipAngle(180 - 1e-3);
  8530. }
  8531. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8532. return (c = acos(c)) && c / sin$1(c);
  8533. });
  8534. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8535. return z;
  8536. });
  8537. function azimuthalEquidistant() {
  8538. return projection(azimuthalEquidistantRaw)
  8539. .scale(79.4188)
  8540. .clipAngle(180 - 1e-3);
  8541. }
  8542. function mercatorRaw(lambda, phi) {
  8543. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8544. }
  8545. mercatorRaw.invert = function(x, y) {
  8546. return [x, 2 * atan(exp(y)) - halfPi$2];
  8547. };
  8548. function mercator() {
  8549. return mercatorProjection(mercatorRaw)
  8550. .scale(961 / tau$3);
  8551. }
  8552. function mercatorProjection(project) {
  8553. var m = projection(project),
  8554. center = m.center,
  8555. scale = m.scale,
  8556. translate = m.translate,
  8557. clipExtent = m.clipExtent,
  8558. x0 = null, y0, x1, y1; // clip extent
  8559. m.scale = function(_) {
  8560. return arguments.length ? (scale(_), reclip()) : scale();
  8561. };
  8562. m.translate = function(_) {
  8563. return arguments.length ? (translate(_), reclip()) : translate();
  8564. };
  8565. m.center = function(_) {
  8566. return arguments.length ? (center(_), reclip()) : center();
  8567. };
  8568. m.clipExtent = function(_) {
  8569. 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]];
  8570. };
  8571. function reclip() {
  8572. var k = pi$3 * scale(),
  8573. t = m(rotation(m.rotate()).invert([0, 0]));
  8574. return clipExtent(x0 == null
  8575. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8576. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8577. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8578. }
  8579. return reclip();
  8580. }
  8581. function tany(y) {
  8582. return tan((halfPi$2 + y) / 2);
  8583. }
  8584. function conicConformalRaw(y0, y1) {
  8585. var cy0 = cos$1(y0),
  8586. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8587. f = cy0 * pow(tany(y0), n) / n;
  8588. if (!n) return mercatorRaw;
  8589. function project(x, y) {
  8590. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8591. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8592. var r = f / pow(tany(y), n);
  8593. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8594. }
  8595. project.invert = function(x, y) {
  8596. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8597. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8598. };
  8599. return project;
  8600. }
  8601. function conicConformal() {
  8602. return conicProjection(conicConformalRaw)
  8603. .scale(109.5)
  8604. .parallels([30, 30]);
  8605. }
  8606. function equirectangularRaw(lambda, phi) {
  8607. return [lambda, phi];
  8608. }
  8609. equirectangularRaw.invert = equirectangularRaw;
  8610. function equirectangular() {
  8611. return projection(equirectangularRaw)
  8612. .scale(152.63);
  8613. }
  8614. function conicEquidistantRaw(y0, y1) {
  8615. var cy0 = cos$1(y0),
  8616. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8617. g = cy0 / n + y0;
  8618. if (abs(n) < epsilon$2) return equirectangularRaw;
  8619. function project(x, y) {
  8620. var gy = g - y, nx = n * x;
  8621. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8622. }
  8623. project.invert = function(x, y) {
  8624. var gy = g - y;
  8625. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8626. };
  8627. return project;
  8628. }
  8629. function conicEquidistant() {
  8630. return conicProjection(conicEquidistantRaw)
  8631. .scale(131.154)
  8632. .center([0, 13.9389]);
  8633. }
  8634. function gnomonicRaw(x, y) {
  8635. var cy = cos$1(y), k = cos$1(x) * cy;
  8636. return [cy * sin$1(x) / k, sin$1(y) / k];
  8637. }
  8638. gnomonicRaw.invert = azimuthalInvert(atan);
  8639. function gnomonic() {
  8640. return projection(gnomonicRaw)
  8641. .scale(144.049)
  8642. .clipAngle(60);
  8643. }
  8644. function scaleTranslate$1(kx, ky, tx, ty) {
  8645. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8646. point: function(x, y) {
  8647. this.stream.point(x * kx + tx, y * ky + ty);
  8648. }
  8649. });
  8650. }
  8651. function identity$5() {
  8652. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
  8653. x0 = null, y0, x1, y1, // clip extent
  8654. postclip = identity$4,
  8655. cache,
  8656. cacheStream,
  8657. projection;
  8658. function reset() {
  8659. cache = cacheStream = null;
  8660. return projection;
  8661. }
  8662. return projection = {
  8663. stream: function(stream) {
  8664. return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
  8665. },
  8666. postclip: function(_) {
  8667. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8668. },
  8669. clipExtent: function(_) {
  8670. 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]];
  8671. },
  8672. scale: function(_) {
  8673. return arguments.length ? (transform$$1 = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8674. },
  8675. translate: function(_) {
  8676. return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8677. },
  8678. reflectX: function(_) {
  8679. return arguments.length ? (transform$$1 = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8680. },
  8681. reflectY: function(_) {
  8682. return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8683. },
  8684. fitExtent: function(extent, object) {
  8685. return fitExtent(projection, extent, object);
  8686. },
  8687. fitSize: function(size, object) {
  8688. return fitSize(projection, size, object);
  8689. },
  8690. fitWidth: function(width, object) {
  8691. return fitWidth(projection, width, object);
  8692. },
  8693. fitHeight: function(height, object) {
  8694. return fitHeight(projection, height, object);
  8695. }
  8696. };
  8697. }
  8698. function naturalEarth1Raw(lambda, phi) {
  8699. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8700. return [
  8701. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  8702. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  8703. ];
  8704. }
  8705. naturalEarth1Raw.invert = function(x, y) {
  8706. var phi = y, i = 25, delta;
  8707. do {
  8708. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8709. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  8710. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  8711. } while (abs(delta) > epsilon$2 && --i > 0);
  8712. return [
  8713. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  8714. phi
  8715. ];
  8716. };
  8717. function naturalEarth1() {
  8718. return projection(naturalEarth1Raw)
  8719. .scale(175.295);
  8720. }
  8721. function orthographicRaw(x, y) {
  8722. return [cos$1(y) * sin$1(x), sin$1(y)];
  8723. }
  8724. orthographicRaw.invert = azimuthalInvert(asin);
  8725. function orthographic() {
  8726. return projection(orthographicRaw)
  8727. .scale(249.5)
  8728. .clipAngle(90 + epsilon$2);
  8729. }
  8730. function stereographicRaw(x, y) {
  8731. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  8732. return [cy * sin$1(x) / k, sin$1(y) / k];
  8733. }
  8734. stereographicRaw.invert = azimuthalInvert(function(z) {
  8735. return 2 * atan(z);
  8736. });
  8737. function stereographic() {
  8738. return projection(stereographicRaw)
  8739. .scale(250)
  8740. .clipAngle(142);
  8741. }
  8742. function transverseMercatorRaw(lambda, phi) {
  8743. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  8744. }
  8745. transverseMercatorRaw.invert = function(x, y) {
  8746. return [-y, 2 * atan(exp(x)) - halfPi$2];
  8747. };
  8748. function transverseMercator() {
  8749. var m = mercatorProjection(transverseMercatorRaw),
  8750. center = m.center,
  8751. rotate = m.rotate;
  8752. m.center = function(_) {
  8753. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  8754. };
  8755. m.rotate = function(_) {
  8756. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  8757. };
  8758. return rotate([0, 0, 90])
  8759. .scale(159.155);
  8760. }
  8761. function defaultSeparation(a, b) {
  8762. return a.parent === b.parent ? 1 : 2;
  8763. }
  8764. function meanX(children) {
  8765. return children.reduce(meanXReduce, 0) / children.length;
  8766. }
  8767. function meanXReduce(x, c) {
  8768. return x + c.x;
  8769. }
  8770. function maxY(children) {
  8771. return 1 + children.reduce(maxYReduce, 0);
  8772. }
  8773. function maxYReduce(y, c) {
  8774. return Math.max(y, c.y);
  8775. }
  8776. function leafLeft(node) {
  8777. var children;
  8778. while (children = node.children) node = children[0];
  8779. return node;
  8780. }
  8781. function leafRight(node) {
  8782. var children;
  8783. while (children = node.children) node = children[children.length - 1];
  8784. return node;
  8785. }
  8786. function cluster() {
  8787. var separation = defaultSeparation,
  8788. dx = 1,
  8789. dy = 1,
  8790. nodeSize = false;
  8791. function cluster(root) {
  8792. var previousNode,
  8793. x = 0;
  8794. // First walk, computing the initial x & y values.
  8795. root.eachAfter(function(node) {
  8796. var children = node.children;
  8797. if (children) {
  8798. node.x = meanX(children);
  8799. node.y = maxY(children);
  8800. } else {
  8801. node.x = previousNode ? x += separation(node, previousNode) : 0;
  8802. node.y = 0;
  8803. previousNode = node;
  8804. }
  8805. });
  8806. var left = leafLeft(root),
  8807. right = leafRight(root),
  8808. x0 = left.x - separation(left, right) / 2,
  8809. x1 = right.x + separation(right, left) / 2;
  8810. // Second walk, normalizing x & y to the desired size.
  8811. return root.eachAfter(nodeSize ? function(node) {
  8812. node.x = (node.x - root.x) * dx;
  8813. node.y = (root.y - node.y) * dy;
  8814. } : function(node) {
  8815. node.x = (node.x - x0) / (x1 - x0) * dx;
  8816. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  8817. });
  8818. }
  8819. cluster.separation = function(x) {
  8820. return arguments.length ? (separation = x, cluster) : separation;
  8821. };
  8822. cluster.size = function(x) {
  8823. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  8824. };
  8825. cluster.nodeSize = function(x) {
  8826. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  8827. };
  8828. return cluster;
  8829. }
  8830. function count(node) {
  8831. var sum = 0,
  8832. children = node.children,
  8833. i = children && children.length;
  8834. if (!i) sum = 1;
  8835. else while (--i >= 0) sum += children[i].value;
  8836. node.value = sum;
  8837. }
  8838. function node_count() {
  8839. return this.eachAfter(count);
  8840. }
  8841. function node_each(callback) {
  8842. var node = this, current, next = [node], children, i, n;
  8843. do {
  8844. current = next.reverse(), next = [];
  8845. while (node = current.pop()) {
  8846. callback(node), children = node.children;
  8847. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8848. next.push(children[i]);
  8849. }
  8850. }
  8851. } while (next.length);
  8852. return this;
  8853. }
  8854. function node_eachBefore(callback) {
  8855. var node = this, nodes = [node], children, i;
  8856. while (node = nodes.pop()) {
  8857. callback(node), children = node.children;
  8858. if (children) for (i = children.length - 1; i >= 0; --i) {
  8859. nodes.push(children[i]);
  8860. }
  8861. }
  8862. return this;
  8863. }
  8864. function node_eachAfter(callback) {
  8865. var node = this, nodes = [node], next = [], children, i, n;
  8866. while (node = nodes.pop()) {
  8867. next.push(node), children = node.children;
  8868. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8869. nodes.push(children[i]);
  8870. }
  8871. }
  8872. while (node = next.pop()) {
  8873. callback(node);
  8874. }
  8875. return this;
  8876. }
  8877. function node_sum(value) {
  8878. return this.eachAfter(function(node) {
  8879. var sum = +value(node.data) || 0,
  8880. children = node.children,
  8881. i = children && children.length;
  8882. while (--i >= 0) sum += children[i].value;
  8883. node.value = sum;
  8884. });
  8885. }
  8886. function node_sort(compare) {
  8887. return this.eachBefore(function(node) {
  8888. if (node.children) {
  8889. node.children.sort(compare);
  8890. }
  8891. });
  8892. }
  8893. function node_path(end) {
  8894. var start = this,
  8895. ancestor = leastCommonAncestor(start, end),
  8896. nodes = [start];
  8897. while (start !== ancestor) {
  8898. start = start.parent;
  8899. nodes.push(start);
  8900. }
  8901. var k = nodes.length;
  8902. while (end !== ancestor) {
  8903. nodes.splice(k, 0, end);
  8904. end = end.parent;
  8905. }
  8906. return nodes;
  8907. }
  8908. function leastCommonAncestor(a, b) {
  8909. if (a === b) return a;
  8910. var aNodes = a.ancestors(),
  8911. bNodes = b.ancestors(),
  8912. c = null;
  8913. a = aNodes.pop();
  8914. b = bNodes.pop();
  8915. while (a === b) {
  8916. c = a;
  8917. a = aNodes.pop();
  8918. b = bNodes.pop();
  8919. }
  8920. return c;
  8921. }
  8922. function node_ancestors() {
  8923. var node = this, nodes = [node];
  8924. while (node = node.parent) {
  8925. nodes.push(node);
  8926. }
  8927. return nodes;
  8928. }
  8929. function node_descendants() {
  8930. var nodes = [];
  8931. this.each(function(node) {
  8932. nodes.push(node);
  8933. });
  8934. return nodes;
  8935. }
  8936. function node_leaves() {
  8937. var leaves = [];
  8938. this.eachBefore(function(node) {
  8939. if (!node.children) {
  8940. leaves.push(node);
  8941. }
  8942. });
  8943. return leaves;
  8944. }
  8945. function node_links() {
  8946. var root = this, links = [];
  8947. root.each(function(node) {
  8948. if (node !== root) { // Don’t include the root’s parent, if any.
  8949. links.push({source: node.parent, target: node});
  8950. }
  8951. });
  8952. return links;
  8953. }
  8954. function hierarchy(data, children) {
  8955. var root = new Node(data),
  8956. valued = +data.value && (root.value = data.value),
  8957. node,
  8958. nodes = [root],
  8959. child,
  8960. childs,
  8961. i,
  8962. n;
  8963. if (children == null) children = defaultChildren;
  8964. while (node = nodes.pop()) {
  8965. if (valued) node.value = +node.data.value;
  8966. if ((childs = children(node.data)) && (n = childs.length)) {
  8967. node.children = new Array(n);
  8968. for (i = n - 1; i >= 0; --i) {
  8969. nodes.push(child = node.children[i] = new Node(childs[i]));
  8970. child.parent = node;
  8971. child.depth = node.depth + 1;
  8972. }
  8973. }
  8974. }
  8975. return root.eachBefore(computeHeight);
  8976. }
  8977. function node_copy() {
  8978. return hierarchy(this).eachBefore(copyData);
  8979. }
  8980. function defaultChildren(d) {
  8981. return d.children;
  8982. }
  8983. function copyData(node) {
  8984. node.data = node.data.data;
  8985. }
  8986. function computeHeight(node) {
  8987. var height = 0;
  8988. do node.height = height;
  8989. while ((node = node.parent) && (node.height < ++height));
  8990. }
  8991. function Node(data) {
  8992. this.data = data;
  8993. this.depth =
  8994. this.height = 0;
  8995. this.parent = null;
  8996. }
  8997. Node.prototype = hierarchy.prototype = {
  8998. constructor: Node,
  8999. count: node_count,
  9000. each: node_each,
  9001. eachAfter: node_eachAfter,
  9002. eachBefore: node_eachBefore,
  9003. sum: node_sum,
  9004. sort: node_sort,
  9005. path: node_path,
  9006. ancestors: node_ancestors,
  9007. descendants: node_descendants,
  9008. leaves: node_leaves,
  9009. links: node_links,
  9010. copy: node_copy
  9011. };
  9012. var slice$4 = Array.prototype.slice;
  9013. function shuffle$1(array) {
  9014. var m = array.length,
  9015. t,
  9016. i;
  9017. while (m) {
  9018. i = Math.random() * m-- | 0;
  9019. t = array[m];
  9020. array[m] = array[i];
  9021. array[i] = t;
  9022. }
  9023. return array;
  9024. }
  9025. function enclose(circles) {
  9026. var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
  9027. while (i < n) {
  9028. p = circles[i];
  9029. if (e && enclosesWeak(e, p)) ++i;
  9030. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  9031. }
  9032. return e;
  9033. }
  9034. function extendBasis(B, p) {
  9035. var i, j;
  9036. if (enclosesWeakAll(p, B)) return [p];
  9037. // If we get here then B must have at least one element.
  9038. for (i = 0; i < B.length; ++i) {
  9039. if (enclosesNot(p, B[i])
  9040. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  9041. return [B[i], p];
  9042. }
  9043. }
  9044. // If we get here then B must have at least two elements.
  9045. for (i = 0; i < B.length - 1; ++i) {
  9046. for (j = i + 1; j < B.length; ++j) {
  9047. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  9048. && enclosesNot(encloseBasis2(B[i], p), B[j])
  9049. && enclosesNot(encloseBasis2(B[j], p), B[i])
  9050. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  9051. return [B[i], B[j], p];
  9052. }
  9053. }
  9054. }
  9055. // If we get here then something is very wrong.
  9056. throw new Error;
  9057. }
  9058. function enclosesNot(a, b) {
  9059. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  9060. return dr < 0 || dr * dr < dx * dx + dy * dy;
  9061. }
  9062. function enclosesWeak(a, b) {
  9063. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9064. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9065. }
  9066. function enclosesWeakAll(a, B) {
  9067. for (var i = 0; i < B.length; ++i) {
  9068. if (!enclosesWeak(a, B[i])) {
  9069. return false;
  9070. }
  9071. }
  9072. return true;
  9073. }
  9074. function encloseBasis(B) {
  9075. switch (B.length) {
  9076. case 1: return encloseBasis1(B[0]);
  9077. case 2: return encloseBasis2(B[0], B[1]);
  9078. case 3: return encloseBasis3(B[0], B[1], B[2]);
  9079. }
  9080. }
  9081. function encloseBasis1(a) {
  9082. return {
  9083. x: a.x,
  9084. y: a.y,
  9085. r: a.r
  9086. };
  9087. }
  9088. function encloseBasis2(a, b) {
  9089. var x1 = a.x, y1 = a.y, r1 = a.r,
  9090. x2 = b.x, y2 = b.y, r2 = b.r,
  9091. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  9092. l = Math.sqrt(x21 * x21 + y21 * y21);
  9093. return {
  9094. x: (x1 + x2 + x21 / l * r21) / 2,
  9095. y: (y1 + y2 + y21 / l * r21) / 2,
  9096. r: (l + r1 + r2) / 2
  9097. };
  9098. }
  9099. function encloseBasis3(a, b, c) {
  9100. var x1 = a.x, y1 = a.y, r1 = a.r,
  9101. x2 = b.x, y2 = b.y, r2 = b.r,
  9102. x3 = c.x, y3 = c.y, r3 = c.r,
  9103. a2 = x1 - x2,
  9104. a3 = x1 - x3,
  9105. b2 = y1 - y2,
  9106. b3 = y1 - y3,
  9107. c2 = r2 - r1,
  9108. c3 = r3 - r1,
  9109. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  9110. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  9111. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  9112. ab = a3 * b2 - a2 * b3,
  9113. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  9114. xb = (b3 * c2 - b2 * c3) / ab,
  9115. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  9116. yb = (a2 * c3 - a3 * c2) / ab,
  9117. A = xb * xb + yb * yb - 1,
  9118. B = 2 * (r1 + xa * xb + ya * yb),
  9119. C = xa * xa + ya * ya - r1 * r1,
  9120. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  9121. return {
  9122. x: x1 + xa + xb * r,
  9123. y: y1 + ya + yb * r,
  9124. r: r
  9125. };
  9126. }
  9127. function place(b, a, c) {
  9128. var dx = b.x - a.x, x, a2,
  9129. dy = b.y - a.y, y, b2,
  9130. d2 = dx * dx + dy * dy;
  9131. if (d2) {
  9132. a2 = a.r + c.r, a2 *= a2;
  9133. b2 = b.r + c.r, b2 *= b2;
  9134. if (a2 > b2) {
  9135. x = (d2 + b2 - a2) / (2 * d2);
  9136. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  9137. c.x = b.x - x * dx - y * dy;
  9138. c.y = b.y - x * dy + y * dx;
  9139. } else {
  9140. x = (d2 + a2 - b2) / (2 * d2);
  9141. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  9142. c.x = a.x + x * dx - y * dy;
  9143. c.y = a.y + x * dy + y * dx;
  9144. }
  9145. } else {
  9146. c.x = a.x + c.r;
  9147. c.y = a.y;
  9148. }
  9149. }
  9150. function intersects(a, b) {
  9151. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9152. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9153. }
  9154. function score(node) {
  9155. var a = node._,
  9156. b = node.next._,
  9157. ab = a.r + b.r,
  9158. dx = (a.x * b.r + b.x * a.r) / ab,
  9159. dy = (a.y * b.r + b.y * a.r) / ab;
  9160. return dx * dx + dy * dy;
  9161. }
  9162. function Node$1(circle) {
  9163. this._ = circle;
  9164. this.next = null;
  9165. this.previous = null;
  9166. }
  9167. function packEnclose(circles) {
  9168. if (!(n = circles.length)) return 0;
  9169. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  9170. // Place the first circle.
  9171. a = circles[0], a.x = 0, a.y = 0;
  9172. if (!(n > 1)) return a.r;
  9173. // Place the second circle.
  9174. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  9175. if (!(n > 2)) return a.r + b.r;
  9176. // Place the third circle.
  9177. place(b, a, c = circles[2]);
  9178. // Initialize the front-chain using the first three circles a, b and c.
  9179. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  9180. a.next = c.previous = b;
  9181. b.next = a.previous = c;
  9182. c.next = b.previous = a;
  9183. // Attempt to place each remaining circle…
  9184. pack: for (i = 3; i < n; ++i) {
  9185. place(a._, b._, c = circles[i]), c = new Node$1(c);
  9186. // Find the closest intersecting circle on the front-chain, if any.
  9187. // “Closeness” is determined by linear distance along the front-chain.
  9188. // “Ahead” or “behind” is likewise determined by linear distance.
  9189. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  9190. do {
  9191. if (sj <= sk) {
  9192. if (intersects(j._, c._)) {
  9193. b = j, a.next = b, b.previous = a, --i;
  9194. continue pack;
  9195. }
  9196. sj += j._.r, j = j.next;
  9197. } else {
  9198. if (intersects(k._, c._)) {
  9199. a = k, a.next = b, b.previous = a, --i;
  9200. continue pack;
  9201. }
  9202. sk += k._.r, k = k.previous;
  9203. }
  9204. } while (j !== k.next);
  9205. // Success! Insert the new circle c between a and b.
  9206. c.previous = a, c.next = b, a.next = b.previous = b = c;
  9207. // Compute the new closest circle pair to the centroid.
  9208. aa = score(a);
  9209. while ((c = c.next) !== b) {
  9210. if ((ca = score(c)) < aa) {
  9211. a = c, aa = ca;
  9212. }
  9213. }
  9214. b = a.next;
  9215. }
  9216. // Compute the enclosing circle of the front chain.
  9217. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  9218. // Translate the circles to put the enclosing circle around the origin.
  9219. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  9220. return c.r;
  9221. }
  9222. function siblings(circles) {
  9223. packEnclose(circles);
  9224. return circles;
  9225. }
  9226. function optional(f) {
  9227. return f == null ? null : required(f);
  9228. }
  9229. function required(f) {
  9230. if (typeof f !== "function") throw new Error;
  9231. return f;
  9232. }
  9233. function constantZero() {
  9234. return 0;
  9235. }
  9236. function constant$9(x) {
  9237. return function() {
  9238. return x;
  9239. };
  9240. }
  9241. function defaultRadius$1(d) {
  9242. return Math.sqrt(d.value);
  9243. }
  9244. function index$2() {
  9245. var radius = null,
  9246. dx = 1,
  9247. dy = 1,
  9248. padding = constantZero;
  9249. function pack(root) {
  9250. root.x = dx / 2, root.y = dy / 2;
  9251. if (radius) {
  9252. root.eachBefore(radiusLeaf(radius))
  9253. .eachAfter(packChildren(padding, 0.5))
  9254. .eachBefore(translateChild(1));
  9255. } else {
  9256. root.eachBefore(radiusLeaf(defaultRadius$1))
  9257. .eachAfter(packChildren(constantZero, 1))
  9258. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  9259. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  9260. }
  9261. return root;
  9262. }
  9263. pack.radius = function(x) {
  9264. return arguments.length ? (radius = optional(x), pack) : radius;
  9265. };
  9266. pack.size = function(x) {
  9267. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  9268. };
  9269. pack.padding = function(x) {
  9270. return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
  9271. };
  9272. return pack;
  9273. }
  9274. function radiusLeaf(radius) {
  9275. return function(node) {
  9276. if (!node.children) {
  9277. node.r = Math.max(0, +radius(node) || 0);
  9278. }
  9279. };
  9280. }
  9281. function packChildren(padding, k) {
  9282. return function(node) {
  9283. if (children = node.children) {
  9284. var children,
  9285. i,
  9286. n = children.length,
  9287. r = padding(node) * k || 0,
  9288. e;
  9289. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  9290. e = packEnclose(children);
  9291. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  9292. node.r = e + r;
  9293. }
  9294. };
  9295. }
  9296. function translateChild(k) {
  9297. return function(node) {
  9298. var parent = node.parent;
  9299. node.r *= k;
  9300. if (parent) {
  9301. node.x = parent.x + k * node.x;
  9302. node.y = parent.y + k * node.y;
  9303. }
  9304. };
  9305. }
  9306. function roundNode(node) {
  9307. node.x0 = Math.round(node.x0);
  9308. node.y0 = Math.round(node.y0);
  9309. node.x1 = Math.round(node.x1);
  9310. node.y1 = Math.round(node.y1);
  9311. }
  9312. function treemapDice(parent, x0, y0, x1, y1) {
  9313. var nodes = parent.children,
  9314. node,
  9315. i = -1,
  9316. n = nodes.length,
  9317. k = parent.value && (x1 - x0) / parent.value;
  9318. while (++i < n) {
  9319. node = nodes[i], node.y0 = y0, node.y1 = y1;
  9320. node.x0 = x0, node.x1 = x0 += node.value * k;
  9321. }
  9322. }
  9323. function partition() {
  9324. var dx = 1,
  9325. dy = 1,
  9326. padding = 0,
  9327. round = false;
  9328. function partition(root) {
  9329. var n = root.height + 1;
  9330. root.x0 =
  9331. root.y0 = padding;
  9332. root.x1 = dx;
  9333. root.y1 = dy / n;
  9334. root.eachBefore(positionNode(dy, n));
  9335. if (round) root.eachBefore(roundNode);
  9336. return root;
  9337. }
  9338. function positionNode(dy, n) {
  9339. return function(node) {
  9340. if (node.children) {
  9341. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  9342. }
  9343. var x0 = node.x0,
  9344. y0 = node.y0,
  9345. x1 = node.x1 - padding,
  9346. y1 = node.y1 - padding;
  9347. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9348. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9349. node.x0 = x0;
  9350. node.y0 = y0;
  9351. node.x1 = x1;
  9352. node.y1 = y1;
  9353. };
  9354. }
  9355. partition.round = function(x) {
  9356. return arguments.length ? (round = !!x, partition) : round;
  9357. };
  9358. partition.size = function(x) {
  9359. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  9360. };
  9361. partition.padding = function(x) {
  9362. return arguments.length ? (padding = +x, partition) : padding;
  9363. };
  9364. return partition;
  9365. }
  9366. var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
  9367. preroot = {depth: -1},
  9368. ambiguous = {};
  9369. function defaultId(d) {
  9370. return d.id;
  9371. }
  9372. function defaultParentId(d) {
  9373. return d.parentId;
  9374. }
  9375. function stratify() {
  9376. var id = defaultId,
  9377. parentId = defaultParentId;
  9378. function stratify(data) {
  9379. var d,
  9380. i,
  9381. n = data.length,
  9382. root,
  9383. parent,
  9384. node,
  9385. nodes = new Array(n),
  9386. nodeId,
  9387. nodeKey,
  9388. nodeByKey = {};
  9389. for (i = 0; i < n; ++i) {
  9390. d = data[i], node = nodes[i] = new Node(d);
  9391. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  9392. nodeKey = keyPrefix$1 + (node.id = nodeId);
  9393. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  9394. }
  9395. }
  9396. for (i = 0; i < n; ++i) {
  9397. node = nodes[i], nodeId = parentId(data[i], i, data);
  9398. if (nodeId == null || !(nodeId += "")) {
  9399. if (root) throw new Error("multiple roots");
  9400. root = node;
  9401. } else {
  9402. parent = nodeByKey[keyPrefix$1 + nodeId];
  9403. if (!parent) throw new Error("missing: " + nodeId);
  9404. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  9405. if (parent.children) parent.children.push(node);
  9406. else parent.children = [node];
  9407. node.parent = parent;
  9408. }
  9409. }
  9410. if (!root) throw new Error("no root");
  9411. root.parent = preroot;
  9412. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  9413. root.parent = null;
  9414. if (n > 0) throw new Error("cycle");
  9415. return root;
  9416. }
  9417. stratify.id = function(x) {
  9418. return arguments.length ? (id = required(x), stratify) : id;
  9419. };
  9420. stratify.parentId = function(x) {
  9421. return arguments.length ? (parentId = required(x), stratify) : parentId;
  9422. };
  9423. return stratify;
  9424. }
  9425. function defaultSeparation$1(a, b) {
  9426. return a.parent === b.parent ? 1 : 2;
  9427. }
  9428. // function radialSeparation(a, b) {
  9429. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  9430. // }
  9431. // This function is used to traverse the left contour of a subtree (or
  9432. // subforest). It returns the successor of v on this contour. This successor is
  9433. // either given by the leftmost child of v or by the thread of v. The function
  9434. // returns null if and only if v is on the highest level of its subtree.
  9435. function nextLeft(v) {
  9436. var children = v.children;
  9437. return children ? children[0] : v.t;
  9438. }
  9439. // This function works analogously to nextLeft.
  9440. function nextRight(v) {
  9441. var children = v.children;
  9442. return children ? children[children.length - 1] : v.t;
  9443. }
  9444. // Shifts the current subtree rooted at w+. This is done by increasing
  9445. // prelim(w+) and mod(w+) by shift.
  9446. function moveSubtree(wm, wp, shift) {
  9447. var change = shift / (wp.i - wm.i);
  9448. wp.c -= change;
  9449. wp.s += shift;
  9450. wm.c += change;
  9451. wp.z += shift;
  9452. wp.m += shift;
  9453. }
  9454. // All other shifts, applied to the smaller subtrees between w- and w+, are
  9455. // performed by this function. To prepare the shifts, we have to adjust
  9456. // change(w+), shift(w+), and change(w-).
  9457. function executeShifts(v) {
  9458. var shift = 0,
  9459. change = 0,
  9460. children = v.children,
  9461. i = children.length,
  9462. w;
  9463. while (--i >= 0) {
  9464. w = children[i];
  9465. w.z += shift;
  9466. w.m += shift;
  9467. shift += w.s + (change += w.c);
  9468. }
  9469. }
  9470. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  9471. // returns the specified (default) ancestor.
  9472. function nextAncestor(vim, v, ancestor) {
  9473. return vim.a.parent === v.parent ? vim.a : ancestor;
  9474. }
  9475. function TreeNode(node, i) {
  9476. this._ = node;
  9477. this.parent = null;
  9478. this.children = null;
  9479. this.A = null; // default ancestor
  9480. this.a = this; // ancestor
  9481. this.z = 0; // prelim
  9482. this.m = 0; // mod
  9483. this.c = 0; // change
  9484. this.s = 0; // shift
  9485. this.t = null; // thread
  9486. this.i = i; // number
  9487. }
  9488. TreeNode.prototype = Object.create(Node.prototype);
  9489. function treeRoot(root) {
  9490. var tree = new TreeNode(root, 0),
  9491. node,
  9492. nodes = [tree],
  9493. child,
  9494. children,
  9495. i,
  9496. n;
  9497. while (node = nodes.pop()) {
  9498. if (children = node._.children) {
  9499. node.children = new Array(n = children.length);
  9500. for (i = n - 1; i >= 0; --i) {
  9501. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  9502. child.parent = node;
  9503. }
  9504. }
  9505. }
  9506. (tree.parent = new TreeNode(null, 0)).children = [tree];
  9507. return tree;
  9508. }
  9509. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  9510. function tree() {
  9511. var separation = defaultSeparation$1,
  9512. dx = 1,
  9513. dy = 1,
  9514. nodeSize = null;
  9515. function tree(root) {
  9516. var t = treeRoot(root);
  9517. // Compute the layout using Buchheim et al.’s algorithm.
  9518. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9519. t.eachBefore(secondWalk);
  9520. // If a fixed node size is specified, scale x and y.
  9521. if (nodeSize) root.eachBefore(sizeNode);
  9522. // If a fixed tree size is specified, scale x and y based on the extent.
  9523. // Compute the left-most, right-most, and depth-most nodes for extents.
  9524. else {
  9525. var left = root,
  9526. right = root,
  9527. bottom = root;
  9528. root.eachBefore(function(node) {
  9529. if (node.x < left.x) left = node;
  9530. if (node.x > right.x) right = node;
  9531. if (node.depth > bottom.depth) bottom = node;
  9532. });
  9533. var s = left === right ? 1 : separation(left, right) / 2,
  9534. tx = s - left.x,
  9535. kx = dx / (right.x + s + tx),
  9536. ky = dy / (bottom.depth || 1);
  9537. root.eachBefore(function(node) {
  9538. node.x = (node.x + tx) * kx;
  9539. node.y = node.depth * ky;
  9540. });
  9541. }
  9542. return root;
  9543. }
  9544. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9545. // applied recursively to the children of v, as well as the function
  9546. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9547. // node v is placed to the midpoint of its outermost children.
  9548. function firstWalk(v) {
  9549. var children = v.children,
  9550. siblings = v.parent.children,
  9551. w = v.i ? siblings[v.i - 1] : null;
  9552. if (children) {
  9553. executeShifts(v);
  9554. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9555. if (w) {
  9556. v.z = w.z + separation(v._, w._);
  9557. v.m = v.z - midpoint;
  9558. } else {
  9559. v.z = midpoint;
  9560. }
  9561. } else if (w) {
  9562. v.z = w.z + separation(v._, w._);
  9563. }
  9564. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9565. }
  9566. // Computes all real x-coordinates by summing up the modifiers recursively.
  9567. function secondWalk(v) {
  9568. v._.x = v.z + v.parent.m;
  9569. v.m += v.parent.m;
  9570. }
  9571. // The core of the algorithm. Here, a new subtree is combined with the
  9572. // previous subtrees. Threads are used to traverse the inside and outside
  9573. // contours of the left and right subtree up to the highest common level. The
  9574. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9575. // superscript o means outside and i means inside, the subscript - means left
  9576. // subtree and + means right subtree. For summing up the modifiers along the
  9577. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9578. // nodes of the inside contours conflict, we compute the left one of the
  9579. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9580. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9581. // Finally, we add a new thread (if necessary).
  9582. function apportion(v, w, ancestor) {
  9583. if (w) {
  9584. var vip = v,
  9585. vop = v,
  9586. vim = w,
  9587. vom = vip.parent.children[0],
  9588. sip = vip.m,
  9589. sop = vop.m,
  9590. sim = vim.m,
  9591. som = vom.m,
  9592. shift;
  9593. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9594. vom = nextLeft(vom);
  9595. vop = nextRight(vop);
  9596. vop.a = v;
  9597. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9598. if (shift > 0) {
  9599. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9600. sip += shift;
  9601. sop += shift;
  9602. }
  9603. sim += vim.m;
  9604. sip += vip.m;
  9605. som += vom.m;
  9606. sop += vop.m;
  9607. }
  9608. if (vim && !nextRight(vop)) {
  9609. vop.t = vim;
  9610. vop.m += sim - sop;
  9611. }
  9612. if (vip && !nextLeft(vom)) {
  9613. vom.t = vip;
  9614. vom.m += sip - som;
  9615. ancestor = v;
  9616. }
  9617. }
  9618. return ancestor;
  9619. }
  9620. function sizeNode(node) {
  9621. node.x *= dx;
  9622. node.y = node.depth * dy;
  9623. }
  9624. tree.separation = function(x) {
  9625. return arguments.length ? (separation = x, tree) : separation;
  9626. };
  9627. tree.size = function(x) {
  9628. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9629. };
  9630. tree.nodeSize = function(x) {
  9631. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9632. };
  9633. return tree;
  9634. }
  9635. function treemapSlice(parent, x0, y0, x1, y1) {
  9636. var nodes = parent.children,
  9637. node,
  9638. i = -1,
  9639. n = nodes.length,
  9640. k = parent.value && (y1 - y0) / parent.value;
  9641. while (++i < n) {
  9642. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9643. node.y0 = y0, node.y1 = y0 += node.value * k;
  9644. }
  9645. }
  9646. var phi = (1 + Math.sqrt(5)) / 2;
  9647. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9648. var rows = [],
  9649. nodes = parent.children,
  9650. row,
  9651. nodeValue,
  9652. i0 = 0,
  9653. i1 = 0,
  9654. n = nodes.length,
  9655. dx, dy,
  9656. value = parent.value,
  9657. sumValue,
  9658. minValue,
  9659. maxValue,
  9660. newRatio,
  9661. minRatio,
  9662. alpha,
  9663. beta;
  9664. while (i0 < n) {
  9665. dx = x1 - x0, dy = y1 - y0;
  9666. // Find the next non-empty node.
  9667. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9668. minValue = maxValue = sumValue;
  9669. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9670. beta = sumValue * sumValue * alpha;
  9671. minRatio = Math.max(maxValue / beta, beta / minValue);
  9672. // Keep adding nodes while the aspect ratio maintains or improves.
  9673. for (; i1 < n; ++i1) {
  9674. sumValue += nodeValue = nodes[i1].value;
  9675. if (nodeValue < minValue) minValue = nodeValue;
  9676. if (nodeValue > maxValue) maxValue = nodeValue;
  9677. beta = sumValue * sumValue * alpha;
  9678. newRatio = Math.max(maxValue / beta, beta / minValue);
  9679. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9680. minRatio = newRatio;
  9681. }
  9682. // Position and record the row orientation.
  9683. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9684. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9685. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9686. value -= sumValue, i0 = i1;
  9687. }
  9688. return rows;
  9689. }
  9690. var squarify = (function custom(ratio) {
  9691. function squarify(parent, x0, y0, x1, y1) {
  9692. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9693. }
  9694. squarify.ratio = function(x) {
  9695. return custom((x = +x) > 1 ? x : 1);
  9696. };
  9697. return squarify;
  9698. })(phi);
  9699. function index$3() {
  9700. var tile = squarify,
  9701. round = false,
  9702. dx = 1,
  9703. dy = 1,
  9704. paddingStack = [0],
  9705. paddingInner = constantZero,
  9706. paddingTop = constantZero,
  9707. paddingRight = constantZero,
  9708. paddingBottom = constantZero,
  9709. paddingLeft = constantZero;
  9710. function treemap(root) {
  9711. root.x0 =
  9712. root.y0 = 0;
  9713. root.x1 = dx;
  9714. root.y1 = dy;
  9715. root.eachBefore(positionNode);
  9716. paddingStack = [0];
  9717. if (round) root.eachBefore(roundNode);
  9718. return root;
  9719. }
  9720. function positionNode(node) {
  9721. var p = paddingStack[node.depth],
  9722. x0 = node.x0 + p,
  9723. y0 = node.y0 + p,
  9724. x1 = node.x1 - p,
  9725. y1 = node.y1 - p;
  9726. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9727. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9728. node.x0 = x0;
  9729. node.y0 = y0;
  9730. node.x1 = x1;
  9731. node.y1 = y1;
  9732. if (node.children) {
  9733. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  9734. x0 += paddingLeft(node) - p;
  9735. y0 += paddingTop(node) - p;
  9736. x1 -= paddingRight(node) - p;
  9737. y1 -= paddingBottom(node) - p;
  9738. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9739. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9740. tile(node, x0, y0, x1, y1);
  9741. }
  9742. }
  9743. treemap.round = function(x) {
  9744. return arguments.length ? (round = !!x, treemap) : round;
  9745. };
  9746. treemap.size = function(x) {
  9747. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  9748. };
  9749. treemap.tile = function(x) {
  9750. return arguments.length ? (tile = required(x), treemap) : tile;
  9751. };
  9752. treemap.padding = function(x) {
  9753. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  9754. };
  9755. treemap.paddingInner = function(x) {
  9756. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
  9757. };
  9758. treemap.paddingOuter = function(x) {
  9759. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  9760. };
  9761. treemap.paddingTop = function(x) {
  9762. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
  9763. };
  9764. treemap.paddingRight = function(x) {
  9765. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
  9766. };
  9767. treemap.paddingBottom = function(x) {
  9768. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
  9769. };
  9770. treemap.paddingLeft = function(x) {
  9771. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
  9772. };
  9773. return treemap;
  9774. }
  9775. function binary(parent, x0, y0, x1, y1) {
  9776. var nodes = parent.children,
  9777. i, n = nodes.length,
  9778. sum, sums = new Array(n + 1);
  9779. for (sums[0] = sum = i = 0; i < n; ++i) {
  9780. sums[i + 1] = sum += nodes[i].value;
  9781. }
  9782. partition(0, n, parent.value, x0, y0, x1, y1);
  9783. function partition(i, j, value, x0, y0, x1, y1) {
  9784. if (i >= j - 1) {
  9785. var node = nodes[i];
  9786. node.x0 = x0, node.y0 = y0;
  9787. node.x1 = x1, node.y1 = y1;
  9788. return;
  9789. }
  9790. var valueOffset = sums[i],
  9791. valueTarget = (value / 2) + valueOffset,
  9792. k = i + 1,
  9793. hi = j - 1;
  9794. while (k < hi) {
  9795. var mid = k + hi >>> 1;
  9796. if (sums[mid] < valueTarget) k = mid + 1;
  9797. else hi = mid;
  9798. }
  9799. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  9800. var valueLeft = sums[k] - valueOffset,
  9801. valueRight = value - valueLeft;
  9802. if ((x1 - x0) > (y1 - y0)) {
  9803. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  9804. partition(i, k, valueLeft, x0, y0, xk, y1);
  9805. partition(k, j, valueRight, xk, y0, x1, y1);
  9806. } else {
  9807. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  9808. partition(i, k, valueLeft, x0, y0, x1, yk);
  9809. partition(k, j, valueRight, x0, yk, x1, y1);
  9810. }
  9811. }
  9812. }
  9813. function sliceDice(parent, x0, y0, x1, y1) {
  9814. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  9815. }
  9816. var resquarify = (function custom(ratio) {
  9817. function resquarify(parent, x0, y0, x1, y1) {
  9818. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  9819. var rows,
  9820. row,
  9821. nodes,
  9822. i,
  9823. j = -1,
  9824. n,
  9825. m = rows.length,
  9826. value = parent.value;
  9827. while (++j < m) {
  9828. row = rows[j], nodes = row.children;
  9829. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  9830. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  9831. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  9832. value -= row.value;
  9833. }
  9834. } else {
  9835. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9836. rows.ratio = ratio;
  9837. }
  9838. }
  9839. resquarify.ratio = function(x) {
  9840. return custom((x = +x) > 1 ? x : 1);
  9841. };
  9842. return resquarify;
  9843. })(phi);
  9844. function area$2(polygon) {
  9845. var i = -1,
  9846. n = polygon.length,
  9847. a,
  9848. b = polygon[n - 1],
  9849. area = 0;
  9850. while (++i < n) {
  9851. a = b;
  9852. b = polygon[i];
  9853. area += a[1] * b[0] - a[0] * b[1];
  9854. }
  9855. return area / 2;
  9856. }
  9857. function centroid$1(polygon) {
  9858. var i = -1,
  9859. n = polygon.length,
  9860. x = 0,
  9861. y = 0,
  9862. a,
  9863. b = polygon[n - 1],
  9864. c,
  9865. k = 0;
  9866. while (++i < n) {
  9867. a = b;
  9868. b = polygon[i];
  9869. k += c = a[0] * b[1] - b[0] * a[1];
  9870. x += (a[0] + b[0]) * c;
  9871. y += (a[1] + b[1]) * c;
  9872. }
  9873. return k *= 3, [x / k, y / k];
  9874. }
  9875. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  9876. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  9877. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  9878. // negative if clockwise, and zero if the points are collinear.
  9879. function cross$1(a, b, c) {
  9880. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  9881. }
  9882. function lexicographicOrder(a, b) {
  9883. return a[0] - b[0] || a[1] - b[1];
  9884. }
  9885. // Computes the upper convex hull per the monotone chain algorithm.
  9886. // Assumes points.length >= 3, is sorted by x, unique in y.
  9887. // Returns an array of indices into points in left-to-right order.
  9888. function computeUpperHullIndexes(points) {
  9889. var n = points.length,
  9890. indexes = [0, 1],
  9891. size = 2;
  9892. for (var i = 2; i < n; ++i) {
  9893. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  9894. indexes[size++] = i;
  9895. }
  9896. return indexes.slice(0, size); // remove popped points
  9897. }
  9898. function hull(points) {
  9899. if ((n = points.length) < 3) return null;
  9900. var i,
  9901. n,
  9902. sortedPoints = new Array(n),
  9903. flippedPoints = new Array(n);
  9904. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  9905. sortedPoints.sort(lexicographicOrder);
  9906. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  9907. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  9908. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  9909. // Construct the hull polygon, removing possible duplicate endpoints.
  9910. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  9911. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  9912. hull = [];
  9913. // Add upper hull in right-to-l order.
  9914. // Then add lower hull in left-to-right order.
  9915. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  9916. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  9917. return hull;
  9918. }
  9919. function contains$2(polygon, point) {
  9920. var n = polygon.length,
  9921. p = polygon[n - 1],
  9922. x = point[0], y = point[1],
  9923. x0 = p[0], y0 = p[1],
  9924. x1, y1,
  9925. inside = false;
  9926. for (var i = 0; i < n; ++i) {
  9927. p = polygon[i], x1 = p[0], y1 = p[1];
  9928. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  9929. x0 = x1, y0 = y1;
  9930. }
  9931. return inside;
  9932. }
  9933. function length$2(polygon) {
  9934. var i = -1,
  9935. n = polygon.length,
  9936. b = polygon[n - 1],
  9937. xa,
  9938. ya,
  9939. xb = b[0],
  9940. yb = b[1],
  9941. perimeter = 0;
  9942. while (++i < n) {
  9943. xa = xb;
  9944. ya = yb;
  9945. b = polygon[i];
  9946. xb = b[0];
  9947. yb = b[1];
  9948. xa -= xb;
  9949. ya -= yb;
  9950. perimeter += Math.sqrt(xa * xa + ya * ya);
  9951. }
  9952. return perimeter;
  9953. }
  9954. function defaultSource$1() {
  9955. return Math.random();
  9956. }
  9957. var uniform = (function sourceRandomUniform(source) {
  9958. function randomUniform(min, max) {
  9959. min = min == null ? 0 : +min;
  9960. max = max == null ? 1 : +max;
  9961. if (arguments.length === 1) max = min, min = 0;
  9962. else max -= min;
  9963. return function() {
  9964. return source() * max + min;
  9965. };
  9966. }
  9967. randomUniform.source = sourceRandomUniform;
  9968. return randomUniform;
  9969. })(defaultSource$1);
  9970. var normal = (function sourceRandomNormal(source) {
  9971. function randomNormal(mu, sigma) {
  9972. var x, r;
  9973. mu = mu == null ? 0 : +mu;
  9974. sigma = sigma == null ? 1 : +sigma;
  9975. return function() {
  9976. var y;
  9977. // If available, use the second previously-generated uniform random.
  9978. if (x != null) y = x, x = null;
  9979. // Otherwise, generate a new x and y.
  9980. else do {
  9981. x = source() * 2 - 1;
  9982. y = source() * 2 - 1;
  9983. r = x * x + y * y;
  9984. } while (!r || r > 1);
  9985. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  9986. };
  9987. }
  9988. randomNormal.source = sourceRandomNormal;
  9989. return randomNormal;
  9990. })(defaultSource$1);
  9991. var logNormal = (function sourceRandomLogNormal(source) {
  9992. function randomLogNormal() {
  9993. var randomNormal = normal.source(source).apply(this, arguments);
  9994. return function() {
  9995. return Math.exp(randomNormal());
  9996. };
  9997. }
  9998. randomLogNormal.source = sourceRandomLogNormal;
  9999. return randomLogNormal;
  10000. })(defaultSource$1);
  10001. var irwinHall = (function sourceRandomIrwinHall(source) {
  10002. function randomIrwinHall(n) {
  10003. return function() {
  10004. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  10005. return sum;
  10006. };
  10007. }
  10008. randomIrwinHall.source = sourceRandomIrwinHall;
  10009. return randomIrwinHall;
  10010. })(defaultSource$1);
  10011. var bates = (function sourceRandomBates(source) {
  10012. function randomBates(n) {
  10013. var randomIrwinHall = irwinHall.source(source)(n);
  10014. return function() {
  10015. return randomIrwinHall() / n;
  10016. };
  10017. }
  10018. randomBates.source = sourceRandomBates;
  10019. return randomBates;
  10020. })(defaultSource$1);
  10021. var exponential$1 = (function sourceRandomExponential(source) {
  10022. function randomExponential(lambda) {
  10023. return function() {
  10024. return -Math.log(1 - source()) / lambda;
  10025. };
  10026. }
  10027. randomExponential.source = sourceRandomExponential;
  10028. return randomExponential;
  10029. })(defaultSource$1);
  10030. var array$3 = Array.prototype;
  10031. var map$2 = array$3.map;
  10032. var slice$5 = array$3.slice;
  10033. var implicit = {name: "implicit"};
  10034. function ordinal(range) {
  10035. var index = map$1(),
  10036. domain = [],
  10037. unknown = implicit;
  10038. range = range == null ? [] : slice$5.call(range);
  10039. function scale(d) {
  10040. var key = d + "", i = index.get(key);
  10041. if (!i) {
  10042. if (unknown !== implicit) return unknown;
  10043. index.set(key, i = domain.push(d));
  10044. }
  10045. return range[(i - 1) % range.length];
  10046. }
  10047. scale.domain = function(_) {
  10048. if (!arguments.length) return domain.slice();
  10049. domain = [], index = map$1();
  10050. var i = -1, n = _.length, d, key;
  10051. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  10052. return scale;
  10053. };
  10054. scale.range = function(_) {
  10055. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  10056. };
  10057. scale.unknown = function(_) {
  10058. return arguments.length ? (unknown = _, scale) : unknown;
  10059. };
  10060. scale.copy = function() {
  10061. return ordinal()
  10062. .domain(domain)
  10063. .range(range)
  10064. .unknown(unknown);
  10065. };
  10066. return scale;
  10067. }
  10068. function band() {
  10069. var scale = ordinal().unknown(undefined),
  10070. domain = scale.domain,
  10071. ordinalRange = scale.range,
  10072. range$$1 = [0, 1],
  10073. step,
  10074. bandwidth,
  10075. round = false,
  10076. paddingInner = 0,
  10077. paddingOuter = 0,
  10078. align = 0.5;
  10079. delete scale.unknown;
  10080. function rescale() {
  10081. var n = domain().length,
  10082. reverse = range$$1[1] < range$$1[0],
  10083. start = range$$1[reverse - 0],
  10084. stop = range$$1[1 - reverse];
  10085. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  10086. if (round) step = Math.floor(step);
  10087. start += (stop - start - step * (n - paddingInner)) * align;
  10088. bandwidth = step * (1 - paddingInner);
  10089. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  10090. var values = sequence(n).map(function(i) { return start + step * i; });
  10091. return ordinalRange(reverse ? values.reverse() : values);
  10092. }
  10093. scale.domain = function(_) {
  10094. return arguments.length ? (domain(_), rescale()) : domain();
  10095. };
  10096. scale.range = function(_) {
  10097. return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
  10098. };
  10099. scale.rangeRound = function(_) {
  10100. return range$$1 = [+_[0], +_[1]], round = true, rescale();
  10101. };
  10102. scale.bandwidth = function() {
  10103. return bandwidth;
  10104. };
  10105. scale.step = function() {
  10106. return step;
  10107. };
  10108. scale.round = function(_) {
  10109. return arguments.length ? (round = !!_, rescale()) : round;
  10110. };
  10111. scale.padding = function(_) {
  10112. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  10113. };
  10114. scale.paddingInner = function(_) {
  10115. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  10116. };
  10117. scale.paddingOuter = function(_) {
  10118. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  10119. };
  10120. scale.align = function(_) {
  10121. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  10122. };
  10123. scale.copy = function() {
  10124. return band()
  10125. .domain(domain())
  10126. .range(range$$1)
  10127. .round(round)
  10128. .paddingInner(paddingInner)
  10129. .paddingOuter(paddingOuter)
  10130. .align(align);
  10131. };
  10132. return rescale();
  10133. }
  10134. function pointish(scale) {
  10135. var copy = scale.copy;
  10136. scale.padding = scale.paddingOuter;
  10137. delete scale.paddingInner;
  10138. delete scale.paddingOuter;
  10139. scale.copy = function() {
  10140. return pointish(copy());
  10141. };
  10142. return scale;
  10143. }
  10144. function point$1() {
  10145. return pointish(band().paddingInner(1));
  10146. }
  10147. function constant$10(x) {
  10148. return function() {
  10149. return x;
  10150. };
  10151. }
  10152. function number$2(x) {
  10153. return +x;
  10154. }
  10155. var unit = [0, 1];
  10156. function deinterpolateLinear(a, b) {
  10157. return (b -= (a = +a))
  10158. ? function(x) { return (x - a) / b; }
  10159. : constant$10(b);
  10160. }
  10161. function deinterpolateClamp(deinterpolate) {
  10162. return function(a, b) {
  10163. var d = deinterpolate(a = +a, b = +b);
  10164. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  10165. };
  10166. }
  10167. function reinterpolateClamp(reinterpolate$$1) {
  10168. return function(a, b) {
  10169. var r = reinterpolate$$1(a = +a, b = +b);
  10170. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  10171. };
  10172. }
  10173. function bimap(domain, range, deinterpolate, reinterpolate$$1) {
  10174. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  10175. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate$$1(r1, r0);
  10176. else d0 = deinterpolate(d0, d1), r0 = reinterpolate$$1(r0, r1);
  10177. return function(x) { return r0(d0(x)); };
  10178. }
  10179. function polymap(domain, range, deinterpolate, reinterpolate$$1) {
  10180. var j = Math.min(domain.length, range.length) - 1,
  10181. d = new Array(j),
  10182. r = new Array(j),
  10183. i = -1;
  10184. // Reverse descending domains.
  10185. if (domain[j] < domain[0]) {
  10186. domain = domain.slice().reverse();
  10187. range = range.slice().reverse();
  10188. }
  10189. while (++i < j) {
  10190. d[i] = deinterpolate(domain[i], domain[i + 1]);
  10191. r[i] = reinterpolate$$1(range[i], range[i + 1]);
  10192. }
  10193. return function(x) {
  10194. var i = bisectRight(domain, x, 1, j) - 1;
  10195. return r[i](d[i](x));
  10196. };
  10197. }
  10198. function copy(source, target) {
  10199. return target
  10200. .domain(source.domain())
  10201. .range(source.range())
  10202. .interpolate(source.interpolate())
  10203. .clamp(source.clamp());
  10204. }
  10205. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  10206. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  10207. function continuous(deinterpolate, reinterpolate$$1) {
  10208. var domain = unit,
  10209. range = unit,
  10210. interpolate$$1 = interpolateValue,
  10211. clamp = false,
  10212. piecewise$$1,
  10213. output,
  10214. input;
  10215. function rescale() {
  10216. piecewise$$1 = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  10217. output = input = null;
  10218. return scale;
  10219. }
  10220. function scale(x) {
  10221. return (output || (output = piecewise$$1(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  10222. }
  10223. scale.invert = function(y) {
  10224. return (input || (input = piecewise$$1(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate$$1) : reinterpolate$$1)))(+y);
  10225. };
  10226. scale.domain = function(_) {
  10227. return arguments.length ? (domain = map$2.call(_, number$2), rescale()) : domain.slice();
  10228. };
  10229. scale.range = function(_) {
  10230. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10231. };
  10232. scale.rangeRound = function(_) {
  10233. return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
  10234. };
  10235. scale.clamp = function(_) {
  10236. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  10237. };
  10238. scale.interpolate = function(_) {
  10239. return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
  10240. };
  10241. return rescale();
  10242. }
  10243. function tickFormat(domain, count, specifier) {
  10244. var start = domain[0],
  10245. stop = domain[domain.length - 1],
  10246. step = tickStep(start, stop, count == null ? 10 : count),
  10247. precision;
  10248. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10249. switch (specifier.type) {
  10250. case "s": {
  10251. var value = Math.max(Math.abs(start), Math.abs(stop));
  10252. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10253. return exports.formatPrefix(specifier, value);
  10254. }
  10255. case "":
  10256. case "e":
  10257. case "g":
  10258. case "p":
  10259. case "r": {
  10260. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10261. break;
  10262. }
  10263. case "f":
  10264. case "%": {
  10265. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10266. break;
  10267. }
  10268. }
  10269. return exports.format(specifier);
  10270. }
  10271. function linearish(scale) {
  10272. var domain = scale.domain;
  10273. scale.ticks = function(count) {
  10274. var d = domain();
  10275. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10276. };
  10277. scale.tickFormat = function(count, specifier) {
  10278. return tickFormat(domain(), count, specifier);
  10279. };
  10280. scale.nice = function(count) {
  10281. if (count == null) count = 10;
  10282. var d = domain(),
  10283. i0 = 0,
  10284. i1 = d.length - 1,
  10285. start = d[i0],
  10286. stop = d[i1],
  10287. step;
  10288. if (stop < start) {
  10289. step = start, start = stop, stop = step;
  10290. step = i0, i0 = i1, i1 = step;
  10291. }
  10292. step = tickIncrement(start, stop, count);
  10293. if (step > 0) {
  10294. start = Math.floor(start / step) * step;
  10295. stop = Math.ceil(stop / step) * step;
  10296. step = tickIncrement(start, stop, count);
  10297. } else if (step < 0) {
  10298. start = Math.ceil(start * step) / step;
  10299. stop = Math.floor(stop * step) / step;
  10300. step = tickIncrement(start, stop, count);
  10301. }
  10302. if (step > 0) {
  10303. d[i0] = Math.floor(start / step) * step;
  10304. d[i1] = Math.ceil(stop / step) * step;
  10305. domain(d);
  10306. } else if (step < 0) {
  10307. d[i0] = Math.ceil(start * step) / step;
  10308. d[i1] = Math.floor(stop * step) / step;
  10309. domain(d);
  10310. }
  10311. return scale;
  10312. };
  10313. return scale;
  10314. }
  10315. function linear$2() {
  10316. var scale = continuous(deinterpolateLinear, reinterpolate);
  10317. scale.copy = function() {
  10318. return copy(scale, linear$2());
  10319. };
  10320. return linearish(scale);
  10321. }
  10322. function identity$6() {
  10323. var domain = [0, 1];
  10324. function scale(x) {
  10325. return +x;
  10326. }
  10327. scale.invert = scale;
  10328. scale.domain = scale.range = function(_) {
  10329. return arguments.length ? (domain = map$2.call(_, number$2), scale) : domain.slice();
  10330. };
  10331. scale.copy = function() {
  10332. return identity$6().domain(domain);
  10333. };
  10334. return linearish(scale);
  10335. }
  10336. function nice(domain, interval) {
  10337. domain = domain.slice();
  10338. var i0 = 0,
  10339. i1 = domain.length - 1,
  10340. x0 = domain[i0],
  10341. x1 = domain[i1],
  10342. t;
  10343. if (x1 < x0) {
  10344. t = i0, i0 = i1, i1 = t;
  10345. t = x0, x0 = x1, x1 = t;
  10346. }
  10347. domain[i0] = interval.floor(x0);
  10348. domain[i1] = interval.ceil(x1);
  10349. return domain;
  10350. }
  10351. function deinterpolate(a, b) {
  10352. return (b = Math.log(b / a))
  10353. ? function(x) { return Math.log(x / a) / b; }
  10354. : constant$10(b);
  10355. }
  10356. function reinterpolate$1(a, b) {
  10357. return a < 0
  10358. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  10359. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  10360. }
  10361. function pow10(x) {
  10362. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10363. }
  10364. function powp(base) {
  10365. return base === 10 ? pow10
  10366. : base === Math.E ? Math.exp
  10367. : function(x) { return Math.pow(base, x); };
  10368. }
  10369. function logp(base) {
  10370. return base === Math.E ? Math.log
  10371. : base === 10 && Math.log10
  10372. || base === 2 && Math.log2
  10373. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10374. }
  10375. function reflect(f) {
  10376. return function(x) {
  10377. return -f(-x);
  10378. };
  10379. }
  10380. function log$1() {
  10381. var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
  10382. domain = scale.domain,
  10383. base = 10,
  10384. logs = logp(10),
  10385. pows = powp(10);
  10386. function rescale() {
  10387. logs = logp(base), pows = powp(base);
  10388. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  10389. return scale;
  10390. }
  10391. scale.base = function(_) {
  10392. return arguments.length ? (base = +_, rescale()) : base;
  10393. };
  10394. scale.domain = function(_) {
  10395. return arguments.length ? (domain(_), rescale()) : domain();
  10396. };
  10397. scale.ticks = function(count) {
  10398. var d = domain(),
  10399. u = d[0],
  10400. v = d[d.length - 1],
  10401. r;
  10402. if (r = v < u) i = u, u = v, v = i;
  10403. var i = logs(u),
  10404. j = logs(v),
  10405. p,
  10406. k,
  10407. t,
  10408. n = count == null ? 10 : +count,
  10409. z = [];
  10410. if (!(base % 1) && j - i < n) {
  10411. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10412. if (u > 0) for (; i < j; ++i) {
  10413. for (k = 1, p = pows(i); k < base; ++k) {
  10414. t = p * k;
  10415. if (t < u) continue;
  10416. if (t > v) break;
  10417. z.push(t);
  10418. }
  10419. } else for (; i < j; ++i) {
  10420. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10421. t = p * k;
  10422. if (t < u) continue;
  10423. if (t > v) break;
  10424. z.push(t);
  10425. }
  10426. }
  10427. } else {
  10428. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10429. }
  10430. return r ? z.reverse() : z;
  10431. };
  10432. scale.tickFormat = function(count, specifier) {
  10433. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10434. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10435. if (count === Infinity) return specifier;
  10436. if (count == null) count = 10;
  10437. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10438. return function(d) {
  10439. var i = d / pows(Math.round(logs(d)));
  10440. if (i * base < base - 0.5) i *= base;
  10441. return i <= k ? specifier(d) : "";
  10442. };
  10443. };
  10444. scale.nice = function() {
  10445. return domain(nice(domain(), {
  10446. floor: function(x) { return pows(Math.floor(logs(x))); },
  10447. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10448. }));
  10449. };
  10450. scale.copy = function() {
  10451. return copy(scale, log$1().base(base));
  10452. };
  10453. return scale;
  10454. }
  10455. function raise$1(x, exponent) {
  10456. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10457. }
  10458. function pow$1() {
  10459. var exponent = 1,
  10460. scale = continuous(deinterpolate, reinterpolate),
  10461. domain = scale.domain;
  10462. function deinterpolate(a, b) {
  10463. return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
  10464. ? function(x) { return (raise$1(x, exponent) - a) / b; }
  10465. : constant$10(b);
  10466. }
  10467. function reinterpolate(a, b) {
  10468. b = raise$1(b, exponent) - (a = raise$1(a, exponent));
  10469. return function(t) { return raise$1(a + b * t, 1 / exponent); };
  10470. }
  10471. scale.exponent = function(_) {
  10472. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  10473. };
  10474. scale.copy = function() {
  10475. return copy(scale, pow$1().exponent(exponent));
  10476. };
  10477. return linearish(scale);
  10478. }
  10479. function sqrt$1() {
  10480. return pow$1().exponent(0.5);
  10481. }
  10482. function quantile$$1() {
  10483. var domain = [],
  10484. range = [],
  10485. thresholds = [];
  10486. function rescale() {
  10487. var i = 0, n = Math.max(1, range.length);
  10488. thresholds = new Array(n - 1);
  10489. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10490. return scale;
  10491. }
  10492. function scale(x) {
  10493. if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
  10494. }
  10495. scale.invertExtent = function(y) {
  10496. var i = range.indexOf(y);
  10497. return i < 0 ? [NaN, NaN] : [
  10498. i > 0 ? thresholds[i - 1] : domain[0],
  10499. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10500. ];
  10501. };
  10502. scale.domain = function(_) {
  10503. if (!arguments.length) return domain.slice();
  10504. domain = [];
  10505. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10506. domain.sort(ascending);
  10507. return rescale();
  10508. };
  10509. scale.range = function(_) {
  10510. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10511. };
  10512. scale.quantiles = function() {
  10513. return thresholds.slice();
  10514. };
  10515. scale.copy = function() {
  10516. return quantile$$1()
  10517. .domain(domain)
  10518. .range(range);
  10519. };
  10520. return scale;
  10521. }
  10522. function quantize$1() {
  10523. var x0 = 0,
  10524. x1 = 1,
  10525. n = 1,
  10526. domain = [0.5],
  10527. range = [0, 1];
  10528. function scale(x) {
  10529. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10530. }
  10531. function rescale() {
  10532. var i = -1;
  10533. domain = new Array(n);
  10534. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10535. return scale;
  10536. }
  10537. scale.domain = function(_) {
  10538. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10539. };
  10540. scale.range = function(_) {
  10541. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10542. };
  10543. scale.invertExtent = function(y) {
  10544. var i = range.indexOf(y);
  10545. return i < 0 ? [NaN, NaN]
  10546. : i < 1 ? [x0, domain[0]]
  10547. : i >= n ? [domain[n - 1], x1]
  10548. : [domain[i - 1], domain[i]];
  10549. };
  10550. scale.copy = function() {
  10551. return quantize$1()
  10552. .domain([x0, x1])
  10553. .range(range);
  10554. };
  10555. return linearish(scale);
  10556. }
  10557. function threshold$1() {
  10558. var domain = [0.5],
  10559. range = [0, 1],
  10560. n = 1;
  10561. function scale(x) {
  10562. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10563. }
  10564. scale.domain = function(_) {
  10565. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10566. };
  10567. scale.range = function(_) {
  10568. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10569. };
  10570. scale.invertExtent = function(y) {
  10571. var i = range.indexOf(y);
  10572. return [domain[i - 1], domain[i]];
  10573. };
  10574. scale.copy = function() {
  10575. return threshold$1()
  10576. .domain(domain)
  10577. .range(range);
  10578. };
  10579. return scale;
  10580. }
  10581. var t0$1 = new Date,
  10582. t1$1 = new Date;
  10583. function newInterval(floori, offseti, count, field) {
  10584. function interval(date) {
  10585. return floori(date = new Date(+date)), date;
  10586. }
  10587. interval.floor = interval;
  10588. interval.ceil = function(date) {
  10589. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10590. };
  10591. interval.round = function(date) {
  10592. var d0 = interval(date),
  10593. d1 = interval.ceil(date);
  10594. return date - d0 < d1 - date ? d0 : d1;
  10595. };
  10596. interval.offset = function(date, step) {
  10597. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10598. };
  10599. interval.range = function(start, stop, step) {
  10600. var range = [], previous;
  10601. start = interval.ceil(start);
  10602. step = step == null ? 1 : Math.floor(step);
  10603. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10604. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  10605. while (previous < start && start < stop);
  10606. return range;
  10607. };
  10608. interval.filter = function(test) {
  10609. return newInterval(function(date) {
  10610. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10611. }, function(date, step) {
  10612. if (date >= date) {
  10613. if (step < 0) while (++step <= 0) {
  10614. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10615. } else while (--step >= 0) {
  10616. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10617. }
  10618. }
  10619. });
  10620. };
  10621. if (count) {
  10622. interval.count = function(start, end) {
  10623. t0$1.setTime(+start), t1$1.setTime(+end);
  10624. floori(t0$1), floori(t1$1);
  10625. return Math.floor(count(t0$1, t1$1));
  10626. };
  10627. interval.every = function(step) {
  10628. step = Math.floor(step);
  10629. return !isFinite(step) || !(step > 0) ? null
  10630. : !(step > 1) ? interval
  10631. : interval.filter(field
  10632. ? function(d) { return field(d) % step === 0; }
  10633. : function(d) { return interval.count(0, d) % step === 0; });
  10634. };
  10635. }
  10636. return interval;
  10637. }
  10638. var millisecond = newInterval(function() {
  10639. // noop
  10640. }, function(date, step) {
  10641. date.setTime(+date + step);
  10642. }, function(start, end) {
  10643. return end - start;
  10644. });
  10645. // An optimized implementation for this simple case.
  10646. millisecond.every = function(k) {
  10647. k = Math.floor(k);
  10648. if (!isFinite(k) || !(k > 0)) return null;
  10649. if (!(k > 1)) return millisecond;
  10650. return newInterval(function(date) {
  10651. date.setTime(Math.floor(date / k) * k);
  10652. }, function(date, step) {
  10653. date.setTime(+date + step * k);
  10654. }, function(start, end) {
  10655. return (end - start) / k;
  10656. });
  10657. };
  10658. var milliseconds = millisecond.range;
  10659. var durationSecond = 1e3;
  10660. var durationMinute = 6e4;
  10661. var durationHour = 36e5;
  10662. var durationDay = 864e5;
  10663. var durationWeek = 6048e5;
  10664. var second = newInterval(function(date) {
  10665. date.setTime(Math.floor(date / durationSecond) * durationSecond);
  10666. }, function(date, step) {
  10667. date.setTime(+date + step * durationSecond);
  10668. }, function(start, end) {
  10669. return (end - start) / durationSecond;
  10670. }, function(date) {
  10671. return date.getUTCSeconds();
  10672. });
  10673. var seconds = second.range;
  10674. var minute = newInterval(function(date) {
  10675. date.setTime(Math.floor(date / durationMinute) * durationMinute);
  10676. }, function(date, step) {
  10677. date.setTime(+date + step * durationMinute);
  10678. }, function(start, end) {
  10679. return (end - start) / durationMinute;
  10680. }, function(date) {
  10681. return date.getMinutes();
  10682. });
  10683. var minutes = minute.range;
  10684. var hour = newInterval(function(date) {
  10685. var offset = date.getTimezoneOffset() * durationMinute % durationHour;
  10686. if (offset < 0) offset += durationHour;
  10687. date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
  10688. }, function(date, step) {
  10689. date.setTime(+date + step * durationHour);
  10690. }, function(start, end) {
  10691. return (end - start) / durationHour;
  10692. }, function(date) {
  10693. return date.getHours();
  10694. });
  10695. var hours = hour.range;
  10696. var day = newInterval(function(date) {
  10697. date.setHours(0, 0, 0, 0);
  10698. }, function(date, step) {
  10699. date.setDate(date.getDate() + step);
  10700. }, function(start, end) {
  10701. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  10702. }, function(date) {
  10703. return date.getDate() - 1;
  10704. });
  10705. var days = day.range;
  10706. function weekday(i) {
  10707. return newInterval(function(date) {
  10708. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  10709. date.setHours(0, 0, 0, 0);
  10710. }, function(date, step) {
  10711. date.setDate(date.getDate() + step * 7);
  10712. }, function(start, end) {
  10713. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  10714. });
  10715. }
  10716. var sunday = weekday(0);
  10717. var monday = weekday(1);
  10718. var tuesday = weekday(2);
  10719. var wednesday = weekday(3);
  10720. var thursday = weekday(4);
  10721. var friday = weekday(5);
  10722. var saturday = weekday(6);
  10723. var sundays = sunday.range;
  10724. var mondays = monday.range;
  10725. var tuesdays = tuesday.range;
  10726. var wednesdays = wednesday.range;
  10727. var thursdays = thursday.range;
  10728. var fridays = friday.range;
  10729. var saturdays = saturday.range;
  10730. var month = newInterval(function(date) {
  10731. date.setDate(1);
  10732. date.setHours(0, 0, 0, 0);
  10733. }, function(date, step) {
  10734. date.setMonth(date.getMonth() + step);
  10735. }, function(start, end) {
  10736. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  10737. }, function(date) {
  10738. return date.getMonth();
  10739. });
  10740. var months = month.range;
  10741. var year = newInterval(function(date) {
  10742. date.setMonth(0, 1);
  10743. date.setHours(0, 0, 0, 0);
  10744. }, function(date, step) {
  10745. date.setFullYear(date.getFullYear() + step);
  10746. }, function(start, end) {
  10747. return end.getFullYear() - start.getFullYear();
  10748. }, function(date) {
  10749. return date.getFullYear();
  10750. });
  10751. // An optimized implementation for this simple case.
  10752. year.every = function(k) {
  10753. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10754. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  10755. date.setMonth(0, 1);
  10756. date.setHours(0, 0, 0, 0);
  10757. }, function(date, step) {
  10758. date.setFullYear(date.getFullYear() + step * k);
  10759. });
  10760. };
  10761. var years = year.range;
  10762. var utcMinute = newInterval(function(date) {
  10763. date.setUTCSeconds(0, 0);
  10764. }, function(date, step) {
  10765. date.setTime(+date + step * durationMinute);
  10766. }, function(start, end) {
  10767. return (end - start) / durationMinute;
  10768. }, function(date) {
  10769. return date.getUTCMinutes();
  10770. });
  10771. var utcMinutes = utcMinute.range;
  10772. var utcHour = newInterval(function(date) {
  10773. date.setUTCMinutes(0, 0, 0);
  10774. }, function(date, step) {
  10775. date.setTime(+date + step * durationHour);
  10776. }, function(start, end) {
  10777. return (end - start) / durationHour;
  10778. }, function(date) {
  10779. return date.getUTCHours();
  10780. });
  10781. var utcHours = utcHour.range;
  10782. var utcDay = newInterval(function(date) {
  10783. date.setUTCHours(0, 0, 0, 0);
  10784. }, function(date, step) {
  10785. date.setUTCDate(date.getUTCDate() + step);
  10786. }, function(start, end) {
  10787. return (end - start) / durationDay;
  10788. }, function(date) {
  10789. return date.getUTCDate() - 1;
  10790. });
  10791. var utcDays = utcDay.range;
  10792. function utcWeekday(i) {
  10793. return newInterval(function(date) {
  10794. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  10795. date.setUTCHours(0, 0, 0, 0);
  10796. }, function(date, step) {
  10797. date.setUTCDate(date.getUTCDate() + step * 7);
  10798. }, function(start, end) {
  10799. return (end - start) / durationWeek;
  10800. });
  10801. }
  10802. var utcSunday = utcWeekday(0);
  10803. var utcMonday = utcWeekday(1);
  10804. var utcTuesday = utcWeekday(2);
  10805. var utcWednesday = utcWeekday(3);
  10806. var utcThursday = utcWeekday(4);
  10807. var utcFriday = utcWeekday(5);
  10808. var utcSaturday = utcWeekday(6);
  10809. var utcSundays = utcSunday.range;
  10810. var utcMondays = utcMonday.range;
  10811. var utcTuesdays = utcTuesday.range;
  10812. var utcWednesdays = utcWednesday.range;
  10813. var utcThursdays = utcThursday.range;
  10814. var utcFridays = utcFriday.range;
  10815. var utcSaturdays = utcSaturday.range;
  10816. var utcMonth = newInterval(function(date) {
  10817. date.setUTCDate(1);
  10818. date.setUTCHours(0, 0, 0, 0);
  10819. }, function(date, step) {
  10820. date.setUTCMonth(date.getUTCMonth() + step);
  10821. }, function(start, end) {
  10822. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  10823. }, function(date) {
  10824. return date.getUTCMonth();
  10825. });
  10826. var utcMonths = utcMonth.range;
  10827. var utcYear = newInterval(function(date) {
  10828. date.setUTCMonth(0, 1);
  10829. date.setUTCHours(0, 0, 0, 0);
  10830. }, function(date, step) {
  10831. date.setUTCFullYear(date.getUTCFullYear() + step);
  10832. }, function(start, end) {
  10833. return end.getUTCFullYear() - start.getUTCFullYear();
  10834. }, function(date) {
  10835. return date.getUTCFullYear();
  10836. });
  10837. // An optimized implementation for this simple case.
  10838. utcYear.every = function(k) {
  10839. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10840. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  10841. date.setUTCMonth(0, 1);
  10842. date.setUTCHours(0, 0, 0, 0);
  10843. }, function(date, step) {
  10844. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  10845. });
  10846. };
  10847. var utcYears = utcYear.range;
  10848. function localDate(d) {
  10849. if (0 <= d.y && d.y < 100) {
  10850. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  10851. date.setFullYear(d.y);
  10852. return date;
  10853. }
  10854. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  10855. }
  10856. function utcDate(d) {
  10857. if (0 <= d.y && d.y < 100) {
  10858. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  10859. date.setUTCFullYear(d.y);
  10860. return date;
  10861. }
  10862. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  10863. }
  10864. function newYear(y) {
  10865. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  10866. }
  10867. function formatLocale$1(locale) {
  10868. var locale_dateTime = locale.dateTime,
  10869. locale_date = locale.date,
  10870. locale_time = locale.time,
  10871. locale_periods = locale.periods,
  10872. locale_weekdays = locale.days,
  10873. locale_shortWeekdays = locale.shortDays,
  10874. locale_months = locale.months,
  10875. locale_shortMonths = locale.shortMonths;
  10876. var periodRe = formatRe(locale_periods),
  10877. periodLookup = formatLookup(locale_periods),
  10878. weekdayRe = formatRe(locale_weekdays),
  10879. weekdayLookup = formatLookup(locale_weekdays),
  10880. shortWeekdayRe = formatRe(locale_shortWeekdays),
  10881. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  10882. monthRe = formatRe(locale_months),
  10883. monthLookup = formatLookup(locale_months),
  10884. shortMonthRe = formatRe(locale_shortMonths),
  10885. shortMonthLookup = formatLookup(locale_shortMonths);
  10886. var formats = {
  10887. "a": formatShortWeekday,
  10888. "A": formatWeekday,
  10889. "b": formatShortMonth,
  10890. "B": formatMonth,
  10891. "c": null,
  10892. "d": formatDayOfMonth,
  10893. "e": formatDayOfMonth,
  10894. "f": formatMicroseconds,
  10895. "H": formatHour24,
  10896. "I": formatHour12,
  10897. "j": formatDayOfYear,
  10898. "L": formatMilliseconds,
  10899. "m": formatMonthNumber,
  10900. "M": formatMinutes,
  10901. "p": formatPeriod,
  10902. "Q": formatUnixTimestamp,
  10903. "s": formatUnixTimestampSeconds,
  10904. "S": formatSeconds,
  10905. "u": formatWeekdayNumberMonday,
  10906. "U": formatWeekNumberSunday,
  10907. "V": formatWeekNumberISO,
  10908. "w": formatWeekdayNumberSunday,
  10909. "W": formatWeekNumberMonday,
  10910. "x": null,
  10911. "X": null,
  10912. "y": formatYear,
  10913. "Y": formatFullYear,
  10914. "Z": formatZone,
  10915. "%": formatLiteralPercent
  10916. };
  10917. var utcFormats = {
  10918. "a": formatUTCShortWeekday,
  10919. "A": formatUTCWeekday,
  10920. "b": formatUTCShortMonth,
  10921. "B": formatUTCMonth,
  10922. "c": null,
  10923. "d": formatUTCDayOfMonth,
  10924. "e": formatUTCDayOfMonth,
  10925. "f": formatUTCMicroseconds,
  10926. "H": formatUTCHour24,
  10927. "I": formatUTCHour12,
  10928. "j": formatUTCDayOfYear,
  10929. "L": formatUTCMilliseconds,
  10930. "m": formatUTCMonthNumber,
  10931. "M": formatUTCMinutes,
  10932. "p": formatUTCPeriod,
  10933. "Q": formatUnixTimestamp,
  10934. "s": formatUnixTimestampSeconds,
  10935. "S": formatUTCSeconds,
  10936. "u": formatUTCWeekdayNumberMonday,
  10937. "U": formatUTCWeekNumberSunday,
  10938. "V": formatUTCWeekNumberISO,
  10939. "w": formatUTCWeekdayNumberSunday,
  10940. "W": formatUTCWeekNumberMonday,
  10941. "x": null,
  10942. "X": null,
  10943. "y": formatUTCYear,
  10944. "Y": formatUTCFullYear,
  10945. "Z": formatUTCZone,
  10946. "%": formatLiteralPercent
  10947. };
  10948. var parses = {
  10949. "a": parseShortWeekday,
  10950. "A": parseWeekday,
  10951. "b": parseShortMonth,
  10952. "B": parseMonth,
  10953. "c": parseLocaleDateTime,
  10954. "d": parseDayOfMonth,
  10955. "e": parseDayOfMonth,
  10956. "f": parseMicroseconds,
  10957. "H": parseHour24,
  10958. "I": parseHour24,
  10959. "j": parseDayOfYear,
  10960. "L": parseMilliseconds,
  10961. "m": parseMonthNumber,
  10962. "M": parseMinutes,
  10963. "p": parsePeriod,
  10964. "Q": parseUnixTimestamp,
  10965. "s": parseUnixTimestampSeconds,
  10966. "S": parseSeconds,
  10967. "u": parseWeekdayNumberMonday,
  10968. "U": parseWeekNumberSunday,
  10969. "V": parseWeekNumberISO,
  10970. "w": parseWeekdayNumberSunday,
  10971. "W": parseWeekNumberMonday,
  10972. "x": parseLocaleDate,
  10973. "X": parseLocaleTime,
  10974. "y": parseYear,
  10975. "Y": parseFullYear,
  10976. "Z": parseZone,
  10977. "%": parseLiteralPercent
  10978. };
  10979. // These recursive directive definitions must be deferred.
  10980. formats.x = newFormat(locale_date, formats);
  10981. formats.X = newFormat(locale_time, formats);
  10982. formats.c = newFormat(locale_dateTime, formats);
  10983. utcFormats.x = newFormat(locale_date, utcFormats);
  10984. utcFormats.X = newFormat(locale_time, utcFormats);
  10985. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  10986. function newFormat(specifier, formats) {
  10987. return function(date) {
  10988. var string = [],
  10989. i = -1,
  10990. j = 0,
  10991. n = specifier.length,
  10992. c,
  10993. pad,
  10994. format;
  10995. if (!(date instanceof Date)) date = new Date(+date);
  10996. while (++i < n) {
  10997. if (specifier.charCodeAt(i) === 37) {
  10998. string.push(specifier.slice(j, i));
  10999. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  11000. else pad = c === "e" ? " " : "0";
  11001. if (format = formats[c]) c = format(date, pad);
  11002. string.push(c);
  11003. j = i + 1;
  11004. }
  11005. }
  11006. string.push(specifier.slice(j, i));
  11007. return string.join("");
  11008. };
  11009. }
  11010. function newParse(specifier, newDate) {
  11011. return function(string) {
  11012. var d = newYear(1900),
  11013. i = parseSpecifier(d, specifier, string += "", 0),
  11014. week, day$$1;
  11015. if (i != string.length) return null;
  11016. // If a UNIX timestamp is specified, return it.
  11017. if ("Q" in d) return new Date(d.Q);
  11018. // The am-pm flag is 0 for AM, and 1 for PM.
  11019. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  11020. // Convert day-of-week and week-of-year to day-of-year.
  11021. if ("V" in d) {
  11022. if (d.V < 1 || d.V > 53) return null;
  11023. if (!("w" in d)) d.w = 1;
  11024. if ("Z" in d) {
  11025. week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
  11026. week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  11027. week = utcDay.offset(week, (d.V - 1) * 7);
  11028. d.y = week.getUTCFullYear();
  11029. d.m = week.getUTCMonth();
  11030. d.d = week.getUTCDate() + (d.w + 6) % 7;
  11031. } else {
  11032. week = newDate(newYear(d.y)), day$$1 = week.getDay();
  11033. week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
  11034. week = day.offset(week, (d.V - 1) * 7);
  11035. d.y = week.getFullYear();
  11036. d.m = week.getMonth();
  11037. d.d = week.getDate() + (d.w + 6) % 7;
  11038. }
  11039. } else if ("W" in d || "U" in d) {
  11040. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  11041. day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  11042. d.m = 0;
  11043. 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;
  11044. }
  11045. // If a time zone is specified, all fields are interpreted as UTC and then
  11046. // offset according to the specified time zone.
  11047. if ("Z" in d) {
  11048. d.H += d.Z / 100 | 0;
  11049. d.M += d.Z % 100;
  11050. return utcDate(d);
  11051. }
  11052. // Otherwise, all fields are in local time.
  11053. return newDate(d);
  11054. };
  11055. }
  11056. function parseSpecifier(d, specifier, string, j) {
  11057. var i = 0,
  11058. n = specifier.length,
  11059. m = string.length,
  11060. c,
  11061. parse;
  11062. while (i < n) {
  11063. if (j >= m) return -1;
  11064. c = specifier.charCodeAt(i++);
  11065. if (c === 37) {
  11066. c = specifier.charAt(i++);
  11067. parse = parses[c in pads ? specifier.charAt(i++) : c];
  11068. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  11069. } else if (c != string.charCodeAt(j++)) {
  11070. return -1;
  11071. }
  11072. }
  11073. return j;
  11074. }
  11075. function parsePeriod(d, string, i) {
  11076. var n = periodRe.exec(string.slice(i));
  11077. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11078. }
  11079. function parseShortWeekday(d, string, i) {
  11080. var n = shortWeekdayRe.exec(string.slice(i));
  11081. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11082. }
  11083. function parseWeekday(d, string, i) {
  11084. var n = weekdayRe.exec(string.slice(i));
  11085. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11086. }
  11087. function parseShortMonth(d, string, i) {
  11088. var n = shortMonthRe.exec(string.slice(i));
  11089. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11090. }
  11091. function parseMonth(d, string, i) {
  11092. var n = monthRe.exec(string.slice(i));
  11093. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11094. }
  11095. function parseLocaleDateTime(d, string, i) {
  11096. return parseSpecifier(d, locale_dateTime, string, i);
  11097. }
  11098. function parseLocaleDate(d, string, i) {
  11099. return parseSpecifier(d, locale_date, string, i);
  11100. }
  11101. function parseLocaleTime(d, string, i) {
  11102. return parseSpecifier(d, locale_time, string, i);
  11103. }
  11104. function formatShortWeekday(d) {
  11105. return locale_shortWeekdays[d.getDay()];
  11106. }
  11107. function formatWeekday(d) {
  11108. return locale_weekdays[d.getDay()];
  11109. }
  11110. function formatShortMonth(d) {
  11111. return locale_shortMonths[d.getMonth()];
  11112. }
  11113. function formatMonth(d) {
  11114. return locale_months[d.getMonth()];
  11115. }
  11116. function formatPeriod(d) {
  11117. return locale_periods[+(d.getHours() >= 12)];
  11118. }
  11119. function formatUTCShortWeekday(d) {
  11120. return locale_shortWeekdays[d.getUTCDay()];
  11121. }
  11122. function formatUTCWeekday(d) {
  11123. return locale_weekdays[d.getUTCDay()];
  11124. }
  11125. function formatUTCShortMonth(d) {
  11126. return locale_shortMonths[d.getUTCMonth()];
  11127. }
  11128. function formatUTCMonth(d) {
  11129. return locale_months[d.getUTCMonth()];
  11130. }
  11131. function formatUTCPeriod(d) {
  11132. return locale_periods[+(d.getUTCHours() >= 12)];
  11133. }
  11134. return {
  11135. format: function(specifier) {
  11136. var f = newFormat(specifier += "", formats);
  11137. f.toString = function() { return specifier; };
  11138. return f;
  11139. },
  11140. parse: function(specifier) {
  11141. var p = newParse(specifier += "", localDate);
  11142. p.toString = function() { return specifier; };
  11143. return p;
  11144. },
  11145. utcFormat: function(specifier) {
  11146. var f = newFormat(specifier += "", utcFormats);
  11147. f.toString = function() { return specifier; };
  11148. return f;
  11149. },
  11150. utcParse: function(specifier) {
  11151. var p = newParse(specifier, utcDate);
  11152. p.toString = function() { return specifier; };
  11153. return p;
  11154. }
  11155. };
  11156. }
  11157. var pads = {"-": "", "_": " ", "0": "0"},
  11158. numberRe = /^\s*\d+/, // note: ignores next directive
  11159. percentRe = /^%/,
  11160. requoteRe = /[\\^$*+?|[\]().{}]/g;
  11161. function pad(value, fill, width) {
  11162. var sign = value < 0 ? "-" : "",
  11163. string = (sign ? -value : value) + "",
  11164. length = string.length;
  11165. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  11166. }
  11167. function requote(s) {
  11168. return s.replace(requoteRe, "\\$&");
  11169. }
  11170. function formatRe(names) {
  11171. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  11172. }
  11173. function formatLookup(names) {
  11174. var map = {}, i = -1, n = names.length;
  11175. while (++i < n) map[names[i].toLowerCase()] = i;
  11176. return map;
  11177. }
  11178. function parseWeekdayNumberSunday(d, string, i) {
  11179. var n = numberRe.exec(string.slice(i, i + 1));
  11180. return n ? (d.w = +n[0], i + n[0].length) : -1;
  11181. }
  11182. function parseWeekdayNumberMonday(d, string, i) {
  11183. var n = numberRe.exec(string.slice(i, i + 1));
  11184. return n ? (d.u = +n[0], i + n[0].length) : -1;
  11185. }
  11186. function parseWeekNumberSunday(d, string, i) {
  11187. var n = numberRe.exec(string.slice(i, i + 2));
  11188. return n ? (d.U = +n[0], i + n[0].length) : -1;
  11189. }
  11190. function parseWeekNumberISO(d, string, i) {
  11191. var n = numberRe.exec(string.slice(i, i + 2));
  11192. return n ? (d.V = +n[0], i + n[0].length) : -1;
  11193. }
  11194. function parseWeekNumberMonday(d, string, i) {
  11195. var n = numberRe.exec(string.slice(i, i + 2));
  11196. return n ? (d.W = +n[0], i + n[0].length) : -1;
  11197. }
  11198. function parseFullYear(d, string, i) {
  11199. var n = numberRe.exec(string.slice(i, i + 4));
  11200. return n ? (d.y = +n[0], i + n[0].length) : -1;
  11201. }
  11202. function parseYear(d, string, i) {
  11203. var n = numberRe.exec(string.slice(i, i + 2));
  11204. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  11205. }
  11206. function parseZone(d, string, i) {
  11207. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  11208. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  11209. }
  11210. function parseMonthNumber(d, string, i) {
  11211. var n = numberRe.exec(string.slice(i, i + 2));
  11212. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  11213. }
  11214. function parseDayOfMonth(d, string, i) {
  11215. var n = numberRe.exec(string.slice(i, i + 2));
  11216. return n ? (d.d = +n[0], i + n[0].length) : -1;
  11217. }
  11218. function parseDayOfYear(d, string, i) {
  11219. var n = numberRe.exec(string.slice(i, i + 3));
  11220. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  11221. }
  11222. function parseHour24(d, string, i) {
  11223. var n = numberRe.exec(string.slice(i, i + 2));
  11224. return n ? (d.H = +n[0], i + n[0].length) : -1;
  11225. }
  11226. function parseMinutes(d, string, i) {
  11227. var n = numberRe.exec(string.slice(i, i + 2));
  11228. return n ? (d.M = +n[0], i + n[0].length) : -1;
  11229. }
  11230. function parseSeconds(d, string, i) {
  11231. var n = numberRe.exec(string.slice(i, i + 2));
  11232. return n ? (d.S = +n[0], i + n[0].length) : -1;
  11233. }
  11234. function parseMilliseconds(d, string, i) {
  11235. var n = numberRe.exec(string.slice(i, i + 3));
  11236. return n ? (d.L = +n[0], i + n[0].length) : -1;
  11237. }
  11238. function parseMicroseconds(d, string, i) {
  11239. var n = numberRe.exec(string.slice(i, i + 6));
  11240. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  11241. }
  11242. function parseLiteralPercent(d, string, i) {
  11243. var n = percentRe.exec(string.slice(i, i + 1));
  11244. return n ? i + n[0].length : -1;
  11245. }
  11246. function parseUnixTimestamp(d, string, i) {
  11247. var n = numberRe.exec(string.slice(i));
  11248. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  11249. }
  11250. function parseUnixTimestampSeconds(d, string, i) {
  11251. var n = numberRe.exec(string.slice(i));
  11252. return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
  11253. }
  11254. function formatDayOfMonth(d, p) {
  11255. return pad(d.getDate(), p, 2);
  11256. }
  11257. function formatHour24(d, p) {
  11258. return pad(d.getHours(), p, 2);
  11259. }
  11260. function formatHour12(d, p) {
  11261. return pad(d.getHours() % 12 || 12, p, 2);
  11262. }
  11263. function formatDayOfYear(d, p) {
  11264. return pad(1 + day.count(year(d), d), p, 3);
  11265. }
  11266. function formatMilliseconds(d, p) {
  11267. return pad(d.getMilliseconds(), p, 3);
  11268. }
  11269. function formatMicroseconds(d, p) {
  11270. return formatMilliseconds(d, p) + "000";
  11271. }
  11272. function formatMonthNumber(d, p) {
  11273. return pad(d.getMonth() + 1, p, 2);
  11274. }
  11275. function formatMinutes(d, p) {
  11276. return pad(d.getMinutes(), p, 2);
  11277. }
  11278. function formatSeconds(d, p) {
  11279. return pad(d.getSeconds(), p, 2);
  11280. }
  11281. function formatWeekdayNumberMonday(d) {
  11282. var day$$1 = d.getDay();
  11283. return day$$1 === 0 ? 7 : day$$1;
  11284. }
  11285. function formatWeekNumberSunday(d, p) {
  11286. return pad(sunday.count(year(d), d), p, 2);
  11287. }
  11288. function formatWeekNumberISO(d, p) {
  11289. var day$$1 = d.getDay();
  11290. d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
  11291. return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  11292. }
  11293. function formatWeekdayNumberSunday(d) {
  11294. return d.getDay();
  11295. }
  11296. function formatWeekNumberMonday(d, p) {
  11297. return pad(monday.count(year(d), d), p, 2);
  11298. }
  11299. function formatYear(d, p) {
  11300. return pad(d.getFullYear() % 100, p, 2);
  11301. }
  11302. function formatFullYear(d, p) {
  11303. return pad(d.getFullYear() % 10000, p, 4);
  11304. }
  11305. function formatZone(d) {
  11306. var z = d.getTimezoneOffset();
  11307. return (z > 0 ? "-" : (z *= -1, "+"))
  11308. + pad(z / 60 | 0, "0", 2)
  11309. + pad(z % 60, "0", 2);
  11310. }
  11311. function formatUTCDayOfMonth(d, p) {
  11312. return pad(d.getUTCDate(), p, 2);
  11313. }
  11314. function formatUTCHour24(d, p) {
  11315. return pad(d.getUTCHours(), p, 2);
  11316. }
  11317. function formatUTCHour12(d, p) {
  11318. return pad(d.getUTCHours() % 12 || 12, p, 2);
  11319. }
  11320. function formatUTCDayOfYear(d, p) {
  11321. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  11322. }
  11323. function formatUTCMilliseconds(d, p) {
  11324. return pad(d.getUTCMilliseconds(), p, 3);
  11325. }
  11326. function formatUTCMicroseconds(d, p) {
  11327. return formatUTCMilliseconds(d, p) + "000";
  11328. }
  11329. function formatUTCMonthNumber(d, p) {
  11330. return pad(d.getUTCMonth() + 1, p, 2);
  11331. }
  11332. function formatUTCMinutes(d, p) {
  11333. return pad(d.getUTCMinutes(), p, 2);
  11334. }
  11335. function formatUTCSeconds(d, p) {
  11336. return pad(d.getUTCSeconds(), p, 2);
  11337. }
  11338. function formatUTCWeekdayNumberMonday(d) {
  11339. var dow = d.getUTCDay();
  11340. return dow === 0 ? 7 : dow;
  11341. }
  11342. function formatUTCWeekNumberSunday(d, p) {
  11343. return pad(utcSunday.count(utcYear(d), d), p, 2);
  11344. }
  11345. function formatUTCWeekNumberISO(d, p) {
  11346. var day$$1 = d.getUTCDay();
  11347. d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
  11348. return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  11349. }
  11350. function formatUTCWeekdayNumberSunday(d) {
  11351. return d.getUTCDay();
  11352. }
  11353. function formatUTCWeekNumberMonday(d, p) {
  11354. return pad(utcMonday.count(utcYear(d), d), p, 2);
  11355. }
  11356. function formatUTCYear(d, p) {
  11357. return pad(d.getUTCFullYear() % 100, p, 2);
  11358. }
  11359. function formatUTCFullYear(d, p) {
  11360. return pad(d.getUTCFullYear() % 10000, p, 4);
  11361. }
  11362. function formatUTCZone() {
  11363. return "+0000";
  11364. }
  11365. function formatLiteralPercent() {
  11366. return "%";
  11367. }
  11368. function formatUnixTimestamp(d) {
  11369. return +d;
  11370. }
  11371. function formatUnixTimestampSeconds(d) {
  11372. return Math.floor(+d / 1000);
  11373. }
  11374. var locale$1;
  11375. defaultLocale$1({
  11376. dateTime: "%x, %X",
  11377. date: "%-m/%-d/%Y",
  11378. time: "%-I:%M:%S %p",
  11379. periods: ["AM", "PM"],
  11380. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11381. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11382. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11383. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11384. });
  11385. function defaultLocale$1(definition) {
  11386. locale$1 = formatLocale$1(definition);
  11387. exports.timeFormat = locale$1.format;
  11388. exports.timeParse = locale$1.parse;
  11389. exports.utcFormat = locale$1.utcFormat;
  11390. exports.utcParse = locale$1.utcParse;
  11391. return locale$1;
  11392. }
  11393. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11394. function formatIsoNative(date) {
  11395. return date.toISOString();
  11396. }
  11397. var formatIso = Date.prototype.toISOString
  11398. ? formatIsoNative
  11399. : exports.utcFormat(isoSpecifier);
  11400. function parseIsoNative(string) {
  11401. var date = new Date(string);
  11402. return isNaN(date) ? null : date;
  11403. }
  11404. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11405. ? parseIsoNative
  11406. : exports.utcParse(isoSpecifier);
  11407. var durationSecond$1 = 1000,
  11408. durationMinute$1 = durationSecond$1 * 60,
  11409. durationHour$1 = durationMinute$1 * 60,
  11410. durationDay$1 = durationHour$1 * 24,
  11411. durationWeek$1 = durationDay$1 * 7,
  11412. durationMonth = durationDay$1 * 30,
  11413. durationYear = durationDay$1 * 365;
  11414. function date$1(t) {
  11415. return new Date(t);
  11416. }
  11417. function number$3(t) {
  11418. return t instanceof Date ? +t : +new Date(+t);
  11419. }
  11420. function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
  11421. var scale = continuous(deinterpolateLinear, reinterpolate),
  11422. invert = scale.invert,
  11423. domain = scale.domain;
  11424. var formatMillisecond = format(".%L"),
  11425. formatSecond = format(":%S"),
  11426. formatMinute = format("%I:%M"),
  11427. formatHour = format("%I %p"),
  11428. formatDay = format("%a %d"),
  11429. formatWeek = format("%b %d"),
  11430. formatMonth = format("%B"),
  11431. formatYear = format("%Y");
  11432. var tickIntervals = [
  11433. [second$$1, 1, durationSecond$1],
  11434. [second$$1, 5, 5 * durationSecond$1],
  11435. [second$$1, 15, 15 * durationSecond$1],
  11436. [second$$1, 30, 30 * durationSecond$1],
  11437. [minute$$1, 1, durationMinute$1],
  11438. [minute$$1, 5, 5 * durationMinute$1],
  11439. [minute$$1, 15, 15 * durationMinute$1],
  11440. [minute$$1, 30, 30 * durationMinute$1],
  11441. [ hour$$1, 1, durationHour$1 ],
  11442. [ hour$$1, 3, 3 * durationHour$1 ],
  11443. [ hour$$1, 6, 6 * durationHour$1 ],
  11444. [ hour$$1, 12, 12 * durationHour$1 ],
  11445. [ day$$1, 1, durationDay$1 ],
  11446. [ day$$1, 2, 2 * durationDay$1 ],
  11447. [ week, 1, durationWeek$1 ],
  11448. [ month$$1, 1, durationMonth ],
  11449. [ month$$1, 3, 3 * durationMonth ],
  11450. [ year$$1, 1, durationYear ]
  11451. ];
  11452. function tickFormat(date$$1) {
  11453. return (second$$1(date$$1) < date$$1 ? formatMillisecond
  11454. : minute$$1(date$$1) < date$$1 ? formatSecond
  11455. : hour$$1(date$$1) < date$$1 ? formatMinute
  11456. : day$$1(date$$1) < date$$1 ? formatHour
  11457. : month$$1(date$$1) < date$$1 ? (week(date$$1) < date$$1 ? formatDay : formatWeek)
  11458. : year$$1(date$$1) < date$$1 ? formatMonth
  11459. : formatYear)(date$$1);
  11460. }
  11461. function tickInterval(interval, start, stop, step) {
  11462. if (interval == null) interval = 10;
  11463. // If a desired tick count is specified, pick a reasonable tick interval
  11464. // based on the extent of the domain and a rough estimate of tick size.
  11465. // Otherwise, assume interval is already a time interval and use it.
  11466. if (typeof interval === "number") {
  11467. var target = Math.abs(stop - start) / interval,
  11468. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11469. if (i === tickIntervals.length) {
  11470. step = tickStep(start / durationYear, stop / durationYear, interval);
  11471. interval = year$$1;
  11472. } else if (i) {
  11473. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11474. step = i[1];
  11475. interval = i[0];
  11476. } else {
  11477. step = Math.max(tickStep(start, stop, interval), 1);
  11478. interval = millisecond$$1;
  11479. }
  11480. }
  11481. return step == null ? interval : interval.every(step);
  11482. }
  11483. scale.invert = function(y) {
  11484. return new Date(invert(y));
  11485. };
  11486. scale.domain = function(_) {
  11487. return arguments.length ? domain(map$2.call(_, number$3)) : domain().map(date$1);
  11488. };
  11489. scale.ticks = function(interval, step) {
  11490. var d = domain(),
  11491. t0 = d[0],
  11492. t1 = d[d.length - 1],
  11493. r = t1 < t0,
  11494. t;
  11495. if (r) t = t0, t0 = t1, t1 = t;
  11496. t = tickInterval(interval, t0, t1, step);
  11497. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11498. return r ? t.reverse() : t;
  11499. };
  11500. scale.tickFormat = function(count, specifier) {
  11501. return specifier == null ? tickFormat : format(specifier);
  11502. };
  11503. scale.nice = function(interval, step) {
  11504. var d = domain();
  11505. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11506. ? domain(nice(d, interval))
  11507. : scale;
  11508. };
  11509. scale.copy = function() {
  11510. return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
  11511. };
  11512. return scale;
  11513. }
  11514. function time() {
  11515. return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  11516. }
  11517. function utcTime() {
  11518. return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  11519. }
  11520. function sequential(interpolator) {
  11521. var x0 = 0,
  11522. x1 = 1,
  11523. k10 = 1,
  11524. clamp = false;
  11525. function scale(x) {
  11526. var t = (x - x0) * k10;
  11527. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11528. }
  11529. scale.domain = function(_) {
  11530. return arguments.length ? (x0 = +_[0], x1 = +_[1], k10 = x0 === x1 ? 0 : 1 / (x1 - x0), scale) : [x0, x1];
  11531. };
  11532. scale.clamp = function(_) {
  11533. return arguments.length ? (clamp = !!_, scale) : clamp;
  11534. };
  11535. scale.interpolator = function(_) {
  11536. return arguments.length ? (interpolator = _, scale) : interpolator;
  11537. };
  11538. scale.copy = function() {
  11539. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  11540. };
  11541. return linearish(scale);
  11542. }
  11543. function diverging(interpolator) {
  11544. var x0 = 0,
  11545. x1 = 0.5,
  11546. x2 = 1,
  11547. k10 = 1,
  11548. k21 = 1,
  11549. clamp = false;
  11550. function scale(x) {
  11551. var t = 0.5 + ((x = +x) - x1) * (x < x1 ? k10 : k21);
  11552. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11553. }
  11554. scale.domain = function(_) {
  11555. return arguments.length ? (x0 = +_[0], x1 = +_[1], x2 = +_[2], k10 = x0 === x1 ? 0 : 0.5 / (x1 - x0), k21 = x1 === x2 ? 0 : 0.5 / (x2 - x1), scale) : [x0, x1, x2];
  11556. };
  11557. scale.clamp = function(_) {
  11558. return arguments.length ? (clamp = !!_, scale) : clamp;
  11559. };
  11560. scale.interpolator = function(_) {
  11561. return arguments.length ? (interpolator = _, scale) : interpolator;
  11562. };
  11563. scale.copy = function() {
  11564. return diverging(interpolator).domain([x0, x1, x2]).clamp(clamp);
  11565. };
  11566. return linearish(scale);
  11567. }
  11568. function colors(specifier) {
  11569. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  11570. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  11571. return colors;
  11572. }
  11573. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  11574. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  11575. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  11576. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  11577. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  11578. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  11579. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  11580. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  11581. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  11582. function ramp(scheme) {
  11583. return rgbBasis(scheme[scheme.length - 1]);
  11584. }
  11585. var scheme = new Array(3).concat(
  11586. "d8b365f5f5f55ab4ac",
  11587. "a6611adfc27d80cdc1018571",
  11588. "a6611adfc27df5f5f580cdc1018571",
  11589. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  11590. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  11591. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  11592. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  11593. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  11594. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  11595. ).map(colors);
  11596. var BrBG = ramp(scheme);
  11597. var scheme$1 = new Array(3).concat(
  11598. "af8dc3f7f7f77fbf7b",
  11599. "7b3294c2a5cfa6dba0008837",
  11600. "7b3294c2a5cff7f7f7a6dba0008837",
  11601. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  11602. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  11603. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  11604. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  11605. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  11606. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  11607. ).map(colors);
  11608. var PRGn = ramp(scheme$1);
  11609. var scheme$2 = new Array(3).concat(
  11610. "e9a3c9f7f7f7a1d76a",
  11611. "d01c8bf1b6dab8e1864dac26",
  11612. "d01c8bf1b6daf7f7f7b8e1864dac26",
  11613. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  11614. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  11615. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  11616. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  11617. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  11618. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  11619. ).map(colors);
  11620. var PiYG = ramp(scheme$2);
  11621. var scheme$3 = new Array(3).concat(
  11622. "998ec3f7f7f7f1a340",
  11623. "5e3c99b2abd2fdb863e66101",
  11624. "5e3c99b2abd2f7f7f7fdb863e66101",
  11625. "542788998ec3d8daebfee0b6f1a340b35806",
  11626. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  11627. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  11628. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  11629. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  11630. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  11631. ).map(colors);
  11632. var PuOr = ramp(scheme$3);
  11633. var scheme$4 = new Array(3).concat(
  11634. "ef8a62f7f7f767a9cf",
  11635. "ca0020f4a58292c5de0571b0",
  11636. "ca0020f4a582f7f7f792c5de0571b0",
  11637. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  11638. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  11639. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  11640. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  11641. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  11642. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  11643. ).map(colors);
  11644. var RdBu = ramp(scheme$4);
  11645. var scheme$5 = new Array(3).concat(
  11646. "ef8a62ffffff999999",
  11647. "ca0020f4a582bababa404040",
  11648. "ca0020f4a582ffffffbababa404040",
  11649. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  11650. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  11651. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  11652. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  11653. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  11654. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  11655. ).map(colors);
  11656. var RdGy = ramp(scheme$5);
  11657. var scheme$6 = new Array(3).concat(
  11658. "fc8d59ffffbf91bfdb",
  11659. "d7191cfdae61abd9e92c7bb6",
  11660. "d7191cfdae61ffffbfabd9e92c7bb6",
  11661. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  11662. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  11663. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  11664. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  11665. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  11666. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  11667. ).map(colors);
  11668. var RdYlBu = ramp(scheme$6);
  11669. var scheme$7 = new Array(3).concat(
  11670. "fc8d59ffffbf91cf60",
  11671. "d7191cfdae61a6d96a1a9641",
  11672. "d7191cfdae61ffffbfa6d96a1a9641",
  11673. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  11674. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  11675. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  11676. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  11677. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  11678. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  11679. ).map(colors);
  11680. var RdYlGn = ramp(scheme$7);
  11681. var scheme$8 = new Array(3).concat(
  11682. "fc8d59ffffbf99d594",
  11683. "d7191cfdae61abdda42b83ba",
  11684. "d7191cfdae61ffffbfabdda42b83ba",
  11685. "d53e4ffc8d59fee08be6f59899d5943288bd",
  11686. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  11687. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  11688. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  11689. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  11690. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  11691. ).map(colors);
  11692. var Spectral = ramp(scheme$8);
  11693. var scheme$9 = new Array(3).concat(
  11694. "e5f5f999d8c92ca25f",
  11695. "edf8fbb2e2e266c2a4238b45",
  11696. "edf8fbb2e2e266c2a42ca25f006d2c",
  11697. "edf8fbccece699d8c966c2a42ca25f006d2c",
  11698. "edf8fbccece699d8c966c2a441ae76238b45005824",
  11699. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  11700. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  11701. ).map(colors);
  11702. var BuGn = ramp(scheme$9);
  11703. var scheme$10 = new Array(3).concat(
  11704. "e0ecf49ebcda8856a7",
  11705. "edf8fbb3cde38c96c688419d",
  11706. "edf8fbb3cde38c96c68856a7810f7c",
  11707. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  11708. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  11709. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  11710. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  11711. ).map(colors);
  11712. var BuPu = ramp(scheme$10);
  11713. var scheme$11 = new Array(3).concat(
  11714. "e0f3dba8ddb543a2ca",
  11715. "f0f9e8bae4bc7bccc42b8cbe",
  11716. "f0f9e8bae4bc7bccc443a2ca0868ac",
  11717. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  11718. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  11719. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  11720. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  11721. ).map(colors);
  11722. var GnBu = ramp(scheme$11);
  11723. var scheme$12 = new Array(3).concat(
  11724. "fee8c8fdbb84e34a33",
  11725. "fef0d9fdcc8afc8d59d7301f",
  11726. "fef0d9fdcc8afc8d59e34a33b30000",
  11727. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  11728. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  11729. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  11730. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  11731. ).map(colors);
  11732. var OrRd = ramp(scheme$12);
  11733. var scheme$13 = new Array(3).concat(
  11734. "ece2f0a6bddb1c9099",
  11735. "f6eff7bdc9e167a9cf02818a",
  11736. "f6eff7bdc9e167a9cf1c9099016c59",
  11737. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  11738. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  11739. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  11740. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  11741. ).map(colors);
  11742. var PuBuGn = ramp(scheme$13);
  11743. var scheme$14 = new Array(3).concat(
  11744. "ece7f2a6bddb2b8cbe",
  11745. "f1eef6bdc9e174a9cf0570b0",
  11746. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  11747. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  11748. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  11749. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  11750. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  11751. ).map(colors);
  11752. var PuBu = ramp(scheme$14);
  11753. var scheme$15 = new Array(3).concat(
  11754. "e7e1efc994c7dd1c77",
  11755. "f1eef6d7b5d8df65b0ce1256",
  11756. "f1eef6d7b5d8df65b0dd1c77980043",
  11757. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  11758. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  11759. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  11760. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  11761. ).map(colors);
  11762. var PuRd = ramp(scheme$15);
  11763. var scheme$16 = new Array(3).concat(
  11764. "fde0ddfa9fb5c51b8a",
  11765. "feebe2fbb4b9f768a1ae017e",
  11766. "feebe2fbb4b9f768a1c51b8a7a0177",
  11767. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  11768. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  11769. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  11770. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  11771. ).map(colors);
  11772. var RdPu = ramp(scheme$16);
  11773. var scheme$17 = new Array(3).concat(
  11774. "edf8b17fcdbb2c7fb8",
  11775. "ffffcca1dab441b6c4225ea8",
  11776. "ffffcca1dab441b6c42c7fb8253494",
  11777. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  11778. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  11779. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  11780. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  11781. ).map(colors);
  11782. var YlGnBu = ramp(scheme$17);
  11783. var scheme$18 = new Array(3).concat(
  11784. "f7fcb9addd8e31a354",
  11785. "ffffccc2e69978c679238443",
  11786. "ffffccc2e69978c67931a354006837",
  11787. "ffffccd9f0a3addd8e78c67931a354006837",
  11788. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  11789. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  11790. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  11791. ).map(colors);
  11792. var YlGn = ramp(scheme$18);
  11793. var scheme$19 = new Array(3).concat(
  11794. "fff7bcfec44fd95f0e",
  11795. "ffffd4fed98efe9929cc4c02",
  11796. "ffffd4fed98efe9929d95f0e993404",
  11797. "ffffd4fee391fec44ffe9929d95f0e993404",
  11798. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  11799. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  11800. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  11801. ).map(colors);
  11802. var YlOrBr = ramp(scheme$19);
  11803. var scheme$20 = new Array(3).concat(
  11804. "ffeda0feb24cf03b20",
  11805. "ffffb2fecc5cfd8d3ce31a1c",
  11806. "ffffb2fecc5cfd8d3cf03b20bd0026",
  11807. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  11808. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  11809. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  11810. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  11811. ).map(colors);
  11812. var YlOrRd = ramp(scheme$20);
  11813. var scheme$21 = new Array(3).concat(
  11814. "deebf79ecae13182bd",
  11815. "eff3ffbdd7e76baed62171b5",
  11816. "eff3ffbdd7e76baed63182bd08519c",
  11817. "eff3ffc6dbef9ecae16baed63182bd08519c",
  11818. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  11819. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  11820. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  11821. ).map(colors);
  11822. var Blues = ramp(scheme$21);
  11823. var scheme$22 = new Array(3).concat(
  11824. "e5f5e0a1d99b31a354",
  11825. "edf8e9bae4b374c476238b45",
  11826. "edf8e9bae4b374c47631a354006d2c",
  11827. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  11828. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  11829. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  11830. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  11831. ).map(colors);
  11832. var Greens = ramp(scheme$22);
  11833. var scheme$23 = new Array(3).concat(
  11834. "f0f0f0bdbdbd636363",
  11835. "f7f7f7cccccc969696525252",
  11836. "f7f7f7cccccc969696636363252525",
  11837. "f7f7f7d9d9d9bdbdbd969696636363252525",
  11838. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  11839. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  11840. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  11841. ).map(colors);
  11842. var Greys = ramp(scheme$23);
  11843. var scheme$24 = new Array(3).concat(
  11844. "efedf5bcbddc756bb1",
  11845. "f2f0f7cbc9e29e9ac86a51a3",
  11846. "f2f0f7cbc9e29e9ac8756bb154278f",
  11847. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  11848. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  11849. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  11850. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  11851. ).map(colors);
  11852. var Purples = ramp(scheme$24);
  11853. var scheme$25 = new Array(3).concat(
  11854. "fee0d2fc9272de2d26",
  11855. "fee5d9fcae91fb6a4acb181d",
  11856. "fee5d9fcae91fb6a4ade2d26a50f15",
  11857. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  11858. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  11859. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  11860. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  11861. ).map(colors);
  11862. var Reds = ramp(scheme$25);
  11863. var scheme$26 = new Array(3).concat(
  11864. "fee6cefdae6be6550d",
  11865. "feeddefdbe85fd8d3cd94701",
  11866. "feeddefdbe85fd8d3ce6550da63603",
  11867. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  11868. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  11869. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  11870. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  11871. ).map(colors);
  11872. var Oranges = ramp(scheme$26);
  11873. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  11874. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11875. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11876. var c = cubehelix();
  11877. function rainbow(t) {
  11878. if (t < 0 || t > 1) t -= Math.floor(t);
  11879. var ts = Math.abs(t - 0.5);
  11880. c.h = 360 * t - 100;
  11881. c.s = 1.5 - 1.5 * ts;
  11882. c.l = 0.8 - 0.9 * ts;
  11883. return c + "";
  11884. }
  11885. var c$1 = rgb(),
  11886. pi_1_3 = Math.PI / 3,
  11887. pi_2_3 = Math.PI * 2 / 3;
  11888. function sinebow(t) {
  11889. var x;
  11890. t = (0.5 - t) * Math.PI;
  11891. c$1.r = 255 * (x = Math.sin(t)) * x;
  11892. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  11893. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  11894. return c$1 + "";
  11895. }
  11896. function ramp$1(range) {
  11897. var n = range.length;
  11898. return function(t) {
  11899. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  11900. };
  11901. }
  11902. var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  11903. var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  11904. var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  11905. var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  11906. function constant$11(x) {
  11907. return function constant() {
  11908. return x;
  11909. };
  11910. }
  11911. var abs$1 = Math.abs;
  11912. var atan2$1 = Math.atan2;
  11913. var cos$2 = Math.cos;
  11914. var max$2 = Math.max;
  11915. var min$1 = Math.min;
  11916. var sin$2 = Math.sin;
  11917. var sqrt$2 = Math.sqrt;
  11918. var epsilon$3 = 1e-12;
  11919. var pi$4 = Math.PI;
  11920. var halfPi$3 = pi$4 / 2;
  11921. var tau$4 = 2 * pi$4;
  11922. function acos$1(x) {
  11923. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  11924. }
  11925. function asin$1(x) {
  11926. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  11927. }
  11928. function arcInnerRadius(d) {
  11929. return d.innerRadius;
  11930. }
  11931. function arcOuterRadius(d) {
  11932. return d.outerRadius;
  11933. }
  11934. function arcStartAngle(d) {
  11935. return d.startAngle;
  11936. }
  11937. function arcEndAngle(d) {
  11938. return d.endAngle;
  11939. }
  11940. function arcPadAngle(d) {
  11941. return d && d.padAngle; // Note: optional!
  11942. }
  11943. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  11944. var x10 = x1 - x0, y10 = y1 - y0,
  11945. x32 = x3 - x2, y32 = y3 - y2,
  11946. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  11947. return [x0 + t * x10, y0 + t * y10];
  11948. }
  11949. // Compute perpendicular offset line of length rc.
  11950. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  11951. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  11952. var x01 = x0 - x1,
  11953. y01 = y0 - y1,
  11954. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  11955. ox = lo * y01,
  11956. oy = -lo * x01,
  11957. x11 = x0 + ox,
  11958. y11 = y0 + oy,
  11959. x10 = x1 + ox,
  11960. y10 = y1 + oy,
  11961. x00 = (x11 + x10) / 2,
  11962. y00 = (y11 + y10) / 2,
  11963. dx = x10 - x11,
  11964. dy = y10 - y11,
  11965. d2 = dx * dx + dy * dy,
  11966. r = r1 - rc,
  11967. D = x11 * y10 - x10 * y11,
  11968. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  11969. cx0 = (D * dy - dx * d) / d2,
  11970. cy0 = (-D * dx - dy * d) / d2,
  11971. cx1 = (D * dy + dx * d) / d2,
  11972. cy1 = (-D * dx + dy * d) / d2,
  11973. dx0 = cx0 - x00,
  11974. dy0 = cy0 - y00,
  11975. dx1 = cx1 - x00,
  11976. dy1 = cy1 - y00;
  11977. // Pick the closer of the two intersection points.
  11978. // TODO Is there a faster way to determine which intersection to use?
  11979. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  11980. return {
  11981. cx: cx0,
  11982. cy: cy0,
  11983. x01: -ox,
  11984. y01: -oy,
  11985. x11: cx0 * (r1 / r - 1),
  11986. y11: cy0 * (r1 / r - 1)
  11987. };
  11988. }
  11989. function arc() {
  11990. var innerRadius = arcInnerRadius,
  11991. outerRadius = arcOuterRadius,
  11992. cornerRadius = constant$11(0),
  11993. padRadius = null,
  11994. startAngle = arcStartAngle,
  11995. endAngle = arcEndAngle,
  11996. padAngle = arcPadAngle,
  11997. context = null;
  11998. function arc() {
  11999. var buffer,
  12000. r,
  12001. r0 = +innerRadius.apply(this, arguments),
  12002. r1 = +outerRadius.apply(this, arguments),
  12003. a0 = startAngle.apply(this, arguments) - halfPi$3,
  12004. a1 = endAngle.apply(this, arguments) - halfPi$3,
  12005. da = abs$1(a1 - a0),
  12006. cw = a1 > a0;
  12007. if (!context) context = buffer = path();
  12008. // Ensure that the outer radius is always larger than the inner radius.
  12009. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  12010. // Is it a point?
  12011. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  12012. // Or is it a circle or annulus?
  12013. else if (da > tau$4 - epsilon$3) {
  12014. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  12015. context.arc(0, 0, r1, a0, a1, !cw);
  12016. if (r0 > epsilon$3) {
  12017. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  12018. context.arc(0, 0, r0, a1, a0, cw);
  12019. }
  12020. }
  12021. // Or is it a circular or annular sector?
  12022. else {
  12023. var a01 = a0,
  12024. a11 = a1,
  12025. a00 = a0,
  12026. a10 = a1,
  12027. da0 = da,
  12028. da1 = da,
  12029. ap = padAngle.apply(this, arguments) / 2,
  12030. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  12031. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  12032. rc0 = rc,
  12033. rc1 = rc,
  12034. t0,
  12035. t1;
  12036. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  12037. if (rp > epsilon$3) {
  12038. var p0 = asin$1(rp / r0 * sin$2(ap)),
  12039. p1 = asin$1(rp / r1 * sin$2(ap));
  12040. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  12041. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  12042. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  12043. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  12044. }
  12045. var x01 = r1 * cos$2(a01),
  12046. y01 = r1 * sin$2(a01),
  12047. x10 = r0 * cos$2(a10),
  12048. y10 = r0 * sin$2(a10);
  12049. // Apply rounded corners?
  12050. if (rc > epsilon$3) {
  12051. var x11 = r1 * cos$2(a11),
  12052. y11 = r1 * sin$2(a11),
  12053. x00 = r0 * cos$2(a00),
  12054. y00 = r0 * sin$2(a00);
  12055. // Restrict the corner radius according to the sector angle.
  12056. if (da < pi$4) {
  12057. var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  12058. ax = x01 - oc[0],
  12059. ay = y01 - oc[1],
  12060. bx = x11 - oc[0],
  12061. by = y11 - oc[1],
  12062. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  12063. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  12064. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  12065. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  12066. }
  12067. }
  12068. // Is the sector collapsed to a line?
  12069. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  12070. // Does the sector’s outer ring have rounded corners?
  12071. else if (rc1 > epsilon$3) {
  12072. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  12073. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  12074. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12075. // Have the corners merged?
  12076. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12077. // Otherwise, draw the two corners and the ring.
  12078. else {
  12079. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12080. 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);
  12081. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12082. }
  12083. }
  12084. // Or is the outer ring just a circular arc?
  12085. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  12086. // Is there no inner ring, and it’s a circular sector?
  12087. // Or perhaps it’s an annular sector collapsed due to padding?
  12088. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  12089. // Does the sector’s inner ring (or point) have rounded corners?
  12090. else if (rc0 > epsilon$3) {
  12091. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  12092. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  12093. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12094. // Have the corners merged?
  12095. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12096. // Otherwise, draw the two corners and the ring.
  12097. else {
  12098. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12099. 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);
  12100. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12101. }
  12102. }
  12103. // Or is the inner ring just a circular arc?
  12104. else context.arc(0, 0, r0, a10, a00, cw);
  12105. }
  12106. context.closePath();
  12107. if (buffer) return context = null, buffer + "" || null;
  12108. }
  12109. arc.centroid = function() {
  12110. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  12111. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  12112. return [cos$2(a) * r, sin$2(a) * r];
  12113. };
  12114. arc.innerRadius = function(_) {
  12115. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : innerRadius;
  12116. };
  12117. arc.outerRadius = function(_) {
  12118. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : outerRadius;
  12119. };
  12120. arc.cornerRadius = function(_) {
  12121. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : cornerRadius;
  12122. };
  12123. arc.padRadius = function(_) {
  12124. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), arc) : padRadius;
  12125. };
  12126. arc.startAngle = function(_) {
  12127. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : startAngle;
  12128. };
  12129. arc.endAngle = function(_) {
  12130. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : endAngle;
  12131. };
  12132. arc.padAngle = function(_) {
  12133. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : padAngle;
  12134. };
  12135. arc.context = function(_) {
  12136. return arguments.length ? (context = _ == null ? null : _, arc) : context;
  12137. };
  12138. return arc;
  12139. }
  12140. function Linear(context) {
  12141. this._context = context;
  12142. }
  12143. Linear.prototype = {
  12144. areaStart: function() {
  12145. this._line = 0;
  12146. },
  12147. areaEnd: function() {
  12148. this._line = NaN;
  12149. },
  12150. lineStart: function() {
  12151. this._point = 0;
  12152. },
  12153. lineEnd: function() {
  12154. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12155. this._line = 1 - this._line;
  12156. },
  12157. point: function(x, y) {
  12158. x = +x, y = +y;
  12159. switch (this._point) {
  12160. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12161. case 1: this._point = 2; // proceed
  12162. default: this._context.lineTo(x, y); break;
  12163. }
  12164. }
  12165. };
  12166. function curveLinear(context) {
  12167. return new Linear(context);
  12168. }
  12169. function x$3(p) {
  12170. return p[0];
  12171. }
  12172. function y$3(p) {
  12173. return p[1];
  12174. }
  12175. function line() {
  12176. var x$$1 = x$3,
  12177. y$$1 = y$3,
  12178. defined = constant$11(true),
  12179. context = null,
  12180. curve = curveLinear,
  12181. output = null;
  12182. function line(data) {
  12183. var i,
  12184. n = data.length,
  12185. d,
  12186. defined0 = false,
  12187. buffer;
  12188. if (context == null) output = curve(buffer = path());
  12189. for (i = 0; i <= n; ++i) {
  12190. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12191. if (defined0 = !defined0) output.lineStart();
  12192. else output.lineEnd();
  12193. }
  12194. if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
  12195. }
  12196. if (buffer) return output = null, buffer + "" || null;
  12197. }
  12198. line.x = function(_) {
  12199. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), line) : x$$1;
  12200. };
  12201. line.y = function(_) {
  12202. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), line) : y$$1;
  12203. };
  12204. line.defined = function(_) {
  12205. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$11(!!_), line) : defined;
  12206. };
  12207. line.curve = function(_) {
  12208. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  12209. };
  12210. line.context = function(_) {
  12211. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  12212. };
  12213. return line;
  12214. }
  12215. function area$3() {
  12216. var x0 = x$3,
  12217. x1 = null,
  12218. y0 = constant$11(0),
  12219. y1 = y$3,
  12220. defined = constant$11(true),
  12221. context = null,
  12222. curve = curveLinear,
  12223. output = null;
  12224. function area(data) {
  12225. var i,
  12226. j,
  12227. k,
  12228. n = data.length,
  12229. d,
  12230. defined0 = false,
  12231. buffer,
  12232. x0z = new Array(n),
  12233. y0z = new Array(n);
  12234. if (context == null) output = curve(buffer = path());
  12235. for (i = 0; i <= n; ++i) {
  12236. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12237. if (defined0 = !defined0) {
  12238. j = i;
  12239. output.areaStart();
  12240. output.lineStart();
  12241. } else {
  12242. output.lineEnd();
  12243. output.lineStart();
  12244. for (k = i - 1; k >= j; --k) {
  12245. output.point(x0z[k], y0z[k]);
  12246. }
  12247. output.lineEnd();
  12248. output.areaEnd();
  12249. }
  12250. }
  12251. if (defined0) {
  12252. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  12253. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  12254. }
  12255. }
  12256. if (buffer) return output = null, buffer + "" || null;
  12257. }
  12258. function arealine() {
  12259. return line().defined(defined).curve(curve).context(context);
  12260. }
  12261. area.x = function(_) {
  12262. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$11(+_), x1 = null, area) : x0;
  12263. };
  12264. area.x0 = function(_) {
  12265. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$11(+_), area) : x0;
  12266. };
  12267. area.x1 = function(_) {
  12268. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), area) : x1;
  12269. };
  12270. area.y = function(_) {
  12271. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$11(+_), y1 = null, area) : y0;
  12272. };
  12273. area.y0 = function(_) {
  12274. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$11(+_), area) : y0;
  12275. };
  12276. area.y1 = function(_) {
  12277. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), area) : y1;
  12278. };
  12279. area.lineX0 =
  12280. area.lineY0 = function() {
  12281. return arealine().x(x0).y(y0);
  12282. };
  12283. area.lineY1 = function() {
  12284. return arealine().x(x0).y(y1);
  12285. };
  12286. area.lineX1 = function() {
  12287. return arealine().x(x1).y(y0);
  12288. };
  12289. area.defined = function(_) {
  12290. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$11(!!_), area) : defined;
  12291. };
  12292. area.curve = function(_) {
  12293. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  12294. };
  12295. area.context = function(_) {
  12296. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  12297. };
  12298. return area;
  12299. }
  12300. function descending$1(a, b) {
  12301. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  12302. }
  12303. function identity$7(d) {
  12304. return d;
  12305. }
  12306. function pie() {
  12307. var value = identity$7,
  12308. sortValues = descending$1,
  12309. sort = null,
  12310. startAngle = constant$11(0),
  12311. endAngle = constant$11(tau$4),
  12312. padAngle = constant$11(0);
  12313. function pie(data) {
  12314. var i,
  12315. n = data.length,
  12316. j,
  12317. k,
  12318. sum = 0,
  12319. index = new Array(n),
  12320. arcs = new Array(n),
  12321. a0 = +startAngle.apply(this, arguments),
  12322. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  12323. a1,
  12324. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  12325. pa = p * (da < 0 ? -1 : 1),
  12326. v;
  12327. for (i = 0; i < n; ++i) {
  12328. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  12329. sum += v;
  12330. }
  12331. }
  12332. // Optionally sort the arcs by previously-computed values or by data.
  12333. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  12334. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  12335. // Compute the arcs! They are stored in the original data's order.
  12336. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  12337. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  12338. data: data[j],
  12339. index: i,
  12340. value: v,
  12341. startAngle: a0,
  12342. endAngle: a1,
  12343. padAngle: p
  12344. };
  12345. }
  12346. return arcs;
  12347. }
  12348. pie.value = function(_) {
  12349. return arguments.length ? (value = typeof _ === "function" ? _ : constant$11(+_), pie) : value;
  12350. };
  12351. pie.sortValues = function(_) {
  12352. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  12353. };
  12354. pie.sort = function(_) {
  12355. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  12356. };
  12357. pie.startAngle = function(_) {
  12358. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : startAngle;
  12359. };
  12360. pie.endAngle = function(_) {
  12361. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : endAngle;
  12362. };
  12363. pie.padAngle = function(_) {
  12364. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : padAngle;
  12365. };
  12366. return pie;
  12367. }
  12368. var curveRadialLinear = curveRadial(curveLinear);
  12369. function Radial(curve) {
  12370. this._curve = curve;
  12371. }
  12372. Radial.prototype = {
  12373. areaStart: function() {
  12374. this._curve.areaStart();
  12375. },
  12376. areaEnd: function() {
  12377. this._curve.areaEnd();
  12378. },
  12379. lineStart: function() {
  12380. this._curve.lineStart();
  12381. },
  12382. lineEnd: function() {
  12383. this._curve.lineEnd();
  12384. },
  12385. point: function(a, r) {
  12386. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  12387. }
  12388. };
  12389. function curveRadial(curve) {
  12390. function radial(context) {
  12391. return new Radial(curve(context));
  12392. }
  12393. radial._curve = curve;
  12394. return radial;
  12395. }
  12396. function lineRadial(l) {
  12397. var c = l.curve;
  12398. l.angle = l.x, delete l.x;
  12399. l.radius = l.y, delete l.y;
  12400. l.curve = function(_) {
  12401. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12402. };
  12403. return l;
  12404. }
  12405. function lineRadial$1() {
  12406. return lineRadial(line().curve(curveRadialLinear));
  12407. }
  12408. function areaRadial() {
  12409. var a = area$3().curve(curveRadialLinear),
  12410. c = a.curve,
  12411. x0 = a.lineX0,
  12412. x1 = a.lineX1,
  12413. y0 = a.lineY0,
  12414. y1 = a.lineY1;
  12415. a.angle = a.x, delete a.x;
  12416. a.startAngle = a.x0, delete a.x0;
  12417. a.endAngle = a.x1, delete a.x1;
  12418. a.radius = a.y, delete a.y;
  12419. a.innerRadius = a.y0, delete a.y0;
  12420. a.outerRadius = a.y1, delete a.y1;
  12421. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  12422. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  12423. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  12424. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  12425. a.curve = function(_) {
  12426. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12427. };
  12428. return a;
  12429. }
  12430. function pointRadial(x, y) {
  12431. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  12432. }
  12433. var slice$6 = Array.prototype.slice;
  12434. function linkSource(d) {
  12435. return d.source;
  12436. }
  12437. function linkTarget(d) {
  12438. return d.target;
  12439. }
  12440. function link$2(curve) {
  12441. var source = linkSource,
  12442. target = linkTarget,
  12443. x$$1 = x$3,
  12444. y$$1 = y$3,
  12445. context = null;
  12446. function link() {
  12447. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  12448. if (!context) context = buffer = path();
  12449. curve(context, +x$$1.apply(this, (argv[0] = s, argv)), +y$$1.apply(this, argv), +x$$1.apply(this, (argv[0] = t, argv)), +y$$1.apply(this, argv));
  12450. if (buffer) return context = null, buffer + "" || null;
  12451. }
  12452. link.source = function(_) {
  12453. return arguments.length ? (source = _, link) : source;
  12454. };
  12455. link.target = function(_) {
  12456. return arguments.length ? (target = _, link) : target;
  12457. };
  12458. link.x = function(_) {
  12459. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), link) : x$$1;
  12460. };
  12461. link.y = function(_) {
  12462. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), link) : y$$1;
  12463. };
  12464. link.context = function(_) {
  12465. return arguments.length ? (context = _ == null ? null : _, link) : context;
  12466. };
  12467. return link;
  12468. }
  12469. function curveHorizontal(context, x0, y0, x1, y1) {
  12470. context.moveTo(x0, y0);
  12471. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  12472. }
  12473. function curveVertical(context, x0, y0, x1, y1) {
  12474. context.moveTo(x0, y0);
  12475. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  12476. }
  12477. function curveRadial$1(context, x0, y0, x1, y1) {
  12478. var p0 = pointRadial(x0, y0),
  12479. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  12480. p2 = pointRadial(x1, y0),
  12481. p3 = pointRadial(x1, y1);
  12482. context.moveTo(p0[0], p0[1]);
  12483. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  12484. }
  12485. function linkHorizontal() {
  12486. return link$2(curveHorizontal);
  12487. }
  12488. function linkVertical() {
  12489. return link$2(curveVertical);
  12490. }
  12491. function linkRadial() {
  12492. var l = link$2(curveRadial$1);
  12493. l.angle = l.x, delete l.x;
  12494. l.radius = l.y, delete l.y;
  12495. return l;
  12496. }
  12497. var circle$2 = {
  12498. draw: function(context, size) {
  12499. var r = Math.sqrt(size / pi$4);
  12500. context.moveTo(r, 0);
  12501. context.arc(0, 0, r, 0, tau$4);
  12502. }
  12503. };
  12504. var cross$2 = {
  12505. draw: function(context, size) {
  12506. var r = Math.sqrt(size / 5) / 2;
  12507. context.moveTo(-3 * r, -r);
  12508. context.lineTo(-r, -r);
  12509. context.lineTo(-r, -3 * r);
  12510. context.lineTo(r, -3 * r);
  12511. context.lineTo(r, -r);
  12512. context.lineTo(3 * r, -r);
  12513. context.lineTo(3 * r, r);
  12514. context.lineTo(r, r);
  12515. context.lineTo(r, 3 * r);
  12516. context.lineTo(-r, 3 * r);
  12517. context.lineTo(-r, r);
  12518. context.lineTo(-3 * r, r);
  12519. context.closePath();
  12520. }
  12521. };
  12522. var tan30 = Math.sqrt(1 / 3),
  12523. tan30_2 = tan30 * 2;
  12524. var diamond = {
  12525. draw: function(context, size) {
  12526. var y = Math.sqrt(size / tan30_2),
  12527. x = y * tan30;
  12528. context.moveTo(0, -y);
  12529. context.lineTo(x, 0);
  12530. context.lineTo(0, y);
  12531. context.lineTo(-x, 0);
  12532. context.closePath();
  12533. }
  12534. };
  12535. var ka = 0.89081309152928522810,
  12536. kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
  12537. kx = Math.sin(tau$4 / 10) * kr,
  12538. ky = -Math.cos(tau$4 / 10) * kr;
  12539. var star = {
  12540. draw: function(context, size) {
  12541. var r = Math.sqrt(size * ka),
  12542. x = kx * r,
  12543. y = ky * r;
  12544. context.moveTo(0, -r);
  12545. context.lineTo(x, y);
  12546. for (var i = 1; i < 5; ++i) {
  12547. var a = tau$4 * i / 5,
  12548. c = Math.cos(a),
  12549. s = Math.sin(a);
  12550. context.lineTo(s * r, -c * r);
  12551. context.lineTo(c * x - s * y, s * x + c * y);
  12552. }
  12553. context.closePath();
  12554. }
  12555. };
  12556. var square = {
  12557. draw: function(context, size) {
  12558. var w = Math.sqrt(size),
  12559. x = -w / 2;
  12560. context.rect(x, x, w, w);
  12561. }
  12562. };
  12563. var sqrt3 = Math.sqrt(3);
  12564. var triangle = {
  12565. draw: function(context, size) {
  12566. var y = -Math.sqrt(size / (sqrt3 * 3));
  12567. context.moveTo(0, y * 2);
  12568. context.lineTo(-sqrt3 * y, -y);
  12569. context.lineTo(sqrt3 * y, -y);
  12570. context.closePath();
  12571. }
  12572. };
  12573. var c$2 = -0.5,
  12574. s = Math.sqrt(3) / 2,
  12575. k = 1 / Math.sqrt(12),
  12576. a = (k / 2 + 1) * 3;
  12577. var wye = {
  12578. draw: function(context, size) {
  12579. var r = Math.sqrt(size / a),
  12580. x0 = r / 2,
  12581. y0 = r * k,
  12582. x1 = x0,
  12583. y1 = r * k + r,
  12584. x2 = -x1,
  12585. y2 = y1;
  12586. context.moveTo(x0, y0);
  12587. context.lineTo(x1, y1);
  12588. context.lineTo(x2, y2);
  12589. context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
  12590. context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
  12591. context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
  12592. context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
  12593. context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
  12594. context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
  12595. context.closePath();
  12596. }
  12597. };
  12598. var symbols = [
  12599. circle$2,
  12600. cross$2,
  12601. diamond,
  12602. square,
  12603. star,
  12604. triangle,
  12605. wye
  12606. ];
  12607. function symbol() {
  12608. var type = constant$11(circle$2),
  12609. size = constant$11(64),
  12610. context = null;
  12611. function symbol() {
  12612. var buffer;
  12613. if (!context) context = buffer = path();
  12614. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  12615. if (buffer) return context = null, buffer + "" || null;
  12616. }
  12617. symbol.type = function(_) {
  12618. return arguments.length ? (type = typeof _ === "function" ? _ : constant$11(_), symbol) : type;
  12619. };
  12620. symbol.size = function(_) {
  12621. return arguments.length ? (size = typeof _ === "function" ? _ : constant$11(+_), symbol) : size;
  12622. };
  12623. symbol.context = function(_) {
  12624. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  12625. };
  12626. return symbol;
  12627. }
  12628. function noop$3() {}
  12629. function point$2(that, x, y) {
  12630. that._context.bezierCurveTo(
  12631. (2 * that._x0 + that._x1) / 3,
  12632. (2 * that._y0 + that._y1) / 3,
  12633. (that._x0 + 2 * that._x1) / 3,
  12634. (that._y0 + 2 * that._y1) / 3,
  12635. (that._x0 + 4 * that._x1 + x) / 6,
  12636. (that._y0 + 4 * that._y1 + y) / 6
  12637. );
  12638. }
  12639. function Basis(context) {
  12640. this._context = context;
  12641. }
  12642. Basis.prototype = {
  12643. areaStart: function() {
  12644. this._line = 0;
  12645. },
  12646. areaEnd: function() {
  12647. this._line = NaN;
  12648. },
  12649. lineStart: function() {
  12650. this._x0 = this._x1 =
  12651. this._y0 = this._y1 = NaN;
  12652. this._point = 0;
  12653. },
  12654. lineEnd: function() {
  12655. switch (this._point) {
  12656. case 3: point$2(this, this._x1, this._y1); // proceed
  12657. case 2: this._context.lineTo(this._x1, this._y1); break;
  12658. }
  12659. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12660. this._line = 1 - this._line;
  12661. },
  12662. point: function(x, y) {
  12663. x = +x, y = +y;
  12664. switch (this._point) {
  12665. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12666. case 1: this._point = 2; break;
  12667. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  12668. default: point$2(this, x, y); break;
  12669. }
  12670. this._x0 = this._x1, this._x1 = x;
  12671. this._y0 = this._y1, this._y1 = y;
  12672. }
  12673. };
  12674. function basis$2(context) {
  12675. return new Basis(context);
  12676. }
  12677. function BasisClosed(context) {
  12678. this._context = context;
  12679. }
  12680. BasisClosed.prototype = {
  12681. areaStart: noop$3,
  12682. areaEnd: noop$3,
  12683. lineStart: function() {
  12684. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  12685. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  12686. this._point = 0;
  12687. },
  12688. lineEnd: function() {
  12689. switch (this._point) {
  12690. case 1: {
  12691. this._context.moveTo(this._x2, this._y2);
  12692. this._context.closePath();
  12693. break;
  12694. }
  12695. case 2: {
  12696. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  12697. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  12698. this._context.closePath();
  12699. break;
  12700. }
  12701. case 3: {
  12702. this.point(this._x2, this._y2);
  12703. this.point(this._x3, this._y3);
  12704. this.point(this._x4, this._y4);
  12705. break;
  12706. }
  12707. }
  12708. },
  12709. point: function(x, y) {
  12710. x = +x, y = +y;
  12711. switch (this._point) {
  12712. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  12713. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  12714. 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;
  12715. default: point$2(this, x, y); break;
  12716. }
  12717. this._x0 = this._x1, this._x1 = x;
  12718. this._y0 = this._y1, this._y1 = y;
  12719. }
  12720. };
  12721. function basisClosed$1(context) {
  12722. return new BasisClosed(context);
  12723. }
  12724. function BasisOpen(context) {
  12725. this._context = context;
  12726. }
  12727. BasisOpen.prototype = {
  12728. areaStart: function() {
  12729. this._line = 0;
  12730. },
  12731. areaEnd: function() {
  12732. this._line = NaN;
  12733. },
  12734. lineStart: function() {
  12735. this._x0 = this._x1 =
  12736. this._y0 = this._y1 = NaN;
  12737. this._point = 0;
  12738. },
  12739. lineEnd: function() {
  12740. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12741. this._line = 1 - this._line;
  12742. },
  12743. point: function(x, y) {
  12744. x = +x, y = +y;
  12745. switch (this._point) {
  12746. case 0: this._point = 1; break;
  12747. case 1: this._point = 2; break;
  12748. 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;
  12749. case 3: this._point = 4; // proceed
  12750. default: point$2(this, x, y); break;
  12751. }
  12752. this._x0 = this._x1, this._x1 = x;
  12753. this._y0 = this._y1, this._y1 = y;
  12754. }
  12755. };
  12756. function basisOpen(context) {
  12757. return new BasisOpen(context);
  12758. }
  12759. function Bundle(context, beta) {
  12760. this._basis = new Basis(context);
  12761. this._beta = beta;
  12762. }
  12763. Bundle.prototype = {
  12764. lineStart: function() {
  12765. this._x = [];
  12766. this._y = [];
  12767. this._basis.lineStart();
  12768. },
  12769. lineEnd: function() {
  12770. var x = this._x,
  12771. y = this._y,
  12772. j = x.length - 1;
  12773. if (j > 0) {
  12774. var x0 = x[0],
  12775. y0 = y[0],
  12776. dx = x[j] - x0,
  12777. dy = y[j] - y0,
  12778. i = -1,
  12779. t;
  12780. while (++i <= j) {
  12781. t = i / j;
  12782. this._basis.point(
  12783. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  12784. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  12785. );
  12786. }
  12787. }
  12788. this._x = this._y = null;
  12789. this._basis.lineEnd();
  12790. },
  12791. point: function(x, y) {
  12792. this._x.push(+x);
  12793. this._y.push(+y);
  12794. }
  12795. };
  12796. var bundle = (function custom(beta) {
  12797. function bundle(context) {
  12798. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  12799. }
  12800. bundle.beta = function(beta) {
  12801. return custom(+beta);
  12802. };
  12803. return bundle;
  12804. })(0.85);
  12805. function point$3(that, x, y) {
  12806. that._context.bezierCurveTo(
  12807. that._x1 + that._k * (that._x2 - that._x0),
  12808. that._y1 + that._k * (that._y2 - that._y0),
  12809. that._x2 + that._k * (that._x1 - x),
  12810. that._y2 + that._k * (that._y1 - y),
  12811. that._x2,
  12812. that._y2
  12813. );
  12814. }
  12815. function Cardinal(context, tension) {
  12816. this._context = context;
  12817. this._k = (1 - tension) / 6;
  12818. }
  12819. Cardinal.prototype = {
  12820. areaStart: function() {
  12821. this._line = 0;
  12822. },
  12823. areaEnd: function() {
  12824. this._line = NaN;
  12825. },
  12826. lineStart: function() {
  12827. this._x0 = this._x1 = this._x2 =
  12828. this._y0 = this._y1 = this._y2 = NaN;
  12829. this._point = 0;
  12830. },
  12831. lineEnd: function() {
  12832. switch (this._point) {
  12833. case 2: this._context.lineTo(this._x2, this._y2); break;
  12834. case 3: point$3(this, this._x1, this._y1); break;
  12835. }
  12836. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12837. this._line = 1 - this._line;
  12838. },
  12839. point: function(x, y) {
  12840. x = +x, y = +y;
  12841. switch (this._point) {
  12842. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12843. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  12844. case 2: this._point = 3; // proceed
  12845. default: point$3(this, x, y); break;
  12846. }
  12847. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12848. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12849. }
  12850. };
  12851. var cardinal = (function custom(tension) {
  12852. function cardinal(context) {
  12853. return new Cardinal(context, tension);
  12854. }
  12855. cardinal.tension = function(tension) {
  12856. return custom(+tension);
  12857. };
  12858. return cardinal;
  12859. })(0);
  12860. function CardinalClosed(context, tension) {
  12861. this._context = context;
  12862. this._k = (1 - tension) / 6;
  12863. }
  12864. CardinalClosed.prototype = {
  12865. areaStart: noop$3,
  12866. areaEnd: noop$3,
  12867. lineStart: function() {
  12868. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12869. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12870. this._point = 0;
  12871. },
  12872. lineEnd: function() {
  12873. switch (this._point) {
  12874. case 1: {
  12875. this._context.moveTo(this._x3, this._y3);
  12876. this._context.closePath();
  12877. break;
  12878. }
  12879. case 2: {
  12880. this._context.lineTo(this._x3, this._y3);
  12881. this._context.closePath();
  12882. break;
  12883. }
  12884. case 3: {
  12885. this.point(this._x3, this._y3);
  12886. this.point(this._x4, this._y4);
  12887. this.point(this._x5, this._y5);
  12888. break;
  12889. }
  12890. }
  12891. },
  12892. point: function(x, y) {
  12893. x = +x, y = +y;
  12894. switch (this._point) {
  12895. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12896. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12897. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12898. default: point$3(this, x, y); break;
  12899. }
  12900. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12901. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12902. }
  12903. };
  12904. var cardinalClosed = (function custom(tension) {
  12905. function cardinal$$1(context) {
  12906. return new CardinalClosed(context, tension);
  12907. }
  12908. cardinal$$1.tension = function(tension) {
  12909. return custom(+tension);
  12910. };
  12911. return cardinal$$1;
  12912. })(0);
  12913. function CardinalOpen(context, tension) {
  12914. this._context = context;
  12915. this._k = (1 - tension) / 6;
  12916. }
  12917. CardinalOpen.prototype = {
  12918. areaStart: function() {
  12919. this._line = 0;
  12920. },
  12921. areaEnd: function() {
  12922. this._line = NaN;
  12923. },
  12924. lineStart: function() {
  12925. this._x0 = this._x1 = this._x2 =
  12926. this._y0 = this._y1 = this._y2 = NaN;
  12927. this._point = 0;
  12928. },
  12929. lineEnd: function() {
  12930. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12931. this._line = 1 - this._line;
  12932. },
  12933. point: function(x, y) {
  12934. x = +x, y = +y;
  12935. switch (this._point) {
  12936. case 0: this._point = 1; break;
  12937. case 1: this._point = 2; break;
  12938. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12939. case 3: this._point = 4; // proceed
  12940. default: point$3(this, x, y); break;
  12941. }
  12942. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12943. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12944. }
  12945. };
  12946. var cardinalOpen = (function custom(tension) {
  12947. function cardinal$$1(context) {
  12948. return new CardinalOpen(context, tension);
  12949. }
  12950. cardinal$$1.tension = function(tension) {
  12951. return custom(+tension);
  12952. };
  12953. return cardinal$$1;
  12954. })(0);
  12955. function point$4(that, x, y) {
  12956. var x1 = that._x1,
  12957. y1 = that._y1,
  12958. x2 = that._x2,
  12959. y2 = that._y2;
  12960. if (that._l01_a > epsilon$3) {
  12961. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  12962. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  12963. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  12964. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  12965. }
  12966. if (that._l23_a > epsilon$3) {
  12967. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  12968. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  12969. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  12970. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  12971. }
  12972. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  12973. }
  12974. function CatmullRom(context, alpha) {
  12975. this._context = context;
  12976. this._alpha = alpha;
  12977. }
  12978. CatmullRom.prototype = {
  12979. areaStart: function() {
  12980. this._line = 0;
  12981. },
  12982. areaEnd: function() {
  12983. this._line = NaN;
  12984. },
  12985. lineStart: function() {
  12986. this._x0 = this._x1 = this._x2 =
  12987. this._y0 = this._y1 = this._y2 = NaN;
  12988. this._l01_a = this._l12_a = this._l23_a =
  12989. this._l01_2a = this._l12_2a = this._l23_2a =
  12990. this._point = 0;
  12991. },
  12992. lineEnd: function() {
  12993. switch (this._point) {
  12994. case 2: this._context.lineTo(this._x2, this._y2); break;
  12995. case 3: this.point(this._x2, this._y2); break;
  12996. }
  12997. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12998. this._line = 1 - this._line;
  12999. },
  13000. point: function(x, y) {
  13001. x = +x, y = +y;
  13002. if (this._point) {
  13003. var x23 = this._x2 - x,
  13004. y23 = this._y2 - y;
  13005. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13006. }
  13007. switch (this._point) {
  13008. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13009. case 1: this._point = 2; break;
  13010. case 2: this._point = 3; // proceed
  13011. default: point$4(this, x, y); break;
  13012. }
  13013. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13014. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13015. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13016. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13017. }
  13018. };
  13019. var catmullRom = (function custom(alpha) {
  13020. function catmullRom(context) {
  13021. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  13022. }
  13023. catmullRom.alpha = function(alpha) {
  13024. return custom(+alpha);
  13025. };
  13026. return catmullRom;
  13027. })(0.5);
  13028. function CatmullRomClosed(context, alpha) {
  13029. this._context = context;
  13030. this._alpha = alpha;
  13031. }
  13032. CatmullRomClosed.prototype = {
  13033. areaStart: noop$3,
  13034. areaEnd: noop$3,
  13035. lineStart: function() {
  13036. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13037. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13038. this._l01_a = this._l12_a = this._l23_a =
  13039. this._l01_2a = this._l12_2a = this._l23_2a =
  13040. this._point = 0;
  13041. },
  13042. lineEnd: function() {
  13043. switch (this._point) {
  13044. case 1: {
  13045. this._context.moveTo(this._x3, this._y3);
  13046. this._context.closePath();
  13047. break;
  13048. }
  13049. case 2: {
  13050. this._context.lineTo(this._x3, this._y3);
  13051. this._context.closePath();
  13052. break;
  13053. }
  13054. case 3: {
  13055. this.point(this._x3, this._y3);
  13056. this.point(this._x4, this._y4);
  13057. this.point(this._x5, this._y5);
  13058. break;
  13059. }
  13060. }
  13061. },
  13062. point: function(x, y) {
  13063. x = +x, y = +y;
  13064. if (this._point) {
  13065. var x23 = this._x2 - x,
  13066. y23 = this._y2 - y;
  13067. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13068. }
  13069. switch (this._point) {
  13070. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13071. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13072. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13073. default: point$4(this, x, y); break;
  13074. }
  13075. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13076. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13077. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13078. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13079. }
  13080. };
  13081. var catmullRomClosed = (function custom(alpha) {
  13082. function catmullRom$$1(context) {
  13083. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  13084. }
  13085. catmullRom$$1.alpha = function(alpha) {
  13086. return custom(+alpha);
  13087. };
  13088. return catmullRom$$1;
  13089. })(0.5);
  13090. function CatmullRomOpen(context, alpha) {
  13091. this._context = context;
  13092. this._alpha = alpha;
  13093. }
  13094. CatmullRomOpen.prototype = {
  13095. areaStart: function() {
  13096. this._line = 0;
  13097. },
  13098. areaEnd: function() {
  13099. this._line = NaN;
  13100. },
  13101. lineStart: function() {
  13102. this._x0 = this._x1 = this._x2 =
  13103. this._y0 = this._y1 = this._y2 = NaN;
  13104. this._l01_a = this._l12_a = this._l23_a =
  13105. this._l01_2a = this._l12_2a = this._l23_2a =
  13106. this._point = 0;
  13107. },
  13108. lineEnd: function() {
  13109. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13110. this._line = 1 - this._line;
  13111. },
  13112. point: function(x, y) {
  13113. x = +x, y = +y;
  13114. if (this._point) {
  13115. var x23 = this._x2 - x,
  13116. y23 = this._y2 - y;
  13117. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13118. }
  13119. switch (this._point) {
  13120. case 0: this._point = 1; break;
  13121. case 1: this._point = 2; break;
  13122. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13123. case 3: this._point = 4; // proceed
  13124. default: point$4(this, x, y); break;
  13125. }
  13126. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13127. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13128. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13129. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13130. }
  13131. };
  13132. var catmullRomOpen = (function custom(alpha) {
  13133. function catmullRom$$1(context) {
  13134. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  13135. }
  13136. catmullRom$$1.alpha = function(alpha) {
  13137. return custom(+alpha);
  13138. };
  13139. return catmullRom$$1;
  13140. })(0.5);
  13141. function LinearClosed(context) {
  13142. this._context = context;
  13143. }
  13144. LinearClosed.prototype = {
  13145. areaStart: noop$3,
  13146. areaEnd: noop$3,
  13147. lineStart: function() {
  13148. this._point = 0;
  13149. },
  13150. lineEnd: function() {
  13151. if (this._point) this._context.closePath();
  13152. },
  13153. point: function(x, y) {
  13154. x = +x, y = +y;
  13155. if (this._point) this._context.lineTo(x, y);
  13156. else this._point = 1, this._context.moveTo(x, y);
  13157. }
  13158. };
  13159. function linearClosed(context) {
  13160. return new LinearClosed(context);
  13161. }
  13162. function sign$1(x) {
  13163. return x < 0 ? -1 : 1;
  13164. }
  13165. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  13166. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  13167. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  13168. // NOV(II), P. 443, 1990.
  13169. function slope3(that, x2, y2) {
  13170. var h0 = that._x1 - that._x0,
  13171. h1 = x2 - that._x1,
  13172. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  13173. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  13174. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  13175. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  13176. }
  13177. // Calculate a one-sided slope.
  13178. function slope2(that, t) {
  13179. var h = that._x1 - that._x0;
  13180. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  13181. }
  13182. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  13183. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  13184. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  13185. function point$5(that, t0, t1) {
  13186. var x0 = that._x0,
  13187. y0 = that._y0,
  13188. x1 = that._x1,
  13189. y1 = that._y1,
  13190. dx = (x1 - x0) / 3;
  13191. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  13192. }
  13193. function MonotoneX(context) {
  13194. this._context = context;
  13195. }
  13196. MonotoneX.prototype = {
  13197. areaStart: function() {
  13198. this._line = 0;
  13199. },
  13200. areaEnd: function() {
  13201. this._line = NaN;
  13202. },
  13203. lineStart: function() {
  13204. this._x0 = this._x1 =
  13205. this._y0 = this._y1 =
  13206. this._t0 = NaN;
  13207. this._point = 0;
  13208. },
  13209. lineEnd: function() {
  13210. switch (this._point) {
  13211. case 2: this._context.lineTo(this._x1, this._y1); break;
  13212. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  13213. }
  13214. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13215. this._line = 1 - this._line;
  13216. },
  13217. point: function(x, y) {
  13218. var t1 = NaN;
  13219. x = +x, y = +y;
  13220. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  13221. switch (this._point) {
  13222. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13223. case 1: this._point = 2; break;
  13224. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  13225. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  13226. }
  13227. this._x0 = this._x1, this._x1 = x;
  13228. this._y0 = this._y1, this._y1 = y;
  13229. this._t0 = t1;
  13230. }
  13231. };
  13232. function MonotoneY(context) {
  13233. this._context = new ReflectContext(context);
  13234. }
  13235. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  13236. MonotoneX.prototype.point.call(this, y, x);
  13237. };
  13238. function ReflectContext(context) {
  13239. this._context = context;
  13240. }
  13241. ReflectContext.prototype = {
  13242. moveTo: function(x, y) { this._context.moveTo(y, x); },
  13243. closePath: function() { this._context.closePath(); },
  13244. lineTo: function(x, y) { this._context.lineTo(y, x); },
  13245. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  13246. };
  13247. function monotoneX(context) {
  13248. return new MonotoneX(context);
  13249. }
  13250. function monotoneY(context) {
  13251. return new MonotoneY(context);
  13252. }
  13253. function Natural(context) {
  13254. this._context = context;
  13255. }
  13256. Natural.prototype = {
  13257. areaStart: function() {
  13258. this._line = 0;
  13259. },
  13260. areaEnd: function() {
  13261. this._line = NaN;
  13262. },
  13263. lineStart: function() {
  13264. this._x = [];
  13265. this._y = [];
  13266. },
  13267. lineEnd: function() {
  13268. var x = this._x,
  13269. y = this._y,
  13270. n = x.length;
  13271. if (n) {
  13272. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  13273. if (n === 2) {
  13274. this._context.lineTo(x[1], y[1]);
  13275. } else {
  13276. var px = controlPoints(x),
  13277. py = controlPoints(y);
  13278. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  13279. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  13280. }
  13281. }
  13282. }
  13283. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  13284. this._line = 1 - this._line;
  13285. this._x = this._y = null;
  13286. },
  13287. point: function(x, y) {
  13288. this._x.push(+x);
  13289. this._y.push(+y);
  13290. }
  13291. };
  13292. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  13293. function controlPoints(x) {
  13294. var i,
  13295. n = x.length - 1,
  13296. m,
  13297. a = new Array(n),
  13298. b = new Array(n),
  13299. r = new Array(n);
  13300. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  13301. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  13302. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  13303. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  13304. a[n - 1] = r[n - 1] / b[n - 1];
  13305. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  13306. b[n - 1] = (x[n] + a[n - 1]) / 2;
  13307. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  13308. return [a, b];
  13309. }
  13310. function natural(context) {
  13311. return new Natural(context);
  13312. }
  13313. function Step(context, t) {
  13314. this._context = context;
  13315. this._t = t;
  13316. }
  13317. Step.prototype = {
  13318. areaStart: function() {
  13319. this._line = 0;
  13320. },
  13321. areaEnd: function() {
  13322. this._line = NaN;
  13323. },
  13324. lineStart: function() {
  13325. this._x = this._y = NaN;
  13326. this._point = 0;
  13327. },
  13328. lineEnd: function() {
  13329. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  13330. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13331. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  13332. },
  13333. point: function(x, y) {
  13334. x = +x, y = +y;
  13335. switch (this._point) {
  13336. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13337. case 1: this._point = 2; // proceed
  13338. default: {
  13339. if (this._t <= 0) {
  13340. this._context.lineTo(this._x, y);
  13341. this._context.lineTo(x, y);
  13342. } else {
  13343. var x1 = this._x * (1 - this._t) + x * this._t;
  13344. this._context.lineTo(x1, this._y);
  13345. this._context.lineTo(x1, y);
  13346. }
  13347. break;
  13348. }
  13349. }
  13350. this._x = x, this._y = y;
  13351. }
  13352. };
  13353. function step(context) {
  13354. return new Step(context, 0.5);
  13355. }
  13356. function stepBefore(context) {
  13357. return new Step(context, 0);
  13358. }
  13359. function stepAfter(context) {
  13360. return new Step(context, 1);
  13361. }
  13362. function none$1(series, order) {
  13363. if (!((n = series.length) > 1)) return;
  13364. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  13365. s0 = s1, s1 = series[order[i]];
  13366. for (j = 0; j < m; ++j) {
  13367. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  13368. }
  13369. }
  13370. }
  13371. function none$2(series) {
  13372. var n = series.length, o = new Array(n);
  13373. while (--n >= 0) o[n] = n;
  13374. return o;
  13375. }
  13376. function stackValue(d, key) {
  13377. return d[key];
  13378. }
  13379. function stack() {
  13380. var keys = constant$11([]),
  13381. order = none$2,
  13382. offset = none$1,
  13383. value = stackValue;
  13384. function stack(data) {
  13385. var kz = keys.apply(this, arguments),
  13386. i,
  13387. m = data.length,
  13388. n = kz.length,
  13389. sz = new Array(n),
  13390. oz;
  13391. for (i = 0; i < n; ++i) {
  13392. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  13393. si[j] = sij = [0, +value(data[j], ki, j, data)];
  13394. sij.data = data[j];
  13395. }
  13396. si.key = ki;
  13397. }
  13398. for (i = 0, oz = order(sz); i < n; ++i) {
  13399. sz[oz[i]].index = i;
  13400. }
  13401. offset(sz, oz);
  13402. return sz;
  13403. }
  13404. stack.keys = function(_) {
  13405. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$11(slice$6.call(_)), stack) : keys;
  13406. };
  13407. stack.value = function(_) {
  13408. return arguments.length ? (value = typeof _ === "function" ? _ : constant$11(+_), stack) : value;
  13409. };
  13410. stack.order = function(_) {
  13411. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$11(slice$6.call(_)), stack) : order;
  13412. };
  13413. stack.offset = function(_) {
  13414. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  13415. };
  13416. return stack;
  13417. }
  13418. function expand(series, order) {
  13419. if (!((n = series.length) > 0)) return;
  13420. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  13421. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  13422. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  13423. }
  13424. none$1(series, order);
  13425. }
  13426. function diverging$1(series, order) {
  13427. if (!((n = series.length) > 1)) return;
  13428. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  13429. for (yp = yn = 0, i = 0; i < n; ++i) {
  13430. if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
  13431. d[0] = yp, d[1] = yp += dy;
  13432. } else if (dy < 0) {
  13433. d[1] = yn, d[0] = yn += dy;
  13434. } else {
  13435. d[0] = yp;
  13436. }
  13437. }
  13438. }
  13439. }
  13440. function silhouette(series, order) {
  13441. if (!((n = series.length) > 0)) return;
  13442. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  13443. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  13444. s0[j][1] += s0[j][0] = -y / 2;
  13445. }
  13446. none$1(series, order);
  13447. }
  13448. function wiggle(series, order) {
  13449. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  13450. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  13451. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  13452. var si = series[order[i]],
  13453. sij0 = si[j][1] || 0,
  13454. sij1 = si[j - 1][1] || 0,
  13455. s3 = (sij0 - sij1) / 2;
  13456. for (var k = 0; k < i; ++k) {
  13457. var sk = series[order[k]],
  13458. skj0 = sk[j][1] || 0,
  13459. skj1 = sk[j - 1][1] || 0;
  13460. s3 += skj0 - skj1;
  13461. }
  13462. s1 += sij0, s2 += s3 * sij0;
  13463. }
  13464. s0[j - 1][1] += s0[j - 1][0] = y;
  13465. if (s1) y -= s2 / s1;
  13466. }
  13467. s0[j - 1][1] += s0[j - 1][0] = y;
  13468. none$1(series, order);
  13469. }
  13470. function ascending$3(series) {
  13471. var sums = series.map(sum$2);
  13472. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  13473. }
  13474. function sum$2(series) {
  13475. var s = 0, i = -1, n = series.length, v;
  13476. while (++i < n) if (v = +series[i][1]) s += v;
  13477. return s;
  13478. }
  13479. function descending$2(series) {
  13480. return ascending$3(series).reverse();
  13481. }
  13482. function insideOut(series) {
  13483. var n = series.length,
  13484. i,
  13485. j,
  13486. sums = series.map(sum$2),
  13487. order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  13488. top = 0,
  13489. bottom = 0,
  13490. tops = [],
  13491. bottoms = [];
  13492. for (i = 0; i < n; ++i) {
  13493. j = order[i];
  13494. if (top < bottom) {
  13495. top += sums[j];
  13496. tops.push(j);
  13497. } else {
  13498. bottom += sums[j];
  13499. bottoms.push(j);
  13500. }
  13501. }
  13502. return bottoms.reverse().concat(tops);
  13503. }
  13504. function reverse(series) {
  13505. return none$2(series).reverse();
  13506. }
  13507. function constant$12(x) {
  13508. return function() {
  13509. return x;
  13510. };
  13511. }
  13512. function x$4(d) {
  13513. return d[0];
  13514. }
  13515. function y$4(d) {
  13516. return d[1];
  13517. }
  13518. function RedBlackTree() {
  13519. this._ = null; // root node
  13520. }
  13521. function RedBlackNode(node) {
  13522. node.U = // parent node
  13523. node.C = // color - true for red, false for black
  13524. node.L = // left node
  13525. node.R = // right node
  13526. node.P = // previous node
  13527. node.N = null; // next node
  13528. }
  13529. RedBlackTree.prototype = {
  13530. constructor: RedBlackTree,
  13531. insert: function(after, node) {
  13532. var parent, grandpa, uncle;
  13533. if (after) {
  13534. node.P = after;
  13535. node.N = after.N;
  13536. if (after.N) after.N.P = node;
  13537. after.N = node;
  13538. if (after.R) {
  13539. after = after.R;
  13540. while (after.L) after = after.L;
  13541. after.L = node;
  13542. } else {
  13543. after.R = node;
  13544. }
  13545. parent = after;
  13546. } else if (this._) {
  13547. after = RedBlackFirst(this._);
  13548. node.P = null;
  13549. node.N = after;
  13550. after.P = after.L = node;
  13551. parent = after;
  13552. } else {
  13553. node.P = node.N = null;
  13554. this._ = node;
  13555. parent = null;
  13556. }
  13557. node.L = node.R = null;
  13558. node.U = parent;
  13559. node.C = true;
  13560. after = node;
  13561. while (parent && parent.C) {
  13562. grandpa = parent.U;
  13563. if (parent === grandpa.L) {
  13564. uncle = grandpa.R;
  13565. if (uncle && uncle.C) {
  13566. parent.C = uncle.C = false;
  13567. grandpa.C = true;
  13568. after = grandpa;
  13569. } else {
  13570. if (after === parent.R) {
  13571. RedBlackRotateLeft(this, parent);
  13572. after = parent;
  13573. parent = after.U;
  13574. }
  13575. parent.C = false;
  13576. grandpa.C = true;
  13577. RedBlackRotateRight(this, grandpa);
  13578. }
  13579. } else {
  13580. uncle = grandpa.L;
  13581. if (uncle && uncle.C) {
  13582. parent.C = uncle.C = false;
  13583. grandpa.C = true;
  13584. after = grandpa;
  13585. } else {
  13586. if (after === parent.L) {
  13587. RedBlackRotateRight(this, parent);
  13588. after = parent;
  13589. parent = after.U;
  13590. }
  13591. parent.C = false;
  13592. grandpa.C = true;
  13593. RedBlackRotateLeft(this, grandpa);
  13594. }
  13595. }
  13596. parent = after.U;
  13597. }
  13598. this._.C = false;
  13599. },
  13600. remove: function(node) {
  13601. if (node.N) node.N.P = node.P;
  13602. if (node.P) node.P.N = node.N;
  13603. node.N = node.P = null;
  13604. var parent = node.U,
  13605. sibling,
  13606. left = node.L,
  13607. right = node.R,
  13608. next,
  13609. red;
  13610. if (!left) next = right;
  13611. else if (!right) next = left;
  13612. else next = RedBlackFirst(right);
  13613. if (parent) {
  13614. if (parent.L === node) parent.L = next;
  13615. else parent.R = next;
  13616. } else {
  13617. this._ = next;
  13618. }
  13619. if (left && right) {
  13620. red = next.C;
  13621. next.C = node.C;
  13622. next.L = left;
  13623. left.U = next;
  13624. if (next !== right) {
  13625. parent = next.U;
  13626. next.U = node.U;
  13627. node = next.R;
  13628. parent.L = node;
  13629. next.R = right;
  13630. right.U = next;
  13631. } else {
  13632. next.U = parent;
  13633. parent = next;
  13634. node = next.R;
  13635. }
  13636. } else {
  13637. red = node.C;
  13638. node = next;
  13639. }
  13640. if (node) node.U = parent;
  13641. if (red) return;
  13642. if (node && node.C) { node.C = false; return; }
  13643. do {
  13644. if (node === this._) break;
  13645. if (node === parent.L) {
  13646. sibling = parent.R;
  13647. if (sibling.C) {
  13648. sibling.C = false;
  13649. parent.C = true;
  13650. RedBlackRotateLeft(this, parent);
  13651. sibling = parent.R;
  13652. }
  13653. if ((sibling.L && sibling.L.C)
  13654. || (sibling.R && sibling.R.C)) {
  13655. if (!sibling.R || !sibling.R.C) {
  13656. sibling.L.C = false;
  13657. sibling.C = true;
  13658. RedBlackRotateRight(this, sibling);
  13659. sibling = parent.R;
  13660. }
  13661. sibling.C = parent.C;
  13662. parent.C = sibling.R.C = false;
  13663. RedBlackRotateLeft(this, parent);
  13664. node = this._;
  13665. break;
  13666. }
  13667. } else {
  13668. sibling = parent.L;
  13669. if (sibling.C) {
  13670. sibling.C = false;
  13671. parent.C = true;
  13672. RedBlackRotateRight(this, parent);
  13673. sibling = parent.L;
  13674. }
  13675. if ((sibling.L && sibling.L.C)
  13676. || (sibling.R && sibling.R.C)) {
  13677. if (!sibling.L || !sibling.L.C) {
  13678. sibling.R.C = false;
  13679. sibling.C = true;
  13680. RedBlackRotateLeft(this, sibling);
  13681. sibling = parent.L;
  13682. }
  13683. sibling.C = parent.C;
  13684. parent.C = sibling.L.C = false;
  13685. RedBlackRotateRight(this, parent);
  13686. node = this._;
  13687. break;
  13688. }
  13689. }
  13690. sibling.C = true;
  13691. node = parent;
  13692. parent = parent.U;
  13693. } while (!node.C);
  13694. if (node) node.C = false;
  13695. }
  13696. };
  13697. function RedBlackRotateLeft(tree, node) {
  13698. var p = node,
  13699. q = node.R,
  13700. parent = p.U;
  13701. if (parent) {
  13702. if (parent.L === p) parent.L = q;
  13703. else parent.R = q;
  13704. } else {
  13705. tree._ = q;
  13706. }
  13707. q.U = parent;
  13708. p.U = q;
  13709. p.R = q.L;
  13710. if (p.R) p.R.U = p;
  13711. q.L = p;
  13712. }
  13713. function RedBlackRotateRight(tree, node) {
  13714. var p = node,
  13715. q = node.L,
  13716. parent = p.U;
  13717. if (parent) {
  13718. if (parent.L === p) parent.L = q;
  13719. else parent.R = q;
  13720. } else {
  13721. tree._ = q;
  13722. }
  13723. q.U = parent;
  13724. p.U = q;
  13725. p.L = q.R;
  13726. if (p.L) p.L.U = p;
  13727. q.R = p;
  13728. }
  13729. function RedBlackFirst(node) {
  13730. while (node.L) node = node.L;
  13731. return node;
  13732. }
  13733. function createEdge(left, right, v0, v1) {
  13734. var edge = [null, null],
  13735. index = edges.push(edge) - 1;
  13736. edge.left = left;
  13737. edge.right = right;
  13738. if (v0) setEdgeEnd(edge, left, right, v0);
  13739. if (v1) setEdgeEnd(edge, right, left, v1);
  13740. cells[left.index].halfedges.push(index);
  13741. cells[right.index].halfedges.push(index);
  13742. return edge;
  13743. }
  13744. function createBorderEdge(left, v0, v1) {
  13745. var edge = [v0, v1];
  13746. edge.left = left;
  13747. return edge;
  13748. }
  13749. function setEdgeEnd(edge, left, right, vertex) {
  13750. if (!edge[0] && !edge[1]) {
  13751. edge[0] = vertex;
  13752. edge.left = left;
  13753. edge.right = right;
  13754. } else if (edge.left === right) {
  13755. edge[1] = vertex;
  13756. } else {
  13757. edge[0] = vertex;
  13758. }
  13759. }
  13760. // Liang–Barsky line clipping.
  13761. function clipEdge(edge, x0, y0, x1, y1) {
  13762. var a = edge[0],
  13763. b = edge[1],
  13764. ax = a[0],
  13765. ay = a[1],
  13766. bx = b[0],
  13767. by = b[1],
  13768. t0 = 0,
  13769. t1 = 1,
  13770. dx = bx - ax,
  13771. dy = by - ay,
  13772. r;
  13773. r = x0 - ax;
  13774. if (!dx && r > 0) return;
  13775. r /= dx;
  13776. if (dx < 0) {
  13777. if (r < t0) return;
  13778. if (r < t1) t1 = r;
  13779. } else if (dx > 0) {
  13780. if (r > t1) return;
  13781. if (r > t0) t0 = r;
  13782. }
  13783. r = x1 - ax;
  13784. if (!dx && r < 0) return;
  13785. r /= dx;
  13786. if (dx < 0) {
  13787. if (r > t1) return;
  13788. if (r > t0) t0 = r;
  13789. } else if (dx > 0) {
  13790. if (r < t0) return;
  13791. if (r < t1) t1 = r;
  13792. }
  13793. r = y0 - ay;
  13794. if (!dy && r > 0) return;
  13795. r /= dy;
  13796. if (dy < 0) {
  13797. if (r < t0) return;
  13798. if (r < t1) t1 = r;
  13799. } else if (dy > 0) {
  13800. if (r > t1) return;
  13801. if (r > t0) t0 = r;
  13802. }
  13803. r = y1 - ay;
  13804. if (!dy && r < 0) return;
  13805. r /= dy;
  13806. if (dy < 0) {
  13807. if (r > t1) return;
  13808. if (r > t0) t0 = r;
  13809. } else if (dy > 0) {
  13810. if (r < t0) return;
  13811. if (r < t1) t1 = r;
  13812. }
  13813. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  13814. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  13815. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  13816. return true;
  13817. }
  13818. function connectEdge(edge, x0, y0, x1, y1) {
  13819. var v1 = edge[1];
  13820. if (v1) return true;
  13821. var v0 = edge[0],
  13822. left = edge.left,
  13823. right = edge.right,
  13824. lx = left[0],
  13825. ly = left[1],
  13826. rx = right[0],
  13827. ry = right[1],
  13828. fx = (lx + rx) / 2,
  13829. fy = (ly + ry) / 2,
  13830. fm,
  13831. fb;
  13832. if (ry === ly) {
  13833. if (fx < x0 || fx >= x1) return;
  13834. if (lx > rx) {
  13835. if (!v0) v0 = [fx, y0];
  13836. else if (v0[1] >= y1) return;
  13837. v1 = [fx, y1];
  13838. } else {
  13839. if (!v0) v0 = [fx, y1];
  13840. else if (v0[1] < y0) return;
  13841. v1 = [fx, y0];
  13842. }
  13843. } else {
  13844. fm = (lx - rx) / (ry - ly);
  13845. fb = fy - fm * fx;
  13846. if (fm < -1 || fm > 1) {
  13847. if (lx > rx) {
  13848. if (!v0) v0 = [(y0 - fb) / fm, y0];
  13849. else if (v0[1] >= y1) return;
  13850. v1 = [(y1 - fb) / fm, y1];
  13851. } else {
  13852. if (!v0) v0 = [(y1 - fb) / fm, y1];
  13853. else if (v0[1] < y0) return;
  13854. v1 = [(y0 - fb) / fm, y0];
  13855. }
  13856. } else {
  13857. if (ly < ry) {
  13858. if (!v0) v0 = [x0, fm * x0 + fb];
  13859. else if (v0[0] >= x1) return;
  13860. v1 = [x1, fm * x1 + fb];
  13861. } else {
  13862. if (!v0) v0 = [x1, fm * x1 + fb];
  13863. else if (v0[0] < x0) return;
  13864. v1 = [x0, fm * x0 + fb];
  13865. }
  13866. }
  13867. }
  13868. edge[0] = v0;
  13869. edge[1] = v1;
  13870. return true;
  13871. }
  13872. function clipEdges(x0, y0, x1, y1) {
  13873. var i = edges.length,
  13874. edge;
  13875. while (i--) {
  13876. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  13877. || !clipEdge(edge, x0, y0, x1, y1)
  13878. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  13879. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  13880. delete edges[i];
  13881. }
  13882. }
  13883. }
  13884. function createCell(site) {
  13885. return cells[site.index] = {
  13886. site: site,
  13887. halfedges: []
  13888. };
  13889. }
  13890. function cellHalfedgeAngle(cell, edge) {
  13891. var site = cell.site,
  13892. va = edge.left,
  13893. vb = edge.right;
  13894. if (site === vb) vb = va, va = site;
  13895. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  13896. if (site === va) va = edge[1], vb = edge[0];
  13897. else va = edge[0], vb = edge[1];
  13898. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  13899. }
  13900. function cellHalfedgeStart(cell, edge) {
  13901. return edge[+(edge.left !== cell.site)];
  13902. }
  13903. function cellHalfedgeEnd(cell, edge) {
  13904. return edge[+(edge.left === cell.site)];
  13905. }
  13906. function sortCellHalfedges() {
  13907. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  13908. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  13909. var index = new Array(m),
  13910. array = new Array(m);
  13911. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  13912. index.sort(function(i, j) { return array[j] - array[i]; });
  13913. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  13914. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  13915. }
  13916. }
  13917. }
  13918. function clipCells(x0, y0, x1, y1) {
  13919. var nCells = cells.length,
  13920. iCell,
  13921. cell,
  13922. site,
  13923. iHalfedge,
  13924. halfedges,
  13925. nHalfedges,
  13926. start,
  13927. startX,
  13928. startY,
  13929. end,
  13930. endX,
  13931. endY,
  13932. cover = true;
  13933. for (iCell = 0; iCell < nCells; ++iCell) {
  13934. if (cell = cells[iCell]) {
  13935. site = cell.site;
  13936. halfedges = cell.halfedges;
  13937. iHalfedge = halfedges.length;
  13938. // Remove any dangling clipped edges.
  13939. while (iHalfedge--) {
  13940. if (!edges[halfedges[iHalfedge]]) {
  13941. halfedges.splice(iHalfedge, 1);
  13942. }
  13943. }
  13944. // Insert any border edges as necessary.
  13945. iHalfedge = 0, nHalfedges = halfedges.length;
  13946. while (iHalfedge < nHalfedges) {
  13947. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  13948. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  13949. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  13950. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  13951. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  13952. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  13953. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  13954. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  13955. : null)) - 1);
  13956. ++nHalfedges;
  13957. }
  13958. }
  13959. if (nHalfedges) cover = false;
  13960. }
  13961. }
  13962. // If there weren’t any edges, have the closest site cover the extent.
  13963. // It doesn’t matter which corner of the extent we measure!
  13964. if (cover) {
  13965. var dx, dy, d2, dc = Infinity;
  13966. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  13967. if (cell = cells[iCell]) {
  13968. site = cell.site;
  13969. dx = site[0] - x0;
  13970. dy = site[1] - y0;
  13971. d2 = dx * dx + dy * dy;
  13972. if (d2 < dc) dc = d2, cover = cell;
  13973. }
  13974. }
  13975. if (cover) {
  13976. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  13977. cover.halfedges.push(
  13978. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  13979. edges.push(createBorderEdge(site, v01, v11)) - 1,
  13980. edges.push(createBorderEdge(site, v11, v10)) - 1,
  13981. edges.push(createBorderEdge(site, v10, v00)) - 1
  13982. );
  13983. }
  13984. }
  13985. // Lastly delete any cells with no edges; these were entirely clipped.
  13986. for (iCell = 0; iCell < nCells; ++iCell) {
  13987. if (cell = cells[iCell]) {
  13988. if (!cell.halfedges.length) {
  13989. delete cells[iCell];
  13990. }
  13991. }
  13992. }
  13993. }
  13994. var circlePool = [];
  13995. var firstCircle;
  13996. function Circle() {
  13997. RedBlackNode(this);
  13998. this.x =
  13999. this.y =
  14000. this.arc =
  14001. this.site =
  14002. this.cy = null;
  14003. }
  14004. function attachCircle(arc) {
  14005. var lArc = arc.P,
  14006. rArc = arc.N;
  14007. if (!lArc || !rArc) return;
  14008. var lSite = lArc.site,
  14009. cSite = arc.site,
  14010. rSite = rArc.site;
  14011. if (lSite === rSite) return;
  14012. var bx = cSite[0],
  14013. by = cSite[1],
  14014. ax = lSite[0] - bx,
  14015. ay = lSite[1] - by,
  14016. cx = rSite[0] - bx,
  14017. cy = rSite[1] - by;
  14018. var d = 2 * (ax * cy - ay * cx);
  14019. if (d >= -epsilon2$2) return;
  14020. var ha = ax * ax + ay * ay,
  14021. hc = cx * cx + cy * cy,
  14022. x = (cy * ha - ay * hc) / d,
  14023. y = (ax * hc - cx * ha) / d;
  14024. var circle = circlePool.pop() || new Circle;
  14025. circle.arc = arc;
  14026. circle.site = cSite;
  14027. circle.x = x + bx;
  14028. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  14029. arc.circle = circle;
  14030. var before = null,
  14031. node = circles._;
  14032. while (node) {
  14033. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  14034. if (node.L) node = node.L;
  14035. else { before = node.P; break; }
  14036. } else {
  14037. if (node.R) node = node.R;
  14038. else { before = node; break; }
  14039. }
  14040. }
  14041. circles.insert(before, circle);
  14042. if (!before) firstCircle = circle;
  14043. }
  14044. function detachCircle(arc) {
  14045. var circle = arc.circle;
  14046. if (circle) {
  14047. if (!circle.P) firstCircle = circle.N;
  14048. circles.remove(circle);
  14049. circlePool.push(circle);
  14050. RedBlackNode(circle);
  14051. arc.circle = null;
  14052. }
  14053. }
  14054. var beachPool = [];
  14055. function Beach() {
  14056. RedBlackNode(this);
  14057. this.edge =
  14058. this.site =
  14059. this.circle = null;
  14060. }
  14061. function createBeach(site) {
  14062. var beach = beachPool.pop() || new Beach;
  14063. beach.site = site;
  14064. return beach;
  14065. }
  14066. function detachBeach(beach) {
  14067. detachCircle(beach);
  14068. beaches.remove(beach);
  14069. beachPool.push(beach);
  14070. RedBlackNode(beach);
  14071. }
  14072. function removeBeach(beach) {
  14073. var circle = beach.circle,
  14074. x = circle.x,
  14075. y = circle.cy,
  14076. vertex = [x, y],
  14077. previous = beach.P,
  14078. next = beach.N,
  14079. disappearing = [beach];
  14080. detachBeach(beach);
  14081. var lArc = previous;
  14082. while (lArc.circle
  14083. && Math.abs(x - lArc.circle.x) < epsilon$4
  14084. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  14085. previous = lArc.P;
  14086. disappearing.unshift(lArc);
  14087. detachBeach(lArc);
  14088. lArc = previous;
  14089. }
  14090. disappearing.unshift(lArc);
  14091. detachCircle(lArc);
  14092. var rArc = next;
  14093. while (rArc.circle
  14094. && Math.abs(x - rArc.circle.x) < epsilon$4
  14095. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  14096. next = rArc.N;
  14097. disappearing.push(rArc);
  14098. detachBeach(rArc);
  14099. rArc = next;
  14100. }
  14101. disappearing.push(rArc);
  14102. detachCircle(rArc);
  14103. var nArcs = disappearing.length,
  14104. iArc;
  14105. for (iArc = 1; iArc < nArcs; ++iArc) {
  14106. rArc = disappearing[iArc];
  14107. lArc = disappearing[iArc - 1];
  14108. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  14109. }
  14110. lArc = disappearing[0];
  14111. rArc = disappearing[nArcs - 1];
  14112. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  14113. attachCircle(lArc);
  14114. attachCircle(rArc);
  14115. }
  14116. function addBeach(site) {
  14117. var x = site[0],
  14118. directrix = site[1],
  14119. lArc,
  14120. rArc,
  14121. dxl,
  14122. dxr,
  14123. node = beaches._;
  14124. while (node) {
  14125. dxl = leftBreakPoint(node, directrix) - x;
  14126. if (dxl > epsilon$4) node = node.L; else {
  14127. dxr = x - rightBreakPoint(node, directrix);
  14128. if (dxr > epsilon$4) {
  14129. if (!node.R) {
  14130. lArc = node;
  14131. break;
  14132. }
  14133. node = node.R;
  14134. } else {
  14135. if (dxl > -epsilon$4) {
  14136. lArc = node.P;
  14137. rArc = node;
  14138. } else if (dxr > -epsilon$4) {
  14139. lArc = node;
  14140. rArc = node.N;
  14141. } else {
  14142. lArc = rArc = node;
  14143. }
  14144. break;
  14145. }
  14146. }
  14147. }
  14148. createCell(site);
  14149. var newArc = createBeach(site);
  14150. beaches.insert(lArc, newArc);
  14151. if (!lArc && !rArc) return;
  14152. if (lArc === rArc) {
  14153. detachCircle(lArc);
  14154. rArc = createBeach(lArc.site);
  14155. beaches.insert(newArc, rArc);
  14156. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  14157. attachCircle(lArc);
  14158. attachCircle(rArc);
  14159. return;
  14160. }
  14161. if (!rArc) { // && lArc
  14162. newArc.edge = createEdge(lArc.site, newArc.site);
  14163. return;
  14164. }
  14165. // else lArc !== rArc
  14166. detachCircle(lArc);
  14167. detachCircle(rArc);
  14168. var lSite = lArc.site,
  14169. ax = lSite[0],
  14170. ay = lSite[1],
  14171. bx = site[0] - ax,
  14172. by = site[1] - ay,
  14173. rSite = rArc.site,
  14174. cx = rSite[0] - ax,
  14175. cy = rSite[1] - ay,
  14176. d = 2 * (bx * cy - by * cx),
  14177. hb = bx * bx + by * by,
  14178. hc = cx * cx + cy * cy,
  14179. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  14180. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  14181. newArc.edge = createEdge(lSite, site, null, vertex);
  14182. rArc.edge = createEdge(site, rSite, null, vertex);
  14183. attachCircle(lArc);
  14184. attachCircle(rArc);
  14185. }
  14186. function leftBreakPoint(arc, directrix) {
  14187. var site = arc.site,
  14188. rfocx = site[0],
  14189. rfocy = site[1],
  14190. pby2 = rfocy - directrix;
  14191. if (!pby2) return rfocx;
  14192. var lArc = arc.P;
  14193. if (!lArc) return -Infinity;
  14194. site = lArc.site;
  14195. var lfocx = site[0],
  14196. lfocy = site[1],
  14197. plby2 = lfocy - directrix;
  14198. if (!plby2) return lfocx;
  14199. var hl = lfocx - rfocx,
  14200. aby2 = 1 / pby2 - 1 / plby2,
  14201. b = hl / plby2;
  14202. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  14203. return (rfocx + lfocx) / 2;
  14204. }
  14205. function rightBreakPoint(arc, directrix) {
  14206. var rArc = arc.N;
  14207. if (rArc) return leftBreakPoint(rArc, directrix);
  14208. var site = arc.site;
  14209. return site[1] === directrix ? site[0] : Infinity;
  14210. }
  14211. var epsilon$4 = 1e-6;
  14212. var epsilon2$2 = 1e-12;
  14213. var beaches;
  14214. var cells;
  14215. var circles;
  14216. var edges;
  14217. function triangleArea(a, b, c) {
  14218. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  14219. }
  14220. function lexicographic(a, b) {
  14221. return b[1] - a[1]
  14222. || b[0] - a[0];
  14223. }
  14224. function Diagram(sites, extent) {
  14225. var site = sites.sort(lexicographic).pop(),
  14226. x,
  14227. y,
  14228. circle;
  14229. edges = [];
  14230. cells = new Array(sites.length);
  14231. beaches = new RedBlackTree;
  14232. circles = new RedBlackTree;
  14233. while (true) {
  14234. circle = firstCircle;
  14235. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  14236. if (site[0] !== x || site[1] !== y) {
  14237. addBeach(site);
  14238. x = site[0], y = site[1];
  14239. }
  14240. site = sites.pop();
  14241. } else if (circle) {
  14242. removeBeach(circle.arc);
  14243. } else {
  14244. break;
  14245. }
  14246. }
  14247. sortCellHalfedges();
  14248. if (extent) {
  14249. var x0 = +extent[0][0],
  14250. y0 = +extent[0][1],
  14251. x1 = +extent[1][0],
  14252. y1 = +extent[1][1];
  14253. clipEdges(x0, y0, x1, y1);
  14254. clipCells(x0, y0, x1, y1);
  14255. }
  14256. this.edges = edges;
  14257. this.cells = cells;
  14258. beaches =
  14259. circles =
  14260. edges =
  14261. cells = null;
  14262. }
  14263. Diagram.prototype = {
  14264. constructor: Diagram,
  14265. polygons: function() {
  14266. var edges = this.edges;
  14267. return this.cells.map(function(cell) {
  14268. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  14269. polygon.data = cell.site.data;
  14270. return polygon;
  14271. });
  14272. },
  14273. triangles: function() {
  14274. var triangles = [],
  14275. edges = this.edges;
  14276. this.cells.forEach(function(cell, i) {
  14277. if (!(m = (halfedges = cell.halfedges).length)) return;
  14278. var site = cell.site,
  14279. halfedges,
  14280. j = -1,
  14281. m,
  14282. s0,
  14283. e1 = edges[halfedges[m - 1]],
  14284. s1 = e1.left === site ? e1.right : e1.left;
  14285. while (++j < m) {
  14286. s0 = s1;
  14287. e1 = edges[halfedges[j]];
  14288. s1 = e1.left === site ? e1.right : e1.left;
  14289. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  14290. triangles.push([site.data, s0.data, s1.data]);
  14291. }
  14292. }
  14293. });
  14294. return triangles;
  14295. },
  14296. links: function() {
  14297. return this.edges.filter(function(edge) {
  14298. return edge.right;
  14299. }).map(function(edge) {
  14300. return {
  14301. source: edge.left.data,
  14302. target: edge.right.data
  14303. };
  14304. });
  14305. },
  14306. find: function(x, y, radius) {
  14307. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  14308. // Use the previously-found cell, or start with an arbitrary one.
  14309. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  14310. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  14311. // Traverse the half-edges to find a closer cell, if any.
  14312. do {
  14313. cell = that.cells[i0 = i1], i1 = null;
  14314. cell.halfedges.forEach(function(e) {
  14315. var edge = that.edges[e], v = edge.left;
  14316. if ((v === cell.site || !v) && !(v = edge.right)) return;
  14317. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  14318. if (v2 < d2) d2 = v2, i1 = v.index;
  14319. });
  14320. } while (i1 !== null);
  14321. that._found = i0;
  14322. return radius == null || d2 <= radius * radius ? cell.site : null;
  14323. }
  14324. };
  14325. function voronoi() {
  14326. var x$$1 = x$4,
  14327. y$$1 = y$4,
  14328. extent = null;
  14329. function voronoi(data) {
  14330. return new Diagram(data.map(function(d, i) {
  14331. var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
  14332. s.index = i;
  14333. s.data = d;
  14334. return s;
  14335. }), extent);
  14336. }
  14337. voronoi.polygons = function(data) {
  14338. return voronoi(data).polygons();
  14339. };
  14340. voronoi.links = function(data) {
  14341. return voronoi(data).links();
  14342. };
  14343. voronoi.triangles = function(data) {
  14344. return voronoi(data).triangles();
  14345. };
  14346. voronoi.x = function(_) {
  14347. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$12(+_), voronoi) : x$$1;
  14348. };
  14349. voronoi.y = function(_) {
  14350. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$12(+_), voronoi) : y$$1;
  14351. };
  14352. voronoi.extent = function(_) {
  14353. 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]]];
  14354. };
  14355. voronoi.size = function(_) {
  14356. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  14357. };
  14358. return voronoi;
  14359. }
  14360. function constant$13(x) {
  14361. return function() {
  14362. return x;
  14363. };
  14364. }
  14365. function ZoomEvent(target, type, transform) {
  14366. this.target = target;
  14367. this.type = type;
  14368. this.transform = transform;
  14369. }
  14370. function Transform(k, x, y) {
  14371. this.k = k;
  14372. this.x = x;
  14373. this.y = y;
  14374. }
  14375. Transform.prototype = {
  14376. constructor: Transform,
  14377. scale: function(k) {
  14378. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  14379. },
  14380. translate: function(x, y) {
  14381. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  14382. },
  14383. apply: function(point) {
  14384. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  14385. },
  14386. applyX: function(x) {
  14387. return x * this.k + this.x;
  14388. },
  14389. applyY: function(y) {
  14390. return y * this.k + this.y;
  14391. },
  14392. invert: function(location) {
  14393. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  14394. },
  14395. invertX: function(x) {
  14396. return (x - this.x) / this.k;
  14397. },
  14398. invertY: function(y) {
  14399. return (y - this.y) / this.k;
  14400. },
  14401. rescaleX: function(x) {
  14402. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  14403. },
  14404. rescaleY: function(y) {
  14405. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  14406. },
  14407. toString: function() {
  14408. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  14409. }
  14410. };
  14411. var identity$8 = new Transform(1, 0, 0);
  14412. transform$1.prototype = Transform.prototype;
  14413. function transform$1(node) {
  14414. return node.__zoom || identity$8;
  14415. }
  14416. function nopropagation$2() {
  14417. exports.event.stopImmediatePropagation();
  14418. }
  14419. function noevent$2() {
  14420. exports.event.preventDefault();
  14421. exports.event.stopImmediatePropagation();
  14422. }
  14423. // Ignore right-click, since that should open the context menu.
  14424. function defaultFilter$2() {
  14425. return !exports.event.button;
  14426. }
  14427. function defaultExtent$1() {
  14428. var e = this, w, h;
  14429. if (e instanceof SVGElement) {
  14430. e = e.ownerSVGElement || e;
  14431. w = e.width.baseVal.value;
  14432. h = e.height.baseVal.value;
  14433. } else {
  14434. w = e.clientWidth;
  14435. h = e.clientHeight;
  14436. }
  14437. return [[0, 0], [w, h]];
  14438. }
  14439. function defaultTransform() {
  14440. return this.__zoom || identity$8;
  14441. }
  14442. function defaultWheelDelta() {
  14443. return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
  14444. }
  14445. function defaultTouchable$1() {
  14446. return "ontouchstart" in this;
  14447. }
  14448. function defaultConstrain(transform, extent, translateExtent) {
  14449. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  14450. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  14451. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  14452. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  14453. return transform.translate(
  14454. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  14455. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  14456. );
  14457. }
  14458. function zoom() {
  14459. var filter = defaultFilter$2,
  14460. extent = defaultExtent$1,
  14461. constrain = defaultConstrain,
  14462. wheelDelta = defaultWheelDelta,
  14463. touchable = defaultTouchable$1,
  14464. scaleExtent = [0, Infinity],
  14465. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  14466. duration = 250,
  14467. interpolate = interpolateZoom,
  14468. gestures = [],
  14469. listeners = dispatch("start", "zoom", "end"),
  14470. touchstarting,
  14471. touchending,
  14472. touchDelay = 500,
  14473. wheelDelay = 150,
  14474. clickDistance2 = 0;
  14475. function zoom(selection$$1) {
  14476. selection$$1
  14477. .property("__zoom", defaultTransform)
  14478. .on("wheel.zoom", wheeled)
  14479. .on("mousedown.zoom", mousedowned)
  14480. .on("dblclick.zoom", dblclicked)
  14481. .filter(touchable)
  14482. .on("touchstart.zoom", touchstarted)
  14483. .on("touchmove.zoom", touchmoved)
  14484. .on("touchend.zoom touchcancel.zoom", touchended)
  14485. .style("touch-action", "none")
  14486. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  14487. }
  14488. zoom.transform = function(collection, transform) {
  14489. var selection$$1 = collection.selection ? collection.selection() : collection;
  14490. selection$$1.property("__zoom", defaultTransform);
  14491. if (collection !== selection$$1) {
  14492. schedule(collection, transform);
  14493. } else {
  14494. selection$$1.interrupt().each(function() {
  14495. gesture(this, arguments)
  14496. .start()
  14497. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  14498. .end();
  14499. });
  14500. }
  14501. };
  14502. zoom.scaleBy = function(selection$$1, k) {
  14503. zoom.scaleTo(selection$$1, function() {
  14504. var k0 = this.__zoom.k,
  14505. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14506. return k0 * k1;
  14507. });
  14508. };
  14509. zoom.scaleTo = function(selection$$1, k) {
  14510. zoom.transform(selection$$1, function() {
  14511. var e = extent.apply(this, arguments),
  14512. t0 = this.__zoom,
  14513. p0 = centroid(e),
  14514. p1 = t0.invert(p0),
  14515. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14516. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  14517. });
  14518. };
  14519. zoom.translateBy = function(selection$$1, x, y) {
  14520. zoom.transform(selection$$1, function() {
  14521. return constrain(this.__zoom.translate(
  14522. typeof x === "function" ? x.apply(this, arguments) : x,
  14523. typeof y === "function" ? y.apply(this, arguments) : y
  14524. ), extent.apply(this, arguments), translateExtent);
  14525. });
  14526. };
  14527. zoom.translateTo = function(selection$$1, x, y) {
  14528. zoom.transform(selection$$1, function() {
  14529. var e = extent.apply(this, arguments),
  14530. t = this.__zoom,
  14531. p = centroid(e);
  14532. return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
  14533. typeof x === "function" ? -x.apply(this, arguments) : -x,
  14534. typeof y === "function" ? -y.apply(this, arguments) : -y
  14535. ), e, translateExtent);
  14536. });
  14537. };
  14538. function scale(transform, k) {
  14539. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  14540. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  14541. }
  14542. function translate(transform, p0, p1) {
  14543. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  14544. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  14545. }
  14546. function centroid(extent) {
  14547. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  14548. }
  14549. function schedule(transition$$1, transform, center) {
  14550. transition$$1
  14551. .on("start.zoom", function() { gesture(this, arguments).start(); })
  14552. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  14553. .tween("zoom", function() {
  14554. var that = this,
  14555. args = arguments,
  14556. g = gesture(that, args),
  14557. e = extent.apply(that, args),
  14558. p = center || centroid(e),
  14559. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  14560. a = that.__zoom,
  14561. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  14562. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  14563. return function(t) {
  14564. if (t === 1) t = b; // Avoid rounding error on end.
  14565. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  14566. g.zoom(null, t);
  14567. };
  14568. });
  14569. }
  14570. function gesture(that, args) {
  14571. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  14572. if ((g = gestures[i]).that === that) {
  14573. return g;
  14574. }
  14575. }
  14576. return new Gesture(that, args);
  14577. }
  14578. function Gesture(that, args) {
  14579. this.that = that;
  14580. this.args = args;
  14581. this.index = -1;
  14582. this.active = 0;
  14583. this.extent = extent.apply(that, args);
  14584. }
  14585. Gesture.prototype = {
  14586. start: function() {
  14587. if (++this.active === 1) {
  14588. this.index = gestures.push(this) - 1;
  14589. this.emit("start");
  14590. }
  14591. return this;
  14592. },
  14593. zoom: function(key, transform) {
  14594. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  14595. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  14596. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  14597. this.that.__zoom = transform;
  14598. this.emit("zoom");
  14599. return this;
  14600. },
  14601. end: function() {
  14602. if (--this.active === 0) {
  14603. gestures.splice(this.index, 1);
  14604. this.index = -1;
  14605. this.emit("end");
  14606. }
  14607. return this;
  14608. },
  14609. emit: function(type) {
  14610. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  14611. }
  14612. };
  14613. function wheeled() {
  14614. if (!filter.apply(this, arguments)) return;
  14615. var g = gesture(this, arguments),
  14616. t = this.__zoom,
  14617. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  14618. p = mouse(this);
  14619. // If the mouse is in the same location as before, reuse it.
  14620. // If there were recent wheel events, reset the wheel idle timeout.
  14621. if (g.wheel) {
  14622. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  14623. g.mouse[1] = t.invert(g.mouse[0] = p);
  14624. }
  14625. clearTimeout(g.wheel);
  14626. }
  14627. // If this wheel event won’t trigger a transform change, ignore it.
  14628. else if (t.k === k) return;
  14629. // Otherwise, capture the mouse point and location at the start.
  14630. else {
  14631. g.mouse = [p, t.invert(p)];
  14632. interrupt(this);
  14633. g.start();
  14634. }
  14635. noevent$2();
  14636. g.wheel = setTimeout(wheelidled, wheelDelay);
  14637. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  14638. function wheelidled() {
  14639. g.wheel = null;
  14640. g.end();
  14641. }
  14642. }
  14643. function mousedowned() {
  14644. if (touchending || !filter.apply(this, arguments)) return;
  14645. var g = gesture(this, arguments),
  14646. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  14647. p = mouse(this),
  14648. x0 = exports.event.clientX,
  14649. y0 = exports.event.clientY;
  14650. dragDisable(exports.event.view);
  14651. nopropagation$2();
  14652. g.mouse = [p, this.__zoom.invert(p)];
  14653. interrupt(this);
  14654. g.start();
  14655. function mousemoved() {
  14656. noevent$2();
  14657. if (!g.moved) {
  14658. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  14659. g.moved = dx * dx + dy * dy > clickDistance2;
  14660. }
  14661. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  14662. }
  14663. function mouseupped() {
  14664. v.on("mousemove.zoom mouseup.zoom", null);
  14665. yesdrag(exports.event.view, g.moved);
  14666. noevent$2();
  14667. g.end();
  14668. }
  14669. }
  14670. function dblclicked() {
  14671. if (!filter.apply(this, arguments)) return;
  14672. var t0 = this.__zoom,
  14673. p0 = mouse(this),
  14674. p1 = t0.invert(p0),
  14675. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  14676. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  14677. noevent$2();
  14678. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  14679. else select(this).call(zoom.transform, t1);
  14680. }
  14681. function touchstarted() {
  14682. if (!filter.apply(this, arguments)) return;
  14683. var g = gesture(this, arguments),
  14684. touches$$1 = exports.event.changedTouches,
  14685. started,
  14686. n = touches$$1.length, i, t, p;
  14687. nopropagation$2();
  14688. for (i = 0; i < n; ++i) {
  14689. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  14690. p = [p, this.__zoom.invert(p), t.identifier];
  14691. if (!g.touch0) g.touch0 = p, started = true;
  14692. else if (!g.touch1) g.touch1 = p;
  14693. }
  14694. // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
  14695. if (touchstarting) {
  14696. touchstarting = clearTimeout(touchstarting);
  14697. if (!g.touch1) {
  14698. g.end();
  14699. p = select(this).on("dblclick.zoom");
  14700. if (p) p.apply(this, arguments);
  14701. return;
  14702. }
  14703. }
  14704. if (started) {
  14705. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  14706. interrupt(this);
  14707. g.start();
  14708. }
  14709. }
  14710. function touchmoved() {
  14711. var g = gesture(this, arguments),
  14712. touches$$1 = exports.event.changedTouches,
  14713. n = touches$$1.length, i, t, p, l;
  14714. noevent$2();
  14715. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  14716. for (i = 0; i < n; ++i) {
  14717. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  14718. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  14719. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  14720. }
  14721. t = g.that.__zoom;
  14722. if (g.touch1) {
  14723. var p0 = g.touch0[0], l0 = g.touch0[1],
  14724. p1 = g.touch1[0], l1 = g.touch1[1],
  14725. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  14726. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  14727. t = scale(t, Math.sqrt(dp / dl));
  14728. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  14729. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  14730. }
  14731. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  14732. else return;
  14733. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  14734. }
  14735. function touchended() {
  14736. var g = gesture(this, arguments),
  14737. touches$$1 = exports.event.changedTouches,
  14738. n = touches$$1.length, i, t;
  14739. nopropagation$2();
  14740. if (touchending) clearTimeout(touchending);
  14741. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  14742. for (i = 0; i < n; ++i) {
  14743. t = touches$$1[i];
  14744. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  14745. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  14746. }
  14747. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  14748. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  14749. else g.end();
  14750. }
  14751. zoom.wheelDelta = function(_) {
  14752. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$13(+_), zoom) : wheelDelta;
  14753. };
  14754. zoom.filter = function(_) {
  14755. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$13(!!_), zoom) : filter;
  14756. };
  14757. zoom.touchable = function(_) {
  14758. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$13(!!_), zoom) : touchable;
  14759. };
  14760. zoom.extent = function(_) {
  14761. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$13([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  14762. };
  14763. zoom.scaleExtent = function(_) {
  14764. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  14765. };
  14766. zoom.translateExtent = function(_) {
  14767. 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]]];
  14768. };
  14769. zoom.constrain = function(_) {
  14770. return arguments.length ? (constrain = _, zoom) : constrain;
  14771. };
  14772. zoom.duration = function(_) {
  14773. return arguments.length ? (duration = +_, zoom) : duration;
  14774. };
  14775. zoom.interpolate = function(_) {
  14776. return arguments.length ? (interpolate = _, zoom) : interpolate;
  14777. };
  14778. zoom.on = function() {
  14779. var value = listeners.on.apply(listeners, arguments);
  14780. return value === listeners ? zoom : value;
  14781. };
  14782. zoom.clickDistance = function(_) {
  14783. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  14784. };
  14785. return zoom;
  14786. }
  14787. exports.version = version;
  14788. exports.bisect = bisectRight;
  14789. exports.bisectRight = bisectRight;
  14790. exports.bisectLeft = bisectLeft;
  14791. exports.ascending = ascending;
  14792. exports.bisector = bisector;
  14793. exports.cross = cross;
  14794. exports.descending = descending;
  14795. exports.deviation = deviation;
  14796. exports.extent = extent;
  14797. exports.histogram = histogram;
  14798. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  14799. exports.thresholdScott = scott;
  14800. exports.thresholdSturges = thresholdSturges;
  14801. exports.max = max;
  14802. exports.mean = mean;
  14803. exports.median = median;
  14804. exports.merge = merge;
  14805. exports.min = min;
  14806. exports.pairs = pairs;
  14807. exports.permute = permute;
  14808. exports.quantile = threshold;
  14809. exports.range = sequence;
  14810. exports.scan = scan;
  14811. exports.shuffle = shuffle;
  14812. exports.sum = sum;
  14813. exports.ticks = ticks;
  14814. exports.tickIncrement = tickIncrement;
  14815. exports.tickStep = tickStep;
  14816. exports.transpose = transpose;
  14817. exports.variance = variance;
  14818. exports.zip = zip;
  14819. exports.axisTop = axisTop;
  14820. exports.axisRight = axisRight;
  14821. exports.axisBottom = axisBottom;
  14822. exports.axisLeft = axisLeft;
  14823. exports.brush = brush;
  14824. exports.brushX = brushX;
  14825. exports.brushY = brushY;
  14826. exports.brushSelection = brushSelection;
  14827. exports.chord = chord;
  14828. exports.ribbon = ribbon;
  14829. exports.nest = nest;
  14830. exports.set = set$2;
  14831. exports.map = map$1;
  14832. exports.keys = keys;
  14833. exports.values = values;
  14834. exports.entries = entries;
  14835. exports.color = color;
  14836. exports.rgb = rgb;
  14837. exports.hsl = hsl;
  14838. exports.lab = lab;
  14839. exports.hcl = hcl;
  14840. exports.lch = lch;
  14841. exports.gray = gray;
  14842. exports.cubehelix = cubehelix;
  14843. exports.contours = contours;
  14844. exports.contourDensity = density;
  14845. exports.dispatch = dispatch;
  14846. exports.drag = drag;
  14847. exports.dragDisable = dragDisable;
  14848. exports.dragEnable = yesdrag;
  14849. exports.dsvFormat = dsvFormat;
  14850. exports.csvParse = csvParse;
  14851. exports.csvParseRows = csvParseRows;
  14852. exports.csvFormat = csvFormat;
  14853. exports.csvFormatRows = csvFormatRows;
  14854. exports.tsvParse = tsvParse;
  14855. exports.tsvParseRows = tsvParseRows;
  14856. exports.tsvFormat = tsvFormat;
  14857. exports.tsvFormatRows = tsvFormatRows;
  14858. exports.easeLinear = linear$1;
  14859. exports.easeQuad = quadInOut;
  14860. exports.easeQuadIn = quadIn;
  14861. exports.easeQuadOut = quadOut;
  14862. exports.easeQuadInOut = quadInOut;
  14863. exports.easeCubic = cubicInOut;
  14864. exports.easeCubicIn = cubicIn;
  14865. exports.easeCubicOut = cubicOut;
  14866. exports.easeCubicInOut = cubicInOut;
  14867. exports.easePoly = polyInOut;
  14868. exports.easePolyIn = polyIn;
  14869. exports.easePolyOut = polyOut;
  14870. exports.easePolyInOut = polyInOut;
  14871. exports.easeSin = sinInOut;
  14872. exports.easeSinIn = sinIn;
  14873. exports.easeSinOut = sinOut;
  14874. exports.easeSinInOut = sinInOut;
  14875. exports.easeExp = expInOut;
  14876. exports.easeExpIn = expIn;
  14877. exports.easeExpOut = expOut;
  14878. exports.easeExpInOut = expInOut;
  14879. exports.easeCircle = circleInOut;
  14880. exports.easeCircleIn = circleIn;
  14881. exports.easeCircleOut = circleOut;
  14882. exports.easeCircleInOut = circleInOut;
  14883. exports.easeBounce = bounceOut;
  14884. exports.easeBounceIn = bounceIn;
  14885. exports.easeBounceOut = bounceOut;
  14886. exports.easeBounceInOut = bounceInOut;
  14887. exports.easeBack = backInOut;
  14888. exports.easeBackIn = backIn;
  14889. exports.easeBackOut = backOut;
  14890. exports.easeBackInOut = backInOut;
  14891. exports.easeElastic = elasticOut;
  14892. exports.easeElasticIn = elasticIn;
  14893. exports.easeElasticOut = elasticOut;
  14894. exports.easeElasticInOut = elasticInOut;
  14895. exports.blob = blob;
  14896. exports.buffer = buffer;
  14897. exports.dsv = dsv;
  14898. exports.csv = csv$1;
  14899. exports.tsv = tsv$1;
  14900. exports.image = image;
  14901. exports.json = json;
  14902. exports.text = text;
  14903. exports.xml = xml;
  14904. exports.html = html;
  14905. exports.svg = svg;
  14906. exports.forceCenter = center$1;
  14907. exports.forceCollide = collide;
  14908. exports.forceLink = link;
  14909. exports.forceManyBody = manyBody;
  14910. exports.forceRadial = radial;
  14911. exports.forceSimulation = simulation;
  14912. exports.forceX = x$2;
  14913. exports.forceY = y$2;
  14914. exports.formatDefaultLocale = defaultLocale;
  14915. exports.formatLocale = formatLocale;
  14916. exports.formatSpecifier = formatSpecifier;
  14917. exports.precisionFixed = precisionFixed;
  14918. exports.precisionPrefix = precisionPrefix;
  14919. exports.precisionRound = precisionRound;
  14920. exports.geoArea = area$1;
  14921. exports.geoBounds = bounds;
  14922. exports.geoCentroid = centroid;
  14923. exports.geoCircle = circle;
  14924. exports.geoClipAntimeridian = clipAntimeridian;
  14925. exports.geoClipCircle = clipCircle;
  14926. exports.geoClipExtent = extent$1;
  14927. exports.geoClipRectangle = clipRectangle;
  14928. exports.geoContains = contains$1;
  14929. exports.geoDistance = distance;
  14930. exports.geoGraticule = graticule;
  14931. exports.geoGraticule10 = graticule10;
  14932. exports.geoInterpolate = interpolate$1;
  14933. exports.geoLength = length$1;
  14934. exports.geoPath = index$1;
  14935. exports.geoAlbers = albers;
  14936. exports.geoAlbersUsa = albersUsa;
  14937. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  14938. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  14939. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  14940. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  14941. exports.geoConicConformal = conicConformal;
  14942. exports.geoConicConformalRaw = conicConformalRaw;
  14943. exports.geoConicEqualArea = conicEqualArea;
  14944. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  14945. exports.geoConicEquidistant = conicEquidistant;
  14946. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  14947. exports.geoEquirectangular = equirectangular;
  14948. exports.geoEquirectangularRaw = equirectangularRaw;
  14949. exports.geoGnomonic = gnomonic;
  14950. exports.geoGnomonicRaw = gnomonicRaw;
  14951. exports.geoIdentity = identity$5;
  14952. exports.geoProjection = projection;
  14953. exports.geoProjectionMutator = projectionMutator;
  14954. exports.geoMercator = mercator;
  14955. exports.geoMercatorRaw = mercatorRaw;
  14956. exports.geoNaturalEarth1 = naturalEarth1;
  14957. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  14958. exports.geoOrthographic = orthographic;
  14959. exports.geoOrthographicRaw = orthographicRaw;
  14960. exports.geoStereographic = stereographic;
  14961. exports.geoStereographicRaw = stereographicRaw;
  14962. exports.geoTransverseMercator = transverseMercator;
  14963. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  14964. exports.geoRotation = rotation;
  14965. exports.geoStream = geoStream;
  14966. exports.geoTransform = transform;
  14967. exports.cluster = cluster;
  14968. exports.hierarchy = hierarchy;
  14969. exports.pack = index$2;
  14970. exports.packSiblings = siblings;
  14971. exports.packEnclose = enclose;
  14972. exports.partition = partition;
  14973. exports.stratify = stratify;
  14974. exports.tree = tree;
  14975. exports.treemap = index$3;
  14976. exports.treemapBinary = binary;
  14977. exports.treemapDice = treemapDice;
  14978. exports.treemapSlice = treemapSlice;
  14979. exports.treemapSliceDice = sliceDice;
  14980. exports.treemapSquarify = squarify;
  14981. exports.treemapResquarify = resquarify;
  14982. exports.interpolate = interpolateValue;
  14983. exports.interpolateArray = array$1;
  14984. exports.interpolateBasis = basis$1;
  14985. exports.interpolateBasisClosed = basisClosed;
  14986. exports.interpolateDate = date;
  14987. exports.interpolateNumber = reinterpolate;
  14988. exports.interpolateObject = object;
  14989. exports.interpolateRound = interpolateRound;
  14990. exports.interpolateString = interpolateString;
  14991. exports.interpolateTransformCss = interpolateTransformCss;
  14992. exports.interpolateTransformSvg = interpolateTransformSvg;
  14993. exports.interpolateZoom = interpolateZoom;
  14994. exports.interpolateRgb = interpolateRgb;
  14995. exports.interpolateRgbBasis = rgbBasis;
  14996. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  14997. exports.interpolateHsl = hsl$2;
  14998. exports.interpolateHslLong = hslLong;
  14999. exports.interpolateLab = lab$1;
  15000. exports.interpolateHcl = hcl$2;
  15001. exports.interpolateHclLong = hclLong;
  15002. exports.interpolateCubehelix = cubehelix$2;
  15003. exports.interpolateCubehelixLong = cubehelixLong;
  15004. exports.piecewise = piecewise;
  15005. exports.quantize = quantize;
  15006. exports.path = path;
  15007. exports.polygonArea = area$2;
  15008. exports.polygonCentroid = centroid$1;
  15009. exports.polygonHull = hull;
  15010. exports.polygonContains = contains$2;
  15011. exports.polygonLength = length$2;
  15012. exports.quadtree = quadtree;
  15013. exports.randomUniform = uniform;
  15014. exports.randomNormal = normal;
  15015. exports.randomLogNormal = logNormal;
  15016. exports.randomBates = bates;
  15017. exports.randomIrwinHall = irwinHall;
  15018. exports.randomExponential = exponential$1;
  15019. exports.scaleBand = band;
  15020. exports.scalePoint = point$1;
  15021. exports.scaleIdentity = identity$6;
  15022. exports.scaleLinear = linear$2;
  15023. exports.scaleLog = log$1;
  15024. exports.scaleOrdinal = ordinal;
  15025. exports.scaleImplicit = implicit;
  15026. exports.scalePow = pow$1;
  15027. exports.scaleSqrt = sqrt$1;
  15028. exports.scaleQuantile = quantile$$1;
  15029. exports.scaleQuantize = quantize$1;
  15030. exports.scaleThreshold = threshold$1;
  15031. exports.scaleTime = time;
  15032. exports.scaleUtc = utcTime;
  15033. exports.scaleSequential = sequential;
  15034. exports.scaleDiverging = diverging;
  15035. exports.schemeCategory10 = category10;
  15036. exports.schemeAccent = Accent;
  15037. exports.schemeDark2 = Dark2;
  15038. exports.schemePaired = Paired;
  15039. exports.schemePastel1 = Pastel1;
  15040. exports.schemePastel2 = Pastel2;
  15041. exports.schemeSet1 = Set1;
  15042. exports.schemeSet2 = Set2;
  15043. exports.schemeSet3 = Set3;
  15044. exports.interpolateBrBG = BrBG;
  15045. exports.schemeBrBG = scheme;
  15046. exports.interpolatePRGn = PRGn;
  15047. exports.schemePRGn = scheme$1;
  15048. exports.interpolatePiYG = PiYG;
  15049. exports.schemePiYG = scheme$2;
  15050. exports.interpolatePuOr = PuOr;
  15051. exports.schemePuOr = scheme$3;
  15052. exports.interpolateRdBu = RdBu;
  15053. exports.schemeRdBu = scheme$4;
  15054. exports.interpolateRdGy = RdGy;
  15055. exports.schemeRdGy = scheme$5;
  15056. exports.interpolateRdYlBu = RdYlBu;
  15057. exports.schemeRdYlBu = scheme$6;
  15058. exports.interpolateRdYlGn = RdYlGn;
  15059. exports.schemeRdYlGn = scheme$7;
  15060. exports.interpolateSpectral = Spectral;
  15061. exports.schemeSpectral = scheme$8;
  15062. exports.interpolateBuGn = BuGn;
  15063. exports.schemeBuGn = scheme$9;
  15064. exports.interpolateBuPu = BuPu;
  15065. exports.schemeBuPu = scheme$10;
  15066. exports.interpolateGnBu = GnBu;
  15067. exports.schemeGnBu = scheme$11;
  15068. exports.interpolateOrRd = OrRd;
  15069. exports.schemeOrRd = scheme$12;
  15070. exports.interpolatePuBuGn = PuBuGn;
  15071. exports.schemePuBuGn = scheme$13;
  15072. exports.interpolatePuBu = PuBu;
  15073. exports.schemePuBu = scheme$14;
  15074. exports.interpolatePuRd = PuRd;
  15075. exports.schemePuRd = scheme$15;
  15076. exports.interpolateRdPu = RdPu;
  15077. exports.schemeRdPu = scheme$16;
  15078. exports.interpolateYlGnBu = YlGnBu;
  15079. exports.schemeYlGnBu = scheme$17;
  15080. exports.interpolateYlGn = YlGn;
  15081. exports.schemeYlGn = scheme$18;
  15082. exports.interpolateYlOrBr = YlOrBr;
  15083. exports.schemeYlOrBr = scheme$19;
  15084. exports.interpolateYlOrRd = YlOrRd;
  15085. exports.schemeYlOrRd = scheme$20;
  15086. exports.interpolateBlues = Blues;
  15087. exports.schemeBlues = scheme$21;
  15088. exports.interpolateGreens = Greens;
  15089. exports.schemeGreens = scheme$22;
  15090. exports.interpolateGreys = Greys;
  15091. exports.schemeGreys = scheme$23;
  15092. exports.interpolatePurples = Purples;
  15093. exports.schemePurples = scheme$24;
  15094. exports.interpolateReds = Reds;
  15095. exports.schemeReds = scheme$25;
  15096. exports.interpolateOranges = Oranges;
  15097. exports.schemeOranges = scheme$26;
  15098. exports.interpolateCubehelixDefault = cubehelix$3;
  15099. exports.interpolateRainbow = rainbow;
  15100. exports.interpolateWarm = warm;
  15101. exports.interpolateCool = cool;
  15102. exports.interpolateSinebow = sinebow;
  15103. exports.interpolateViridis = viridis;
  15104. exports.interpolateMagma = magma;
  15105. exports.interpolateInferno = inferno;
  15106. exports.interpolatePlasma = plasma;
  15107. exports.create = create;
  15108. exports.creator = creator;
  15109. exports.local = local;
  15110. exports.matcher = matcher$1;
  15111. exports.mouse = mouse;
  15112. exports.namespace = namespace;
  15113. exports.namespaces = namespaces;
  15114. exports.clientPoint = point;
  15115. exports.select = select;
  15116. exports.selectAll = selectAll;
  15117. exports.selection = selection;
  15118. exports.selector = selector;
  15119. exports.selectorAll = selectorAll;
  15120. exports.style = styleValue;
  15121. exports.touch = touch;
  15122. exports.touches = touches;
  15123. exports.window = defaultView;
  15124. exports.customEvent = customEvent;
  15125. exports.arc = arc;
  15126. exports.area = area$3;
  15127. exports.line = line;
  15128. exports.pie = pie;
  15129. exports.areaRadial = areaRadial;
  15130. exports.radialArea = areaRadial;
  15131. exports.lineRadial = lineRadial$1;
  15132. exports.radialLine = lineRadial$1;
  15133. exports.pointRadial = pointRadial;
  15134. exports.linkHorizontal = linkHorizontal;
  15135. exports.linkVertical = linkVertical;
  15136. exports.linkRadial = linkRadial;
  15137. exports.symbol = symbol;
  15138. exports.symbols = symbols;
  15139. exports.symbolCircle = circle$2;
  15140. exports.symbolCross = cross$2;
  15141. exports.symbolDiamond = diamond;
  15142. exports.symbolSquare = square;
  15143. exports.symbolStar = star;
  15144. exports.symbolTriangle = triangle;
  15145. exports.symbolWye = wye;
  15146. exports.curveBasisClosed = basisClosed$1;
  15147. exports.curveBasisOpen = basisOpen;
  15148. exports.curveBasis = basis$2;
  15149. exports.curveBundle = bundle;
  15150. exports.curveCardinalClosed = cardinalClosed;
  15151. exports.curveCardinalOpen = cardinalOpen;
  15152. exports.curveCardinal = cardinal;
  15153. exports.curveCatmullRomClosed = catmullRomClosed;
  15154. exports.curveCatmullRomOpen = catmullRomOpen;
  15155. exports.curveCatmullRom = catmullRom;
  15156. exports.curveLinearClosed = linearClosed;
  15157. exports.curveLinear = curveLinear;
  15158. exports.curveMonotoneX = monotoneX;
  15159. exports.curveMonotoneY = monotoneY;
  15160. exports.curveNatural = natural;
  15161. exports.curveStep = step;
  15162. exports.curveStepAfter = stepAfter;
  15163. exports.curveStepBefore = stepBefore;
  15164. exports.stack = stack;
  15165. exports.stackOffsetExpand = expand;
  15166. exports.stackOffsetDiverging = diverging$1;
  15167. exports.stackOffsetNone = none$1;
  15168. exports.stackOffsetSilhouette = silhouette;
  15169. exports.stackOffsetWiggle = wiggle;
  15170. exports.stackOrderAscending = ascending$3;
  15171. exports.stackOrderDescending = descending$2;
  15172. exports.stackOrderInsideOut = insideOut;
  15173. exports.stackOrderNone = none$2;
  15174. exports.stackOrderReverse = reverse;
  15175. exports.timeInterval = newInterval;
  15176. exports.timeMillisecond = millisecond;
  15177. exports.timeMilliseconds = milliseconds;
  15178. exports.utcMillisecond = millisecond;
  15179. exports.utcMilliseconds = milliseconds;
  15180. exports.timeSecond = second;
  15181. exports.timeSeconds = seconds;
  15182. exports.utcSecond = second;
  15183. exports.utcSeconds = seconds;
  15184. exports.timeMinute = minute;
  15185. exports.timeMinutes = minutes;
  15186. exports.timeHour = hour;
  15187. exports.timeHours = hours;
  15188. exports.timeDay = day;
  15189. exports.timeDays = days;
  15190. exports.timeWeek = sunday;
  15191. exports.timeWeeks = sundays;
  15192. exports.timeSunday = sunday;
  15193. exports.timeSundays = sundays;
  15194. exports.timeMonday = monday;
  15195. exports.timeMondays = mondays;
  15196. exports.timeTuesday = tuesday;
  15197. exports.timeTuesdays = tuesdays;
  15198. exports.timeWednesday = wednesday;
  15199. exports.timeWednesdays = wednesdays;
  15200. exports.timeThursday = thursday;
  15201. exports.timeThursdays = thursdays;
  15202. exports.timeFriday = friday;
  15203. exports.timeFridays = fridays;
  15204. exports.timeSaturday = saturday;
  15205. exports.timeSaturdays = saturdays;
  15206. exports.timeMonth = month;
  15207. exports.timeMonths = months;
  15208. exports.timeYear = year;
  15209. exports.timeYears = years;
  15210. exports.utcMinute = utcMinute;
  15211. exports.utcMinutes = utcMinutes;
  15212. exports.utcHour = utcHour;
  15213. exports.utcHours = utcHours;
  15214. exports.utcDay = utcDay;
  15215. exports.utcDays = utcDays;
  15216. exports.utcWeek = utcSunday;
  15217. exports.utcWeeks = utcSundays;
  15218. exports.utcSunday = utcSunday;
  15219. exports.utcSundays = utcSundays;
  15220. exports.utcMonday = utcMonday;
  15221. exports.utcMondays = utcMondays;
  15222. exports.utcTuesday = utcTuesday;
  15223. exports.utcTuesdays = utcTuesdays;
  15224. exports.utcWednesday = utcWednesday;
  15225. exports.utcWednesdays = utcWednesdays;
  15226. exports.utcThursday = utcThursday;
  15227. exports.utcThursdays = utcThursdays;
  15228. exports.utcFriday = utcFriday;
  15229. exports.utcFridays = utcFridays;
  15230. exports.utcSaturday = utcSaturday;
  15231. exports.utcSaturdays = utcSaturdays;
  15232. exports.utcMonth = utcMonth;
  15233. exports.utcMonths = utcMonths;
  15234. exports.utcYear = utcYear;
  15235. exports.utcYears = utcYears;
  15236. exports.timeFormatDefaultLocale = defaultLocale$1;
  15237. exports.timeFormatLocale = formatLocale$1;
  15238. exports.isoFormat = formatIso;
  15239. exports.isoParse = parseIso;
  15240. exports.now = now;
  15241. exports.timer = timer;
  15242. exports.timerFlush = timerFlush;
  15243. exports.timeout = timeout$1;
  15244. exports.interval = interval$1;
  15245. exports.transition = transition;
  15246. exports.active = active;
  15247. exports.interrupt = interrupt;
  15248. exports.voronoi = voronoi;
  15249. exports.zoom = zoom;
  15250. exports.zoomTransform = transform$1;
  15251. exports.zoomIdentity = identity$8;
  15252. Object.defineProperty(exports, '__esModule', { value: true });
  15253. })));