d3.js 484 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857
  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. })));