d3.js 482 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788
  1. // https://d3js.org Version 5.1.0. Copyright 2018 Mike Bostock.
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (factory((global.d3 = global.d3 || {})));
  6. }(this, (function (exports) { 'use strict';
  7. var version = "5.1.0";
  8. function ascending(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function bisector(compare) {
  12. if (compare.length === 1) compare = ascendingComparator(compare);
  13. return {
  14. left: function(a, x, lo, hi) {
  15. if (lo == null) lo = 0;
  16. if (hi == null) hi = a.length;
  17. while (lo < hi) {
  18. var mid = lo + hi >>> 1;
  19. if (compare(a[mid], x) < 0) lo = mid + 1;
  20. else hi = mid;
  21. }
  22. return lo;
  23. },
  24. right: function(a, x, lo, hi) {
  25. if (lo == null) lo = 0;
  26. if (hi == null) hi = a.length;
  27. while (lo < hi) {
  28. var mid = lo + hi >>> 1;
  29. if (compare(a[mid], x) > 0) hi = mid;
  30. else lo = mid + 1;
  31. }
  32. return lo;
  33. }
  34. };
  35. }
  36. function ascendingComparator(f) {
  37. return function(d, x) {
  38. return ascending(f(d), x);
  39. };
  40. }
  41. var ascendingBisect = bisector(ascending);
  42. var bisectRight = ascendingBisect.right;
  43. var bisectLeft = ascendingBisect.left;
  44. function pairs(array, f) {
  45. if (f == null) f = pair;
  46. var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
  47. while (i < n) pairs[i] = f(p, p = array[++i]);
  48. return pairs;
  49. }
  50. function pair(a, b) {
  51. return [a, b];
  52. }
  53. function cross(values0, values1, reduce) {
  54. var n0 = values0.length,
  55. n1 = values1.length,
  56. values = new Array(n0 * n1),
  57. i0,
  58. i1,
  59. i,
  60. value0;
  61. if (reduce == null) reduce = pair;
  62. for (i0 = i = 0; i0 < n0; ++i0) {
  63. for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
  64. values[i] = reduce(value0, values1[i1]);
  65. }
  66. }
  67. return values;
  68. }
  69. function descending(a, b) {
  70. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  71. }
  72. function number(x) {
  73. return x === null ? NaN : +x;
  74. }
  75. function variance(values, valueof) {
  76. var n = values.length,
  77. m = 0,
  78. i = -1,
  79. mean = 0,
  80. value,
  81. delta,
  82. sum = 0;
  83. if (valueof == null) {
  84. while (++i < n) {
  85. if (!isNaN(value = number(values[i]))) {
  86. delta = value - mean;
  87. mean += delta / ++m;
  88. sum += delta * (value - mean);
  89. }
  90. }
  91. }
  92. else {
  93. while (++i < n) {
  94. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  95. delta = value - mean;
  96. mean += delta / ++m;
  97. sum += delta * (value - mean);
  98. }
  99. }
  100. }
  101. if (m > 1) return sum / (m - 1);
  102. }
  103. function deviation(array, f) {
  104. var v = variance(array, f);
  105. return v ? Math.sqrt(v) : v;
  106. }
  107. function extent(values, valueof) {
  108. var n = values.length,
  109. i = -1,
  110. value,
  111. min,
  112. max;
  113. if (valueof == null) {
  114. while (++i < n) { // Find the first comparable value.
  115. if ((value = values[i]) != null && value >= value) {
  116. min = max = value;
  117. while (++i < n) { // Compare the remaining values.
  118. if ((value = values[i]) != null) {
  119. if (min > value) min = value;
  120. if (max < value) max = value;
  121. }
  122. }
  123. }
  124. }
  125. }
  126. else {
  127. while (++i < n) { // Find the first comparable value.
  128. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  129. min = max = value;
  130. while (++i < n) { // Compare the remaining values.
  131. if ((value = valueof(values[i], i, values)) != null) {
  132. if (min > value) min = value;
  133. if (max < value) max = value;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. return [min, max];
  140. }
  141. var array = Array.prototype;
  142. var slice = array.slice;
  143. var map = array.map;
  144. function constant(x) {
  145. return function() {
  146. return x;
  147. };
  148. }
  149. function identity(x) {
  150. return x;
  151. }
  152. function sequence(start, stop, step) {
  153. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  154. var i = -1,
  155. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  156. range = new Array(n);
  157. while (++i < n) {
  158. range[i] = start + i * step;
  159. }
  160. return range;
  161. }
  162. var e10 = Math.sqrt(50),
  163. e5 = Math.sqrt(10),
  164. e2 = Math.sqrt(2);
  165. function ticks(start, stop, count) {
  166. var reverse,
  167. i = -1,
  168. n,
  169. ticks,
  170. step;
  171. stop = +stop, start = +start, count = +count;
  172. if (start === stop && count > 0) return [start];
  173. if (reverse = stop < start) n = start, start = stop, stop = n;
  174. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  175. if (step > 0) {
  176. start = Math.ceil(start / step);
  177. stop = Math.floor(stop / step);
  178. ticks = new Array(n = Math.ceil(stop - start + 1));
  179. while (++i < n) ticks[i] = (start + i) * step;
  180. } else {
  181. start = Math.floor(start * step);
  182. stop = Math.ceil(stop * step);
  183. ticks = new Array(n = Math.ceil(start - stop + 1));
  184. while (++i < n) ticks[i] = (start - i) / step;
  185. }
  186. if (reverse) ticks.reverse();
  187. return ticks;
  188. }
  189. function tickIncrement(start, stop, count) {
  190. var step = (stop - start) / Math.max(0, count),
  191. power = Math.floor(Math.log(step) / Math.LN10),
  192. error = step / Math.pow(10, power);
  193. return power >= 0
  194. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  195. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  196. }
  197. function tickStep(start, stop, count) {
  198. var step0 = Math.abs(stop - start) / Math.max(0, count),
  199. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  200. error = step0 / step1;
  201. if (error >= e10) step1 *= 10;
  202. else if (error >= e5) step1 *= 5;
  203. else if (error >= e2) step1 *= 2;
  204. return stop < start ? -step1 : step1;
  205. }
  206. function thresholdSturges(values) {
  207. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  208. }
  209. function histogram() {
  210. var value = identity,
  211. domain = extent,
  212. threshold = thresholdSturges;
  213. function histogram(data) {
  214. var i,
  215. n = data.length,
  216. x,
  217. values = new Array(n);
  218. for (i = 0; i < n; ++i) {
  219. values[i] = value(data[i], i, data);
  220. }
  221. var xz = domain(values),
  222. x0 = xz[0],
  223. x1 = xz[1],
  224. tz = threshold(values, x0, x1);
  225. // Convert number of thresholds into uniform thresholds.
  226. if (!Array.isArray(tz)) {
  227. tz = tickStep(x0, x1, tz);
  228. tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
  229. }
  230. // Remove any thresholds outside the domain.
  231. var m = tz.length;
  232. while (tz[0] <= x0) tz.shift(), --m;
  233. while (tz[m - 1] > x1) tz.pop(), --m;
  234. var bins = new Array(m + 1),
  235. bin;
  236. // Initialize bins.
  237. for (i = 0; i <= m; ++i) {
  238. bin = bins[i] = [];
  239. bin.x0 = i > 0 ? tz[i - 1] : x0;
  240. bin.x1 = i < m ? tz[i] : x1;
  241. }
  242. // Assign data to bins by value, ignoring any outside the domain.
  243. for (i = 0; i < n; ++i) {
  244. x = values[i];
  245. if (x0 <= x && x <= x1) {
  246. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  247. }
  248. }
  249. return bins;
  250. }
  251. histogram.value = function(_) {
  252. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  253. };
  254. histogram.domain = function(_) {
  255. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  256. };
  257. histogram.thresholds = function(_) {
  258. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  259. };
  260. return histogram;
  261. }
  262. function threshold(values, p, valueof) {
  263. if (valueof == null) valueof = number;
  264. if (!(n = values.length)) return;
  265. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  266. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  267. var n,
  268. i = (n - 1) * p,
  269. i0 = Math.floor(i),
  270. value0 = +valueof(values[i0], i0, values),
  271. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  272. return value0 + (value1 - value0) * (i - i0);
  273. }
  274. function freedmanDiaconis(values, min, max) {
  275. values = map.call(values, number).sort(ascending);
  276. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  277. }
  278. function scott(values, min, max) {
  279. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  280. }
  281. function max(values, valueof) {
  282. var n = values.length,
  283. i = -1,
  284. value,
  285. max;
  286. if (valueof == null) {
  287. while (++i < n) { // Find the first comparable value.
  288. if ((value = values[i]) != null && value >= value) {
  289. max = value;
  290. while (++i < n) { // Compare the remaining values.
  291. if ((value = values[i]) != null && value > max) {
  292. max = value;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. else {
  299. while (++i < n) { // Find the first comparable value.
  300. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  301. max = value;
  302. while (++i < n) { // Compare the remaining values.
  303. if ((value = valueof(values[i], i, values)) != null && value > max) {
  304. max = value;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. return max;
  311. }
  312. function mean(values, valueof) {
  313. var n = values.length,
  314. m = n,
  315. i = -1,
  316. value,
  317. sum = 0;
  318. if (valueof == null) {
  319. while (++i < n) {
  320. if (!isNaN(value = number(values[i]))) sum += value;
  321. else --m;
  322. }
  323. }
  324. else {
  325. while (++i < n) {
  326. if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
  327. else --m;
  328. }
  329. }
  330. if (m) return sum / m;
  331. }
  332. function median(values, valueof) {
  333. var n = values.length,
  334. i = -1,
  335. value,
  336. numbers = [];
  337. if (valueof == null) {
  338. while (++i < n) {
  339. if (!isNaN(value = number(values[i]))) {
  340. numbers.push(value);
  341. }
  342. }
  343. }
  344. else {
  345. while (++i < n) {
  346. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  347. numbers.push(value);
  348. }
  349. }
  350. }
  351. return threshold(numbers.sort(ascending), 0.5);
  352. }
  353. function merge(arrays) {
  354. var n = arrays.length,
  355. m,
  356. i = -1,
  357. j = 0,
  358. merged,
  359. array;
  360. while (++i < n) j += arrays[i].length;
  361. merged = new Array(j);
  362. while (--n >= 0) {
  363. array = arrays[n];
  364. m = array.length;
  365. while (--m >= 0) {
  366. merged[--j] = array[m];
  367. }
  368. }
  369. return merged;
  370. }
  371. function min(values, valueof) {
  372. var n = values.length,
  373. i = -1,
  374. value,
  375. min;
  376. if (valueof == null) {
  377. while (++i < n) { // Find the first comparable value.
  378. if ((value = values[i]) != null && value >= value) {
  379. min = value;
  380. while (++i < n) { // Compare the remaining values.
  381. if ((value = values[i]) != null && min > value) {
  382. min = value;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. else {
  389. while (++i < n) { // Find the first comparable value.
  390. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  391. min = value;
  392. while (++i < n) { // Compare the remaining values.
  393. if ((value = valueof(values[i], i, values)) != null && min > value) {
  394. min = value;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. return min;
  401. }
  402. function permute(array, indexes) {
  403. var i = indexes.length, permutes = new Array(i);
  404. while (i--) permutes[i] = array[indexes[i]];
  405. return permutes;
  406. }
  407. function scan(values, compare) {
  408. if (!(n = values.length)) return;
  409. var n,
  410. i = 0,
  411. j = 0,
  412. xi,
  413. xj = values[j];
  414. if (compare == null) compare = ascending;
  415. while (++i < n) {
  416. if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
  417. xj = xi, j = i;
  418. }
  419. }
  420. if (compare(xj, xj) === 0) return j;
  421. }
  422. function shuffle(array, i0, i1) {
  423. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  424. t,
  425. i;
  426. while (m) {
  427. i = Math.random() * m-- | 0;
  428. t = array[m + i0];
  429. array[m + i0] = array[i + i0];
  430. array[i + i0] = t;
  431. }
  432. return array;
  433. }
  434. function sum(values, valueof) {
  435. var n = values.length,
  436. i = -1,
  437. value,
  438. sum = 0;
  439. if (valueof == null) {
  440. while (++i < n) {
  441. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  442. }
  443. }
  444. else {
  445. while (++i < n) {
  446. if (value = +valueof(values[i], i, values)) sum += value;
  447. }
  448. }
  449. return sum;
  450. }
  451. function transpose(matrix) {
  452. if (!(n = matrix.length)) return [];
  453. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  454. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  455. row[j] = matrix[j][i];
  456. }
  457. }
  458. return transpose;
  459. }
  460. function length(d) {
  461. return d.length;
  462. }
  463. function zip() {
  464. return transpose(arguments);
  465. }
  466. var slice$1 = Array.prototype.slice;
  467. function identity$1(x) {
  468. return x;
  469. }
  470. var top = 1,
  471. right = 2,
  472. bottom = 3,
  473. left = 4,
  474. epsilon = 1e-6;
  475. function translateX(x) {
  476. return "translate(" + (x + 0.5) + ",0)";
  477. }
  478. function translateY(y) {
  479. return "translate(0," + (y + 0.5) + ")";
  480. }
  481. function number$1(scale) {
  482. return function(d) {
  483. return +scale(d);
  484. };
  485. }
  486. function center(scale) {
  487. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  488. if (scale.round()) offset = Math.round(offset);
  489. return function(d) {
  490. return +scale(d) + offset;
  491. };
  492. }
  493. function entering() {
  494. return !this.__axis;
  495. }
  496. function axis(orient, scale) {
  497. var tickArguments = [],
  498. tickValues = null,
  499. tickFormat = null,
  500. tickSizeInner = 6,
  501. tickSizeOuter = 6,
  502. tickPadding = 3,
  503. k = orient === top || orient === left ? -1 : 1,
  504. x = orient === left || orient === right ? "x" : "y",
  505. transform = orient === top || orient === bottom ? translateX : translateY;
  506. function axis(context) {
  507. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  508. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  509. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  510. range = scale.range(),
  511. range0 = +range[0] + 0.5,
  512. range1 = +range[range.length - 1] + 0.5,
  513. position = (scale.bandwidth ? center : number$1)(scale.copy()),
  514. selection = context.selection ? context.selection() : context,
  515. path = selection.selectAll(".domain").data([null]),
  516. tick = selection.selectAll(".tick").data(values, scale).order(),
  517. tickExit = tick.exit(),
  518. tickEnter = tick.enter().append("g").attr("class", "tick"),
  519. line = tick.select("line"),
  520. text = tick.select("text");
  521. path = path.merge(path.enter().insert("path", ".tick")
  522. .attr("class", "domain")
  523. .attr("stroke", "#000"));
  524. tick = tick.merge(tickEnter);
  525. line = line.merge(tickEnter.append("line")
  526. .attr("stroke", "#000")
  527. .attr(x + "2", k * tickSizeInner));
  528. text = text.merge(tickEnter.append("text")
  529. .attr("fill", "#000")
  530. .attr(x, k * spacing)
  531. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  532. if (context !== selection) {
  533. path = path.transition(context);
  534. tick = tick.transition(context);
  535. line = line.transition(context);
  536. text = text.transition(context);
  537. tickExit = tickExit.transition(context)
  538. .attr("opacity", epsilon)
  539. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  540. tickEnter
  541. .attr("opacity", epsilon)
  542. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  543. }
  544. tickExit.remove();
  545. path
  546. .attr("d", orient === left || orient == right
  547. ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
  548. : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
  549. tick
  550. .attr("opacity", 1)
  551. .attr("transform", function(d) { return transform(position(d)); });
  552. line
  553. .attr(x + "2", k * tickSizeInner);
  554. text
  555. .attr(x, k * spacing)
  556. .text(format);
  557. selection.filter(entering)
  558. .attr("fill", "none")
  559. .attr("font-size", 10)
  560. .attr("font-family", "sans-serif")
  561. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  562. selection
  563. .each(function() { this.__axis = position; });
  564. }
  565. axis.scale = function(_) {
  566. return arguments.length ? (scale = _, axis) : scale;
  567. };
  568. axis.ticks = function() {
  569. return tickArguments = slice$1.call(arguments), axis;
  570. };
  571. axis.tickArguments = function(_) {
  572. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  573. };
  574. axis.tickValues = function(_) {
  575. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  576. };
  577. axis.tickFormat = function(_) {
  578. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  579. };
  580. axis.tickSize = function(_) {
  581. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  582. };
  583. axis.tickSizeInner = function(_) {
  584. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  585. };
  586. axis.tickSizeOuter = function(_) {
  587. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  588. };
  589. axis.tickPadding = function(_) {
  590. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  591. };
  592. return axis;
  593. }
  594. function axisTop(scale) {
  595. return axis(top, scale);
  596. }
  597. function axisRight(scale) {
  598. return axis(right, scale);
  599. }
  600. function axisBottom(scale) {
  601. return axis(bottom, scale);
  602. }
  603. function axisLeft(scale) {
  604. return axis(left, scale);
  605. }
  606. var noop = {value: function() {}};
  607. function dispatch() {
  608. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  609. if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
  610. _[t] = [];
  611. }
  612. return new Dispatch(_);
  613. }
  614. function Dispatch(_) {
  615. this._ = _;
  616. }
  617. function parseTypenames(typenames, types) {
  618. return typenames.trim().split(/^|\s+/).map(function(t) {
  619. var name = "", i = t.indexOf(".");
  620. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  621. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  622. return {type: t, name: name};
  623. });
  624. }
  625. Dispatch.prototype = dispatch.prototype = {
  626. constructor: Dispatch,
  627. on: function(typename, callback) {
  628. var _ = this._,
  629. T = parseTypenames(typename + "", _),
  630. t,
  631. i = -1,
  632. n = T.length;
  633. // If no callback was specified, return the callback of the given type and name.
  634. if (arguments.length < 2) {
  635. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  636. return;
  637. }
  638. // If a type was specified, set the callback for the given type and name.
  639. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  640. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  641. while (++i < n) {
  642. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  643. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  644. }
  645. return this;
  646. },
  647. copy: function() {
  648. var copy = {}, _ = this._;
  649. for (var t in _) copy[t] = _[t].slice();
  650. return new Dispatch(copy);
  651. },
  652. call: function(type, that) {
  653. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  654. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  655. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  656. },
  657. apply: function(type, that, args) {
  658. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  659. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  660. }
  661. };
  662. function get(type, name) {
  663. for (var i = 0, n = type.length, c; i < n; ++i) {
  664. if ((c = type[i]).name === name) {
  665. return c.value;
  666. }
  667. }
  668. }
  669. function set(type, name, callback) {
  670. for (var i = 0, n = type.length; i < n; ++i) {
  671. if (type[i].name === name) {
  672. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  673. break;
  674. }
  675. }
  676. if (callback != null) type.push({name: name, value: callback});
  677. return type;
  678. }
  679. var xhtml = "http://www.w3.org/1999/xhtml";
  680. var namespaces = {
  681. svg: "http://www.w3.org/2000/svg",
  682. xhtml: xhtml,
  683. xlink: "http://www.w3.org/1999/xlink",
  684. xml: "http://www.w3.org/XML/1998/namespace",
  685. xmlns: "http://www.w3.org/2000/xmlns/"
  686. };
  687. function namespace(name) {
  688. var prefix = name += "", i = prefix.indexOf(":");
  689. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  690. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  691. }
  692. function creatorInherit(name) {
  693. return function() {
  694. var document = this.ownerDocument,
  695. uri = this.namespaceURI;
  696. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  697. ? document.createElement(name)
  698. : document.createElementNS(uri, name);
  699. };
  700. }
  701. function creatorFixed(fullname) {
  702. return function() {
  703. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  704. };
  705. }
  706. function creator(name) {
  707. var fullname = namespace(name);
  708. return (fullname.local
  709. ? creatorFixed
  710. : creatorInherit)(fullname);
  711. }
  712. function none() {}
  713. function selector(selector) {
  714. return selector == null ? none : function() {
  715. return this.querySelector(selector);
  716. };
  717. }
  718. function selection_select(select) {
  719. if (typeof select !== "function") select = selector(select);
  720. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  721. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  722. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  723. if ("__data__" in node) subnode.__data__ = node.__data__;
  724. subgroup[i] = subnode;
  725. }
  726. }
  727. }
  728. return new Selection(subgroups, this._parents);
  729. }
  730. function empty() {
  731. return [];
  732. }
  733. function selectorAll(selector) {
  734. return selector == null ? empty : function() {
  735. return this.querySelectorAll(selector);
  736. };
  737. }
  738. function selection_selectAll(select) {
  739. if (typeof select !== "function") select = selectorAll(select);
  740. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  741. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  742. if (node = group[i]) {
  743. subgroups.push(select.call(node, node.__data__, i, group));
  744. parents.push(node);
  745. }
  746. }
  747. }
  748. return new Selection(subgroups, parents);
  749. }
  750. var matcher = function(selector) {
  751. return function() {
  752. return this.matches(selector);
  753. };
  754. };
  755. if (typeof document !== "undefined") {
  756. var element = document.documentElement;
  757. if (!element.matches) {
  758. var vendorMatches = element.webkitMatchesSelector
  759. || element.msMatchesSelector
  760. || element.mozMatchesSelector
  761. || element.oMatchesSelector;
  762. matcher = function(selector) {
  763. return function() {
  764. return vendorMatches.call(this, selector);
  765. };
  766. };
  767. }
  768. }
  769. var matcher$1 = matcher;
  770. function selection_filter(match) {
  771. if (typeof match !== "function") match = matcher$1(match);
  772. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  773. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  774. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  775. subgroup.push(node);
  776. }
  777. }
  778. }
  779. return new Selection(subgroups, this._parents);
  780. }
  781. function sparse(update) {
  782. return new Array(update.length);
  783. }
  784. function selection_enter() {
  785. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  786. }
  787. function EnterNode(parent, datum) {
  788. this.ownerDocument = parent.ownerDocument;
  789. this.namespaceURI = parent.namespaceURI;
  790. this._next = null;
  791. this._parent = parent;
  792. this.__data__ = datum;
  793. }
  794. EnterNode.prototype = {
  795. constructor: EnterNode,
  796. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  797. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  798. querySelector: function(selector) { return this._parent.querySelector(selector); },
  799. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  800. };
  801. function constant$1(x) {
  802. return function() {
  803. return x;
  804. };
  805. }
  806. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  807. function bindIndex(parent, group, enter, update, exit, data) {
  808. var i = 0,
  809. node,
  810. groupLength = group.length,
  811. dataLength = data.length;
  812. // Put any non-null nodes that fit into update.
  813. // Put any null nodes into enter.
  814. // Put any remaining data into enter.
  815. for (; i < dataLength; ++i) {
  816. if (node = group[i]) {
  817. node.__data__ = data[i];
  818. update[i] = node;
  819. } else {
  820. enter[i] = new EnterNode(parent, data[i]);
  821. }
  822. }
  823. // Put any non-null nodes that don’t fit into exit.
  824. for (; i < groupLength; ++i) {
  825. if (node = group[i]) {
  826. exit[i] = node;
  827. }
  828. }
  829. }
  830. function bindKey(parent, group, enter, update, exit, data, key) {
  831. var i,
  832. node,
  833. nodeByKeyValue = {},
  834. groupLength = group.length,
  835. dataLength = data.length,
  836. keyValues = new Array(groupLength),
  837. keyValue;
  838. // Compute the key for each node.
  839. // If multiple nodes have the same key, the duplicates are added to exit.
  840. for (i = 0; i < groupLength; ++i) {
  841. if (node = group[i]) {
  842. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  843. if (keyValue in nodeByKeyValue) {
  844. exit[i] = node;
  845. } else {
  846. nodeByKeyValue[keyValue] = node;
  847. }
  848. }
  849. }
  850. // Compute the key for each datum.
  851. // If there a node associated with this key, join and add it to update.
  852. // If there is not (or the key is a duplicate), add it to enter.
  853. for (i = 0; i < dataLength; ++i) {
  854. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  855. if (node = nodeByKeyValue[keyValue]) {
  856. update[i] = node;
  857. node.__data__ = data[i];
  858. nodeByKeyValue[keyValue] = null;
  859. } else {
  860. enter[i] = new EnterNode(parent, data[i]);
  861. }
  862. }
  863. // Add any remaining nodes that were not bound to data to exit.
  864. for (i = 0; i < groupLength; ++i) {
  865. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  866. exit[i] = node;
  867. }
  868. }
  869. }
  870. function selection_data(value, key) {
  871. if (!value) {
  872. data = new Array(this.size()), j = -1;
  873. this.each(function(d) { data[++j] = d; });
  874. return data;
  875. }
  876. var bind = key ? bindKey : bindIndex,
  877. parents = this._parents,
  878. groups = this._groups;
  879. if (typeof value !== "function") value = constant$1(value);
  880. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  881. var parent = parents[j],
  882. group = groups[j],
  883. groupLength = group.length,
  884. data = value.call(parent, parent && parent.__data__, j, parents),
  885. dataLength = data.length,
  886. enterGroup = enter[j] = new Array(dataLength),
  887. updateGroup = update[j] = new Array(dataLength),
  888. exitGroup = exit[j] = new Array(groupLength);
  889. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  890. // Now connect the enter nodes to their following update node, such that
  891. // appendChild can insert the materialized enter node before this node,
  892. // rather than at the end of the parent node.
  893. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  894. if (previous = enterGroup[i0]) {
  895. if (i0 >= i1) i1 = i0 + 1;
  896. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  897. previous._next = next || null;
  898. }
  899. }
  900. }
  901. update = new Selection(update, parents);
  902. update._enter = enter;
  903. update._exit = exit;
  904. return update;
  905. }
  906. function selection_exit() {
  907. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  908. }
  909. function selection_merge(selection$$1) {
  910. 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) {
  911. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  912. if (node = group0[i] || group1[i]) {
  913. merge[i] = node;
  914. }
  915. }
  916. }
  917. for (; j < m0; ++j) {
  918. merges[j] = groups0[j];
  919. }
  920. return new Selection(merges, this._parents);
  921. }
  922. function selection_order() {
  923. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  924. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  925. if (node = group[i]) {
  926. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  927. next = node;
  928. }
  929. }
  930. }
  931. return this;
  932. }
  933. function selection_sort(compare) {
  934. if (!compare) compare = ascending$1;
  935. function compareNode(a, b) {
  936. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  937. }
  938. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  939. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  940. if (node = group[i]) {
  941. sortgroup[i] = node;
  942. }
  943. }
  944. sortgroup.sort(compareNode);
  945. }
  946. return new Selection(sortgroups, this._parents).order();
  947. }
  948. function ascending$1(a, b) {
  949. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  950. }
  951. function selection_call() {
  952. var callback = arguments[0];
  953. arguments[0] = this;
  954. callback.apply(null, arguments);
  955. return this;
  956. }
  957. function selection_nodes() {
  958. var nodes = new Array(this.size()), i = -1;
  959. this.each(function() { nodes[++i] = this; });
  960. return nodes;
  961. }
  962. function selection_node() {
  963. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  964. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  965. var node = group[i];
  966. if (node) return node;
  967. }
  968. }
  969. return null;
  970. }
  971. function selection_size() {
  972. var size = 0;
  973. this.each(function() { ++size; });
  974. return size;
  975. }
  976. function selection_empty() {
  977. return !this.node();
  978. }
  979. function selection_each(callback) {
  980. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  981. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  982. if (node = group[i]) callback.call(node, node.__data__, i, group);
  983. }
  984. }
  985. return this;
  986. }
  987. function attrRemove(name) {
  988. return function() {
  989. this.removeAttribute(name);
  990. };
  991. }
  992. function attrRemoveNS(fullname) {
  993. return function() {
  994. this.removeAttributeNS(fullname.space, fullname.local);
  995. };
  996. }
  997. function attrConstant(name, value) {
  998. return function() {
  999. this.setAttribute(name, value);
  1000. };
  1001. }
  1002. function attrConstantNS(fullname, value) {
  1003. return function() {
  1004. this.setAttributeNS(fullname.space, fullname.local, value);
  1005. };
  1006. }
  1007. function attrFunction(name, value) {
  1008. return function() {
  1009. var v = value.apply(this, arguments);
  1010. if (v == null) this.removeAttribute(name);
  1011. else this.setAttribute(name, v);
  1012. };
  1013. }
  1014. function attrFunctionNS(fullname, value) {
  1015. return function() {
  1016. var v = value.apply(this, arguments);
  1017. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1018. else this.setAttributeNS(fullname.space, fullname.local, v);
  1019. };
  1020. }
  1021. function selection_attr(name, value) {
  1022. var fullname = namespace(name);
  1023. if (arguments.length < 2) {
  1024. var node = this.node();
  1025. return fullname.local
  1026. ? node.getAttributeNS(fullname.space, fullname.local)
  1027. : node.getAttribute(fullname);
  1028. }
  1029. return this.each((value == null
  1030. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1031. ? (fullname.local ? attrFunctionNS : attrFunction)
  1032. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1033. }
  1034. function defaultView(node) {
  1035. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1036. || (node.document && node) // node is a Window
  1037. || node.defaultView; // node is a Document
  1038. }
  1039. function styleRemove(name) {
  1040. return function() {
  1041. this.style.removeProperty(name);
  1042. };
  1043. }
  1044. function styleConstant(name, value, priority) {
  1045. return function() {
  1046. this.style.setProperty(name, value, priority);
  1047. };
  1048. }
  1049. function styleFunction(name, value, priority) {
  1050. return function() {
  1051. var v = value.apply(this, arguments);
  1052. if (v == null) this.style.removeProperty(name);
  1053. else this.style.setProperty(name, v, priority);
  1054. };
  1055. }
  1056. function selection_style(name, value, priority) {
  1057. return arguments.length > 1
  1058. ? this.each((value == null
  1059. ? styleRemove : typeof value === "function"
  1060. ? styleFunction
  1061. : styleConstant)(name, value, priority == null ? "" : priority))
  1062. : styleValue(this.node(), name);
  1063. }
  1064. function styleValue(node, name) {
  1065. return node.style.getPropertyValue(name)
  1066. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1067. }
  1068. function propertyRemove(name) {
  1069. return function() {
  1070. delete this[name];
  1071. };
  1072. }
  1073. function propertyConstant(name, value) {
  1074. return function() {
  1075. this[name] = value;
  1076. };
  1077. }
  1078. function propertyFunction(name, value) {
  1079. return function() {
  1080. var v = value.apply(this, arguments);
  1081. if (v == null) delete this[name];
  1082. else this[name] = v;
  1083. };
  1084. }
  1085. function selection_property(name, value) {
  1086. return arguments.length > 1
  1087. ? this.each((value == null
  1088. ? propertyRemove : typeof value === "function"
  1089. ? propertyFunction
  1090. : propertyConstant)(name, value))
  1091. : this.node()[name];
  1092. }
  1093. function classArray(string) {
  1094. return string.trim().split(/^|\s+/);
  1095. }
  1096. function classList(node) {
  1097. return node.classList || new ClassList(node);
  1098. }
  1099. function ClassList(node) {
  1100. this._node = node;
  1101. this._names = classArray(node.getAttribute("class") || "");
  1102. }
  1103. ClassList.prototype = {
  1104. add: function(name) {
  1105. var i = this._names.indexOf(name);
  1106. if (i < 0) {
  1107. this._names.push(name);
  1108. this._node.setAttribute("class", this._names.join(" "));
  1109. }
  1110. },
  1111. remove: function(name) {
  1112. var i = this._names.indexOf(name);
  1113. if (i >= 0) {
  1114. this._names.splice(i, 1);
  1115. this._node.setAttribute("class", this._names.join(" "));
  1116. }
  1117. },
  1118. contains: function(name) {
  1119. return this._names.indexOf(name) >= 0;
  1120. }
  1121. };
  1122. function classedAdd(node, names) {
  1123. var list = classList(node), i = -1, n = names.length;
  1124. while (++i < n) list.add(names[i]);
  1125. }
  1126. function classedRemove(node, names) {
  1127. var list = classList(node), i = -1, n = names.length;
  1128. while (++i < n) list.remove(names[i]);
  1129. }
  1130. function classedTrue(names) {
  1131. return function() {
  1132. classedAdd(this, names);
  1133. };
  1134. }
  1135. function classedFalse(names) {
  1136. return function() {
  1137. classedRemove(this, names);
  1138. };
  1139. }
  1140. function classedFunction(names, value) {
  1141. return function() {
  1142. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1143. };
  1144. }
  1145. function selection_classed(name, value) {
  1146. var names = classArray(name + "");
  1147. if (arguments.length < 2) {
  1148. var list = classList(this.node()), i = -1, n = names.length;
  1149. while (++i < n) if (!list.contains(names[i])) return false;
  1150. return true;
  1151. }
  1152. return this.each((typeof value === "function"
  1153. ? classedFunction : value
  1154. ? classedTrue
  1155. : classedFalse)(names, value));
  1156. }
  1157. function textRemove() {
  1158. this.textContent = "";
  1159. }
  1160. function textConstant(value) {
  1161. return function() {
  1162. this.textContent = value;
  1163. };
  1164. }
  1165. function textFunction(value) {
  1166. return function() {
  1167. var v = value.apply(this, arguments);
  1168. this.textContent = v == null ? "" : v;
  1169. };
  1170. }
  1171. function selection_text(value) {
  1172. return arguments.length
  1173. ? this.each(value == null
  1174. ? textRemove : (typeof value === "function"
  1175. ? textFunction
  1176. : textConstant)(value))
  1177. : this.node().textContent;
  1178. }
  1179. function htmlRemove() {
  1180. this.innerHTML = "";
  1181. }
  1182. function htmlConstant(value) {
  1183. return function() {
  1184. this.innerHTML = value;
  1185. };
  1186. }
  1187. function htmlFunction(value) {
  1188. return function() {
  1189. var v = value.apply(this, arguments);
  1190. this.innerHTML = v == null ? "" : v;
  1191. };
  1192. }
  1193. function selection_html(value) {
  1194. return arguments.length
  1195. ? this.each(value == null
  1196. ? htmlRemove : (typeof value === "function"
  1197. ? htmlFunction
  1198. : htmlConstant)(value))
  1199. : this.node().innerHTML;
  1200. }
  1201. function raise() {
  1202. if (this.nextSibling) this.parentNode.appendChild(this);
  1203. }
  1204. function selection_raise() {
  1205. return this.each(raise);
  1206. }
  1207. function lower() {
  1208. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1209. }
  1210. function selection_lower() {
  1211. return this.each(lower);
  1212. }
  1213. function selection_append(name) {
  1214. var create = typeof name === "function" ? name : creator(name);
  1215. return this.select(function() {
  1216. return this.appendChild(create.apply(this, arguments));
  1217. });
  1218. }
  1219. function constantNull() {
  1220. return null;
  1221. }
  1222. function selection_insert(name, before) {
  1223. var create = typeof name === "function" ? name : creator(name),
  1224. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1225. return this.select(function() {
  1226. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1227. });
  1228. }
  1229. function remove() {
  1230. var parent = this.parentNode;
  1231. if (parent) parent.removeChild(this);
  1232. }
  1233. function selection_remove() {
  1234. return this.each(remove);
  1235. }
  1236. function selection_cloneShallow() {
  1237. return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
  1238. }
  1239. function selection_cloneDeep() {
  1240. return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
  1241. }
  1242. function selection_clone(deep) {
  1243. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  1244. }
  1245. function selection_datum(value) {
  1246. return arguments.length
  1247. ? this.property("__data__", value)
  1248. : this.node().__data__;
  1249. }
  1250. var filterEvents = {};
  1251. exports.event = null;
  1252. if (typeof document !== "undefined") {
  1253. var element$1 = document.documentElement;
  1254. if (!("onmouseenter" in element$1)) {
  1255. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  1256. }
  1257. }
  1258. function filterContextListener(listener, index, group) {
  1259. listener = contextListener(listener, index, group);
  1260. return function(event) {
  1261. var related = event.relatedTarget;
  1262. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  1263. listener.call(this, event);
  1264. }
  1265. };
  1266. }
  1267. function contextListener(listener, index, group) {
  1268. return function(event1) {
  1269. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  1270. exports.event = event1;
  1271. try {
  1272. listener.call(this, this.__data__, index, group);
  1273. } finally {
  1274. exports.event = event0;
  1275. }
  1276. };
  1277. }
  1278. function parseTypenames$1(typenames) {
  1279. return typenames.trim().split(/^|\s+/).map(function(t) {
  1280. var name = "", i = t.indexOf(".");
  1281. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1282. return {type: t, name: name};
  1283. });
  1284. }
  1285. function onRemove(typename) {
  1286. return function() {
  1287. var on = this.__on;
  1288. if (!on) return;
  1289. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  1290. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  1291. this.removeEventListener(o.type, o.listener, o.capture);
  1292. } else {
  1293. on[++i] = o;
  1294. }
  1295. }
  1296. if (++i) on.length = i;
  1297. else delete this.__on;
  1298. };
  1299. }
  1300. function onAdd(typename, value, capture) {
  1301. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  1302. return function(d, i, group) {
  1303. var on = this.__on, o, listener = wrap(value, i, group);
  1304. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  1305. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  1306. this.removeEventListener(o.type, o.listener, o.capture);
  1307. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  1308. o.value = value;
  1309. return;
  1310. }
  1311. }
  1312. this.addEventListener(typename.type, listener, capture);
  1313. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  1314. if (!on) this.__on = [o];
  1315. else on.push(o);
  1316. };
  1317. }
  1318. function selection_on(typename, value, capture) {
  1319. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  1320. if (arguments.length < 2) {
  1321. var on = this.node().__on;
  1322. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  1323. for (i = 0, o = on[j]; i < n; ++i) {
  1324. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  1325. return o.value;
  1326. }
  1327. }
  1328. }
  1329. return;
  1330. }
  1331. on = value ? onAdd : onRemove;
  1332. if (capture == null) capture = false;
  1333. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  1334. return this;
  1335. }
  1336. function customEvent(event1, listener, that, args) {
  1337. var event0 = exports.event;
  1338. event1.sourceEvent = exports.event;
  1339. exports.event = event1;
  1340. try {
  1341. return listener.apply(that, args);
  1342. } finally {
  1343. exports.event = event0;
  1344. }
  1345. }
  1346. function dispatchEvent(node, type, params) {
  1347. var window = defaultView(node),
  1348. event = window.CustomEvent;
  1349. if (typeof event === "function") {
  1350. event = new event(type, params);
  1351. } else {
  1352. event = window.document.createEvent("Event");
  1353. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1354. else event.initEvent(type, false, false);
  1355. }
  1356. node.dispatchEvent(event);
  1357. }
  1358. function dispatchConstant(type, params) {
  1359. return function() {
  1360. return dispatchEvent(this, type, params);
  1361. };
  1362. }
  1363. function dispatchFunction(type, params) {
  1364. return function() {
  1365. return dispatchEvent(this, type, params.apply(this, arguments));
  1366. };
  1367. }
  1368. function selection_dispatch(type, params) {
  1369. return this.each((typeof params === "function"
  1370. ? dispatchFunction
  1371. : dispatchConstant)(type, params));
  1372. }
  1373. var root = [null];
  1374. function Selection(groups, parents) {
  1375. this._groups = groups;
  1376. this._parents = parents;
  1377. }
  1378. function selection() {
  1379. return new Selection([[document.documentElement]], root);
  1380. }
  1381. Selection.prototype = selection.prototype = {
  1382. constructor: Selection,
  1383. select: selection_select,
  1384. selectAll: selection_selectAll,
  1385. filter: selection_filter,
  1386. data: selection_data,
  1387. enter: selection_enter,
  1388. exit: selection_exit,
  1389. merge: selection_merge,
  1390. order: selection_order,
  1391. sort: selection_sort,
  1392. call: selection_call,
  1393. nodes: selection_nodes,
  1394. node: selection_node,
  1395. size: selection_size,
  1396. empty: selection_empty,
  1397. each: selection_each,
  1398. attr: selection_attr,
  1399. style: selection_style,
  1400. property: selection_property,
  1401. classed: selection_classed,
  1402. text: selection_text,
  1403. html: selection_html,
  1404. raise: selection_raise,
  1405. lower: selection_lower,
  1406. append: selection_append,
  1407. insert: selection_insert,
  1408. remove: selection_remove,
  1409. clone: selection_clone,
  1410. datum: selection_datum,
  1411. on: selection_on,
  1412. dispatch: selection_dispatch
  1413. };
  1414. function select(selector) {
  1415. return typeof selector === "string"
  1416. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1417. : new Selection([[selector]], root);
  1418. }
  1419. function create(name) {
  1420. return select(creator(name).call(document.documentElement));
  1421. }
  1422. var nextId = 0;
  1423. function local() {
  1424. return new Local;
  1425. }
  1426. function Local() {
  1427. this._ = "@" + (++nextId).toString(36);
  1428. }
  1429. Local.prototype = local.prototype = {
  1430. constructor: Local,
  1431. get: function(node) {
  1432. var id = this._;
  1433. while (!(id in node)) if (!(node = node.parentNode)) return;
  1434. return node[id];
  1435. },
  1436. set: function(node, value) {
  1437. return node[this._] = value;
  1438. },
  1439. remove: function(node) {
  1440. return this._ in node && delete node[this._];
  1441. },
  1442. toString: function() {
  1443. return this._;
  1444. }
  1445. };
  1446. function sourceEvent() {
  1447. var current = exports.event, source;
  1448. while (source = current.sourceEvent) current = source;
  1449. return current;
  1450. }
  1451. function point(node, event) {
  1452. var svg = node.ownerSVGElement || node;
  1453. if (svg.createSVGPoint) {
  1454. var point = svg.createSVGPoint();
  1455. point.x = event.clientX, point.y = event.clientY;
  1456. point = point.matrixTransform(node.getScreenCTM().inverse());
  1457. return [point.x, point.y];
  1458. }
  1459. var rect = node.getBoundingClientRect();
  1460. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  1461. }
  1462. function mouse(node) {
  1463. var event = sourceEvent();
  1464. if (event.changedTouches) event = event.changedTouches[0];
  1465. return point(node, event);
  1466. }
  1467. function selectAll(selector) {
  1468. return typeof selector === "string"
  1469. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1470. : new Selection([selector == null ? [] : selector], root);
  1471. }
  1472. function touch(node, touches, identifier) {
  1473. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1474. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1475. if ((touch = touches[i]).identifier === identifier) {
  1476. return point(node, touch);
  1477. }
  1478. }
  1479. return null;
  1480. }
  1481. function touches(node, touches) {
  1482. if (touches == null) touches = sourceEvent().touches;
  1483. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1484. points[i] = point(node, touches[i]);
  1485. }
  1486. return points;
  1487. }
  1488. function nopropagation() {
  1489. exports.event.stopImmediatePropagation();
  1490. }
  1491. function noevent() {
  1492. exports.event.preventDefault();
  1493. exports.event.stopImmediatePropagation();
  1494. }
  1495. function dragDisable(view) {
  1496. var root = view.document.documentElement,
  1497. selection$$1 = select(view).on("dragstart.drag", noevent, true);
  1498. if ("onselectstart" in root) {
  1499. selection$$1.on("selectstart.drag", noevent, true);
  1500. } else {
  1501. root.__noselect = root.style.MozUserSelect;
  1502. root.style.MozUserSelect = "none";
  1503. }
  1504. }
  1505. function yesdrag(view, noclick) {
  1506. var root = view.document.documentElement,
  1507. selection$$1 = select(view).on("dragstart.drag", null);
  1508. if (noclick) {
  1509. selection$$1.on("click.drag", noevent, true);
  1510. setTimeout(function() { selection$$1.on("click.drag", null); }, 0);
  1511. }
  1512. if ("onselectstart" in root) {
  1513. selection$$1.on("selectstart.drag", null);
  1514. } else {
  1515. root.style.MozUserSelect = root.__noselect;
  1516. delete root.__noselect;
  1517. }
  1518. }
  1519. function constant$2(x) {
  1520. return function() {
  1521. return x;
  1522. };
  1523. }
  1524. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1525. this.target = target;
  1526. this.type = type;
  1527. this.subject = subject;
  1528. this.identifier = id;
  1529. this.active = active;
  1530. this.x = x;
  1531. this.y = y;
  1532. this.dx = dx;
  1533. this.dy = dy;
  1534. this._ = dispatch;
  1535. }
  1536. DragEvent.prototype.on = function() {
  1537. var value = this._.on.apply(this._, arguments);
  1538. return value === this._ ? this : value;
  1539. };
  1540. // Ignore right-click, since that should open the context menu.
  1541. function defaultFilter() {
  1542. return !exports.event.button;
  1543. }
  1544. function defaultContainer() {
  1545. return this.parentNode;
  1546. }
  1547. function defaultSubject(d) {
  1548. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1549. }
  1550. function defaultTouchable() {
  1551. return "ontouchstart" in this;
  1552. }
  1553. function drag() {
  1554. var filter = defaultFilter,
  1555. container = defaultContainer,
  1556. subject = defaultSubject,
  1557. touchable = defaultTouchable,
  1558. gestures = {},
  1559. listeners = dispatch("start", "drag", "end"),
  1560. active = 0,
  1561. mousedownx,
  1562. mousedowny,
  1563. mousemoving,
  1564. touchending,
  1565. clickDistance2 = 0;
  1566. function drag(selection$$1) {
  1567. selection$$1
  1568. .on("mousedown.drag", mousedowned)
  1569. .filter(touchable)
  1570. .on("touchstart.drag", touchstarted)
  1571. .on("touchmove.drag", touchmoved)
  1572. .on("touchend.drag touchcancel.drag", touchended)
  1573. .style("touch-action", "none")
  1574. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1575. }
  1576. function mousedowned() {
  1577. if (touchending || !filter.apply(this, arguments)) return;
  1578. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1579. if (!gesture) return;
  1580. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1581. dragDisable(exports.event.view);
  1582. nopropagation();
  1583. mousemoving = false;
  1584. mousedownx = exports.event.clientX;
  1585. mousedowny = exports.event.clientY;
  1586. gesture("start");
  1587. }
  1588. function mousemoved() {
  1589. noevent();
  1590. if (!mousemoving) {
  1591. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1592. mousemoving = dx * dx + dy * dy > clickDistance2;
  1593. }
  1594. gestures.mouse("drag");
  1595. }
  1596. function mouseupped() {
  1597. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1598. yesdrag(exports.event.view, mousemoving);
  1599. noevent();
  1600. gestures.mouse("end");
  1601. }
  1602. function touchstarted() {
  1603. if (!filter.apply(this, arguments)) return;
  1604. var touches$$1 = exports.event.changedTouches,
  1605. c = container.apply(this, arguments),
  1606. n = touches$$1.length, i, gesture;
  1607. for (i = 0; i < n; ++i) {
  1608. if (gesture = beforestart(touches$$1[i].identifier, c, touch, this, arguments)) {
  1609. nopropagation();
  1610. gesture("start");
  1611. }
  1612. }
  1613. }
  1614. function touchmoved() {
  1615. var touches$$1 = exports.event.changedTouches,
  1616. n = touches$$1.length, i, gesture;
  1617. for (i = 0; i < n; ++i) {
  1618. if (gesture = gestures[touches$$1[i].identifier]) {
  1619. noevent();
  1620. gesture("drag");
  1621. }
  1622. }
  1623. }
  1624. function touchended() {
  1625. var touches$$1 = exports.event.changedTouches,
  1626. n = touches$$1.length, i, gesture;
  1627. if (touchending) clearTimeout(touchending);
  1628. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1629. for (i = 0; i < n; ++i) {
  1630. if (gesture = gestures[touches$$1[i].identifier]) {
  1631. nopropagation();
  1632. gesture("end");
  1633. }
  1634. }
  1635. }
  1636. function beforestart(id, container, point$$1, that, args) {
  1637. var p = point$$1(container, id), s, dx, dy,
  1638. sublisteners = listeners.copy();
  1639. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1640. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1641. dx = s.x - p[0] || 0;
  1642. dy = s.y - p[1] || 0;
  1643. return true;
  1644. })) return;
  1645. return function gesture(type) {
  1646. var p0 = p, n;
  1647. switch (type) {
  1648. case "start": gestures[id] = gesture, n = active++; break;
  1649. case "end": delete gestures[id], --active; // nobreak
  1650. case "drag": p = point$$1(container, id), n = active; break;
  1651. }
  1652. 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]);
  1653. };
  1654. }
  1655. drag.filter = function(_) {
  1656. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1657. };
  1658. drag.container = function(_) {
  1659. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1660. };
  1661. drag.subject = function(_) {
  1662. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1663. };
  1664. drag.touchable = function(_) {
  1665. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
  1666. };
  1667. drag.on = function() {
  1668. var value = listeners.on.apply(listeners, arguments);
  1669. return value === listeners ? drag : value;
  1670. };
  1671. drag.clickDistance = function(_) {
  1672. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1673. };
  1674. return drag;
  1675. }
  1676. function define(constructor, factory, prototype) {
  1677. constructor.prototype = factory.prototype = prototype;
  1678. prototype.constructor = constructor;
  1679. }
  1680. function extend(parent, definition) {
  1681. var prototype = Object.create(parent.prototype);
  1682. for (var key in definition) prototype[key] = definition[key];
  1683. return prototype;
  1684. }
  1685. function Color() {}
  1686. var darker = 0.7;
  1687. var brighter = 1 / darker;
  1688. var reI = "\\s*([+-]?\\d+)\\s*",
  1689. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  1690. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  1691. reHex3 = /^#([0-9a-f]{3})$/,
  1692. reHex6 = /^#([0-9a-f]{6})$/,
  1693. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  1694. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  1695. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  1696. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  1697. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  1698. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1699. var named = {
  1700. aliceblue: 0xf0f8ff,
  1701. antiquewhite: 0xfaebd7,
  1702. aqua: 0x00ffff,
  1703. aquamarine: 0x7fffd4,
  1704. azure: 0xf0ffff,
  1705. beige: 0xf5f5dc,
  1706. bisque: 0xffe4c4,
  1707. black: 0x000000,
  1708. blanchedalmond: 0xffebcd,
  1709. blue: 0x0000ff,
  1710. blueviolet: 0x8a2be2,
  1711. brown: 0xa52a2a,
  1712. burlywood: 0xdeb887,
  1713. cadetblue: 0x5f9ea0,
  1714. chartreuse: 0x7fff00,
  1715. chocolate: 0xd2691e,
  1716. coral: 0xff7f50,
  1717. cornflowerblue: 0x6495ed,
  1718. cornsilk: 0xfff8dc,
  1719. crimson: 0xdc143c,
  1720. cyan: 0x00ffff,
  1721. darkblue: 0x00008b,
  1722. darkcyan: 0x008b8b,
  1723. darkgoldenrod: 0xb8860b,
  1724. darkgray: 0xa9a9a9,
  1725. darkgreen: 0x006400,
  1726. darkgrey: 0xa9a9a9,
  1727. darkkhaki: 0xbdb76b,
  1728. darkmagenta: 0x8b008b,
  1729. darkolivegreen: 0x556b2f,
  1730. darkorange: 0xff8c00,
  1731. darkorchid: 0x9932cc,
  1732. darkred: 0x8b0000,
  1733. darksalmon: 0xe9967a,
  1734. darkseagreen: 0x8fbc8f,
  1735. darkslateblue: 0x483d8b,
  1736. darkslategray: 0x2f4f4f,
  1737. darkslategrey: 0x2f4f4f,
  1738. darkturquoise: 0x00ced1,
  1739. darkviolet: 0x9400d3,
  1740. deeppink: 0xff1493,
  1741. deepskyblue: 0x00bfff,
  1742. dimgray: 0x696969,
  1743. dimgrey: 0x696969,
  1744. dodgerblue: 0x1e90ff,
  1745. firebrick: 0xb22222,
  1746. floralwhite: 0xfffaf0,
  1747. forestgreen: 0x228b22,
  1748. fuchsia: 0xff00ff,
  1749. gainsboro: 0xdcdcdc,
  1750. ghostwhite: 0xf8f8ff,
  1751. gold: 0xffd700,
  1752. goldenrod: 0xdaa520,
  1753. gray: 0x808080,
  1754. green: 0x008000,
  1755. greenyellow: 0xadff2f,
  1756. grey: 0x808080,
  1757. honeydew: 0xf0fff0,
  1758. hotpink: 0xff69b4,
  1759. indianred: 0xcd5c5c,
  1760. indigo: 0x4b0082,
  1761. ivory: 0xfffff0,
  1762. khaki: 0xf0e68c,
  1763. lavender: 0xe6e6fa,
  1764. lavenderblush: 0xfff0f5,
  1765. lawngreen: 0x7cfc00,
  1766. lemonchiffon: 0xfffacd,
  1767. lightblue: 0xadd8e6,
  1768. lightcoral: 0xf08080,
  1769. lightcyan: 0xe0ffff,
  1770. lightgoldenrodyellow: 0xfafad2,
  1771. lightgray: 0xd3d3d3,
  1772. lightgreen: 0x90ee90,
  1773. lightgrey: 0xd3d3d3,
  1774. lightpink: 0xffb6c1,
  1775. lightsalmon: 0xffa07a,
  1776. lightseagreen: 0x20b2aa,
  1777. lightskyblue: 0x87cefa,
  1778. lightslategray: 0x778899,
  1779. lightslategrey: 0x778899,
  1780. lightsteelblue: 0xb0c4de,
  1781. lightyellow: 0xffffe0,
  1782. lime: 0x00ff00,
  1783. limegreen: 0x32cd32,
  1784. linen: 0xfaf0e6,
  1785. magenta: 0xff00ff,
  1786. maroon: 0x800000,
  1787. mediumaquamarine: 0x66cdaa,
  1788. mediumblue: 0x0000cd,
  1789. mediumorchid: 0xba55d3,
  1790. mediumpurple: 0x9370db,
  1791. mediumseagreen: 0x3cb371,
  1792. mediumslateblue: 0x7b68ee,
  1793. mediumspringgreen: 0x00fa9a,
  1794. mediumturquoise: 0x48d1cc,
  1795. mediumvioletred: 0xc71585,
  1796. midnightblue: 0x191970,
  1797. mintcream: 0xf5fffa,
  1798. mistyrose: 0xffe4e1,
  1799. moccasin: 0xffe4b5,
  1800. navajowhite: 0xffdead,
  1801. navy: 0x000080,
  1802. oldlace: 0xfdf5e6,
  1803. olive: 0x808000,
  1804. olivedrab: 0x6b8e23,
  1805. orange: 0xffa500,
  1806. orangered: 0xff4500,
  1807. orchid: 0xda70d6,
  1808. palegoldenrod: 0xeee8aa,
  1809. palegreen: 0x98fb98,
  1810. paleturquoise: 0xafeeee,
  1811. palevioletred: 0xdb7093,
  1812. papayawhip: 0xffefd5,
  1813. peachpuff: 0xffdab9,
  1814. peru: 0xcd853f,
  1815. pink: 0xffc0cb,
  1816. plum: 0xdda0dd,
  1817. powderblue: 0xb0e0e6,
  1818. purple: 0x800080,
  1819. rebeccapurple: 0x663399,
  1820. red: 0xff0000,
  1821. rosybrown: 0xbc8f8f,
  1822. royalblue: 0x4169e1,
  1823. saddlebrown: 0x8b4513,
  1824. salmon: 0xfa8072,
  1825. sandybrown: 0xf4a460,
  1826. seagreen: 0x2e8b57,
  1827. seashell: 0xfff5ee,
  1828. sienna: 0xa0522d,
  1829. silver: 0xc0c0c0,
  1830. skyblue: 0x87ceeb,
  1831. slateblue: 0x6a5acd,
  1832. slategray: 0x708090,
  1833. slategrey: 0x708090,
  1834. snow: 0xfffafa,
  1835. springgreen: 0x00ff7f,
  1836. steelblue: 0x4682b4,
  1837. tan: 0xd2b48c,
  1838. teal: 0x008080,
  1839. thistle: 0xd8bfd8,
  1840. tomato: 0xff6347,
  1841. turquoise: 0x40e0d0,
  1842. violet: 0xee82ee,
  1843. wheat: 0xf5deb3,
  1844. white: 0xffffff,
  1845. whitesmoke: 0xf5f5f5,
  1846. yellow: 0xffff00,
  1847. yellowgreen: 0x9acd32
  1848. };
  1849. define(Color, color, {
  1850. displayable: function() {
  1851. return this.rgb().displayable();
  1852. },
  1853. toString: function() {
  1854. return this.rgb() + "";
  1855. }
  1856. });
  1857. function color(format) {
  1858. var m;
  1859. format = (format + "").trim().toLowerCase();
  1860. 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
  1861. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  1862. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1863. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1864. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1865. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1866. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1867. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1868. : named.hasOwnProperty(format) ? rgbn(named[format])
  1869. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1870. : null;
  1871. }
  1872. function rgbn(n) {
  1873. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1874. }
  1875. function rgba(r, g, b, a) {
  1876. if (a <= 0) r = g = b = NaN;
  1877. return new Rgb(r, g, b, a);
  1878. }
  1879. function rgbConvert(o) {
  1880. if (!(o instanceof Color)) o = color(o);
  1881. if (!o) return new Rgb;
  1882. o = o.rgb();
  1883. return new Rgb(o.r, o.g, o.b, o.opacity);
  1884. }
  1885. function rgb(r, g, b, opacity) {
  1886. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1887. }
  1888. function Rgb(r, g, b, opacity) {
  1889. this.r = +r;
  1890. this.g = +g;
  1891. this.b = +b;
  1892. this.opacity = +opacity;
  1893. }
  1894. define(Rgb, rgb, extend(Color, {
  1895. brighter: function(k) {
  1896. k = k == null ? brighter : Math.pow(brighter, k);
  1897. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1898. },
  1899. darker: function(k) {
  1900. k = k == null ? darker : Math.pow(darker, k);
  1901. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1902. },
  1903. rgb: function() {
  1904. return this;
  1905. },
  1906. displayable: function() {
  1907. return (0 <= this.r && this.r <= 255)
  1908. && (0 <= this.g && this.g <= 255)
  1909. && (0 <= this.b && this.b <= 255)
  1910. && (0 <= this.opacity && this.opacity <= 1);
  1911. },
  1912. toString: function() {
  1913. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1914. return (a === 1 ? "rgb(" : "rgba(")
  1915. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1916. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1917. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1918. + (a === 1 ? ")" : ", " + a + ")");
  1919. }
  1920. }));
  1921. function hsla(h, s, l, a) {
  1922. if (a <= 0) h = s = l = NaN;
  1923. else if (l <= 0 || l >= 1) h = s = NaN;
  1924. else if (s <= 0) h = NaN;
  1925. return new Hsl(h, s, l, a);
  1926. }
  1927. function hslConvert(o) {
  1928. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1929. if (!(o instanceof Color)) o = color(o);
  1930. if (!o) return new Hsl;
  1931. if (o instanceof Hsl) return o;
  1932. o = o.rgb();
  1933. var r = o.r / 255,
  1934. g = o.g / 255,
  1935. b = o.b / 255,
  1936. min = Math.min(r, g, b),
  1937. max = Math.max(r, g, b),
  1938. h = NaN,
  1939. s = max - min,
  1940. l = (max + min) / 2;
  1941. if (s) {
  1942. if (r === max) h = (g - b) / s + (g < b) * 6;
  1943. else if (g === max) h = (b - r) / s + 2;
  1944. else h = (r - g) / s + 4;
  1945. s /= l < 0.5 ? max + min : 2 - max - min;
  1946. h *= 60;
  1947. } else {
  1948. s = l > 0 && l < 1 ? 0 : h;
  1949. }
  1950. return new Hsl(h, s, l, o.opacity);
  1951. }
  1952. function hsl(h, s, l, opacity) {
  1953. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1954. }
  1955. function Hsl(h, s, l, opacity) {
  1956. this.h = +h;
  1957. this.s = +s;
  1958. this.l = +l;
  1959. this.opacity = +opacity;
  1960. }
  1961. define(Hsl, hsl, extend(Color, {
  1962. brighter: function(k) {
  1963. k = k == null ? brighter : Math.pow(brighter, k);
  1964. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1965. },
  1966. darker: function(k) {
  1967. k = k == null ? darker : Math.pow(darker, k);
  1968. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1969. },
  1970. rgb: function() {
  1971. var h = this.h % 360 + (this.h < 0) * 360,
  1972. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1973. l = this.l,
  1974. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1975. m1 = 2 * l - m2;
  1976. return new Rgb(
  1977. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  1978. hsl2rgb(h, m1, m2),
  1979. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  1980. this.opacity
  1981. );
  1982. },
  1983. displayable: function() {
  1984. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  1985. && (0 <= this.l && this.l <= 1)
  1986. && (0 <= this.opacity && this.opacity <= 1);
  1987. }
  1988. }));
  1989. /* From FvD 13.37, CSS Color Module Level 3 */
  1990. function hsl2rgb(h, m1, m2) {
  1991. return (h < 60 ? m1 + (m2 - m1) * h / 60
  1992. : h < 180 ? m2
  1993. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  1994. : m1) * 255;
  1995. }
  1996. var deg2rad = Math.PI / 180;
  1997. var rad2deg = 180 / Math.PI;
  1998. // https://beta.observablehq.com/@mbostock/lab-and-rgb
  1999. var K = 18,
  2000. Xn = 0.96422,
  2001. Yn = 1,
  2002. Zn = 0.82521,
  2003. t0 = 4 / 29,
  2004. t1 = 6 / 29,
  2005. t2 = 3 * t1 * t1,
  2006. t3 = t1 * t1 * t1;
  2007. function labConvert(o) {
  2008. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2009. if (o instanceof Hcl) {
  2010. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2011. var h = o.h * deg2rad;
  2012. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2013. }
  2014. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2015. var r = rgb2lrgb(o.r),
  2016. g = rgb2lrgb(o.g),
  2017. b = rgb2lrgb(o.b),
  2018. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2019. if (r === g && g === b) x = z = y; else {
  2020. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2021. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2022. }
  2023. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2024. }
  2025. function gray(l, opacity) {
  2026. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2027. }
  2028. function lab(l, a, b, opacity) {
  2029. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2030. }
  2031. function Lab(l, a, b, opacity) {
  2032. this.l = +l;
  2033. this.a = +a;
  2034. this.b = +b;
  2035. this.opacity = +opacity;
  2036. }
  2037. define(Lab, lab, extend(Color, {
  2038. brighter: function(k) {
  2039. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2040. },
  2041. darker: function(k) {
  2042. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2043. },
  2044. rgb: function() {
  2045. var y = (this.l + 16) / 116,
  2046. x = isNaN(this.a) ? y : y + this.a / 500,
  2047. z = isNaN(this.b) ? y : y - this.b / 200;
  2048. x = Xn * lab2xyz(x);
  2049. y = Yn * lab2xyz(y);
  2050. z = Zn * lab2xyz(z);
  2051. return new Rgb(
  2052. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2053. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2054. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2055. this.opacity
  2056. );
  2057. }
  2058. }));
  2059. function xyz2lab(t) {
  2060. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2061. }
  2062. function lab2xyz(t) {
  2063. return t > t1 ? t * t * t : t2 * (t - t0);
  2064. }
  2065. function lrgb2rgb(x) {
  2066. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2067. }
  2068. function rgb2lrgb(x) {
  2069. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2070. }
  2071. function hclConvert(o) {
  2072. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2073. if (!(o instanceof Lab)) o = labConvert(o);
  2074. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0, o.l, o.opacity);
  2075. var h = Math.atan2(o.b, o.a) * rad2deg;
  2076. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2077. }
  2078. function lch(l, c, h, opacity) {
  2079. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2080. }
  2081. function hcl(h, c, l, opacity) {
  2082. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2083. }
  2084. function Hcl(h, c, l, opacity) {
  2085. this.h = +h;
  2086. this.c = +c;
  2087. this.l = +l;
  2088. this.opacity = +opacity;
  2089. }
  2090. define(Hcl, hcl, extend(Color, {
  2091. brighter: function(k) {
  2092. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2093. },
  2094. darker: function(k) {
  2095. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2096. },
  2097. rgb: function() {
  2098. return labConvert(this).rgb();
  2099. }
  2100. }));
  2101. var A = -0.14861,
  2102. B = +1.78277,
  2103. C = -0.29227,
  2104. D = -0.90649,
  2105. E = +1.97294,
  2106. ED = E * D,
  2107. EB = E * B,
  2108. BC_DA = B * C - D * A;
  2109. function cubehelixConvert(o) {
  2110. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2111. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2112. var r = o.r / 255,
  2113. g = o.g / 255,
  2114. b = o.b / 255,
  2115. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2116. bl = b - l,
  2117. k = (E * (g - l) - C * bl) / D,
  2118. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2119. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2120. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2121. }
  2122. function cubehelix(h, s, l, opacity) {
  2123. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2124. }
  2125. function Cubehelix(h, s, l, opacity) {
  2126. this.h = +h;
  2127. this.s = +s;
  2128. this.l = +l;
  2129. this.opacity = +opacity;
  2130. }
  2131. define(Cubehelix, cubehelix, extend(Color, {
  2132. brighter: function(k) {
  2133. k = k == null ? brighter : Math.pow(brighter, k);
  2134. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2135. },
  2136. darker: function(k) {
  2137. k = k == null ? darker : Math.pow(darker, k);
  2138. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2139. },
  2140. rgb: function() {
  2141. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2142. l = +this.l,
  2143. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2144. cosh = Math.cos(h),
  2145. sinh = Math.sin(h);
  2146. return new Rgb(
  2147. 255 * (l + a * (A * cosh + B * sinh)),
  2148. 255 * (l + a * (C * cosh + D * sinh)),
  2149. 255 * (l + a * (E * cosh)),
  2150. this.opacity
  2151. );
  2152. }
  2153. }));
  2154. function basis(t1, v0, v1, v2, v3) {
  2155. var t2 = t1 * t1, t3 = t2 * t1;
  2156. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2157. + (4 - 6 * t2 + 3 * t3) * v1
  2158. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2159. + t3 * v3) / 6;
  2160. }
  2161. function basis$1(values) {
  2162. var n = values.length - 1;
  2163. return function(t) {
  2164. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2165. v1 = values[i],
  2166. v2 = values[i + 1],
  2167. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2168. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2169. return basis((t - i / n) * n, v0, v1, v2, v3);
  2170. };
  2171. }
  2172. function basisClosed(values) {
  2173. var n = values.length;
  2174. return function(t) {
  2175. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2176. v0 = values[(i + n - 1) % n],
  2177. v1 = values[i % n],
  2178. v2 = values[(i + 1) % n],
  2179. v3 = values[(i + 2) % n];
  2180. return basis((t - i / n) * n, v0, v1, v2, v3);
  2181. };
  2182. }
  2183. function constant$3(x) {
  2184. return function() {
  2185. return x;
  2186. };
  2187. }
  2188. function linear(a, d) {
  2189. return function(t) {
  2190. return a + t * d;
  2191. };
  2192. }
  2193. function exponential(a, b, y) {
  2194. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2195. return Math.pow(a + t * b, y);
  2196. };
  2197. }
  2198. function hue(a, b) {
  2199. var d = b - a;
  2200. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2201. }
  2202. function gamma(y) {
  2203. return (y = +y) === 1 ? nogamma : function(a, b) {
  2204. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2205. };
  2206. }
  2207. function nogamma(a, b) {
  2208. var d = b - a;
  2209. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2210. }
  2211. var interpolateRgb = (function rgbGamma(y) {
  2212. var color$$1 = gamma(y);
  2213. function rgb$$1(start, end) {
  2214. var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
  2215. g = color$$1(start.g, end.g),
  2216. b = color$$1(start.b, end.b),
  2217. opacity = nogamma(start.opacity, end.opacity);
  2218. return function(t) {
  2219. start.r = r(t);
  2220. start.g = g(t);
  2221. start.b = b(t);
  2222. start.opacity = opacity(t);
  2223. return start + "";
  2224. };
  2225. }
  2226. rgb$$1.gamma = rgbGamma;
  2227. return rgb$$1;
  2228. })(1);
  2229. function rgbSpline(spline) {
  2230. return function(colors) {
  2231. var n = colors.length,
  2232. r = new Array(n),
  2233. g = new Array(n),
  2234. b = new Array(n),
  2235. i, color$$1;
  2236. for (i = 0; i < n; ++i) {
  2237. color$$1 = rgb(colors[i]);
  2238. r[i] = color$$1.r || 0;
  2239. g[i] = color$$1.g || 0;
  2240. b[i] = color$$1.b || 0;
  2241. }
  2242. r = spline(r);
  2243. g = spline(g);
  2244. b = spline(b);
  2245. color$$1.opacity = 1;
  2246. return function(t) {
  2247. color$$1.r = r(t);
  2248. color$$1.g = g(t);
  2249. color$$1.b = b(t);
  2250. return color$$1 + "";
  2251. };
  2252. };
  2253. }
  2254. var rgbBasis = rgbSpline(basis$1);
  2255. var rgbBasisClosed = rgbSpline(basisClosed);
  2256. function array$1(a, b) {
  2257. var nb = b ? b.length : 0,
  2258. na = a ? Math.min(nb, a.length) : 0,
  2259. x = new Array(na),
  2260. c = new Array(nb),
  2261. i;
  2262. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2263. for (; i < nb; ++i) c[i] = b[i];
  2264. return function(t) {
  2265. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2266. return c;
  2267. };
  2268. }
  2269. function date(a, b) {
  2270. var d = new Date;
  2271. return a = +a, b -= a, function(t) {
  2272. return d.setTime(a + b * t), d;
  2273. };
  2274. }
  2275. function reinterpolate(a, b) {
  2276. return a = +a, b -= a, function(t) {
  2277. return a + b * t;
  2278. };
  2279. }
  2280. function object(a, b) {
  2281. var i = {},
  2282. c = {},
  2283. k;
  2284. if (a === null || typeof a !== "object") a = {};
  2285. if (b === null || typeof b !== "object") b = {};
  2286. for (k in b) {
  2287. if (k in a) {
  2288. i[k] = interpolateValue(a[k], b[k]);
  2289. } else {
  2290. c[k] = b[k];
  2291. }
  2292. }
  2293. return function(t) {
  2294. for (k in i) c[k] = i[k](t);
  2295. return c;
  2296. };
  2297. }
  2298. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  2299. reB = new RegExp(reA.source, "g");
  2300. function zero(b) {
  2301. return function() {
  2302. return b;
  2303. };
  2304. }
  2305. function one(b) {
  2306. return function(t) {
  2307. return b(t) + "";
  2308. };
  2309. }
  2310. function interpolateString(a, b) {
  2311. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2312. am, // current match in a
  2313. bm, // current match in b
  2314. bs, // string preceding current number in b, if any
  2315. i = -1, // index in s
  2316. s = [], // string constants and placeholders
  2317. q = []; // number interpolators
  2318. // Coerce inputs to strings.
  2319. a = a + "", b = b + "";
  2320. // Interpolate pairs of numbers in a & b.
  2321. while ((am = reA.exec(a))
  2322. && (bm = reB.exec(b))) {
  2323. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2324. bs = b.slice(bi, bs);
  2325. if (s[i]) s[i] += bs; // coalesce with previous string
  2326. else s[++i] = bs;
  2327. }
  2328. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2329. if (s[i]) s[i] += bm; // coalesce with previous string
  2330. else s[++i] = bm;
  2331. } else { // interpolate non-matching numbers
  2332. s[++i] = null;
  2333. q.push({i: i, x: reinterpolate(am, bm)});
  2334. }
  2335. bi = reB.lastIndex;
  2336. }
  2337. // Add remains of b.
  2338. if (bi < b.length) {
  2339. bs = b.slice(bi);
  2340. if (s[i]) s[i] += bs; // coalesce with previous string
  2341. else s[++i] = bs;
  2342. }
  2343. // Special optimization for only a single match.
  2344. // Otherwise, interpolate each of the numbers and rejoin the string.
  2345. return s.length < 2 ? (q[0]
  2346. ? one(q[0].x)
  2347. : zero(b))
  2348. : (b = q.length, function(t) {
  2349. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2350. return s.join("");
  2351. });
  2352. }
  2353. function interpolateValue(a, b) {
  2354. var t = typeof b, c;
  2355. return b == null || t === "boolean" ? constant$3(b)
  2356. : (t === "number" ? reinterpolate
  2357. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2358. : b instanceof color ? interpolateRgb
  2359. : b instanceof Date ? date
  2360. : Array.isArray(b) ? array$1
  2361. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2362. : reinterpolate)(a, b);
  2363. }
  2364. function interpolateRound(a, b) {
  2365. return a = +a, b -= a, function(t) {
  2366. return Math.round(a + b * t);
  2367. };
  2368. }
  2369. var degrees = 180 / Math.PI;
  2370. var identity$2 = {
  2371. translateX: 0,
  2372. translateY: 0,
  2373. rotate: 0,
  2374. skewX: 0,
  2375. scaleX: 1,
  2376. scaleY: 1
  2377. };
  2378. function decompose(a, b, c, d, e, f) {
  2379. var scaleX, scaleY, skewX;
  2380. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2381. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2382. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2383. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2384. return {
  2385. translateX: e,
  2386. translateY: f,
  2387. rotate: Math.atan2(b, a) * degrees,
  2388. skewX: Math.atan(skewX) * degrees,
  2389. scaleX: scaleX,
  2390. scaleY: scaleY
  2391. };
  2392. }
  2393. var cssNode,
  2394. cssRoot,
  2395. cssView,
  2396. svgNode;
  2397. function parseCss(value) {
  2398. if (value === "none") return identity$2;
  2399. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2400. cssNode.style.transform = value;
  2401. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2402. cssRoot.removeChild(cssNode);
  2403. value = value.slice(7, -1).split(",");
  2404. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2405. }
  2406. function parseSvg(value) {
  2407. if (value == null) return identity$2;
  2408. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2409. svgNode.setAttribute("transform", value);
  2410. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2411. value = value.matrix;
  2412. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2413. }
  2414. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2415. function pop(s) {
  2416. return s.length ? s.pop() + " " : "";
  2417. }
  2418. function translate(xa, ya, xb, yb, s, q) {
  2419. if (xa !== xb || ya !== yb) {
  2420. var i = s.push("translate(", null, pxComma, null, pxParen);
  2421. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2422. } else if (xb || yb) {
  2423. s.push("translate(" + xb + pxComma + yb + pxParen);
  2424. }
  2425. }
  2426. function rotate(a, b, s, q) {
  2427. if (a !== b) {
  2428. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2429. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
  2430. } else if (b) {
  2431. s.push(pop(s) + "rotate(" + b + degParen);
  2432. }
  2433. }
  2434. function skewX(a, b, s, q) {
  2435. if (a !== b) {
  2436. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
  2437. } else if (b) {
  2438. s.push(pop(s) + "skewX(" + b + degParen);
  2439. }
  2440. }
  2441. function scale(xa, ya, xb, yb, s, q) {
  2442. if (xa !== xb || ya !== yb) {
  2443. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2444. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2445. } else if (xb !== 1 || yb !== 1) {
  2446. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2447. }
  2448. }
  2449. return function(a, b) {
  2450. var s = [], // string constants and placeholders
  2451. q = []; // number interpolators
  2452. a = parse(a), b = parse(b);
  2453. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2454. rotate(a.rotate, b.rotate, s, q);
  2455. skewX(a.skewX, b.skewX, s, q);
  2456. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2457. a = b = null; // gc
  2458. return function(t) {
  2459. var i = -1, n = q.length, o;
  2460. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2461. return s.join("");
  2462. };
  2463. };
  2464. }
  2465. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2466. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2467. var rho = Math.SQRT2,
  2468. rho2 = 2,
  2469. rho4 = 4,
  2470. epsilon2 = 1e-12;
  2471. function cosh(x) {
  2472. return ((x = Math.exp(x)) + 1 / x) / 2;
  2473. }
  2474. function sinh(x) {
  2475. return ((x = Math.exp(x)) - 1 / x) / 2;
  2476. }
  2477. function tanh(x) {
  2478. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2479. }
  2480. // p0 = [ux0, uy0, w0]
  2481. // p1 = [ux1, uy1, w1]
  2482. function interpolateZoom(p0, p1) {
  2483. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2484. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2485. dx = ux1 - ux0,
  2486. dy = uy1 - uy0,
  2487. d2 = dx * dx + dy * dy,
  2488. i,
  2489. S;
  2490. // Special case for u0 ≅ u1.
  2491. if (d2 < epsilon2) {
  2492. S = Math.log(w1 / w0) / rho;
  2493. i = function(t) {
  2494. return [
  2495. ux0 + t * dx,
  2496. uy0 + t * dy,
  2497. w0 * Math.exp(rho * t * S)
  2498. ];
  2499. };
  2500. }
  2501. // General case.
  2502. else {
  2503. var d1 = Math.sqrt(d2),
  2504. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2505. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2506. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2507. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2508. S = (r1 - r0) / rho;
  2509. i = function(t) {
  2510. var s = t * S,
  2511. coshr0 = cosh(r0),
  2512. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2513. return [
  2514. ux0 + u * dx,
  2515. uy0 + u * dy,
  2516. w0 * coshr0 / cosh(rho * s + r0)
  2517. ];
  2518. };
  2519. }
  2520. i.duration = S * 1000;
  2521. return i;
  2522. }
  2523. function hsl$1(hue$$1) {
  2524. return function(start, end) {
  2525. var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
  2526. s = nogamma(start.s, end.s),
  2527. l = nogamma(start.l, end.l),
  2528. opacity = nogamma(start.opacity, end.opacity);
  2529. return function(t) {
  2530. start.h = h(t);
  2531. start.s = s(t);
  2532. start.l = l(t);
  2533. start.opacity = opacity(t);
  2534. return start + "";
  2535. };
  2536. }
  2537. }
  2538. var hsl$2 = hsl$1(hue);
  2539. var hslLong = hsl$1(nogamma);
  2540. function lab$1(start, end) {
  2541. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2542. a = nogamma(start.a, end.a),
  2543. b = nogamma(start.b, end.b),
  2544. opacity = nogamma(start.opacity, end.opacity);
  2545. return function(t) {
  2546. start.l = l(t);
  2547. start.a = a(t);
  2548. start.b = b(t);
  2549. start.opacity = opacity(t);
  2550. return start + "";
  2551. };
  2552. }
  2553. function hcl$1(hue$$1) {
  2554. return function(start, end) {
  2555. var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
  2556. c = nogamma(start.c, end.c),
  2557. l = nogamma(start.l, end.l),
  2558. opacity = nogamma(start.opacity, end.opacity);
  2559. return function(t) {
  2560. start.h = h(t);
  2561. start.c = c(t);
  2562. start.l = l(t);
  2563. start.opacity = opacity(t);
  2564. return start + "";
  2565. };
  2566. }
  2567. }
  2568. var hcl$2 = hcl$1(hue);
  2569. var hclLong = hcl$1(nogamma);
  2570. function cubehelix$1(hue$$1) {
  2571. return (function cubehelixGamma(y) {
  2572. y = +y;
  2573. function cubehelix$$1(start, end) {
  2574. var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2575. s = nogamma(start.s, end.s),
  2576. l = nogamma(start.l, end.l),
  2577. opacity = nogamma(start.opacity, end.opacity);
  2578. return function(t) {
  2579. start.h = h(t);
  2580. start.s = s(t);
  2581. start.l = l(Math.pow(t, y));
  2582. start.opacity = opacity(t);
  2583. return start + "";
  2584. };
  2585. }
  2586. cubehelix$$1.gamma = cubehelixGamma;
  2587. return cubehelix$$1;
  2588. })(1);
  2589. }
  2590. var cubehelix$2 = cubehelix$1(hue);
  2591. var cubehelixLong = cubehelix$1(nogamma);
  2592. function quantize(interpolator, n) {
  2593. var samples = new Array(n);
  2594. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2595. return samples;
  2596. }
  2597. var frame = 0, // is an animation frame pending?
  2598. timeout = 0, // is a timeout pending?
  2599. interval = 0, // are any timers active?
  2600. pokeDelay = 1000, // how frequently we check for clock skew
  2601. taskHead,
  2602. taskTail,
  2603. clockLast = 0,
  2604. clockNow = 0,
  2605. clockSkew = 0,
  2606. clock = typeof performance === "object" && performance.now ? performance : Date,
  2607. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2608. function now() {
  2609. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2610. }
  2611. function clearNow() {
  2612. clockNow = 0;
  2613. }
  2614. function Timer() {
  2615. this._call =
  2616. this._time =
  2617. this._next = null;
  2618. }
  2619. Timer.prototype = timer.prototype = {
  2620. constructor: Timer,
  2621. restart: function(callback, delay, time) {
  2622. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2623. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2624. if (!this._next && taskTail !== this) {
  2625. if (taskTail) taskTail._next = this;
  2626. else taskHead = this;
  2627. taskTail = this;
  2628. }
  2629. this._call = callback;
  2630. this._time = time;
  2631. sleep();
  2632. },
  2633. stop: function() {
  2634. if (this._call) {
  2635. this._call = null;
  2636. this._time = Infinity;
  2637. sleep();
  2638. }
  2639. }
  2640. };
  2641. function timer(callback, delay, time) {
  2642. var t = new Timer;
  2643. t.restart(callback, delay, time);
  2644. return t;
  2645. }
  2646. function timerFlush() {
  2647. now(); // Get the current time, if not already set.
  2648. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2649. var t = taskHead, e;
  2650. while (t) {
  2651. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2652. t = t._next;
  2653. }
  2654. --frame;
  2655. }
  2656. function wake() {
  2657. clockNow = (clockLast = clock.now()) + clockSkew;
  2658. frame = timeout = 0;
  2659. try {
  2660. timerFlush();
  2661. } finally {
  2662. frame = 0;
  2663. nap();
  2664. clockNow = 0;
  2665. }
  2666. }
  2667. function poke() {
  2668. var now = clock.now(), delay = now - clockLast;
  2669. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2670. }
  2671. function nap() {
  2672. var t0, t1 = taskHead, t2, time = Infinity;
  2673. while (t1) {
  2674. if (t1._call) {
  2675. if (time > t1._time) time = t1._time;
  2676. t0 = t1, t1 = t1._next;
  2677. } else {
  2678. t2 = t1._next, t1._next = null;
  2679. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2680. }
  2681. }
  2682. taskTail = t0;
  2683. sleep(time);
  2684. }
  2685. function sleep(time) {
  2686. if (frame) return; // Soonest alarm already set, or will be.
  2687. if (timeout) timeout = clearTimeout(timeout);
  2688. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2689. if (delay > 24) {
  2690. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2691. if (interval) interval = clearInterval(interval);
  2692. } else {
  2693. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2694. frame = 1, setFrame(wake);
  2695. }
  2696. }
  2697. function timeout$1(callback, delay, time) {
  2698. var t = new Timer;
  2699. delay = delay == null ? 0 : +delay;
  2700. t.restart(function(elapsed) {
  2701. t.stop();
  2702. callback(elapsed + delay);
  2703. }, delay, time);
  2704. return t;
  2705. }
  2706. function interval$1(callback, delay, time) {
  2707. var t = new Timer, total = delay;
  2708. if (delay == null) return t.restart(callback, delay, time), t;
  2709. delay = +delay, time = time == null ? now() : +time;
  2710. t.restart(function tick(elapsed) {
  2711. elapsed += total;
  2712. t.restart(tick, total += delay, time);
  2713. callback(elapsed);
  2714. }, delay, time);
  2715. return t;
  2716. }
  2717. var emptyOn = dispatch("start", "end", "interrupt");
  2718. var emptyTween = [];
  2719. var CREATED = 0;
  2720. var SCHEDULED = 1;
  2721. var STARTING = 2;
  2722. var STARTED = 3;
  2723. var RUNNING = 4;
  2724. var ENDING = 5;
  2725. var ENDED = 6;
  2726. function schedule(node, name, id, index, group, timing) {
  2727. var schedules = node.__transition;
  2728. if (!schedules) node.__transition = {};
  2729. else if (id in schedules) return;
  2730. create$1(node, id, {
  2731. name: name,
  2732. index: index, // For context during callback.
  2733. group: group, // For context during callback.
  2734. on: emptyOn,
  2735. tween: emptyTween,
  2736. time: timing.time,
  2737. delay: timing.delay,
  2738. duration: timing.duration,
  2739. ease: timing.ease,
  2740. timer: null,
  2741. state: CREATED
  2742. });
  2743. }
  2744. function init(node, id) {
  2745. var schedule = get$1(node, id);
  2746. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  2747. return schedule;
  2748. }
  2749. function set$1(node, id) {
  2750. var schedule = get$1(node, id);
  2751. if (schedule.state > STARTING) throw new Error("too late; already started");
  2752. return schedule;
  2753. }
  2754. function get$1(node, id) {
  2755. var schedule = node.__transition;
  2756. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  2757. return schedule;
  2758. }
  2759. function create$1(node, id, self) {
  2760. var schedules = node.__transition,
  2761. tween;
  2762. // Initialize the self timer when the transition is created.
  2763. // Note the actual delay is not known until the first callback!
  2764. schedules[id] = self;
  2765. self.timer = timer(schedule, 0, self.time);
  2766. function schedule(elapsed) {
  2767. self.state = SCHEDULED;
  2768. self.timer.restart(start, self.delay, self.time);
  2769. // If the elapsed delay is less than our first sleep, start immediately.
  2770. if (self.delay <= elapsed) start(elapsed - self.delay);
  2771. }
  2772. function start(elapsed) {
  2773. var i, j, n, o;
  2774. // If the state is not SCHEDULED, then we previously errored on start.
  2775. if (self.state !== SCHEDULED) return stop();
  2776. for (i in schedules) {
  2777. o = schedules[i];
  2778. if (o.name !== self.name) continue;
  2779. // While this element already has a starting transition during this frame,
  2780. // defer starting an interrupting transition until that transition has a
  2781. // chance to tick (and possibly end); see d3/d3-transition#54!
  2782. if (o.state === STARTED) return timeout$1(start);
  2783. // Interrupt the active transition, if any.
  2784. // Dispatch the interrupt event.
  2785. if (o.state === RUNNING) {
  2786. o.state = ENDED;
  2787. o.timer.stop();
  2788. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2789. delete schedules[i];
  2790. }
  2791. // Cancel any pre-empted transitions. No interrupt event is dispatched
  2792. // because the cancelled transitions never started. Note that this also
  2793. // removes this transition from the pending list!
  2794. else if (+i < id) {
  2795. o.state = ENDED;
  2796. o.timer.stop();
  2797. delete schedules[i];
  2798. }
  2799. }
  2800. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2801. // Note the transition may be canceled after start and before the first tick!
  2802. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2803. // Assuming this is successful, subsequent callbacks go straight to tick.
  2804. timeout$1(function() {
  2805. if (self.state === STARTED) {
  2806. self.state = RUNNING;
  2807. self.timer.restart(tick, self.delay, self.time);
  2808. tick(elapsed);
  2809. }
  2810. });
  2811. // Dispatch the start event.
  2812. // Note this must be done before the tween are initialized.
  2813. self.state = STARTING;
  2814. self.on.call("start", node, node.__data__, self.index, self.group);
  2815. if (self.state !== STARTING) return; // interrupted
  2816. self.state = STARTED;
  2817. // Initialize the tween, deleting null tween.
  2818. tween = new Array(n = self.tween.length);
  2819. for (i = 0, j = -1; i < n; ++i) {
  2820. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2821. tween[++j] = o;
  2822. }
  2823. }
  2824. tween.length = j + 1;
  2825. }
  2826. function tick(elapsed) {
  2827. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2828. i = -1,
  2829. n = tween.length;
  2830. while (++i < n) {
  2831. tween[i].call(null, t);
  2832. }
  2833. // Dispatch the end event.
  2834. if (self.state === ENDING) {
  2835. self.on.call("end", node, node.__data__, self.index, self.group);
  2836. stop();
  2837. }
  2838. }
  2839. function stop() {
  2840. self.state = ENDED;
  2841. self.timer.stop();
  2842. delete schedules[id];
  2843. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2844. delete node.__transition;
  2845. }
  2846. }
  2847. function interrupt(node, name) {
  2848. var schedules = node.__transition,
  2849. schedule$$1,
  2850. active,
  2851. empty = true,
  2852. i;
  2853. if (!schedules) return;
  2854. name = name == null ? null : name + "";
  2855. for (i in schedules) {
  2856. if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
  2857. active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
  2858. schedule$$1.state = ENDED;
  2859. schedule$$1.timer.stop();
  2860. if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
  2861. delete schedules[i];
  2862. }
  2863. if (empty) delete node.__transition;
  2864. }
  2865. function selection_interrupt(name) {
  2866. return this.each(function() {
  2867. interrupt(this, name);
  2868. });
  2869. }
  2870. function tweenRemove(id, name) {
  2871. var tween0, tween1;
  2872. return function() {
  2873. var schedule$$1 = set$1(this, id),
  2874. tween = schedule$$1.tween;
  2875. // If this node shared tween with the previous node,
  2876. // just assign the updated shared tween and we’re done!
  2877. // Otherwise, copy-on-write.
  2878. if (tween !== tween0) {
  2879. tween1 = tween0 = tween;
  2880. for (var i = 0, n = tween1.length; i < n; ++i) {
  2881. if (tween1[i].name === name) {
  2882. tween1 = tween1.slice();
  2883. tween1.splice(i, 1);
  2884. break;
  2885. }
  2886. }
  2887. }
  2888. schedule$$1.tween = tween1;
  2889. };
  2890. }
  2891. function tweenFunction(id, name, value) {
  2892. var tween0, tween1;
  2893. if (typeof value !== "function") throw new Error;
  2894. return function() {
  2895. var schedule$$1 = set$1(this, id),
  2896. tween = schedule$$1.tween;
  2897. // If this node shared tween with the previous node,
  2898. // just assign the updated shared tween and we’re done!
  2899. // Otherwise, copy-on-write.
  2900. if (tween !== tween0) {
  2901. tween1 = (tween0 = tween).slice();
  2902. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2903. if (tween1[i].name === name) {
  2904. tween1[i] = t;
  2905. break;
  2906. }
  2907. }
  2908. if (i === n) tween1.push(t);
  2909. }
  2910. schedule$$1.tween = tween1;
  2911. };
  2912. }
  2913. function transition_tween(name, value) {
  2914. var id = this._id;
  2915. name += "";
  2916. if (arguments.length < 2) {
  2917. var tween = get$1(this.node(), id).tween;
  2918. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2919. if ((t = tween[i]).name === name) {
  2920. return t.value;
  2921. }
  2922. }
  2923. return null;
  2924. }
  2925. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2926. }
  2927. function tweenValue(transition, name, value) {
  2928. var id = transition._id;
  2929. transition.each(function() {
  2930. var schedule$$1 = set$1(this, id);
  2931. (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
  2932. });
  2933. return function(node) {
  2934. return get$1(node, id).value[name];
  2935. };
  2936. }
  2937. function interpolate(a, b) {
  2938. var c;
  2939. return (typeof b === "number" ? reinterpolate
  2940. : b instanceof color ? interpolateRgb
  2941. : (c = color(b)) ? (b = c, interpolateRgb)
  2942. : interpolateString)(a, b);
  2943. }
  2944. function attrRemove$1(name) {
  2945. return function() {
  2946. this.removeAttribute(name);
  2947. };
  2948. }
  2949. function attrRemoveNS$1(fullname) {
  2950. return function() {
  2951. this.removeAttributeNS(fullname.space, fullname.local);
  2952. };
  2953. }
  2954. function attrConstant$1(name, interpolate$$1, value1) {
  2955. var value00,
  2956. interpolate0;
  2957. return function() {
  2958. var value0 = this.getAttribute(name);
  2959. return value0 === value1 ? null
  2960. : value0 === value00 ? interpolate0
  2961. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2962. };
  2963. }
  2964. function attrConstantNS$1(fullname, interpolate$$1, value1) {
  2965. var value00,
  2966. interpolate0;
  2967. return function() {
  2968. var value0 = this.getAttributeNS(fullname.space, fullname.local);
  2969. return value0 === value1 ? null
  2970. : value0 === value00 ? interpolate0
  2971. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2972. };
  2973. }
  2974. function attrFunction$1(name, interpolate$$1, value) {
  2975. var value00,
  2976. value10,
  2977. interpolate0;
  2978. return function() {
  2979. var value0, value1 = value(this);
  2980. if (value1 == null) return void this.removeAttribute(name);
  2981. value0 = this.getAttribute(name);
  2982. return value0 === value1 ? null
  2983. : value0 === value00 && value1 === value10 ? interpolate0
  2984. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  2985. };
  2986. }
  2987. function attrFunctionNS$1(fullname, interpolate$$1, value) {
  2988. var value00,
  2989. value10,
  2990. interpolate0;
  2991. return function() {
  2992. var value0, value1 = value(this);
  2993. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  2994. value0 = this.getAttributeNS(fullname.space, fullname.local);
  2995. return value0 === value1 ? null
  2996. : value0 === value00 && value1 === value10 ? interpolate0
  2997. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  2998. };
  2999. }
  3000. function transition_attr(name, value) {
  3001. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  3002. return this.attrTween(name, typeof value === "function"
  3003. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  3004. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  3005. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
  3006. }
  3007. function attrTweenNS(fullname, value) {
  3008. function tween() {
  3009. var node = this, i = value.apply(node, arguments);
  3010. return i && function(t) {
  3011. node.setAttributeNS(fullname.space, fullname.local, i(t));
  3012. };
  3013. }
  3014. tween._value = value;
  3015. return tween;
  3016. }
  3017. function attrTween(name, value) {
  3018. function tween() {
  3019. var node = this, i = value.apply(node, arguments);
  3020. return i && function(t) {
  3021. node.setAttribute(name, i(t));
  3022. };
  3023. }
  3024. tween._value = value;
  3025. return tween;
  3026. }
  3027. function transition_attrTween(name, value) {
  3028. var key = "attr." + name;
  3029. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3030. if (value == null) return this.tween(key, null);
  3031. if (typeof value !== "function") throw new Error;
  3032. var fullname = namespace(name);
  3033. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3034. }
  3035. function delayFunction(id, value) {
  3036. return function() {
  3037. init(this, id).delay = +value.apply(this, arguments);
  3038. };
  3039. }
  3040. function delayConstant(id, value) {
  3041. return value = +value, function() {
  3042. init(this, id).delay = value;
  3043. };
  3044. }
  3045. function transition_delay(value) {
  3046. var id = this._id;
  3047. return arguments.length
  3048. ? this.each((typeof value === "function"
  3049. ? delayFunction
  3050. : delayConstant)(id, value))
  3051. : get$1(this.node(), id).delay;
  3052. }
  3053. function durationFunction(id, value) {
  3054. return function() {
  3055. set$1(this, id).duration = +value.apply(this, arguments);
  3056. };
  3057. }
  3058. function durationConstant(id, value) {
  3059. return value = +value, function() {
  3060. set$1(this, id).duration = value;
  3061. };
  3062. }
  3063. function transition_duration(value) {
  3064. var id = this._id;
  3065. return arguments.length
  3066. ? this.each((typeof value === "function"
  3067. ? durationFunction
  3068. : durationConstant)(id, value))
  3069. : get$1(this.node(), id).duration;
  3070. }
  3071. function easeConstant(id, value) {
  3072. if (typeof value !== "function") throw new Error;
  3073. return function() {
  3074. set$1(this, id).ease = value;
  3075. };
  3076. }
  3077. function transition_ease(value) {
  3078. var id = this._id;
  3079. return arguments.length
  3080. ? this.each(easeConstant(id, value))
  3081. : get$1(this.node(), id).ease;
  3082. }
  3083. function transition_filter(match) {
  3084. if (typeof match !== "function") match = matcher$1(match);
  3085. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3086. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3087. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3088. subgroup.push(node);
  3089. }
  3090. }
  3091. }
  3092. return new Transition(subgroups, this._parents, this._name, this._id);
  3093. }
  3094. function transition_merge(transition$$1) {
  3095. if (transition$$1._id !== this._id) throw new Error;
  3096. 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) {
  3097. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3098. if (node = group0[i] || group1[i]) {
  3099. merge[i] = node;
  3100. }
  3101. }
  3102. }
  3103. for (; j < m0; ++j) {
  3104. merges[j] = groups0[j];
  3105. }
  3106. return new Transition(merges, this._parents, this._name, this._id);
  3107. }
  3108. function start(name) {
  3109. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3110. var i = t.indexOf(".");
  3111. if (i >= 0) t = t.slice(0, i);
  3112. return !t || t === "start";
  3113. });
  3114. }
  3115. function onFunction(id, name, listener) {
  3116. var on0, on1, sit = start(name) ? init : set$1;
  3117. return function() {
  3118. var schedule$$1 = sit(this, id),
  3119. on = schedule$$1.on;
  3120. // If this node shared a dispatch with the previous node,
  3121. // just assign the updated shared dispatch and we’re done!
  3122. // Otherwise, copy-on-write.
  3123. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3124. schedule$$1.on = on1;
  3125. };
  3126. }
  3127. function transition_on(name, listener) {
  3128. var id = this._id;
  3129. return arguments.length < 2
  3130. ? get$1(this.node(), id).on.on(name)
  3131. : this.each(onFunction(id, name, listener));
  3132. }
  3133. function removeFunction(id) {
  3134. return function() {
  3135. var parent = this.parentNode;
  3136. for (var i in this.__transition) if (+i !== id) return;
  3137. if (parent) parent.removeChild(this);
  3138. };
  3139. }
  3140. function transition_remove() {
  3141. return this.on("end.remove", removeFunction(this._id));
  3142. }
  3143. function transition_select(select$$1) {
  3144. var name = this._name,
  3145. id = this._id;
  3146. if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
  3147. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3148. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3149. if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
  3150. if ("__data__" in node) subnode.__data__ = node.__data__;
  3151. subgroup[i] = subnode;
  3152. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3153. }
  3154. }
  3155. }
  3156. return new Transition(subgroups, this._parents, name, id);
  3157. }
  3158. function transition_selectAll(select$$1) {
  3159. var name = this._name,
  3160. id = this._id;
  3161. if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
  3162. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3163. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3164. if (node = group[i]) {
  3165. 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) {
  3166. if (child = children[k]) {
  3167. schedule(child, name, id, k, children, inherit);
  3168. }
  3169. }
  3170. subgroups.push(children);
  3171. parents.push(node);
  3172. }
  3173. }
  3174. }
  3175. return new Transition(subgroups, parents, name, id);
  3176. }
  3177. var Selection$1 = selection.prototype.constructor;
  3178. function transition_selection() {
  3179. return new Selection$1(this._groups, this._parents);
  3180. }
  3181. function styleRemove$1(name, interpolate$$1) {
  3182. var value00,
  3183. value10,
  3184. interpolate0;
  3185. return function() {
  3186. var value0 = styleValue(this, name),
  3187. value1 = (this.style.removeProperty(name), styleValue(this, name));
  3188. return value0 === value1 ? null
  3189. : value0 === value00 && value1 === value10 ? interpolate0
  3190. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3191. };
  3192. }
  3193. function styleRemoveEnd(name) {
  3194. return function() {
  3195. this.style.removeProperty(name);
  3196. };
  3197. }
  3198. function styleConstant$1(name, interpolate$$1, value1) {
  3199. var value00,
  3200. interpolate0;
  3201. return function() {
  3202. var value0 = styleValue(this, name);
  3203. return value0 === value1 ? null
  3204. : value0 === value00 ? interpolate0
  3205. : interpolate0 = interpolate$$1(value00 = value0, value1);
  3206. };
  3207. }
  3208. function styleFunction$1(name, interpolate$$1, value) {
  3209. var value00,
  3210. value10,
  3211. interpolate0;
  3212. return function() {
  3213. var value0 = styleValue(this, name),
  3214. value1 = value(this);
  3215. if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
  3216. return value0 === value1 ? null
  3217. : value0 === value00 && value1 === value10 ? interpolate0
  3218. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3219. };
  3220. }
  3221. function transition_style(name, value, priority) {
  3222. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3223. return value == null ? this
  3224. .styleTween(name, styleRemove$1(name, i))
  3225. .on("end.style." + name, styleRemoveEnd(name))
  3226. : this.styleTween(name, typeof value === "function"
  3227. ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
  3228. : styleConstant$1(name, i, value + ""), priority);
  3229. }
  3230. function styleTween(name, value, priority) {
  3231. function tween() {
  3232. var node = this, i = value.apply(node, arguments);
  3233. return i && function(t) {
  3234. node.style.setProperty(name, i(t), priority);
  3235. };
  3236. }
  3237. tween._value = value;
  3238. return tween;
  3239. }
  3240. function transition_styleTween(name, value, priority) {
  3241. var key = "style." + (name += "");
  3242. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3243. if (value == null) return this.tween(key, null);
  3244. if (typeof value !== "function") throw new Error;
  3245. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3246. }
  3247. function textConstant$1(value) {
  3248. return function() {
  3249. this.textContent = value;
  3250. };
  3251. }
  3252. function textFunction$1(value) {
  3253. return function() {
  3254. var value1 = value(this);
  3255. this.textContent = value1 == null ? "" : value1;
  3256. };
  3257. }
  3258. function transition_text(value) {
  3259. return this.tween("text", typeof value === "function"
  3260. ? textFunction$1(tweenValue(this, "text", value))
  3261. : textConstant$1(value == null ? "" : value + ""));
  3262. }
  3263. function transition_transition() {
  3264. var name = this._name,
  3265. id0 = this._id,
  3266. id1 = newId();
  3267. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3268. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3269. if (node = group[i]) {
  3270. var inherit = get$1(node, id0);
  3271. schedule(node, name, id1, i, group, {
  3272. time: inherit.time + inherit.delay + inherit.duration,
  3273. delay: 0,
  3274. duration: inherit.duration,
  3275. ease: inherit.ease
  3276. });
  3277. }
  3278. }
  3279. }
  3280. return new Transition(groups, this._parents, name, id1);
  3281. }
  3282. var id = 0;
  3283. function Transition(groups, parents, name, id) {
  3284. this._groups = groups;
  3285. this._parents = parents;
  3286. this._name = name;
  3287. this._id = id;
  3288. }
  3289. function transition(name) {
  3290. return selection().transition(name);
  3291. }
  3292. function newId() {
  3293. return ++id;
  3294. }
  3295. var selection_prototype = selection.prototype;
  3296. Transition.prototype = transition.prototype = {
  3297. constructor: Transition,
  3298. select: transition_select,
  3299. selectAll: transition_selectAll,
  3300. filter: transition_filter,
  3301. merge: transition_merge,
  3302. selection: transition_selection,
  3303. transition: transition_transition,
  3304. call: selection_prototype.call,
  3305. nodes: selection_prototype.nodes,
  3306. node: selection_prototype.node,
  3307. size: selection_prototype.size,
  3308. empty: selection_prototype.empty,
  3309. each: selection_prototype.each,
  3310. on: transition_on,
  3311. attr: transition_attr,
  3312. attrTween: transition_attrTween,
  3313. style: transition_style,
  3314. styleTween: transition_styleTween,
  3315. text: transition_text,
  3316. remove: transition_remove,
  3317. tween: transition_tween,
  3318. delay: transition_delay,
  3319. duration: transition_duration,
  3320. ease: transition_ease
  3321. };
  3322. function linear$1(t) {
  3323. return +t;
  3324. }
  3325. function quadIn(t) {
  3326. return t * t;
  3327. }
  3328. function quadOut(t) {
  3329. return t * (2 - t);
  3330. }
  3331. function quadInOut(t) {
  3332. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3333. }
  3334. function cubicIn(t) {
  3335. return t * t * t;
  3336. }
  3337. function cubicOut(t) {
  3338. return --t * t * t + 1;
  3339. }
  3340. function cubicInOut(t) {
  3341. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3342. }
  3343. var exponent = 3;
  3344. var polyIn = (function custom(e) {
  3345. e = +e;
  3346. function polyIn(t) {
  3347. return Math.pow(t, e);
  3348. }
  3349. polyIn.exponent = custom;
  3350. return polyIn;
  3351. })(exponent);
  3352. var polyOut = (function custom(e) {
  3353. e = +e;
  3354. function polyOut(t) {
  3355. return 1 - Math.pow(1 - t, e);
  3356. }
  3357. polyOut.exponent = custom;
  3358. return polyOut;
  3359. })(exponent);
  3360. var polyInOut = (function custom(e) {
  3361. e = +e;
  3362. function polyInOut(t) {
  3363. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3364. }
  3365. polyInOut.exponent = custom;
  3366. return polyInOut;
  3367. })(exponent);
  3368. var pi = Math.PI,
  3369. halfPi = pi / 2;
  3370. function sinIn(t) {
  3371. return 1 - Math.cos(t * halfPi);
  3372. }
  3373. function sinOut(t) {
  3374. return Math.sin(t * halfPi);
  3375. }
  3376. function sinInOut(t) {
  3377. return (1 - Math.cos(pi * t)) / 2;
  3378. }
  3379. function expIn(t) {
  3380. return Math.pow(2, 10 * t - 10);
  3381. }
  3382. function expOut(t) {
  3383. return 1 - Math.pow(2, -10 * t);
  3384. }
  3385. function expInOut(t) {
  3386. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3387. }
  3388. function circleIn(t) {
  3389. return 1 - Math.sqrt(1 - t * t);
  3390. }
  3391. function circleOut(t) {
  3392. return Math.sqrt(1 - --t * t);
  3393. }
  3394. function circleInOut(t) {
  3395. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3396. }
  3397. var b1 = 4 / 11,
  3398. b2 = 6 / 11,
  3399. b3 = 8 / 11,
  3400. b4 = 3 / 4,
  3401. b5 = 9 / 11,
  3402. b6 = 10 / 11,
  3403. b7 = 15 / 16,
  3404. b8 = 21 / 22,
  3405. b9 = 63 / 64,
  3406. b0 = 1 / b1 / b1;
  3407. function bounceIn(t) {
  3408. return 1 - bounceOut(1 - t);
  3409. }
  3410. function bounceOut(t) {
  3411. 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;
  3412. }
  3413. function bounceInOut(t) {
  3414. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3415. }
  3416. var overshoot = 1.70158;
  3417. var backIn = (function custom(s) {
  3418. s = +s;
  3419. function backIn(t) {
  3420. return t * t * ((s + 1) * t - s);
  3421. }
  3422. backIn.overshoot = custom;
  3423. return backIn;
  3424. })(overshoot);
  3425. var backOut = (function custom(s) {
  3426. s = +s;
  3427. function backOut(t) {
  3428. return --t * t * ((s + 1) * t + s) + 1;
  3429. }
  3430. backOut.overshoot = custom;
  3431. return backOut;
  3432. })(overshoot);
  3433. var backInOut = (function custom(s) {
  3434. s = +s;
  3435. function backInOut(t) {
  3436. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3437. }
  3438. backInOut.overshoot = custom;
  3439. return backInOut;
  3440. })(overshoot);
  3441. var tau = 2 * Math.PI,
  3442. amplitude = 1,
  3443. period = 0.3;
  3444. var elasticIn = (function custom(a, p) {
  3445. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3446. function elasticIn(t) {
  3447. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3448. }
  3449. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3450. elasticIn.period = function(p) { return custom(a, p); };
  3451. return elasticIn;
  3452. })(amplitude, period);
  3453. var elasticOut = (function custom(a, p) {
  3454. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3455. function elasticOut(t) {
  3456. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3457. }
  3458. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3459. elasticOut.period = function(p) { return custom(a, p); };
  3460. return elasticOut;
  3461. })(amplitude, period);
  3462. var elasticInOut = (function custom(a, p) {
  3463. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3464. function elasticInOut(t) {
  3465. return ((t = t * 2 - 1) < 0
  3466. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3467. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3468. }
  3469. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3470. elasticInOut.period = function(p) { return custom(a, p); };
  3471. return elasticInOut;
  3472. })(amplitude, period);
  3473. var defaultTiming = {
  3474. time: null, // Set on use.
  3475. delay: 0,
  3476. duration: 250,
  3477. ease: cubicInOut
  3478. };
  3479. function inherit(node, id) {
  3480. var timing;
  3481. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3482. if (!(node = node.parentNode)) {
  3483. return defaultTiming.time = now(), defaultTiming;
  3484. }
  3485. }
  3486. return timing;
  3487. }
  3488. function selection_transition(name) {
  3489. var id,
  3490. timing;
  3491. if (name instanceof Transition) {
  3492. id = name._id, name = name._name;
  3493. } else {
  3494. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3495. }
  3496. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3497. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3498. if (node = group[i]) {
  3499. schedule(node, name, id, i, group, timing || inherit(node, id));
  3500. }
  3501. }
  3502. }
  3503. return new Transition(groups, this._parents, name, id);
  3504. }
  3505. selection.prototype.interrupt = selection_interrupt;
  3506. selection.prototype.transition = selection_transition;
  3507. var root$1 = [null];
  3508. function active(node, name) {
  3509. var schedules = node.__transition,
  3510. schedule$$1,
  3511. i;
  3512. if (schedules) {
  3513. name = name == null ? null : name + "";
  3514. for (i in schedules) {
  3515. if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
  3516. return new Transition([[node]], root$1, name, +i);
  3517. }
  3518. }
  3519. }
  3520. return null;
  3521. }
  3522. function constant$4(x) {
  3523. return function() {
  3524. return x;
  3525. };
  3526. }
  3527. function BrushEvent(target, type, selection) {
  3528. this.target = target;
  3529. this.type = type;
  3530. this.selection = selection;
  3531. }
  3532. function nopropagation$1() {
  3533. exports.event.stopImmediatePropagation();
  3534. }
  3535. function noevent$1() {
  3536. exports.event.preventDefault();
  3537. exports.event.stopImmediatePropagation();
  3538. }
  3539. var MODE_DRAG = {name: "drag"},
  3540. MODE_SPACE = {name: "space"},
  3541. MODE_HANDLE = {name: "handle"},
  3542. MODE_CENTER = {name: "center"};
  3543. var X = {
  3544. name: "x",
  3545. handles: ["e", "w"].map(type),
  3546. input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
  3547. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3548. };
  3549. var Y = {
  3550. name: "y",
  3551. handles: ["n", "s"].map(type),
  3552. input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
  3553. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3554. };
  3555. var XY = {
  3556. name: "xy",
  3557. handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
  3558. input: function(xy) { return xy; },
  3559. output: function(xy) { return xy; }
  3560. };
  3561. var cursors = {
  3562. overlay: "crosshair",
  3563. selection: "move",
  3564. n: "ns-resize",
  3565. e: "ew-resize",
  3566. s: "ns-resize",
  3567. w: "ew-resize",
  3568. nw: "nwse-resize",
  3569. ne: "nesw-resize",
  3570. se: "nwse-resize",
  3571. sw: "nesw-resize"
  3572. };
  3573. var flipX = {
  3574. e: "w",
  3575. w: "e",
  3576. nw: "ne",
  3577. ne: "nw",
  3578. se: "sw",
  3579. sw: "se"
  3580. };
  3581. var flipY = {
  3582. n: "s",
  3583. s: "n",
  3584. nw: "sw",
  3585. ne: "se",
  3586. se: "ne",
  3587. sw: "nw"
  3588. };
  3589. var signsX = {
  3590. overlay: +1,
  3591. selection: +1,
  3592. n: null,
  3593. e: +1,
  3594. s: null,
  3595. w: -1,
  3596. nw: -1,
  3597. ne: +1,
  3598. se: +1,
  3599. sw: -1
  3600. };
  3601. var signsY = {
  3602. overlay: +1,
  3603. selection: +1,
  3604. n: -1,
  3605. e: null,
  3606. s: +1,
  3607. w: null,
  3608. nw: -1,
  3609. ne: -1,
  3610. se: +1,
  3611. sw: +1
  3612. };
  3613. function type(t) {
  3614. return {type: t};
  3615. }
  3616. // Ignore right-click, since that should open the context menu.
  3617. function defaultFilter$1() {
  3618. return !exports.event.button;
  3619. }
  3620. function defaultExtent() {
  3621. var svg = this.ownerSVGElement || this;
  3622. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3623. }
  3624. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3625. function local$1(node) {
  3626. while (!node.__brush) if (!(node = node.parentNode)) return;
  3627. return node.__brush;
  3628. }
  3629. function empty$1(extent) {
  3630. return extent[0][0] === extent[1][0]
  3631. || extent[0][1] === extent[1][1];
  3632. }
  3633. function brushSelection(node) {
  3634. var state = node.__brush;
  3635. return state ? state.dim.output(state.selection) : null;
  3636. }
  3637. function brushX() {
  3638. return brush$1(X);
  3639. }
  3640. function brushY() {
  3641. return brush$1(Y);
  3642. }
  3643. function brush() {
  3644. return brush$1(XY);
  3645. }
  3646. function brush$1(dim) {
  3647. var extent = defaultExtent,
  3648. filter = defaultFilter$1,
  3649. listeners = dispatch(brush, "start", "brush", "end"),
  3650. handleSize = 6,
  3651. touchending;
  3652. function brush(group) {
  3653. var overlay = group
  3654. .property("__brush", initialize)
  3655. .selectAll(".overlay")
  3656. .data([type("overlay")]);
  3657. overlay.enter().append("rect")
  3658. .attr("class", "overlay")
  3659. .attr("pointer-events", "all")
  3660. .attr("cursor", cursors.overlay)
  3661. .merge(overlay)
  3662. .each(function() {
  3663. var extent = local$1(this).extent;
  3664. select(this)
  3665. .attr("x", extent[0][0])
  3666. .attr("y", extent[0][1])
  3667. .attr("width", extent[1][0] - extent[0][0])
  3668. .attr("height", extent[1][1] - extent[0][1]);
  3669. });
  3670. group.selectAll(".selection")
  3671. .data([type("selection")])
  3672. .enter().append("rect")
  3673. .attr("class", "selection")
  3674. .attr("cursor", cursors.selection)
  3675. .attr("fill", "#777")
  3676. .attr("fill-opacity", 0.3)
  3677. .attr("stroke", "#fff")
  3678. .attr("shape-rendering", "crispEdges");
  3679. var handle = group.selectAll(".handle")
  3680. .data(dim.handles, function(d) { return d.type; });
  3681. handle.exit().remove();
  3682. handle.enter().append("rect")
  3683. .attr("class", function(d) { return "handle handle--" + d.type; })
  3684. .attr("cursor", function(d) { return cursors[d.type]; });
  3685. group
  3686. .each(redraw)
  3687. .attr("fill", "none")
  3688. .attr("pointer-events", "all")
  3689. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  3690. .on("mousedown.brush touchstart.brush", started);
  3691. }
  3692. brush.move = function(group, selection$$1) {
  3693. if (group.selection) {
  3694. group
  3695. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3696. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3697. .tween("brush", function() {
  3698. var that = this,
  3699. state = that.__brush,
  3700. emit = emitter(that, arguments),
  3701. selection0 = state.selection,
  3702. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
  3703. i = interpolateValue(selection0, selection1);
  3704. function tween(t) {
  3705. state.selection = t === 1 && empty$1(selection1) ? null : i(t);
  3706. redraw.call(that);
  3707. emit.brush();
  3708. }
  3709. return selection0 && selection1 ? tween : tween(1);
  3710. });
  3711. } else {
  3712. group
  3713. .each(function() {
  3714. var that = this,
  3715. args = arguments,
  3716. state = that.__brush,
  3717. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
  3718. emit = emitter(that, args).beforestart();
  3719. interrupt(that);
  3720. state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
  3721. redraw.call(that);
  3722. emit.start().brush().end();
  3723. });
  3724. }
  3725. };
  3726. function redraw() {
  3727. var group = select(this),
  3728. selection$$1 = local$1(this).selection;
  3729. if (selection$$1) {
  3730. group.selectAll(".selection")
  3731. .style("display", null)
  3732. .attr("x", selection$$1[0][0])
  3733. .attr("y", selection$$1[0][1])
  3734. .attr("width", selection$$1[1][0] - selection$$1[0][0])
  3735. .attr("height", selection$$1[1][1] - selection$$1[0][1]);
  3736. group.selectAll(".handle")
  3737. .style("display", null)
  3738. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2; })
  3739. .attr("y", function(d) { return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2; })
  3740. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize; })
  3741. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize; });
  3742. }
  3743. else {
  3744. group.selectAll(".selection,.handle")
  3745. .style("display", "none")
  3746. .attr("x", null)
  3747. .attr("y", null)
  3748. .attr("width", null)
  3749. .attr("height", null);
  3750. }
  3751. }
  3752. function emitter(that, args) {
  3753. return that.__brush.emitter || new Emitter(that, args);
  3754. }
  3755. function Emitter(that, args) {
  3756. this.that = that;
  3757. this.args = args;
  3758. this.state = that.__brush;
  3759. this.active = 0;
  3760. }
  3761. Emitter.prototype = {
  3762. beforestart: function() {
  3763. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3764. return this;
  3765. },
  3766. start: function() {
  3767. if (this.starting) this.starting = false, this.emit("start");
  3768. return this;
  3769. },
  3770. brush: function() {
  3771. this.emit("brush");
  3772. return this;
  3773. },
  3774. end: function() {
  3775. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3776. return this;
  3777. },
  3778. emit: function(type) {
  3779. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3780. }
  3781. };
  3782. function started() {
  3783. if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
  3784. else if (touchending) return;
  3785. if (!filter.apply(this, arguments)) return;
  3786. var that = this,
  3787. type = exports.event.target.__data__.type,
  3788. mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3789. signX = dim === Y ? null : signsX[type],
  3790. signY = dim === X ? null : signsY[type],
  3791. state = local$1(that),
  3792. extent = state.extent,
  3793. selection$$1 = state.selection,
  3794. W = extent[0][0], w0, w1,
  3795. N = extent[0][1], n0, n1,
  3796. E = extent[1][0], e0, e1,
  3797. S = extent[1][1], s0, s1,
  3798. dx,
  3799. dy,
  3800. moving,
  3801. shifting = signX && signY && exports.event.shiftKey,
  3802. lockX,
  3803. lockY,
  3804. point0 = mouse(that),
  3805. point$$1 = point0,
  3806. emit = emitter(that, arguments).beforestart();
  3807. if (type === "overlay") {
  3808. state.selection = selection$$1 = [
  3809. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3810. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3811. ];
  3812. } else {
  3813. w0 = selection$$1[0][0];
  3814. n0 = selection$$1[0][1];
  3815. e0 = selection$$1[1][0];
  3816. s0 = selection$$1[1][1];
  3817. }
  3818. w1 = w0;
  3819. n1 = n0;
  3820. e1 = e0;
  3821. s1 = s0;
  3822. var group = select(that)
  3823. .attr("pointer-events", "none");
  3824. var overlay = group.selectAll(".overlay")
  3825. .attr("cursor", cursors[type]);
  3826. if (exports.event.touches) {
  3827. group
  3828. .on("touchmove.brush", moved, true)
  3829. .on("touchend.brush touchcancel.brush", ended, true);
  3830. } else {
  3831. var view = select(exports.event.view)
  3832. .on("keydown.brush", keydowned, true)
  3833. .on("keyup.brush", keyupped, true)
  3834. .on("mousemove.brush", moved, true)
  3835. .on("mouseup.brush", ended, true);
  3836. dragDisable(exports.event.view);
  3837. }
  3838. nopropagation$1();
  3839. interrupt(that);
  3840. redraw.call(that);
  3841. emit.start();
  3842. function moved() {
  3843. var point1 = mouse(that);
  3844. if (shifting && !lockX && !lockY) {
  3845. if (Math.abs(point1[0] - point$$1[0]) > Math.abs(point1[1] - point$$1[1])) lockY = true;
  3846. else lockX = true;
  3847. }
  3848. point$$1 = point1;
  3849. moving = true;
  3850. noevent$1();
  3851. move();
  3852. }
  3853. function move() {
  3854. var t;
  3855. dx = point$$1[0] - point0[0];
  3856. dy = point$$1[1] - point0[1];
  3857. switch (mode) {
  3858. case MODE_SPACE:
  3859. case MODE_DRAG: {
  3860. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  3861. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  3862. break;
  3863. }
  3864. case MODE_HANDLE: {
  3865. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  3866. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  3867. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  3868. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  3869. break;
  3870. }
  3871. case MODE_CENTER: {
  3872. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  3873. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  3874. break;
  3875. }
  3876. }
  3877. if (e1 < w1) {
  3878. signX *= -1;
  3879. t = w0, w0 = e0, e0 = t;
  3880. t = w1, w1 = e1, e1 = t;
  3881. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  3882. }
  3883. if (s1 < n1) {
  3884. signY *= -1;
  3885. t = n0, n0 = s0, s0 = t;
  3886. t = n1, n1 = s1, s1 = t;
  3887. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  3888. }
  3889. if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
  3890. if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
  3891. if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
  3892. if (selection$$1[0][0] !== w1
  3893. || selection$$1[0][1] !== n1
  3894. || selection$$1[1][0] !== e1
  3895. || selection$$1[1][1] !== s1) {
  3896. state.selection = [[w1, n1], [e1, s1]];
  3897. redraw.call(that);
  3898. emit.brush();
  3899. }
  3900. }
  3901. function ended() {
  3902. nopropagation$1();
  3903. if (exports.event.touches) {
  3904. if (exports.event.touches.length) return;
  3905. if (touchending) clearTimeout(touchending);
  3906. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  3907. group.on("touchmove.brush touchend.brush touchcancel.brush", null);
  3908. } else {
  3909. yesdrag(exports.event.view, moving);
  3910. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  3911. }
  3912. group.attr("pointer-events", "all");
  3913. overlay.attr("cursor", cursors.overlay);
  3914. if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
  3915. if (empty$1(selection$$1)) state.selection = null, redraw.call(that);
  3916. emit.end();
  3917. }
  3918. function keydowned() {
  3919. switch (exports.event.keyCode) {
  3920. case 16: { // SHIFT
  3921. shifting = signX && signY;
  3922. break;
  3923. }
  3924. case 18: { // ALT
  3925. if (mode === MODE_HANDLE) {
  3926. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3927. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3928. mode = MODE_CENTER;
  3929. move();
  3930. }
  3931. break;
  3932. }
  3933. case 32: { // SPACE; takes priority over ALT
  3934. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  3935. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  3936. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  3937. mode = MODE_SPACE;
  3938. overlay.attr("cursor", cursors.selection);
  3939. move();
  3940. }
  3941. break;
  3942. }
  3943. default: return;
  3944. }
  3945. noevent$1();
  3946. }
  3947. function keyupped() {
  3948. switch (exports.event.keyCode) {
  3949. case 16: { // SHIFT
  3950. if (shifting) {
  3951. lockX = lockY = shifting = false;
  3952. move();
  3953. }
  3954. break;
  3955. }
  3956. case 18: { // ALT
  3957. if (mode === MODE_CENTER) {
  3958. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3959. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3960. mode = MODE_HANDLE;
  3961. move();
  3962. }
  3963. break;
  3964. }
  3965. case 32: { // SPACE
  3966. if (mode === MODE_SPACE) {
  3967. if (exports.event.altKey) {
  3968. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3969. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3970. mode = MODE_CENTER;
  3971. } else {
  3972. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3973. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3974. mode = MODE_HANDLE;
  3975. }
  3976. overlay.attr("cursor", cursors[type]);
  3977. move();
  3978. }
  3979. break;
  3980. }
  3981. default: return;
  3982. }
  3983. noevent$1();
  3984. }
  3985. }
  3986. function initialize() {
  3987. var state = this.__brush || {selection: null};
  3988. state.extent = extent.apply(this, arguments);
  3989. state.dim = dim;
  3990. return state;
  3991. }
  3992. brush.extent = function(_) {
  3993. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
  3994. };
  3995. brush.filter = function(_) {
  3996. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  3997. };
  3998. brush.handleSize = function(_) {
  3999. return arguments.length ? (handleSize = +_, brush) : handleSize;
  4000. };
  4001. brush.on = function() {
  4002. var value = listeners.on.apply(listeners, arguments);
  4003. return value === listeners ? brush : value;
  4004. };
  4005. return brush;
  4006. }
  4007. var cos = Math.cos;
  4008. var sin = Math.sin;
  4009. var pi$1 = Math.PI;
  4010. var halfPi$1 = pi$1 / 2;
  4011. var tau$1 = pi$1 * 2;
  4012. var max$1 = Math.max;
  4013. function compareValue(compare) {
  4014. return function(a, b) {
  4015. return compare(
  4016. a.source.value + a.target.value,
  4017. b.source.value + b.target.value
  4018. );
  4019. };
  4020. }
  4021. function chord() {
  4022. var padAngle = 0,
  4023. sortGroups = null,
  4024. sortSubgroups = null,
  4025. sortChords = null;
  4026. function chord(matrix) {
  4027. var n = matrix.length,
  4028. groupSums = [],
  4029. groupIndex = sequence(n),
  4030. subgroupIndex = [],
  4031. chords = [],
  4032. groups = chords.groups = new Array(n),
  4033. subgroups = new Array(n * n),
  4034. k,
  4035. x,
  4036. x0,
  4037. dx,
  4038. i,
  4039. j;
  4040. // Compute the sum.
  4041. k = 0, i = -1; while (++i < n) {
  4042. x = 0, j = -1; while (++j < n) {
  4043. x += matrix[i][j];
  4044. }
  4045. groupSums.push(x);
  4046. subgroupIndex.push(sequence(n));
  4047. k += x;
  4048. }
  4049. // Sort groups…
  4050. if (sortGroups) groupIndex.sort(function(a, b) {
  4051. return sortGroups(groupSums[a], groupSums[b]);
  4052. });
  4053. // Sort subgroups…
  4054. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4055. d.sort(function(a, b) {
  4056. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4057. });
  4058. });
  4059. // Convert the sum to scaling factor for [0, 2pi].
  4060. // TODO Allow start and end angle to be specified?
  4061. // TODO Allow padding to be specified as percentage?
  4062. k = max$1(0, tau$1 - padAngle * n) / k;
  4063. dx = k ? padAngle : tau$1 / n;
  4064. // Compute the start and end angle for each group and subgroup.
  4065. // Note: Opera has a bug reordering object literal properties!
  4066. x = 0, i = -1; while (++i < n) {
  4067. x0 = x, j = -1; while (++j < n) {
  4068. var di = groupIndex[i],
  4069. dj = subgroupIndex[di][j],
  4070. v = matrix[di][dj],
  4071. a0 = x,
  4072. a1 = x += v * k;
  4073. subgroups[dj * n + di] = {
  4074. index: di,
  4075. subindex: dj,
  4076. startAngle: a0,
  4077. endAngle: a1,
  4078. value: v
  4079. };
  4080. }
  4081. groups[di] = {
  4082. index: di,
  4083. startAngle: x0,
  4084. endAngle: x,
  4085. value: groupSums[di]
  4086. };
  4087. x += dx;
  4088. }
  4089. // Generate chords for each (non-empty) subgroup-subgroup link.
  4090. i = -1; while (++i < n) {
  4091. j = i - 1; while (++j < n) {
  4092. var source = subgroups[j * n + i],
  4093. target = subgroups[i * n + j];
  4094. if (source.value || target.value) {
  4095. chords.push(source.value < target.value
  4096. ? {source: target, target: source}
  4097. : {source: source, target: target});
  4098. }
  4099. }
  4100. }
  4101. return sortChords ? chords.sort(sortChords) : chords;
  4102. }
  4103. chord.padAngle = function(_) {
  4104. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4105. };
  4106. chord.sortGroups = function(_) {
  4107. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4108. };
  4109. chord.sortSubgroups = function(_) {
  4110. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4111. };
  4112. chord.sortChords = function(_) {
  4113. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4114. };
  4115. return chord;
  4116. }
  4117. var slice$2 = Array.prototype.slice;
  4118. function constant$5(x) {
  4119. return function() {
  4120. return x;
  4121. };
  4122. }
  4123. var pi$2 = Math.PI,
  4124. tau$2 = 2 * pi$2,
  4125. epsilon$1 = 1e-6,
  4126. tauEpsilon = tau$2 - epsilon$1;
  4127. function Path() {
  4128. this._x0 = this._y0 = // start of current subpath
  4129. this._x1 = this._y1 = null; // end of current subpath
  4130. this._ = "";
  4131. }
  4132. function path() {
  4133. return new Path;
  4134. }
  4135. Path.prototype = path.prototype = {
  4136. constructor: Path,
  4137. moveTo: function(x, y) {
  4138. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4139. },
  4140. closePath: function() {
  4141. if (this._x1 !== null) {
  4142. this._x1 = this._x0, this._y1 = this._y0;
  4143. this._ += "Z";
  4144. }
  4145. },
  4146. lineTo: function(x, y) {
  4147. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4148. },
  4149. quadraticCurveTo: function(x1, y1, x, y) {
  4150. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4151. },
  4152. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4153. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4154. },
  4155. arcTo: function(x1, y1, x2, y2, r) {
  4156. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4157. var x0 = this._x1,
  4158. y0 = this._y1,
  4159. x21 = x2 - x1,
  4160. y21 = y2 - y1,
  4161. x01 = x0 - x1,
  4162. y01 = y0 - y1,
  4163. l01_2 = x01 * x01 + y01 * y01;
  4164. // Is the radius negative? Error.
  4165. if (r < 0) throw new Error("negative radius: " + r);
  4166. // Is this path empty? Move to (x1,y1).
  4167. if (this._x1 === null) {
  4168. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4169. }
  4170. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4171. else if (!(l01_2 > epsilon$1)) {}
  4172. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4173. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4174. // Or, is the radius zero? Line to (x1,y1).
  4175. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4176. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4177. }
  4178. // Otherwise, draw an arc!
  4179. else {
  4180. var x20 = x2 - x0,
  4181. y20 = y2 - y0,
  4182. l21_2 = x21 * x21 + y21 * y21,
  4183. l20_2 = x20 * x20 + y20 * y20,
  4184. l21 = Math.sqrt(l21_2),
  4185. l01 = Math.sqrt(l01_2),
  4186. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4187. t01 = l / l01,
  4188. t21 = l / l21;
  4189. // If the start tangent is not coincident with (x0,y0), line to.
  4190. if (Math.abs(t01 - 1) > epsilon$1) {
  4191. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4192. }
  4193. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4194. }
  4195. },
  4196. arc: function(x, y, r, a0, a1, ccw) {
  4197. x = +x, y = +y, r = +r;
  4198. var dx = r * Math.cos(a0),
  4199. dy = r * Math.sin(a0),
  4200. x0 = x + dx,
  4201. y0 = y + dy,
  4202. cw = 1 ^ ccw,
  4203. da = ccw ? a0 - a1 : a1 - a0;
  4204. // Is the radius negative? Error.
  4205. if (r < 0) throw new Error("negative radius: " + r);
  4206. // Is this path empty? Move to (x0,y0).
  4207. if (this._x1 === null) {
  4208. this._ += "M" + x0 + "," + y0;
  4209. }
  4210. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4211. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4212. this._ += "L" + x0 + "," + y0;
  4213. }
  4214. // Is this arc empty? We’re done.
  4215. if (!r) return;
  4216. // Does the angle go the wrong way? Flip the direction.
  4217. if (da < 0) da = da % tau$2 + tau$2;
  4218. // Is this a complete circle? Draw two arcs to complete the circle.
  4219. if (da > tauEpsilon) {
  4220. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4221. }
  4222. // Is this arc non-empty? Draw an arc!
  4223. else if (da > epsilon$1) {
  4224. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4225. }
  4226. },
  4227. rect: function(x, y, w, h) {
  4228. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4229. },
  4230. toString: function() {
  4231. return this._;
  4232. }
  4233. };
  4234. function defaultSource(d) {
  4235. return d.source;
  4236. }
  4237. function defaultTarget(d) {
  4238. return d.target;
  4239. }
  4240. function defaultRadius(d) {
  4241. return d.radius;
  4242. }
  4243. function defaultStartAngle(d) {
  4244. return d.startAngle;
  4245. }
  4246. function defaultEndAngle(d) {
  4247. return d.endAngle;
  4248. }
  4249. function ribbon() {
  4250. var source = defaultSource,
  4251. target = defaultTarget,
  4252. radius = defaultRadius,
  4253. startAngle = defaultStartAngle,
  4254. endAngle = defaultEndAngle,
  4255. context = null;
  4256. function ribbon() {
  4257. var buffer,
  4258. argv = slice$2.call(arguments),
  4259. s = source.apply(this, argv),
  4260. t = target.apply(this, argv),
  4261. sr = +radius.apply(this, (argv[0] = s, argv)),
  4262. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4263. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4264. sx0 = sr * cos(sa0),
  4265. sy0 = sr * sin(sa0),
  4266. tr = +radius.apply(this, (argv[0] = t, argv)),
  4267. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4268. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4269. if (!context) context = buffer = path();
  4270. context.moveTo(sx0, sy0);
  4271. context.arc(0, 0, sr, sa0, sa1);
  4272. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4273. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4274. context.arc(0, 0, tr, ta0, ta1);
  4275. }
  4276. context.quadraticCurveTo(0, 0, sx0, sy0);
  4277. context.closePath();
  4278. if (buffer) return context = null, buffer + "" || null;
  4279. }
  4280. ribbon.radius = function(_) {
  4281. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4282. };
  4283. ribbon.startAngle = function(_) {
  4284. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4285. };
  4286. ribbon.endAngle = function(_) {
  4287. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4288. };
  4289. ribbon.source = function(_) {
  4290. return arguments.length ? (source = _, ribbon) : source;
  4291. };
  4292. ribbon.target = function(_) {
  4293. return arguments.length ? (target = _, ribbon) : target;
  4294. };
  4295. ribbon.context = function(_) {
  4296. return arguments.length ? (context = _ == null ? null : _, ribbon) : context;
  4297. };
  4298. return ribbon;
  4299. }
  4300. var prefix = "$";
  4301. function Map() {}
  4302. Map.prototype = map$1.prototype = {
  4303. constructor: Map,
  4304. has: function(key) {
  4305. return (prefix + key) in this;
  4306. },
  4307. get: function(key) {
  4308. return this[prefix + key];
  4309. },
  4310. set: function(key, value) {
  4311. this[prefix + key] = value;
  4312. return this;
  4313. },
  4314. remove: function(key) {
  4315. var property = prefix + key;
  4316. return property in this && delete this[property];
  4317. },
  4318. clear: function() {
  4319. for (var property in this) if (property[0] === prefix) delete this[property];
  4320. },
  4321. keys: function() {
  4322. var keys = [];
  4323. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4324. return keys;
  4325. },
  4326. values: function() {
  4327. var values = [];
  4328. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4329. return values;
  4330. },
  4331. entries: function() {
  4332. var entries = [];
  4333. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4334. return entries;
  4335. },
  4336. size: function() {
  4337. var size = 0;
  4338. for (var property in this) if (property[0] === prefix) ++size;
  4339. return size;
  4340. },
  4341. empty: function() {
  4342. for (var property in this) if (property[0] === prefix) return false;
  4343. return true;
  4344. },
  4345. each: function(f) {
  4346. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4347. }
  4348. };
  4349. function map$1(object, f) {
  4350. var map = new Map;
  4351. // Copy constructor.
  4352. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4353. // Index array by numeric index or specified key function.
  4354. else if (Array.isArray(object)) {
  4355. var i = -1,
  4356. n = object.length,
  4357. o;
  4358. if (f == null) while (++i < n) map.set(i, object[i]);
  4359. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4360. }
  4361. // Convert object to map.
  4362. else if (object) for (var key in object) map.set(key, object[key]);
  4363. return map;
  4364. }
  4365. function nest() {
  4366. var keys = [],
  4367. sortKeys = [],
  4368. sortValues,
  4369. rollup,
  4370. nest;
  4371. function apply(array, depth, createResult, setResult) {
  4372. if (depth >= keys.length) {
  4373. if (sortValues != null) array.sort(sortValues);
  4374. return rollup != null ? rollup(array) : array;
  4375. }
  4376. var i = -1,
  4377. n = array.length,
  4378. key = keys[depth++],
  4379. keyValue,
  4380. value,
  4381. valuesByKey = map$1(),
  4382. values,
  4383. result = createResult();
  4384. while (++i < n) {
  4385. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4386. values.push(value);
  4387. } else {
  4388. valuesByKey.set(keyValue, [value]);
  4389. }
  4390. }
  4391. valuesByKey.each(function(values, key) {
  4392. setResult(result, key, apply(values, depth, createResult, setResult));
  4393. });
  4394. return result;
  4395. }
  4396. function entries(map, depth) {
  4397. if (++depth > keys.length) return map;
  4398. var array, sortKey = sortKeys[depth - 1];
  4399. if (rollup != null && depth >= keys.length) array = map.entries();
  4400. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4401. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4402. }
  4403. return nest = {
  4404. object: function(array) { return apply(array, 0, createObject, setObject); },
  4405. map: function(array) { return apply(array, 0, createMap, setMap); },
  4406. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4407. key: function(d) { keys.push(d); return nest; },
  4408. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4409. sortValues: function(order) { sortValues = order; return nest; },
  4410. rollup: function(f) { rollup = f; return nest; }
  4411. };
  4412. }
  4413. function createObject() {
  4414. return {};
  4415. }
  4416. function setObject(object, key, value) {
  4417. object[key] = value;
  4418. }
  4419. function createMap() {
  4420. return map$1();
  4421. }
  4422. function setMap(map, key, value) {
  4423. map.set(key, value);
  4424. }
  4425. function Set() {}
  4426. var proto = map$1.prototype;
  4427. Set.prototype = set$2.prototype = {
  4428. constructor: Set,
  4429. has: proto.has,
  4430. add: function(value) {
  4431. value += "";
  4432. this[prefix + value] = value;
  4433. return this;
  4434. },
  4435. remove: proto.remove,
  4436. clear: proto.clear,
  4437. values: proto.keys,
  4438. size: proto.size,
  4439. empty: proto.empty,
  4440. each: proto.each
  4441. };
  4442. function set$2(object, f) {
  4443. var set = new Set;
  4444. // Copy constructor.
  4445. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4446. // Otherwise, assume it’s an array.
  4447. else if (object) {
  4448. var i = -1, n = object.length;
  4449. if (f == null) while (++i < n) set.add(object[i]);
  4450. else while (++i < n) set.add(f(object[i], i, object));
  4451. }
  4452. return set;
  4453. }
  4454. function keys(map) {
  4455. var keys = [];
  4456. for (var key in map) keys.push(key);
  4457. return keys;
  4458. }
  4459. function values(map) {
  4460. var values = [];
  4461. for (var key in map) values.push(map[key]);
  4462. return values;
  4463. }
  4464. function entries(map) {
  4465. var entries = [];
  4466. for (var key in map) entries.push({key: key, value: map[key]});
  4467. return entries;
  4468. }
  4469. var array$2 = Array.prototype;
  4470. var slice$3 = array$2.slice;
  4471. function ascending$2(a, b) {
  4472. return a - b;
  4473. }
  4474. function area(ring) {
  4475. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  4476. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  4477. return area;
  4478. }
  4479. function constant$6(x) {
  4480. return function() {
  4481. return x;
  4482. };
  4483. }
  4484. function contains(ring, hole) {
  4485. var i = -1, n = hole.length, c;
  4486. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  4487. return 0;
  4488. }
  4489. function ringContains(ring, point) {
  4490. var x = point[0], y = point[1], contains = -1;
  4491. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  4492. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  4493. if (segmentContains(pi, pj, point)) return 0;
  4494. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  4495. }
  4496. return contains;
  4497. }
  4498. function segmentContains(a, b, c) {
  4499. var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  4500. }
  4501. function collinear(a, b, c) {
  4502. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  4503. }
  4504. function within(p, q, r) {
  4505. return p <= q && q <= r || r <= q && q <= p;
  4506. }
  4507. function noop$1() {}
  4508. var cases = [
  4509. [],
  4510. [[[1.0, 1.5], [0.5, 1.0]]],
  4511. [[[1.5, 1.0], [1.0, 1.5]]],
  4512. [[[1.5, 1.0], [0.5, 1.0]]],
  4513. [[[1.0, 0.5], [1.5, 1.0]]],
  4514. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  4515. [[[1.0, 0.5], [1.0, 1.5]]],
  4516. [[[1.0, 0.5], [0.5, 1.0]]],
  4517. [[[0.5, 1.0], [1.0, 0.5]]],
  4518. [[[1.0, 1.5], [1.0, 0.5]]],
  4519. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  4520. [[[1.5, 1.0], [1.0, 0.5]]],
  4521. [[[0.5, 1.0], [1.5, 1.0]]],
  4522. [[[1.0, 1.5], [1.5, 1.0]]],
  4523. [[[0.5, 1.0], [1.0, 1.5]]],
  4524. []
  4525. ];
  4526. function contours() {
  4527. var dx = 1,
  4528. dy = 1,
  4529. threshold$$1 = thresholdSturges,
  4530. smooth = smoothLinear;
  4531. function contours(values) {
  4532. var tz = threshold$$1(values);
  4533. // Convert number of thresholds into uniform thresholds.
  4534. if (!Array.isArray(tz)) {
  4535. var domain = extent(values), start = domain[0], stop = domain[1];
  4536. tz = tickStep(start, stop, tz);
  4537. tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
  4538. } else {
  4539. tz = tz.slice().sort(ascending$2);
  4540. }
  4541. return tz.map(function(value) {
  4542. return contour(values, value);
  4543. });
  4544. }
  4545. // Accumulate, smooth contour rings, assign holes to exterior rings.
  4546. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  4547. function contour(values, value) {
  4548. var polygons = [],
  4549. holes = [];
  4550. isorings(values, value, function(ring) {
  4551. smooth(ring, values, value);
  4552. if (area(ring) > 0) polygons.push([ring]);
  4553. else holes.push(ring);
  4554. });
  4555. holes.forEach(function(hole) {
  4556. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  4557. if (contains((polygon = polygons[i])[0], hole) !== -1) {
  4558. polygon.push(hole);
  4559. return;
  4560. }
  4561. }
  4562. });
  4563. return {
  4564. type: "MultiPolygon",
  4565. value: value,
  4566. coordinates: polygons
  4567. };
  4568. }
  4569. // Marching squares with isolines stitched into rings.
  4570. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  4571. function isorings(values, value, callback) {
  4572. var fragmentByStart = new Array,
  4573. fragmentByEnd = new Array,
  4574. x, y, t0, t1, t2, t3;
  4575. // Special case for the first row (y = -1, t2 = t3 = 0).
  4576. x = y = -1;
  4577. t1 = values[0] >= value;
  4578. cases[t1 << 1].forEach(stitch);
  4579. while (++x < dx - 1) {
  4580. t0 = t1, t1 = values[x + 1] >= value;
  4581. cases[t0 | t1 << 1].forEach(stitch);
  4582. }
  4583. cases[t1 << 0].forEach(stitch);
  4584. // General case for the intermediate rows.
  4585. while (++y < dy - 1) {
  4586. x = -1;
  4587. t1 = values[y * dx + dx] >= value;
  4588. t2 = values[y * dx] >= value;
  4589. cases[t1 << 1 | t2 << 2].forEach(stitch);
  4590. while (++x < dx - 1) {
  4591. t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
  4592. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4593. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  4594. }
  4595. cases[t1 | t2 << 3].forEach(stitch);
  4596. }
  4597. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  4598. x = -1;
  4599. t2 = values[y * dx] >= value;
  4600. cases[t2 << 2].forEach(stitch);
  4601. while (++x < dx - 1) {
  4602. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4603. cases[t2 << 2 | t3 << 3].forEach(stitch);
  4604. }
  4605. cases[t2 << 3].forEach(stitch);
  4606. function stitch(line) {
  4607. var start = [line[0][0] + x, line[0][1] + y],
  4608. end = [line[1][0] + x, line[1][1] + y],
  4609. startIndex = index(start),
  4610. endIndex = index(end),
  4611. f, g;
  4612. if (f = fragmentByEnd[startIndex]) {
  4613. if (g = fragmentByStart[endIndex]) {
  4614. delete fragmentByEnd[f.end];
  4615. delete fragmentByStart[g.start];
  4616. if (f === g) {
  4617. f.ring.push(end);
  4618. callback(f.ring);
  4619. } else {
  4620. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  4621. }
  4622. } else {
  4623. delete fragmentByEnd[f.end];
  4624. f.ring.push(end);
  4625. fragmentByEnd[f.end = endIndex] = f;
  4626. }
  4627. } else if (f = fragmentByStart[endIndex]) {
  4628. if (g = fragmentByEnd[startIndex]) {
  4629. delete fragmentByStart[f.start];
  4630. delete fragmentByEnd[g.end];
  4631. if (f === g) {
  4632. f.ring.push(end);
  4633. callback(f.ring);
  4634. } else {
  4635. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  4636. }
  4637. } else {
  4638. delete fragmentByStart[f.start];
  4639. f.ring.unshift(start);
  4640. fragmentByStart[f.start = startIndex] = f;
  4641. }
  4642. } else {
  4643. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  4644. }
  4645. }
  4646. }
  4647. function index(point) {
  4648. return point[0] * 2 + point[1] * (dx + 1) * 4;
  4649. }
  4650. function smoothLinear(ring, values, value) {
  4651. ring.forEach(function(point) {
  4652. var x = point[0],
  4653. y = point[1],
  4654. xt = x | 0,
  4655. yt = y | 0,
  4656. v0,
  4657. v1 = values[yt * dx + xt];
  4658. if (x > 0 && x < dx && xt === x) {
  4659. v0 = values[yt * dx + xt - 1];
  4660. point[0] = x + (value - v0) / (v1 - v0) - 0.5;
  4661. }
  4662. if (y > 0 && y < dy && yt === y) {
  4663. v0 = values[(yt - 1) * dx + xt];
  4664. point[1] = y + (value - v0) / (v1 - v0) - 0.5;
  4665. }
  4666. });
  4667. }
  4668. contours.contour = contour;
  4669. contours.size = function(_) {
  4670. if (!arguments.length) return [dx, dy];
  4671. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4672. if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
  4673. return dx = _0, dy = _1, contours;
  4674. };
  4675. contours.thresholds = function(_) {
  4676. return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold$$1;
  4677. };
  4678. contours.smooth = function(_) {
  4679. return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
  4680. };
  4681. return contours;
  4682. }
  4683. // TODO Optimize edge cases.
  4684. // TODO Optimize index calculation.
  4685. // TODO Optimize arguments.
  4686. function blurX(source, target, r) {
  4687. var n = source.width,
  4688. m = source.height,
  4689. w = (r << 1) + 1;
  4690. for (var j = 0; j < m; ++j) {
  4691. for (var i = 0, sr = 0; i < n + r; ++i) {
  4692. if (i < n) {
  4693. sr += source.data[i + j * n];
  4694. }
  4695. if (i >= r) {
  4696. if (i >= w) {
  4697. sr -= source.data[i - w + j * n];
  4698. }
  4699. target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
  4700. }
  4701. }
  4702. }
  4703. }
  4704. // TODO Optimize edge cases.
  4705. // TODO Optimize index calculation.
  4706. // TODO Optimize arguments.
  4707. function blurY(source, target, r) {
  4708. var n = source.width,
  4709. m = source.height,
  4710. w = (r << 1) + 1;
  4711. for (var i = 0; i < n; ++i) {
  4712. for (var j = 0, sr = 0; j < m + r; ++j) {
  4713. if (j < m) {
  4714. sr += source.data[i + j * n];
  4715. }
  4716. if (j >= r) {
  4717. if (j >= w) {
  4718. sr -= source.data[i + (j - w) * n];
  4719. }
  4720. target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
  4721. }
  4722. }
  4723. }
  4724. }
  4725. function defaultX(d) {
  4726. return d[0];
  4727. }
  4728. function defaultY(d) {
  4729. return d[1];
  4730. }
  4731. function density() {
  4732. var x = defaultX,
  4733. y = defaultY,
  4734. dx = 960,
  4735. dy = 500,
  4736. r = 20, // blur radius
  4737. k = 2, // log2(grid cell size)
  4738. o = r * 3, // grid offset, to pad for blur
  4739. n = (dx + o * 2) >> k, // grid width
  4740. m = (dy + o * 2) >> k, // grid height
  4741. threshold$$1 = constant$6(20);
  4742. function density(data) {
  4743. var values0 = new Float32Array(n * m),
  4744. values1 = new Float32Array(n * m);
  4745. data.forEach(function(d, i, data) {
  4746. var xi = (x(d, i, data) + o) >> k,
  4747. yi = (y(d, i, data) + o) >> k;
  4748. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  4749. ++values0[xi + yi * n];
  4750. }
  4751. });
  4752. // TODO Optimize.
  4753. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4754. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4755. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4756. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4757. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4758. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4759. var tz = threshold$$1(values0);
  4760. // Convert number of thresholds into uniform thresholds.
  4761. if (!Array.isArray(tz)) {
  4762. var stop = max(values0);
  4763. tz = tickStep(0, stop, tz);
  4764. tz = sequence(0, Math.floor(stop / tz) * tz, tz);
  4765. tz.shift();
  4766. }
  4767. return contours()
  4768. .thresholds(tz)
  4769. .size([n, m])
  4770. (values0)
  4771. .map(transform);
  4772. }
  4773. function transform(geometry) {
  4774. geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
  4775. geometry.coordinates.forEach(transformPolygon);
  4776. return geometry;
  4777. }
  4778. function transformPolygon(coordinates) {
  4779. coordinates.forEach(transformRing);
  4780. }
  4781. function transformRing(coordinates) {
  4782. coordinates.forEach(transformPoint);
  4783. }
  4784. // TODO Optimize.
  4785. function transformPoint(coordinates) {
  4786. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  4787. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  4788. }
  4789. function resize() {
  4790. o = r * 3;
  4791. n = (dx + o * 2) >> k;
  4792. m = (dy + o * 2) >> k;
  4793. return density;
  4794. }
  4795. density.x = function(_) {
  4796. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
  4797. };
  4798. density.y = function(_) {
  4799. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
  4800. };
  4801. density.size = function(_) {
  4802. if (!arguments.length) return [dx, dy];
  4803. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4804. if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
  4805. return dx = _0, dy = _1, resize();
  4806. };
  4807. density.cellSize = function(_) {
  4808. if (!arguments.length) return 1 << k;
  4809. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  4810. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  4811. };
  4812. density.thresholds = function(_) {
  4813. return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold$$1;
  4814. };
  4815. density.bandwidth = function(_) {
  4816. if (!arguments.length) return Math.sqrt(r * (r + 1));
  4817. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  4818. return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
  4819. };
  4820. return density;
  4821. }
  4822. var EOL = {},
  4823. EOF = {},
  4824. QUOTE = 34,
  4825. NEWLINE = 10,
  4826. RETURN = 13;
  4827. function objectConverter(columns) {
  4828. return new Function("d", "return {" + columns.map(function(name, i) {
  4829. return JSON.stringify(name) + ": d[" + i + "]";
  4830. }).join(",") + "}");
  4831. }
  4832. function customConverter(columns, f) {
  4833. var object = objectConverter(columns);
  4834. return function(row, i) {
  4835. return f(object(row), i, columns);
  4836. };
  4837. }
  4838. // Compute unique columns in order of discovery.
  4839. function inferColumns(rows) {
  4840. var columnSet = Object.create(null),
  4841. columns = [];
  4842. rows.forEach(function(row) {
  4843. for (var column in row) {
  4844. if (!(column in columnSet)) {
  4845. columns.push(columnSet[column] = column);
  4846. }
  4847. }
  4848. });
  4849. return columns;
  4850. }
  4851. function dsvFormat(delimiter) {
  4852. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  4853. DELIMITER = delimiter.charCodeAt(0);
  4854. function parse(text, f) {
  4855. var convert, columns, rows = parseRows(text, function(row, i) {
  4856. if (convert) return convert(row, i - 1);
  4857. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  4858. });
  4859. rows.columns = columns || [];
  4860. return rows;
  4861. }
  4862. function parseRows(text, f) {
  4863. var rows = [], // output rows
  4864. N = text.length,
  4865. I = 0, // current character index
  4866. n = 0, // current line number
  4867. t, // current token
  4868. eof = N <= 0, // current token followed by EOF?
  4869. eol = false; // current token followed by EOL?
  4870. // Strip the trailing newline.
  4871. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  4872. if (text.charCodeAt(N - 1) === RETURN) --N;
  4873. function token() {
  4874. if (eof) return EOF;
  4875. if (eol) return eol = false, EOL;
  4876. // Unescape quotes.
  4877. var i, j = I, c;
  4878. if (text.charCodeAt(j) === QUOTE) {
  4879. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  4880. if ((i = I) >= N) eof = true;
  4881. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  4882. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4883. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  4884. }
  4885. // Find next delimiter or newline.
  4886. while (I < N) {
  4887. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  4888. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4889. else if (c !== DELIMITER) continue;
  4890. return text.slice(j, i);
  4891. }
  4892. // Return last token before EOF.
  4893. return eof = true, text.slice(j, N);
  4894. }
  4895. while ((t = token()) !== EOF) {
  4896. var row = [];
  4897. while (t !== EOL && t !== EOF) row.push(t), t = token();
  4898. if (f && (row = f(row, n++)) == null) continue;
  4899. rows.push(row);
  4900. }
  4901. return rows;
  4902. }
  4903. function format(rows, columns) {
  4904. if (columns == null) columns = inferColumns(rows);
  4905. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  4906. return columns.map(function(column) {
  4907. return formatValue(row[column]);
  4908. }).join(delimiter);
  4909. })).join("\n");
  4910. }
  4911. function formatRows(rows) {
  4912. return rows.map(formatRow).join("\n");
  4913. }
  4914. function formatRow(row) {
  4915. return row.map(formatValue).join(delimiter);
  4916. }
  4917. function formatValue(text) {
  4918. return text == null ? ""
  4919. : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
  4920. : text;
  4921. }
  4922. return {
  4923. parse: parse,
  4924. parseRows: parseRows,
  4925. format: format,
  4926. formatRows: formatRows
  4927. };
  4928. }
  4929. var csv = dsvFormat(",");
  4930. var csvParse = csv.parse;
  4931. var csvParseRows = csv.parseRows;
  4932. var csvFormat = csv.format;
  4933. var csvFormatRows = csv.formatRows;
  4934. var tsv = dsvFormat("\t");
  4935. var tsvParse = tsv.parse;
  4936. var tsvParseRows = tsv.parseRows;
  4937. var tsvFormat = tsv.format;
  4938. var tsvFormatRows = tsv.formatRows;
  4939. function responseBlob(response) {
  4940. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4941. return response.blob();
  4942. }
  4943. function blob(input, init) {
  4944. return fetch(input, init).then(responseBlob);
  4945. }
  4946. function responseArrayBuffer(response) {
  4947. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4948. return response.arrayBuffer();
  4949. }
  4950. function buffer(input, init) {
  4951. return fetch(input, init).then(responseArrayBuffer);
  4952. }
  4953. function responseText(response) {
  4954. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4955. return response.text();
  4956. }
  4957. function text(input, init) {
  4958. return fetch(input, init).then(responseText);
  4959. }
  4960. function dsvParse(parse) {
  4961. return function(input, init, row) {
  4962. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  4963. return text(input, init).then(function(response) {
  4964. return parse(response, row);
  4965. });
  4966. };
  4967. }
  4968. function dsv(delimiter, input, init, row) {
  4969. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  4970. var format = dsvFormat(delimiter);
  4971. return text(input, init).then(function(response) {
  4972. return format.parse(response, row);
  4973. });
  4974. }
  4975. var csv$1 = dsvParse(csvParse);
  4976. var tsv$1 = dsvParse(tsvParse);
  4977. function image(input, init) {
  4978. return new Promise(function(resolve, reject) {
  4979. var image = new Image;
  4980. for (var key in init) image[key] = init[key];
  4981. image.onerror = reject;
  4982. image.onload = function() { resolve(image); };
  4983. image.src = input;
  4984. });
  4985. }
  4986. function responseJson(response) {
  4987. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  4988. return response.json();
  4989. }
  4990. function json(input, init) {
  4991. return fetch(input, init).then(responseJson);
  4992. }
  4993. function parser(type) {
  4994. return function(input, init) {
  4995. return text(input, init).then(function(text$$1) {
  4996. return (new DOMParser).parseFromString(text$$1, type);
  4997. });
  4998. };
  4999. }
  5000. var xml = parser("application/xml");
  5001. var html = parser("text/html");
  5002. var svg = parser("image/svg+xml");
  5003. function center$1(x, y) {
  5004. var nodes;
  5005. if (x == null) x = 0;
  5006. if (y == null) y = 0;
  5007. function force() {
  5008. var i,
  5009. n = nodes.length,
  5010. node,
  5011. sx = 0,
  5012. sy = 0;
  5013. for (i = 0; i < n; ++i) {
  5014. node = nodes[i], sx += node.x, sy += node.y;
  5015. }
  5016. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  5017. node = nodes[i], node.x -= sx, node.y -= sy;
  5018. }
  5019. }
  5020. force.initialize = function(_) {
  5021. nodes = _;
  5022. };
  5023. force.x = function(_) {
  5024. return arguments.length ? (x = +_, force) : x;
  5025. };
  5026. force.y = function(_) {
  5027. return arguments.length ? (y = +_, force) : y;
  5028. };
  5029. return force;
  5030. }
  5031. function constant$7(x) {
  5032. return function() {
  5033. return x;
  5034. };
  5035. }
  5036. function jiggle() {
  5037. return (Math.random() - 0.5) * 1e-6;
  5038. }
  5039. function tree_add(d) {
  5040. var x = +this._x.call(null, d),
  5041. y = +this._y.call(null, d);
  5042. return add(this.cover(x, y), x, y, d);
  5043. }
  5044. function add(tree, x, y, d) {
  5045. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  5046. var parent,
  5047. node = tree._root,
  5048. leaf = {data: d},
  5049. x0 = tree._x0,
  5050. y0 = tree._y0,
  5051. x1 = tree._x1,
  5052. y1 = tree._y1,
  5053. xm,
  5054. ym,
  5055. xp,
  5056. yp,
  5057. right,
  5058. bottom,
  5059. i,
  5060. j;
  5061. // If the tree is empty, initialize the root as a leaf.
  5062. if (!node) return tree._root = leaf, tree;
  5063. // Find the existing leaf for the new point, or add it.
  5064. while (node.length) {
  5065. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5066. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5067. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  5068. }
  5069. // Is the new point is exactly coincident with the existing point?
  5070. xp = +tree._x.call(null, node.data);
  5071. yp = +tree._y.call(null, node.data);
  5072. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  5073. // Otherwise, split the leaf node until the old and new point are separated.
  5074. do {
  5075. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  5076. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5077. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5078. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  5079. return parent[j] = node, parent[i] = leaf, tree;
  5080. }
  5081. function addAll(data) {
  5082. var d, i, n = data.length,
  5083. x,
  5084. y,
  5085. xz = new Array(n),
  5086. yz = new Array(n),
  5087. x0 = Infinity,
  5088. y0 = Infinity,
  5089. x1 = -Infinity,
  5090. y1 = -Infinity;
  5091. // Compute the points and their extent.
  5092. for (i = 0; i < n; ++i) {
  5093. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  5094. xz[i] = x;
  5095. yz[i] = y;
  5096. if (x < x0) x0 = x;
  5097. if (x > x1) x1 = x;
  5098. if (y < y0) y0 = y;
  5099. if (y > y1) y1 = y;
  5100. }
  5101. // If there were no (valid) points, inherit the existing extent.
  5102. if (x1 < x0) x0 = this._x0, x1 = this._x1;
  5103. if (y1 < y0) y0 = this._y0, y1 = this._y1;
  5104. // Expand the tree to cover the new points.
  5105. this.cover(x0, y0).cover(x1, y1);
  5106. // Add the new points.
  5107. for (i = 0; i < n; ++i) {
  5108. add(this, xz[i], yz[i], data[i]);
  5109. }
  5110. return this;
  5111. }
  5112. function tree_cover(x, y) {
  5113. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  5114. var x0 = this._x0,
  5115. y0 = this._y0,
  5116. x1 = this._x1,
  5117. y1 = this._y1;
  5118. // If the quadtree has no extent, initialize them.
  5119. // Integer extent are necessary so that if we later double the extent,
  5120. // the existing quadrant boundaries don’t change due to floating point error!
  5121. if (isNaN(x0)) {
  5122. x1 = (x0 = Math.floor(x)) + 1;
  5123. y1 = (y0 = Math.floor(y)) + 1;
  5124. }
  5125. // Otherwise, double repeatedly to cover.
  5126. else if (x0 > x || x > x1 || y0 > y || y > y1) {
  5127. var z = x1 - x0,
  5128. node = this._root,
  5129. parent,
  5130. i;
  5131. switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
  5132. case 0: {
  5133. do parent = new Array(4), parent[i] = node, node = parent;
  5134. while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
  5135. break;
  5136. }
  5137. case 1: {
  5138. do parent = new Array(4), parent[i] = node, node = parent;
  5139. while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
  5140. break;
  5141. }
  5142. case 2: {
  5143. do parent = new Array(4), parent[i] = node, node = parent;
  5144. while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
  5145. break;
  5146. }
  5147. case 3: {
  5148. do parent = new Array(4), parent[i] = node, node = parent;
  5149. while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
  5150. break;
  5151. }
  5152. }
  5153. if (this._root && this._root.length) this._root = node;
  5154. }
  5155. // If the quadtree covers the point already, just return.
  5156. else return this;
  5157. this._x0 = x0;
  5158. this._y0 = y0;
  5159. this._x1 = x1;
  5160. this._y1 = y1;
  5161. return this;
  5162. }
  5163. function tree_data() {
  5164. var data = [];
  5165. this.visit(function(node) {
  5166. if (!node.length) do data.push(node.data); while (node = node.next)
  5167. });
  5168. return data;
  5169. }
  5170. function tree_extent(_) {
  5171. return arguments.length
  5172. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  5173. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  5174. }
  5175. function Quad(node, x0, y0, x1, y1) {
  5176. this.node = node;
  5177. this.x0 = x0;
  5178. this.y0 = y0;
  5179. this.x1 = x1;
  5180. this.y1 = y1;
  5181. }
  5182. function tree_find(x, y, radius) {
  5183. var data,
  5184. x0 = this._x0,
  5185. y0 = this._y0,
  5186. x1,
  5187. y1,
  5188. x2,
  5189. y2,
  5190. x3 = this._x1,
  5191. y3 = this._y1,
  5192. quads = [],
  5193. node = this._root,
  5194. q,
  5195. i;
  5196. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  5197. if (radius == null) radius = Infinity;
  5198. else {
  5199. x0 = x - radius, y0 = y - radius;
  5200. x3 = x + radius, y3 = y + radius;
  5201. radius *= radius;
  5202. }
  5203. while (q = quads.pop()) {
  5204. // Stop searching if this quadrant can’t contain a closer node.
  5205. if (!(node = q.node)
  5206. || (x1 = q.x0) > x3
  5207. || (y1 = q.y0) > y3
  5208. || (x2 = q.x1) < x0
  5209. || (y2 = q.y1) < y0) continue;
  5210. // Bisect the current quadrant.
  5211. if (node.length) {
  5212. var xm = (x1 + x2) / 2,
  5213. ym = (y1 + y2) / 2;
  5214. quads.push(
  5215. new Quad(node[3], xm, ym, x2, y2),
  5216. new Quad(node[2], x1, ym, xm, y2),
  5217. new Quad(node[1], xm, y1, x2, ym),
  5218. new Quad(node[0], x1, y1, xm, ym)
  5219. );
  5220. // Visit the closest quadrant first.
  5221. if (i = (y >= ym) << 1 | (x >= xm)) {
  5222. q = quads[quads.length - 1];
  5223. quads[quads.length - 1] = quads[quads.length - 1 - i];
  5224. quads[quads.length - 1 - i] = q;
  5225. }
  5226. }
  5227. // Visit this point. (Visiting coincident points isn’t necessary!)
  5228. else {
  5229. var dx = x - +this._x.call(null, node.data),
  5230. dy = y - +this._y.call(null, node.data),
  5231. d2 = dx * dx + dy * dy;
  5232. if (d2 < radius) {
  5233. var d = Math.sqrt(radius = d2);
  5234. x0 = x - d, y0 = y - d;
  5235. x3 = x + d, y3 = y + d;
  5236. data = node.data;
  5237. }
  5238. }
  5239. }
  5240. return data;
  5241. }
  5242. function tree_remove(d) {
  5243. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  5244. var parent,
  5245. node = this._root,
  5246. retainer,
  5247. previous,
  5248. next,
  5249. x0 = this._x0,
  5250. y0 = this._y0,
  5251. x1 = this._x1,
  5252. y1 = this._y1,
  5253. x,
  5254. y,
  5255. xm,
  5256. ym,
  5257. right,
  5258. bottom,
  5259. i,
  5260. j;
  5261. // If the tree is empty, initialize the root as a leaf.
  5262. if (!node) return this;
  5263. // Find the leaf node for the point.
  5264. // While descending, also retain the deepest parent with a non-removed sibling.
  5265. if (node.length) while (true) {
  5266. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5267. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5268. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  5269. if (!node.length) break;
  5270. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  5271. }
  5272. // Find the point to remove.
  5273. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  5274. if (next = node.next) delete node.next;
  5275. // If there are multiple coincident points, remove just the point.
  5276. if (previous) return next ? previous.next = next : delete previous.next, this;
  5277. // If this is the root point, remove it.
  5278. if (!parent) return this._root = next, this;
  5279. // Remove this leaf.
  5280. next ? parent[i] = next : delete parent[i];
  5281. // If the parent now contains exactly one leaf, collapse superfluous parents.
  5282. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  5283. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  5284. && !node.length) {
  5285. if (retainer) retainer[j] = node;
  5286. else this._root = node;
  5287. }
  5288. return this;
  5289. }
  5290. function removeAll(data) {
  5291. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  5292. return this;
  5293. }
  5294. function tree_root() {
  5295. return this._root;
  5296. }
  5297. function tree_size() {
  5298. var size = 0;
  5299. this.visit(function(node) {
  5300. if (!node.length) do ++size; while (node = node.next)
  5301. });
  5302. return size;
  5303. }
  5304. function tree_visit(callback) {
  5305. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  5306. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  5307. while (q = quads.pop()) {
  5308. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  5309. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5310. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5311. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5312. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5313. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5314. }
  5315. }
  5316. return this;
  5317. }
  5318. function tree_visitAfter(callback) {
  5319. var quads = [], next = [], q;
  5320. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  5321. while (q = quads.pop()) {
  5322. var node = q.node;
  5323. if (node.length) {
  5324. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5325. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5326. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5327. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5328. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5329. }
  5330. next.push(q);
  5331. }
  5332. while (q = next.pop()) {
  5333. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  5334. }
  5335. return this;
  5336. }
  5337. function defaultX$1(d) {
  5338. return d[0];
  5339. }
  5340. function tree_x(_) {
  5341. return arguments.length ? (this._x = _, this) : this._x;
  5342. }
  5343. function defaultY$1(d) {
  5344. return d[1];
  5345. }
  5346. function tree_y(_) {
  5347. return arguments.length ? (this._y = _, this) : this._y;
  5348. }
  5349. function quadtree(nodes, x, y) {
  5350. var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
  5351. return nodes == null ? tree : tree.addAll(nodes);
  5352. }
  5353. function Quadtree(x, y, x0, y0, x1, y1) {
  5354. this._x = x;
  5355. this._y = y;
  5356. this._x0 = x0;
  5357. this._y0 = y0;
  5358. this._x1 = x1;
  5359. this._y1 = y1;
  5360. this._root = undefined;
  5361. }
  5362. function leaf_copy(leaf) {
  5363. var copy = {data: leaf.data}, next = copy;
  5364. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  5365. return copy;
  5366. }
  5367. var treeProto = quadtree.prototype = Quadtree.prototype;
  5368. treeProto.copy = function() {
  5369. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  5370. node = this._root,
  5371. nodes,
  5372. child;
  5373. if (!node) return copy;
  5374. if (!node.length) return copy._root = leaf_copy(node), copy;
  5375. nodes = [{source: node, target: copy._root = new Array(4)}];
  5376. while (node = nodes.pop()) {
  5377. for (var i = 0; i < 4; ++i) {
  5378. if (child = node.source[i]) {
  5379. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  5380. else node.target[i] = leaf_copy(child);
  5381. }
  5382. }
  5383. }
  5384. return copy;
  5385. };
  5386. treeProto.add = tree_add;
  5387. treeProto.addAll = addAll;
  5388. treeProto.cover = tree_cover;
  5389. treeProto.data = tree_data;
  5390. treeProto.extent = tree_extent;
  5391. treeProto.find = tree_find;
  5392. treeProto.remove = tree_remove;
  5393. treeProto.removeAll = removeAll;
  5394. treeProto.root = tree_root;
  5395. treeProto.size = tree_size;
  5396. treeProto.visit = tree_visit;
  5397. treeProto.visitAfter = tree_visitAfter;
  5398. treeProto.x = tree_x;
  5399. treeProto.y = tree_y;
  5400. function x(d) {
  5401. return d.x + d.vx;
  5402. }
  5403. function y(d) {
  5404. return d.y + d.vy;
  5405. }
  5406. function collide(radius) {
  5407. var nodes,
  5408. radii,
  5409. strength = 1,
  5410. iterations = 1;
  5411. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  5412. function force() {
  5413. var i, n = nodes.length,
  5414. tree,
  5415. node,
  5416. xi,
  5417. yi,
  5418. ri,
  5419. ri2;
  5420. for (var k = 0; k < iterations; ++k) {
  5421. tree = quadtree(nodes, x, y).visitAfter(prepare);
  5422. for (i = 0; i < n; ++i) {
  5423. node = nodes[i];
  5424. ri = radii[node.index], ri2 = ri * ri;
  5425. xi = node.x + node.vx;
  5426. yi = node.y + node.vy;
  5427. tree.visit(apply);
  5428. }
  5429. }
  5430. function apply(quad, x0, y0, x1, y1) {
  5431. var data = quad.data, rj = quad.r, r = ri + rj;
  5432. if (data) {
  5433. if (data.index > node.index) {
  5434. var x = xi - data.x - data.vx,
  5435. y = yi - data.y - data.vy,
  5436. l = x * x + y * y;
  5437. if (l < r * r) {
  5438. if (x === 0) x = jiggle(), l += x * x;
  5439. if (y === 0) y = jiggle(), l += y * y;
  5440. l = (r - (l = Math.sqrt(l))) / l * strength;
  5441. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5442. node.vy += (y *= l) * r;
  5443. data.vx -= x * (r = 1 - r);
  5444. data.vy -= y * r;
  5445. }
  5446. }
  5447. return;
  5448. }
  5449. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5450. }
  5451. }
  5452. function prepare(quad) {
  5453. if (quad.data) return quad.r = radii[quad.data.index];
  5454. for (var i = quad.r = 0; i < 4; ++i) {
  5455. if (quad[i] && quad[i].r > quad.r) {
  5456. quad.r = quad[i].r;
  5457. }
  5458. }
  5459. }
  5460. function initialize() {
  5461. if (!nodes) return;
  5462. var i, n = nodes.length, node;
  5463. radii = new Array(n);
  5464. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5465. }
  5466. force.initialize = function(_) {
  5467. nodes = _;
  5468. initialize();
  5469. };
  5470. force.iterations = function(_) {
  5471. return arguments.length ? (iterations = +_, force) : iterations;
  5472. };
  5473. force.strength = function(_) {
  5474. return arguments.length ? (strength = +_, force) : strength;
  5475. };
  5476. force.radius = function(_) {
  5477. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5478. };
  5479. return force;
  5480. }
  5481. function index(d) {
  5482. return d.index;
  5483. }
  5484. function find(nodeById, nodeId) {
  5485. var node = nodeById.get(nodeId);
  5486. if (!node) throw new Error("missing: " + nodeId);
  5487. return node;
  5488. }
  5489. function link(links) {
  5490. var id = index,
  5491. strength = defaultStrength,
  5492. strengths,
  5493. distance = constant$7(30),
  5494. distances,
  5495. nodes,
  5496. count,
  5497. bias,
  5498. iterations = 1;
  5499. if (links == null) links = [];
  5500. function defaultStrength(link) {
  5501. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5502. }
  5503. function force(alpha) {
  5504. for (var k = 0, n = links.length; k < iterations; ++k) {
  5505. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5506. link = links[i], source = link.source, target = link.target;
  5507. x = target.x + target.vx - source.x - source.vx || jiggle();
  5508. y = target.y + target.vy - source.y - source.vy || jiggle();
  5509. l = Math.sqrt(x * x + y * y);
  5510. l = (l - distances[i]) / l * alpha * strengths[i];
  5511. x *= l, y *= l;
  5512. target.vx -= x * (b = bias[i]);
  5513. target.vy -= y * b;
  5514. source.vx += x * (b = 1 - b);
  5515. source.vy += y * b;
  5516. }
  5517. }
  5518. }
  5519. function initialize() {
  5520. if (!nodes) return;
  5521. var i,
  5522. n = nodes.length,
  5523. m = links.length,
  5524. nodeById = map$1(nodes, id),
  5525. link;
  5526. for (i = 0, count = new Array(n); i < m; ++i) {
  5527. link = links[i], link.index = i;
  5528. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5529. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5530. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5531. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5532. }
  5533. for (i = 0, bias = new Array(m); i < m; ++i) {
  5534. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5535. }
  5536. strengths = new Array(m), initializeStrength();
  5537. distances = new Array(m), initializeDistance();
  5538. }
  5539. function initializeStrength() {
  5540. if (!nodes) return;
  5541. for (var i = 0, n = links.length; i < n; ++i) {
  5542. strengths[i] = +strength(links[i], i, links);
  5543. }
  5544. }
  5545. function initializeDistance() {
  5546. if (!nodes) return;
  5547. for (var i = 0, n = links.length; i < n; ++i) {
  5548. distances[i] = +distance(links[i], i, links);
  5549. }
  5550. }
  5551. force.initialize = function(_) {
  5552. nodes = _;
  5553. initialize();
  5554. };
  5555. force.links = function(_) {
  5556. return arguments.length ? (links = _, initialize(), force) : links;
  5557. };
  5558. force.id = function(_) {
  5559. return arguments.length ? (id = _, force) : id;
  5560. };
  5561. force.iterations = function(_) {
  5562. return arguments.length ? (iterations = +_, force) : iterations;
  5563. };
  5564. force.strength = function(_) {
  5565. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  5566. };
  5567. force.distance = function(_) {
  5568. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  5569. };
  5570. return force;
  5571. }
  5572. function x$1(d) {
  5573. return d.x;
  5574. }
  5575. function y$1(d) {
  5576. return d.y;
  5577. }
  5578. var initialRadius = 10,
  5579. initialAngle = Math.PI * (3 - Math.sqrt(5));
  5580. function simulation(nodes) {
  5581. var simulation,
  5582. alpha = 1,
  5583. alphaMin = 0.001,
  5584. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5585. alphaTarget = 0,
  5586. velocityDecay = 0.6,
  5587. forces = map$1(),
  5588. stepper = timer(step),
  5589. event = dispatch("tick", "end");
  5590. if (nodes == null) nodes = [];
  5591. function step() {
  5592. tick();
  5593. event.call("tick", simulation);
  5594. if (alpha < alphaMin) {
  5595. stepper.stop();
  5596. event.call("end", simulation);
  5597. }
  5598. }
  5599. function tick() {
  5600. var i, n = nodes.length, node;
  5601. alpha += (alphaTarget - alpha) * alphaDecay;
  5602. forces.each(function(force) {
  5603. force(alpha);
  5604. });
  5605. for (i = 0; i < n; ++i) {
  5606. node = nodes[i];
  5607. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5608. else node.x = node.fx, node.vx = 0;
  5609. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5610. else node.y = node.fy, node.vy = 0;
  5611. }
  5612. }
  5613. function initializeNodes() {
  5614. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5615. node = nodes[i], node.index = i;
  5616. if (isNaN(node.x) || isNaN(node.y)) {
  5617. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5618. node.x = radius * Math.cos(angle);
  5619. node.y = radius * Math.sin(angle);
  5620. }
  5621. if (isNaN(node.vx) || isNaN(node.vy)) {
  5622. node.vx = node.vy = 0;
  5623. }
  5624. }
  5625. }
  5626. function initializeForce(force) {
  5627. if (force.initialize) force.initialize(nodes);
  5628. return force;
  5629. }
  5630. initializeNodes();
  5631. return simulation = {
  5632. tick: tick,
  5633. restart: function() {
  5634. return stepper.restart(step), simulation;
  5635. },
  5636. stop: function() {
  5637. return stepper.stop(), simulation;
  5638. },
  5639. nodes: function(_) {
  5640. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5641. },
  5642. alpha: function(_) {
  5643. return arguments.length ? (alpha = +_, simulation) : alpha;
  5644. },
  5645. alphaMin: function(_) {
  5646. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5647. },
  5648. alphaDecay: function(_) {
  5649. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5650. },
  5651. alphaTarget: function(_) {
  5652. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5653. },
  5654. velocityDecay: function(_) {
  5655. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5656. },
  5657. force: function(name, _) {
  5658. return arguments.length > 1 ? (_ == null ? forces.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
  5659. },
  5660. find: function(x, y, radius) {
  5661. var i = 0,
  5662. n = nodes.length,
  5663. dx,
  5664. dy,
  5665. d2,
  5666. node,
  5667. closest;
  5668. if (radius == null) radius = Infinity;
  5669. else radius *= radius;
  5670. for (i = 0; i < n; ++i) {
  5671. node = nodes[i];
  5672. dx = x - node.x;
  5673. dy = y - node.y;
  5674. d2 = dx * dx + dy * dy;
  5675. if (d2 < radius) closest = node, radius = d2;
  5676. }
  5677. return closest;
  5678. },
  5679. on: function(name, _) {
  5680. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5681. }
  5682. };
  5683. }
  5684. function manyBody() {
  5685. var nodes,
  5686. node,
  5687. alpha,
  5688. strength = constant$7(-30),
  5689. strengths,
  5690. distanceMin2 = 1,
  5691. distanceMax2 = Infinity,
  5692. theta2 = 0.81;
  5693. function force(_) {
  5694. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5695. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5696. }
  5697. function initialize() {
  5698. if (!nodes) return;
  5699. var i, n = nodes.length, node;
  5700. strengths = new Array(n);
  5701. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5702. }
  5703. function accumulate(quad) {
  5704. var strength = 0, q, c, weight = 0, x, y, i;
  5705. // For internal nodes, accumulate forces from child quadrants.
  5706. if (quad.length) {
  5707. for (x = y = i = 0; i < 4; ++i) {
  5708. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5709. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5710. }
  5711. }
  5712. quad.x = x / weight;
  5713. quad.y = y / weight;
  5714. }
  5715. // For leaf nodes, accumulate forces from coincident quadrants.
  5716. else {
  5717. q = quad;
  5718. q.x = q.data.x;
  5719. q.y = q.data.y;
  5720. do strength += strengths[q.data.index];
  5721. while (q = q.next);
  5722. }
  5723. quad.value = strength;
  5724. }
  5725. function apply(quad, x1, _, x2) {
  5726. if (!quad.value) return true;
  5727. var x = quad.x - node.x,
  5728. y = quad.y - node.y,
  5729. w = x2 - x1,
  5730. l = x * x + y * y;
  5731. // Apply the Barnes-Hut approximation if possible.
  5732. // Limit forces for very close nodes; randomize direction if coincident.
  5733. if (w * w / theta2 < l) {
  5734. if (l < distanceMax2) {
  5735. if (x === 0) x = jiggle(), l += x * x;
  5736. if (y === 0) y = jiggle(), l += y * y;
  5737. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5738. node.vx += x * quad.value * alpha / l;
  5739. node.vy += y * quad.value * alpha / l;
  5740. }
  5741. return true;
  5742. }
  5743. // Otherwise, process points directly.
  5744. else if (quad.length || l >= distanceMax2) return;
  5745. // Limit forces for very close nodes; randomize direction if coincident.
  5746. if (quad.data !== node || quad.next) {
  5747. if (x === 0) x = jiggle(), l += x * x;
  5748. if (y === 0) y = jiggle(), l += y * y;
  5749. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5750. }
  5751. do if (quad.data !== node) {
  5752. w = strengths[quad.data.index] * alpha / l;
  5753. node.vx += x * w;
  5754. node.vy += y * w;
  5755. } while (quad = quad.next);
  5756. }
  5757. force.initialize = function(_) {
  5758. nodes = _;
  5759. initialize();
  5760. };
  5761. force.strength = function(_) {
  5762. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5763. };
  5764. force.distanceMin = function(_) {
  5765. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5766. };
  5767. force.distanceMax = function(_) {
  5768. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5769. };
  5770. force.theta = function(_) {
  5771. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  5772. };
  5773. return force;
  5774. }
  5775. function radial(radius, x, y) {
  5776. var nodes,
  5777. strength = constant$7(0.1),
  5778. strengths,
  5779. radiuses;
  5780. if (typeof radius !== "function") radius = constant$7(+radius);
  5781. if (x == null) x = 0;
  5782. if (y == null) y = 0;
  5783. function force(alpha) {
  5784. for (var i = 0, n = nodes.length; i < n; ++i) {
  5785. var node = nodes[i],
  5786. dx = node.x - x || 1e-6,
  5787. dy = node.y - y || 1e-6,
  5788. r = Math.sqrt(dx * dx + dy * dy),
  5789. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  5790. node.vx += dx * k;
  5791. node.vy += dy * k;
  5792. }
  5793. }
  5794. function initialize() {
  5795. if (!nodes) return;
  5796. var i, n = nodes.length;
  5797. strengths = new Array(n);
  5798. radiuses = new Array(n);
  5799. for (i = 0; i < n; ++i) {
  5800. radiuses[i] = +radius(nodes[i], i, nodes);
  5801. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  5802. }
  5803. }
  5804. force.initialize = function(_) {
  5805. nodes = _, initialize();
  5806. };
  5807. force.strength = function(_) {
  5808. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5809. };
  5810. force.radius = function(_) {
  5811. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5812. };
  5813. force.x = function(_) {
  5814. return arguments.length ? (x = +_, force) : x;
  5815. };
  5816. force.y = function(_) {
  5817. return arguments.length ? (y = +_, force) : y;
  5818. };
  5819. return force;
  5820. }
  5821. function x$2(x) {
  5822. var strength = constant$7(0.1),
  5823. nodes,
  5824. strengths,
  5825. xz;
  5826. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  5827. function force(alpha) {
  5828. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5829. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  5830. }
  5831. }
  5832. function initialize() {
  5833. if (!nodes) return;
  5834. var i, n = nodes.length;
  5835. strengths = new Array(n);
  5836. xz = new Array(n);
  5837. for (i = 0; i < n; ++i) {
  5838. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5839. }
  5840. }
  5841. force.initialize = function(_) {
  5842. nodes = _;
  5843. initialize();
  5844. };
  5845. force.strength = function(_) {
  5846. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5847. };
  5848. force.x = function(_) {
  5849. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  5850. };
  5851. return force;
  5852. }
  5853. function y$2(y) {
  5854. var strength = constant$7(0.1),
  5855. nodes,
  5856. strengths,
  5857. yz;
  5858. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  5859. function force(alpha) {
  5860. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5861. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  5862. }
  5863. }
  5864. function initialize() {
  5865. if (!nodes) return;
  5866. var i, n = nodes.length;
  5867. strengths = new Array(n);
  5868. yz = new Array(n);
  5869. for (i = 0; i < n; ++i) {
  5870. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5871. }
  5872. }
  5873. force.initialize = function(_) {
  5874. nodes = _;
  5875. initialize();
  5876. };
  5877. force.strength = function(_) {
  5878. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5879. };
  5880. force.y = function(_) {
  5881. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  5882. };
  5883. return force;
  5884. }
  5885. // Computes the decimal coefficient and exponent of the specified number x with
  5886. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  5887. // For example, formatDecimal(1.23) returns ["123", 0].
  5888. function formatDecimal(x, p) {
  5889. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  5890. var i, coefficient = x.slice(0, i);
  5891. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  5892. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  5893. return [
  5894. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  5895. +x.slice(i + 1)
  5896. ];
  5897. }
  5898. function exponent$1(x) {
  5899. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  5900. }
  5901. function formatGroup(grouping, thousands) {
  5902. return function(value, width) {
  5903. var i = value.length,
  5904. t = [],
  5905. j = 0,
  5906. g = grouping[0],
  5907. length = 0;
  5908. while (i > 0 && g > 0) {
  5909. if (length + g + 1 > width) g = Math.max(1, width - length);
  5910. t.push(value.substring(i -= g, i + g));
  5911. if ((length += g + 1) > width) break;
  5912. g = grouping[j = (j + 1) % grouping.length];
  5913. }
  5914. return t.reverse().join(thousands);
  5915. };
  5916. }
  5917. function formatNumerals(numerals) {
  5918. return function(value) {
  5919. return value.replace(/[0-9]/g, function(i) {
  5920. return numerals[+i];
  5921. });
  5922. };
  5923. }
  5924. function formatDefault(x, p) {
  5925. x = x.toPrecision(p);
  5926. out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
  5927. switch (x[i]) {
  5928. case ".": i0 = i1 = i; break;
  5929. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  5930. case "e": break out;
  5931. default: if (i0 > 0) i0 = 0; break;
  5932. }
  5933. }
  5934. return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
  5935. }
  5936. var prefixExponent;
  5937. function formatPrefixAuto(x, p) {
  5938. var d = formatDecimal(x, p);
  5939. if (!d) return x + "";
  5940. var coefficient = d[0],
  5941. exponent = d[1],
  5942. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  5943. n = coefficient.length;
  5944. return i === n ? coefficient
  5945. : i > n ? coefficient + new Array(i - n + 1).join("0")
  5946. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  5947. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  5948. }
  5949. function formatRounded(x, p) {
  5950. var d = formatDecimal(x, p);
  5951. if (!d) return x + "";
  5952. var coefficient = d[0],
  5953. exponent = d[1];
  5954. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  5955. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  5956. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  5957. }
  5958. var formatTypes = {
  5959. "": formatDefault,
  5960. "%": function(x, p) { return (x * 100).toFixed(p); },
  5961. "b": function(x) { return Math.round(x).toString(2); },
  5962. "c": function(x) { return x + ""; },
  5963. "d": function(x) { return Math.round(x).toString(10); },
  5964. "e": function(x, p) { return x.toExponential(p); },
  5965. "f": function(x, p) { return x.toFixed(p); },
  5966. "g": function(x, p) { return x.toPrecision(p); },
  5967. "o": function(x) { return Math.round(x).toString(8); },
  5968. "p": function(x, p) { return formatRounded(x * 100, p); },
  5969. "r": formatRounded,
  5970. "s": formatPrefixAuto,
  5971. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  5972. "x": function(x) { return Math.round(x).toString(16); }
  5973. };
  5974. // [[fill]align][sign][symbol][0][width][,][.precision][type]
  5975. var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
  5976. function formatSpecifier(specifier) {
  5977. return new FormatSpecifier(specifier);
  5978. }
  5979. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  5980. function FormatSpecifier(specifier) {
  5981. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  5982. var match,
  5983. fill = match[1] || " ",
  5984. align = match[2] || ">",
  5985. sign = match[3] || "-",
  5986. symbol = match[4] || "",
  5987. zero = !!match[5],
  5988. width = match[6] && +match[6],
  5989. comma = !!match[7],
  5990. precision = match[8] && +match[8].slice(1),
  5991. type = match[9] || "";
  5992. // The "n" type is an alias for ",g".
  5993. if (type === "n") comma = true, type = "g";
  5994. // Map invalid types to the default format.
  5995. else if (!formatTypes[type]) type = "";
  5996. // If zero fill is specified, padding goes after sign and before digits.
  5997. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  5998. this.fill = fill;
  5999. this.align = align;
  6000. this.sign = sign;
  6001. this.symbol = symbol;
  6002. this.zero = zero;
  6003. this.width = width;
  6004. this.comma = comma;
  6005. this.precision = precision;
  6006. this.type = type;
  6007. }
  6008. FormatSpecifier.prototype.toString = function() {
  6009. return this.fill
  6010. + this.align
  6011. + this.sign
  6012. + this.symbol
  6013. + (this.zero ? "0" : "")
  6014. + (this.width == null ? "" : Math.max(1, this.width | 0))
  6015. + (this.comma ? "," : "")
  6016. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  6017. + this.type;
  6018. };
  6019. function identity$3(x) {
  6020. return x;
  6021. }
  6022. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  6023. function formatLocale(locale) {
  6024. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  6025. currency = locale.currency,
  6026. decimal = locale.decimal,
  6027. numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
  6028. percent = locale.percent || "%";
  6029. function newFormat(specifier) {
  6030. specifier = formatSpecifier(specifier);
  6031. var fill = specifier.fill,
  6032. align = specifier.align,
  6033. sign = specifier.sign,
  6034. symbol = specifier.symbol,
  6035. zero = specifier.zero,
  6036. width = specifier.width,
  6037. comma = specifier.comma,
  6038. precision = specifier.precision,
  6039. type = specifier.type;
  6040. // Compute the prefix and suffix.
  6041. // For SI-prefix, the suffix is lazily computed.
  6042. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  6043. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
  6044. // What format function should we use?
  6045. // Is this an integer type?
  6046. // Can this type generate exponential notation?
  6047. var formatType = formatTypes[type],
  6048. maybeSuffix = !type || /[defgprs%]/.test(type);
  6049. // Set the default precision if not specified,
  6050. // or clamp the specified precision to the supported range.
  6051. // For significant precision, it must be in [1, 21].
  6052. // For fixed precision, it must be in [0, 20].
  6053. precision = precision == null ? (type ? 6 : 12)
  6054. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  6055. : Math.max(0, Math.min(20, precision));
  6056. function format(value) {
  6057. var valuePrefix = prefix,
  6058. valueSuffix = suffix,
  6059. i, n, c;
  6060. if (type === "c") {
  6061. valueSuffix = formatType(value) + valueSuffix;
  6062. value = "";
  6063. } else {
  6064. value = +value;
  6065. // Perform the initial formatting.
  6066. var valueNegative = value < 0;
  6067. value = formatType(Math.abs(value), precision);
  6068. // If a negative value rounds to zero during formatting, treat as positive.
  6069. if (valueNegative && +value === 0) valueNegative = false;
  6070. // Compute the prefix and suffix.
  6071. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  6072. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  6073. // Break the formatted value into the integer “value” part that can be
  6074. // grouped, and fractional or exponential “suffix” part that is not.
  6075. if (maybeSuffix) {
  6076. i = -1, n = value.length;
  6077. while (++i < n) {
  6078. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  6079. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  6080. value = value.slice(0, i);
  6081. break;
  6082. }
  6083. }
  6084. }
  6085. }
  6086. // If the fill character is not "0", grouping is applied before padding.
  6087. if (comma && !zero) value = group(value, Infinity);
  6088. // Compute the padding.
  6089. var length = valuePrefix.length + value.length + valueSuffix.length,
  6090. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  6091. // If the fill character is "0", grouping is applied after padding.
  6092. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  6093. // Reconstruct the final output based on the desired alignment.
  6094. switch (align) {
  6095. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  6096. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  6097. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  6098. default: value = padding + valuePrefix + value + valueSuffix; break;
  6099. }
  6100. return numerals(value);
  6101. }
  6102. format.toString = function() {
  6103. return specifier + "";
  6104. };
  6105. return format;
  6106. }
  6107. function formatPrefix(specifier, value) {
  6108. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  6109. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  6110. k = Math.pow(10, -e),
  6111. prefix = prefixes[8 + e / 3];
  6112. return function(value) {
  6113. return f(k * value) + prefix;
  6114. };
  6115. }
  6116. return {
  6117. format: newFormat,
  6118. formatPrefix: formatPrefix
  6119. };
  6120. }
  6121. var locale;
  6122. defaultLocale({
  6123. decimal: ".",
  6124. thousands: ",",
  6125. grouping: [3],
  6126. currency: ["$", ""]
  6127. });
  6128. function defaultLocale(definition) {
  6129. locale = formatLocale(definition);
  6130. exports.format = locale.format;
  6131. exports.formatPrefix = locale.formatPrefix;
  6132. return locale;
  6133. }
  6134. function precisionFixed(step) {
  6135. return Math.max(0, -exponent$1(Math.abs(step)));
  6136. }
  6137. function precisionPrefix(step, value) {
  6138. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  6139. }
  6140. function precisionRound(step, max) {
  6141. step = Math.abs(step), max = Math.abs(max) - step;
  6142. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  6143. }
  6144. // Adds floating point numbers with twice the normal precision.
  6145. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  6146. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  6147. // 305–363 (1997).
  6148. // Code adapted from GeographicLib by Charles F. F. Karney,
  6149. // http://geographiclib.sourceforge.net/
  6150. function adder() {
  6151. return new Adder;
  6152. }
  6153. function Adder() {
  6154. this.reset();
  6155. }
  6156. Adder.prototype = {
  6157. constructor: Adder,
  6158. reset: function() {
  6159. this.s = // rounded value
  6160. this.t = 0; // exact error
  6161. },
  6162. add: function(y) {
  6163. add$1(temp, y, this.t);
  6164. add$1(this, temp.s, this.s);
  6165. if (this.s) this.t += temp.t;
  6166. else this.s = temp.t;
  6167. },
  6168. valueOf: function() {
  6169. return this.s;
  6170. }
  6171. };
  6172. var temp = new Adder;
  6173. function add$1(adder, a, b) {
  6174. var x = adder.s = a + b,
  6175. bv = x - a,
  6176. av = x - bv;
  6177. adder.t = (a - av) + (b - bv);
  6178. }
  6179. var epsilon$2 = 1e-6;
  6180. var epsilon2$1 = 1e-12;
  6181. var pi$3 = Math.PI;
  6182. var halfPi$2 = pi$3 / 2;
  6183. var quarterPi = pi$3 / 4;
  6184. var tau$3 = pi$3 * 2;
  6185. var degrees$1 = 180 / pi$3;
  6186. var radians = pi$3 / 180;
  6187. var abs = Math.abs;
  6188. var atan = Math.atan;
  6189. var atan2 = Math.atan2;
  6190. var cos$1 = Math.cos;
  6191. var ceil = Math.ceil;
  6192. var exp = Math.exp;
  6193. var log = Math.log;
  6194. var pow = Math.pow;
  6195. var sin$1 = Math.sin;
  6196. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  6197. var sqrt = Math.sqrt;
  6198. var tan = Math.tan;
  6199. function acos(x) {
  6200. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  6201. }
  6202. function asin(x) {
  6203. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  6204. }
  6205. function haversin(x) {
  6206. return (x = sin$1(x / 2)) * x;
  6207. }
  6208. function noop$2() {}
  6209. function streamGeometry(geometry, stream) {
  6210. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  6211. streamGeometryType[geometry.type](geometry, stream);
  6212. }
  6213. }
  6214. var streamObjectType = {
  6215. Feature: function(object, stream) {
  6216. streamGeometry(object.geometry, stream);
  6217. },
  6218. FeatureCollection: function(object, stream) {
  6219. var features = object.features, i = -1, n = features.length;
  6220. while (++i < n) streamGeometry(features[i].geometry, stream);
  6221. }
  6222. };
  6223. var streamGeometryType = {
  6224. Sphere: function(object, stream) {
  6225. stream.sphere();
  6226. },
  6227. Point: function(object, stream) {
  6228. object = object.coordinates;
  6229. stream.point(object[0], object[1], object[2]);
  6230. },
  6231. MultiPoint: function(object, stream) {
  6232. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6233. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  6234. },
  6235. LineString: function(object, stream) {
  6236. streamLine(object.coordinates, stream, 0);
  6237. },
  6238. MultiLineString: function(object, stream) {
  6239. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6240. while (++i < n) streamLine(coordinates[i], stream, 0);
  6241. },
  6242. Polygon: function(object, stream) {
  6243. streamPolygon(object.coordinates, stream);
  6244. },
  6245. MultiPolygon: function(object, stream) {
  6246. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6247. while (++i < n) streamPolygon(coordinates[i], stream);
  6248. },
  6249. GeometryCollection: function(object, stream) {
  6250. var geometries = object.geometries, i = -1, n = geometries.length;
  6251. while (++i < n) streamGeometry(geometries[i], stream);
  6252. }
  6253. };
  6254. function streamLine(coordinates, stream, closed) {
  6255. var i = -1, n = coordinates.length - closed, coordinate;
  6256. stream.lineStart();
  6257. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  6258. stream.lineEnd();
  6259. }
  6260. function streamPolygon(coordinates, stream) {
  6261. var i = -1, n = coordinates.length;
  6262. stream.polygonStart();
  6263. while (++i < n) streamLine(coordinates[i], stream, 1);
  6264. stream.polygonEnd();
  6265. }
  6266. function geoStream(object, stream) {
  6267. if (object && streamObjectType.hasOwnProperty(object.type)) {
  6268. streamObjectType[object.type](object, stream);
  6269. } else {
  6270. streamGeometry(object, stream);
  6271. }
  6272. }
  6273. var areaRingSum = adder();
  6274. var areaSum = adder(),
  6275. lambda00,
  6276. phi00,
  6277. lambda0,
  6278. cosPhi0,
  6279. sinPhi0;
  6280. var areaStream = {
  6281. point: noop$2,
  6282. lineStart: noop$2,
  6283. lineEnd: noop$2,
  6284. polygonStart: function() {
  6285. areaRingSum.reset();
  6286. areaStream.lineStart = areaRingStart;
  6287. areaStream.lineEnd = areaRingEnd;
  6288. },
  6289. polygonEnd: function() {
  6290. var areaRing = +areaRingSum;
  6291. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  6292. this.lineStart = this.lineEnd = this.point = noop$2;
  6293. },
  6294. sphere: function() {
  6295. areaSum.add(tau$3);
  6296. }
  6297. };
  6298. function areaRingStart() {
  6299. areaStream.point = areaPointFirst;
  6300. }
  6301. function areaRingEnd() {
  6302. areaPoint(lambda00, phi00);
  6303. }
  6304. function areaPointFirst(lambda, phi) {
  6305. areaStream.point = areaPoint;
  6306. lambda00 = lambda, phi00 = phi;
  6307. lambda *= radians, phi *= radians;
  6308. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  6309. }
  6310. function areaPoint(lambda, phi) {
  6311. lambda *= radians, phi *= radians;
  6312. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  6313. // Spherical excess E for a spherical triangle with vertices: south pole,
  6314. // previous point, current point. Uses a formula derived from Cagnoli’s
  6315. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  6316. var dLambda = lambda - lambda0,
  6317. sdLambda = dLambda >= 0 ? 1 : -1,
  6318. adLambda = sdLambda * dLambda,
  6319. cosPhi = cos$1(phi),
  6320. sinPhi = sin$1(phi),
  6321. k = sinPhi0 * sinPhi,
  6322. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  6323. v = k * sdLambda * sin$1(adLambda);
  6324. areaRingSum.add(atan2(v, u));
  6325. // Advance the previous points.
  6326. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  6327. }
  6328. function area$1(object) {
  6329. areaSum.reset();
  6330. geoStream(object, areaStream);
  6331. return areaSum * 2;
  6332. }
  6333. function spherical(cartesian) {
  6334. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  6335. }
  6336. function cartesian(spherical) {
  6337. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  6338. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  6339. }
  6340. function cartesianDot(a, b) {
  6341. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6342. }
  6343. function cartesianCross(a, b) {
  6344. 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]];
  6345. }
  6346. // TODO return a
  6347. function cartesianAddInPlace(a, b) {
  6348. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  6349. }
  6350. function cartesianScale(vector, k) {
  6351. return [vector[0] * k, vector[1] * k, vector[2] * k];
  6352. }
  6353. // TODO return d
  6354. function cartesianNormalizeInPlace(d) {
  6355. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  6356. d[0] /= l, d[1] /= l, d[2] /= l;
  6357. }
  6358. var lambda0$1, phi0, lambda1, phi1, // bounds
  6359. lambda2, // previous lambda-coordinate
  6360. lambda00$1, phi00$1, // first point
  6361. p0, // previous 3D point
  6362. deltaSum = adder(),
  6363. ranges,
  6364. range;
  6365. var boundsStream = {
  6366. point: boundsPoint,
  6367. lineStart: boundsLineStart,
  6368. lineEnd: boundsLineEnd,
  6369. polygonStart: function() {
  6370. boundsStream.point = boundsRingPoint;
  6371. boundsStream.lineStart = boundsRingStart;
  6372. boundsStream.lineEnd = boundsRingEnd;
  6373. deltaSum.reset();
  6374. areaStream.polygonStart();
  6375. },
  6376. polygonEnd: function() {
  6377. areaStream.polygonEnd();
  6378. boundsStream.point = boundsPoint;
  6379. boundsStream.lineStart = boundsLineStart;
  6380. boundsStream.lineEnd = boundsLineEnd;
  6381. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6382. else if (deltaSum > epsilon$2) phi1 = 90;
  6383. else if (deltaSum < -epsilon$2) phi0 = -90;
  6384. range[0] = lambda0$1, range[1] = lambda1;
  6385. }
  6386. };
  6387. function boundsPoint(lambda, phi) {
  6388. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6389. if (phi < phi0) phi0 = phi;
  6390. if (phi > phi1) phi1 = phi;
  6391. }
  6392. function linePoint(lambda, phi) {
  6393. var p = cartesian([lambda * radians, phi * radians]);
  6394. if (p0) {
  6395. var normal = cartesianCross(p0, p),
  6396. equatorial = [normal[1], -normal[0], 0],
  6397. inflection = cartesianCross(equatorial, normal);
  6398. cartesianNormalizeInPlace(inflection);
  6399. inflection = spherical(inflection);
  6400. var delta = lambda - lambda2,
  6401. sign$$1 = delta > 0 ? 1 : -1,
  6402. lambdai = inflection[0] * degrees$1 * sign$$1,
  6403. phii,
  6404. antimeridian = abs(delta) > 180;
  6405. if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  6406. phii = inflection[1] * degrees$1;
  6407. if (phii > phi1) phi1 = phii;
  6408. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  6409. phii = -inflection[1] * degrees$1;
  6410. if (phii < phi0) phi0 = phii;
  6411. } else {
  6412. if (phi < phi0) phi0 = phi;
  6413. if (phi > phi1) phi1 = phi;
  6414. }
  6415. if (antimeridian) {
  6416. if (lambda < lambda2) {
  6417. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6418. } else {
  6419. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6420. }
  6421. } else {
  6422. if (lambda1 >= lambda0$1) {
  6423. if (lambda < lambda0$1) lambda0$1 = lambda;
  6424. if (lambda > lambda1) lambda1 = lambda;
  6425. } else {
  6426. if (lambda > lambda2) {
  6427. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6428. } else {
  6429. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6430. }
  6431. }
  6432. }
  6433. } else {
  6434. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6435. }
  6436. if (phi < phi0) phi0 = phi;
  6437. if (phi > phi1) phi1 = phi;
  6438. p0 = p, lambda2 = lambda;
  6439. }
  6440. function boundsLineStart() {
  6441. boundsStream.point = linePoint;
  6442. }
  6443. function boundsLineEnd() {
  6444. range[0] = lambda0$1, range[1] = lambda1;
  6445. boundsStream.point = boundsPoint;
  6446. p0 = null;
  6447. }
  6448. function boundsRingPoint(lambda, phi) {
  6449. if (p0) {
  6450. var delta = lambda - lambda2;
  6451. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6452. } else {
  6453. lambda00$1 = lambda, phi00$1 = phi;
  6454. }
  6455. areaStream.point(lambda, phi);
  6456. linePoint(lambda, phi);
  6457. }
  6458. function boundsRingStart() {
  6459. areaStream.lineStart();
  6460. }
  6461. function boundsRingEnd() {
  6462. boundsRingPoint(lambda00$1, phi00$1);
  6463. areaStream.lineEnd();
  6464. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6465. range[0] = lambda0$1, range[1] = lambda1;
  6466. p0 = null;
  6467. }
  6468. // Finds the left-right distance between two longitudes.
  6469. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6470. // the distance between ±180° to be 360°.
  6471. function angle(lambda0, lambda1) {
  6472. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6473. }
  6474. function rangeCompare(a, b) {
  6475. return a[0] - b[0];
  6476. }
  6477. function rangeContains(range, x) {
  6478. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6479. }
  6480. function bounds(feature) {
  6481. var i, n, a, b, merged, deltaMax, delta;
  6482. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6483. ranges = [];
  6484. geoStream(feature, boundsStream);
  6485. // First, sort ranges by their minimum longitudes.
  6486. if (n = ranges.length) {
  6487. ranges.sort(rangeCompare);
  6488. // Then, merge any ranges that overlap.
  6489. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6490. b = ranges[i];
  6491. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6492. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6493. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6494. } else {
  6495. merged.push(a = b);
  6496. }
  6497. }
  6498. // Finally, find the largest gap between the merged ranges.
  6499. // The final bounding box will be the inverse of this gap.
  6500. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6501. b = merged[i];
  6502. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6503. }
  6504. }
  6505. ranges = range = null;
  6506. return lambda0$1 === Infinity || phi0 === Infinity
  6507. ? [[NaN, NaN], [NaN, NaN]]
  6508. : [[lambda0$1, phi0], [lambda1, phi1]];
  6509. }
  6510. var W0, W1,
  6511. X0, Y0, Z0,
  6512. X1, Y1, Z1,
  6513. X2, Y2, Z2,
  6514. lambda00$2, phi00$2, // first point
  6515. x0, y0, z0; // previous point
  6516. var centroidStream = {
  6517. sphere: noop$2,
  6518. point: centroidPoint,
  6519. lineStart: centroidLineStart,
  6520. lineEnd: centroidLineEnd,
  6521. polygonStart: function() {
  6522. centroidStream.lineStart = centroidRingStart;
  6523. centroidStream.lineEnd = centroidRingEnd;
  6524. },
  6525. polygonEnd: function() {
  6526. centroidStream.lineStart = centroidLineStart;
  6527. centroidStream.lineEnd = centroidLineEnd;
  6528. }
  6529. };
  6530. // Arithmetic mean of Cartesian vectors.
  6531. function centroidPoint(lambda, phi) {
  6532. lambda *= radians, phi *= radians;
  6533. var cosPhi = cos$1(phi);
  6534. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6535. }
  6536. function centroidPointCartesian(x, y, z) {
  6537. ++W0;
  6538. X0 += (x - X0) / W0;
  6539. Y0 += (y - Y0) / W0;
  6540. Z0 += (z - Z0) / W0;
  6541. }
  6542. function centroidLineStart() {
  6543. centroidStream.point = centroidLinePointFirst;
  6544. }
  6545. function centroidLinePointFirst(lambda, phi) {
  6546. lambda *= radians, phi *= radians;
  6547. var cosPhi = cos$1(phi);
  6548. x0 = cosPhi * cos$1(lambda);
  6549. y0 = cosPhi * sin$1(lambda);
  6550. z0 = sin$1(phi);
  6551. centroidStream.point = centroidLinePoint;
  6552. centroidPointCartesian(x0, y0, z0);
  6553. }
  6554. function centroidLinePoint(lambda, phi) {
  6555. lambda *= radians, phi *= radians;
  6556. var cosPhi = cos$1(phi),
  6557. x = cosPhi * cos$1(lambda),
  6558. y = cosPhi * sin$1(lambda),
  6559. z = sin$1(phi),
  6560. 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);
  6561. W1 += w;
  6562. X1 += w * (x0 + (x0 = x));
  6563. Y1 += w * (y0 + (y0 = y));
  6564. Z1 += w * (z0 + (z0 = z));
  6565. centroidPointCartesian(x0, y0, z0);
  6566. }
  6567. function centroidLineEnd() {
  6568. centroidStream.point = centroidPoint;
  6569. }
  6570. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6571. // J. Applied Mechanics 42, 239 (1975).
  6572. function centroidRingStart() {
  6573. centroidStream.point = centroidRingPointFirst;
  6574. }
  6575. function centroidRingEnd() {
  6576. centroidRingPoint(lambda00$2, phi00$2);
  6577. centroidStream.point = centroidPoint;
  6578. }
  6579. function centroidRingPointFirst(lambda, phi) {
  6580. lambda00$2 = lambda, phi00$2 = phi;
  6581. lambda *= radians, phi *= radians;
  6582. centroidStream.point = centroidRingPoint;
  6583. var cosPhi = cos$1(phi);
  6584. x0 = cosPhi * cos$1(lambda);
  6585. y0 = cosPhi * sin$1(lambda);
  6586. z0 = sin$1(phi);
  6587. centroidPointCartesian(x0, y0, z0);
  6588. }
  6589. function centroidRingPoint(lambda, phi) {
  6590. lambda *= radians, phi *= radians;
  6591. var cosPhi = cos$1(phi),
  6592. x = cosPhi * cos$1(lambda),
  6593. y = cosPhi * sin$1(lambda),
  6594. z = sin$1(phi),
  6595. cx = y0 * z - z0 * y,
  6596. cy = z0 * x - x0 * z,
  6597. cz = x0 * y - y0 * x,
  6598. m = sqrt(cx * cx + cy * cy + cz * cz),
  6599. w = asin(m), // line weight = angle
  6600. v = m && -w / m; // area weight multiplier
  6601. X2 += v * cx;
  6602. Y2 += v * cy;
  6603. Z2 += v * cz;
  6604. W1 += w;
  6605. X1 += w * (x0 + (x0 = x));
  6606. Y1 += w * (y0 + (y0 = y));
  6607. Z1 += w * (z0 + (z0 = z));
  6608. centroidPointCartesian(x0, y0, z0);
  6609. }
  6610. function centroid(object) {
  6611. W0 = W1 =
  6612. X0 = Y0 = Z0 =
  6613. X1 = Y1 = Z1 =
  6614. X2 = Y2 = Z2 = 0;
  6615. geoStream(object, centroidStream);
  6616. var x = X2,
  6617. y = Y2,
  6618. z = Z2,
  6619. m = x * x + y * y + z * z;
  6620. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6621. if (m < epsilon2$1) {
  6622. x = X1, y = Y1, z = Z1;
  6623. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6624. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6625. m = x * x + y * y + z * z;
  6626. // If the feature still has an undefined ccentroid, then return.
  6627. if (m < epsilon2$1) return [NaN, NaN];
  6628. }
  6629. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6630. }
  6631. function constant$8(x) {
  6632. return function() {
  6633. return x;
  6634. };
  6635. }
  6636. function compose(a, b) {
  6637. function compose(x, y) {
  6638. return x = a(x, y), b(x[0], x[1]);
  6639. }
  6640. if (a.invert && b.invert) compose.invert = function(x, y) {
  6641. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6642. };
  6643. return compose;
  6644. }
  6645. function rotationIdentity(lambda, phi) {
  6646. return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6647. }
  6648. rotationIdentity.invert = rotationIdentity;
  6649. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6650. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6651. : rotationLambda(deltaLambda))
  6652. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6653. : rotationIdentity);
  6654. }
  6655. function forwardRotationLambda(deltaLambda) {
  6656. return function(lambda, phi) {
  6657. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6658. };
  6659. }
  6660. function rotationLambda(deltaLambda) {
  6661. var rotation = forwardRotationLambda(deltaLambda);
  6662. rotation.invert = forwardRotationLambda(-deltaLambda);
  6663. return rotation;
  6664. }
  6665. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6666. var cosDeltaPhi = cos$1(deltaPhi),
  6667. sinDeltaPhi = sin$1(deltaPhi),
  6668. cosDeltaGamma = cos$1(deltaGamma),
  6669. sinDeltaGamma = sin$1(deltaGamma);
  6670. function rotation(lambda, phi) {
  6671. var cosPhi = cos$1(phi),
  6672. x = cos$1(lambda) * cosPhi,
  6673. y = sin$1(lambda) * cosPhi,
  6674. z = sin$1(phi),
  6675. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6676. return [
  6677. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6678. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6679. ];
  6680. }
  6681. rotation.invert = function(lambda, phi) {
  6682. var cosPhi = cos$1(phi),
  6683. x = cos$1(lambda) * cosPhi,
  6684. y = sin$1(lambda) * cosPhi,
  6685. z = sin$1(phi),
  6686. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6687. return [
  6688. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6689. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6690. ];
  6691. };
  6692. return rotation;
  6693. }
  6694. function rotation(rotate) {
  6695. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6696. function forward(coordinates) {
  6697. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6698. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6699. }
  6700. forward.invert = function(coordinates) {
  6701. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6702. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6703. };
  6704. return forward;
  6705. }
  6706. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6707. function circleStream(stream, radius, delta, direction, t0, t1) {
  6708. if (!delta) return;
  6709. var cosRadius = cos$1(radius),
  6710. sinRadius = sin$1(radius),
  6711. step = direction * delta;
  6712. if (t0 == null) {
  6713. t0 = radius + direction * tau$3;
  6714. t1 = radius - step / 2;
  6715. } else {
  6716. t0 = circleRadius(cosRadius, t0);
  6717. t1 = circleRadius(cosRadius, t1);
  6718. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6719. }
  6720. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6721. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6722. stream.point(point[0], point[1]);
  6723. }
  6724. }
  6725. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6726. function circleRadius(cosRadius, point) {
  6727. point = cartesian(point), point[0] -= cosRadius;
  6728. cartesianNormalizeInPlace(point);
  6729. var radius = acos(-point[1]);
  6730. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6731. }
  6732. function circle() {
  6733. var center = constant$8([0, 0]),
  6734. radius = constant$8(90),
  6735. precision = constant$8(6),
  6736. ring,
  6737. rotate,
  6738. stream = {point: point};
  6739. function point(x, y) {
  6740. ring.push(x = rotate(x, y));
  6741. x[0] *= degrees$1, x[1] *= degrees$1;
  6742. }
  6743. function circle() {
  6744. var c = center.apply(this, arguments),
  6745. r = radius.apply(this, arguments) * radians,
  6746. p = precision.apply(this, arguments) * radians;
  6747. ring = [];
  6748. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6749. circleStream(stream, r, p, 1);
  6750. c = {type: "Polygon", coordinates: [ring]};
  6751. ring = rotate = null;
  6752. return c;
  6753. }
  6754. circle.center = function(_) {
  6755. return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
  6756. };
  6757. circle.radius = function(_) {
  6758. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
  6759. };
  6760. circle.precision = function(_) {
  6761. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
  6762. };
  6763. return circle;
  6764. }
  6765. function clipBuffer() {
  6766. var lines = [],
  6767. line;
  6768. return {
  6769. point: function(x, y) {
  6770. line.push([x, y]);
  6771. },
  6772. lineStart: function() {
  6773. lines.push(line = []);
  6774. },
  6775. lineEnd: noop$2,
  6776. rejoin: function() {
  6777. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  6778. },
  6779. result: function() {
  6780. var result = lines;
  6781. lines = [];
  6782. line = null;
  6783. return result;
  6784. }
  6785. };
  6786. }
  6787. function pointEqual(a, b) {
  6788. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  6789. }
  6790. function Intersection(point, points, other, entry) {
  6791. this.x = point;
  6792. this.z = points;
  6793. this.o = other; // another intersection
  6794. this.e = entry; // is an entry?
  6795. this.v = false; // visited
  6796. this.n = this.p = null; // next & previous
  6797. }
  6798. // A generalized polygon clipping algorithm: given a polygon that has been cut
  6799. // into its visible line segments, and rejoins the segments by interpolating
  6800. // along the clip edge.
  6801. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  6802. var subject = [],
  6803. clip = [],
  6804. i,
  6805. n;
  6806. segments.forEach(function(segment) {
  6807. if ((n = segment.length - 1) <= 0) return;
  6808. var n, p0 = segment[0], p1 = segment[n], x;
  6809. // If the first and last points of a segment are coincident, then treat as a
  6810. // closed ring. TODO if all rings are closed, then the winding order of the
  6811. // exterior ring should be checked.
  6812. if (pointEqual(p0, p1)) {
  6813. stream.lineStart();
  6814. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  6815. stream.lineEnd();
  6816. return;
  6817. }
  6818. subject.push(x = new Intersection(p0, segment, null, true));
  6819. clip.push(x.o = new Intersection(p0, null, x, false));
  6820. subject.push(x = new Intersection(p1, segment, null, false));
  6821. clip.push(x.o = new Intersection(p1, null, x, true));
  6822. });
  6823. if (!subject.length) return;
  6824. clip.sort(compareIntersection);
  6825. link$1(subject);
  6826. link$1(clip);
  6827. for (i = 0, n = clip.length; i < n; ++i) {
  6828. clip[i].e = startInside = !startInside;
  6829. }
  6830. var start = subject[0],
  6831. points,
  6832. point;
  6833. while (1) {
  6834. // Find first unvisited intersection.
  6835. var current = start,
  6836. isSubject = true;
  6837. while (current.v) if ((current = current.n) === start) return;
  6838. points = current.z;
  6839. stream.lineStart();
  6840. do {
  6841. current.v = current.o.v = true;
  6842. if (current.e) {
  6843. if (isSubject) {
  6844. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  6845. } else {
  6846. interpolate(current.x, current.n.x, 1, stream);
  6847. }
  6848. current = current.n;
  6849. } else {
  6850. if (isSubject) {
  6851. points = current.p.z;
  6852. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  6853. } else {
  6854. interpolate(current.x, current.p.x, -1, stream);
  6855. }
  6856. current = current.p;
  6857. }
  6858. current = current.o;
  6859. points = current.z;
  6860. isSubject = !isSubject;
  6861. } while (!current.v);
  6862. stream.lineEnd();
  6863. }
  6864. }
  6865. function link$1(array) {
  6866. if (!(n = array.length)) return;
  6867. var n,
  6868. i = 0,
  6869. a = array[0],
  6870. b;
  6871. while (++i < n) {
  6872. a.n = b = array[i];
  6873. b.p = a;
  6874. a = b;
  6875. }
  6876. a.n = b = array[0];
  6877. b.p = a;
  6878. }
  6879. var sum$1 = adder();
  6880. function polygonContains(polygon, point) {
  6881. var lambda = point[0],
  6882. phi = point[1],
  6883. sinPhi = sin$1(phi),
  6884. normal = [sin$1(lambda), -cos$1(lambda), 0],
  6885. angle = 0,
  6886. winding = 0;
  6887. sum$1.reset();
  6888. if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
  6889. else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
  6890. for (var i = 0, n = polygon.length; i < n; ++i) {
  6891. if (!(m = (ring = polygon[i]).length)) continue;
  6892. var ring,
  6893. m,
  6894. point0 = ring[m - 1],
  6895. lambda0 = point0[0],
  6896. phi0 = point0[1] / 2 + quarterPi,
  6897. sinPhi0 = sin$1(phi0),
  6898. cosPhi0 = cos$1(phi0);
  6899. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  6900. var point1 = ring[j],
  6901. lambda1 = point1[0],
  6902. phi1 = point1[1] / 2 + quarterPi,
  6903. sinPhi1 = sin$1(phi1),
  6904. cosPhi1 = cos$1(phi1),
  6905. delta = lambda1 - lambda0,
  6906. sign$$1 = delta >= 0 ? 1 : -1,
  6907. absDelta = sign$$1 * delta,
  6908. antimeridian = absDelta > pi$3,
  6909. k = sinPhi0 * sinPhi1;
  6910. sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  6911. angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
  6912. // Are the longitudes either side of the point’s meridian (lambda),
  6913. // and are the latitudes smaller than the parallel (phi)?
  6914. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  6915. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  6916. cartesianNormalizeInPlace(arc);
  6917. var intersection = cartesianCross(normal, arc);
  6918. cartesianNormalizeInPlace(intersection);
  6919. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  6920. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  6921. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  6922. }
  6923. }
  6924. }
  6925. }
  6926. // First, determine whether the South pole is inside or outside:
  6927. //
  6928. // It is inside if:
  6929. // * the polygon winds around it in a clockwise direction.
  6930. // * the polygon does not (cumulatively) wind around it, but has a negative
  6931. // (counter-clockwise) area.
  6932. //
  6933. // Second, count the (signed) number of times a segment crosses a lambda
  6934. // from the point to the South pole. If it is zero, then the point is the
  6935. // same side as the South pole.
  6936. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  6937. }
  6938. function clip(pointVisible, clipLine, interpolate, start) {
  6939. return function(sink) {
  6940. var line = clipLine(sink),
  6941. ringBuffer = clipBuffer(),
  6942. ringSink = clipLine(ringBuffer),
  6943. polygonStarted = false,
  6944. polygon,
  6945. segments,
  6946. ring;
  6947. var clip = {
  6948. point: point,
  6949. lineStart: lineStart,
  6950. lineEnd: lineEnd,
  6951. polygonStart: function() {
  6952. clip.point = pointRing;
  6953. clip.lineStart = ringStart;
  6954. clip.lineEnd = ringEnd;
  6955. segments = [];
  6956. polygon = [];
  6957. },
  6958. polygonEnd: function() {
  6959. clip.point = point;
  6960. clip.lineStart = lineStart;
  6961. clip.lineEnd = lineEnd;
  6962. segments = merge(segments);
  6963. var startInside = polygonContains(polygon, start);
  6964. if (segments.length) {
  6965. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6966. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  6967. } else if (startInside) {
  6968. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6969. sink.lineStart();
  6970. interpolate(null, null, 1, sink);
  6971. sink.lineEnd();
  6972. }
  6973. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  6974. segments = polygon = null;
  6975. },
  6976. sphere: function() {
  6977. sink.polygonStart();
  6978. sink.lineStart();
  6979. interpolate(null, null, 1, sink);
  6980. sink.lineEnd();
  6981. sink.polygonEnd();
  6982. }
  6983. };
  6984. function point(lambda, phi) {
  6985. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  6986. }
  6987. function pointLine(lambda, phi) {
  6988. line.point(lambda, phi);
  6989. }
  6990. function lineStart() {
  6991. clip.point = pointLine;
  6992. line.lineStart();
  6993. }
  6994. function lineEnd() {
  6995. clip.point = point;
  6996. line.lineEnd();
  6997. }
  6998. function pointRing(lambda, phi) {
  6999. ring.push([lambda, phi]);
  7000. ringSink.point(lambda, phi);
  7001. }
  7002. function ringStart() {
  7003. ringSink.lineStart();
  7004. ring = [];
  7005. }
  7006. function ringEnd() {
  7007. pointRing(ring[0][0], ring[0][1]);
  7008. ringSink.lineEnd();
  7009. var clean = ringSink.clean(),
  7010. ringSegments = ringBuffer.result(),
  7011. i, n = ringSegments.length, m,
  7012. segment,
  7013. point;
  7014. ring.pop();
  7015. polygon.push(ring);
  7016. ring = null;
  7017. if (!n) return;
  7018. // No intersections.
  7019. if (clean & 1) {
  7020. segment = ringSegments[0];
  7021. if ((m = segment.length - 1) > 0) {
  7022. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7023. sink.lineStart();
  7024. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7025. sink.lineEnd();
  7026. }
  7027. return;
  7028. }
  7029. // Rejoin connected segments.
  7030. // TODO reuse ringBuffer.rejoin()?
  7031. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7032. segments.push(ringSegments.filter(validSegment));
  7033. }
  7034. return clip;
  7035. };
  7036. }
  7037. function validSegment(segment) {
  7038. return segment.length > 1;
  7039. }
  7040. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7041. // and circle clipping, the same comparison is used.
  7042. function compareIntersection(a, b) {
  7043. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7044. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7045. }
  7046. var clipAntimeridian = clip(
  7047. function() { return true; },
  7048. clipAntimeridianLine,
  7049. clipAntimeridianInterpolate,
  7050. [-pi$3, -halfPi$2]
  7051. );
  7052. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7053. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7054. // intersections, and the first and last segments should be rejoined.
  7055. function clipAntimeridianLine(stream) {
  7056. var lambda0 = NaN,
  7057. phi0 = NaN,
  7058. sign0 = NaN,
  7059. clean; // no intersections
  7060. return {
  7061. lineStart: function() {
  7062. stream.lineStart();
  7063. clean = 1;
  7064. },
  7065. point: function(lambda1, phi1) {
  7066. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7067. delta = abs(lambda1 - lambda0);
  7068. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7069. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7070. stream.point(sign0, phi0);
  7071. stream.lineEnd();
  7072. stream.lineStart();
  7073. stream.point(sign1, phi0);
  7074. stream.point(lambda1, phi0);
  7075. clean = 0;
  7076. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7077. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7078. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7079. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7080. stream.point(sign0, phi0);
  7081. stream.lineEnd();
  7082. stream.lineStart();
  7083. stream.point(sign1, phi0);
  7084. clean = 0;
  7085. }
  7086. stream.point(lambda0 = lambda1, phi0 = phi1);
  7087. sign0 = sign1;
  7088. },
  7089. lineEnd: function() {
  7090. stream.lineEnd();
  7091. lambda0 = phi0 = NaN;
  7092. },
  7093. clean: function() {
  7094. return 2 - clean; // if intersections, rejoin first and last segments
  7095. }
  7096. };
  7097. }
  7098. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7099. var cosPhi0,
  7100. cosPhi1,
  7101. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7102. return abs(sinLambda0Lambda1) > epsilon$2
  7103. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7104. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7105. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7106. : (phi0 + phi1) / 2;
  7107. }
  7108. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7109. var phi;
  7110. if (from == null) {
  7111. phi = direction * halfPi$2;
  7112. stream.point(-pi$3, phi);
  7113. stream.point(0, phi);
  7114. stream.point(pi$3, phi);
  7115. stream.point(pi$3, 0);
  7116. stream.point(pi$3, -phi);
  7117. stream.point(0, -phi);
  7118. stream.point(-pi$3, -phi);
  7119. stream.point(-pi$3, 0);
  7120. stream.point(-pi$3, phi);
  7121. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7122. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7123. phi = direction * lambda / 2;
  7124. stream.point(-lambda, phi);
  7125. stream.point(0, phi);
  7126. stream.point(lambda, phi);
  7127. } else {
  7128. stream.point(to[0], to[1]);
  7129. }
  7130. }
  7131. function clipCircle(radius) {
  7132. var cr = cos$1(radius),
  7133. delta = 6 * radians,
  7134. smallRadius = cr > 0,
  7135. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7136. function interpolate(from, to, direction, stream) {
  7137. circleStream(stream, radius, delta, direction, from, to);
  7138. }
  7139. function visible(lambda, phi) {
  7140. return cos$1(lambda) * cos$1(phi) > cr;
  7141. }
  7142. // Takes a line and cuts into visible segments. Return values used for polygon
  7143. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7144. // intersections 2 - there were intersections, and the first and last segments
  7145. // should be rejoined.
  7146. function clipLine(stream) {
  7147. var point0, // previous point
  7148. c0, // code for previous point
  7149. v0, // visibility of previous point
  7150. v00, // visibility of first point
  7151. clean; // no intersections
  7152. return {
  7153. lineStart: function() {
  7154. v00 = v0 = false;
  7155. clean = 1;
  7156. },
  7157. point: function(lambda, phi) {
  7158. var point1 = [lambda, phi],
  7159. point2,
  7160. v = visible(lambda, phi),
  7161. c = smallRadius
  7162. ? v ? 0 : code(lambda, phi)
  7163. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7164. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7165. // Handle degeneracies.
  7166. // TODO ignore if not clipping polygons.
  7167. if (v !== v0) {
  7168. point2 = intersect(point0, point1);
  7169. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7170. point1[0] += epsilon$2;
  7171. point1[1] += epsilon$2;
  7172. v = visible(point1[0], point1[1]);
  7173. }
  7174. }
  7175. if (v !== v0) {
  7176. clean = 0;
  7177. if (v) {
  7178. // outside going in
  7179. stream.lineStart();
  7180. point2 = intersect(point1, point0);
  7181. stream.point(point2[0], point2[1]);
  7182. } else {
  7183. // inside going out
  7184. point2 = intersect(point0, point1);
  7185. stream.point(point2[0], point2[1]);
  7186. stream.lineEnd();
  7187. }
  7188. point0 = point2;
  7189. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7190. var t;
  7191. // If the codes for two points are different, or are both zero,
  7192. // and there this segment intersects with the small circle.
  7193. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7194. clean = 0;
  7195. if (smallRadius) {
  7196. stream.lineStart();
  7197. stream.point(t[0][0], t[0][1]);
  7198. stream.point(t[1][0], t[1][1]);
  7199. stream.lineEnd();
  7200. } else {
  7201. stream.point(t[1][0], t[1][1]);
  7202. stream.lineEnd();
  7203. stream.lineStart();
  7204. stream.point(t[0][0], t[0][1]);
  7205. }
  7206. }
  7207. }
  7208. if (v && (!point0 || !pointEqual(point0, point1))) {
  7209. stream.point(point1[0], point1[1]);
  7210. }
  7211. point0 = point1, v0 = v, c0 = c;
  7212. },
  7213. lineEnd: function() {
  7214. if (v0) stream.lineEnd();
  7215. point0 = null;
  7216. },
  7217. // Rejoin first and last segments if there were intersections and the first
  7218. // and last points were visible.
  7219. clean: function() {
  7220. return clean | ((v00 && v0) << 1);
  7221. }
  7222. };
  7223. }
  7224. // Intersects the great circle between a and b with the clip circle.
  7225. function intersect(a, b, two) {
  7226. var pa = cartesian(a),
  7227. pb = cartesian(b);
  7228. // We have two planes, n1.p = d1 and n2.p = d2.
  7229. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7230. var n1 = [1, 0, 0], // normal
  7231. n2 = cartesianCross(pa, pb),
  7232. n2n2 = cartesianDot(n2, n2),
  7233. n1n2 = n2[0], // cartesianDot(n1, n2),
  7234. determinant = n2n2 - n1n2 * n1n2;
  7235. // Two polar points.
  7236. if (!determinant) return !two && a;
  7237. var c1 = cr * n2n2 / determinant,
  7238. c2 = -cr * n1n2 / determinant,
  7239. n1xn2 = cartesianCross(n1, n2),
  7240. A = cartesianScale(n1, c1),
  7241. B = cartesianScale(n2, c2);
  7242. cartesianAddInPlace(A, B);
  7243. // Solve |p(t)|^2 = 1.
  7244. var u = n1xn2,
  7245. w = cartesianDot(A, u),
  7246. uu = cartesianDot(u, u),
  7247. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7248. if (t2 < 0) return;
  7249. var t = sqrt(t2),
  7250. q = cartesianScale(u, (-w - t) / uu);
  7251. cartesianAddInPlace(q, A);
  7252. q = spherical(q);
  7253. if (!two) return q;
  7254. // Two intersection points.
  7255. var lambda0 = a[0],
  7256. lambda1 = b[0],
  7257. phi0 = a[1],
  7258. phi1 = b[1],
  7259. z;
  7260. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7261. var delta = lambda1 - lambda0,
  7262. polar = abs(delta - pi$3) < epsilon$2,
  7263. meridian = polar || delta < epsilon$2;
  7264. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7265. // Check that the first point is between a and b.
  7266. if (meridian
  7267. ? polar
  7268. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7269. : phi0 <= q[1] && q[1] <= phi1
  7270. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7271. var q1 = cartesianScale(u, (-w + t) / uu);
  7272. cartesianAddInPlace(q1, A);
  7273. return [q, spherical(q1)];
  7274. }
  7275. }
  7276. // Generates a 4-bit vector representing the location of a point relative to
  7277. // the small circle's bounding box.
  7278. function code(lambda, phi) {
  7279. var r = smallRadius ? radius : pi$3 - radius,
  7280. code = 0;
  7281. if (lambda < -r) code |= 1; // left
  7282. else if (lambda > r) code |= 2; // right
  7283. if (phi < -r) code |= 4; // below
  7284. else if (phi > r) code |= 8; // above
  7285. return code;
  7286. }
  7287. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7288. }
  7289. function clipLine(a, b, x0, y0, x1, y1) {
  7290. var ax = a[0],
  7291. ay = a[1],
  7292. bx = b[0],
  7293. by = b[1],
  7294. t0 = 0,
  7295. t1 = 1,
  7296. dx = bx - ax,
  7297. dy = by - ay,
  7298. r;
  7299. r = x0 - ax;
  7300. if (!dx && r > 0) return;
  7301. r /= dx;
  7302. if (dx < 0) {
  7303. if (r < t0) return;
  7304. if (r < t1) t1 = r;
  7305. } else if (dx > 0) {
  7306. if (r > t1) return;
  7307. if (r > t0) t0 = r;
  7308. }
  7309. r = x1 - ax;
  7310. if (!dx && r < 0) return;
  7311. r /= dx;
  7312. if (dx < 0) {
  7313. if (r > t1) return;
  7314. if (r > t0) t0 = r;
  7315. } else if (dx > 0) {
  7316. if (r < t0) return;
  7317. if (r < t1) t1 = r;
  7318. }
  7319. r = y0 - ay;
  7320. if (!dy && r > 0) return;
  7321. r /= dy;
  7322. if (dy < 0) {
  7323. if (r < t0) return;
  7324. if (r < t1) t1 = r;
  7325. } else if (dy > 0) {
  7326. if (r > t1) return;
  7327. if (r > t0) t0 = r;
  7328. }
  7329. r = y1 - ay;
  7330. if (!dy && r < 0) return;
  7331. r /= dy;
  7332. if (dy < 0) {
  7333. if (r > t1) return;
  7334. if (r > t0) t0 = r;
  7335. } else if (dy > 0) {
  7336. if (r < t0) return;
  7337. if (r < t1) t1 = r;
  7338. }
  7339. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  7340. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  7341. return true;
  7342. }
  7343. var clipMax = 1e9, clipMin = -clipMax;
  7344. // TODO Use d3-polygon’s polygonContains here for the ring check?
  7345. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  7346. function clipRectangle(x0, y0, x1, y1) {
  7347. function visible(x, y) {
  7348. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  7349. }
  7350. function interpolate(from, to, direction, stream) {
  7351. var a = 0, a1 = 0;
  7352. if (from == null
  7353. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  7354. || comparePoint(from, to) < 0 ^ direction > 0) {
  7355. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  7356. while ((a = (a + direction + 4) % 4) !== a1);
  7357. } else {
  7358. stream.point(to[0], to[1]);
  7359. }
  7360. }
  7361. function corner(p, direction) {
  7362. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  7363. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  7364. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  7365. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  7366. }
  7367. function compareIntersection(a, b) {
  7368. return comparePoint(a.x, b.x);
  7369. }
  7370. function comparePoint(a, b) {
  7371. var ca = corner(a, 1),
  7372. cb = corner(b, 1);
  7373. return ca !== cb ? ca - cb
  7374. : ca === 0 ? b[1] - a[1]
  7375. : ca === 1 ? a[0] - b[0]
  7376. : ca === 2 ? a[1] - b[1]
  7377. : b[0] - a[0];
  7378. }
  7379. return function(stream) {
  7380. var activeStream = stream,
  7381. bufferStream = clipBuffer(),
  7382. segments,
  7383. polygon,
  7384. ring,
  7385. x__, y__, v__, // first point
  7386. x_, y_, v_, // previous point
  7387. first,
  7388. clean;
  7389. var clipStream = {
  7390. point: point,
  7391. lineStart: lineStart,
  7392. lineEnd: lineEnd,
  7393. polygonStart: polygonStart,
  7394. polygonEnd: polygonEnd
  7395. };
  7396. function point(x, y) {
  7397. if (visible(x, y)) activeStream.point(x, y);
  7398. }
  7399. function polygonInside() {
  7400. var winding = 0;
  7401. for (var i = 0, n = polygon.length; i < n; ++i) {
  7402. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  7403. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  7404. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  7405. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  7406. }
  7407. }
  7408. return winding;
  7409. }
  7410. // Buffer geometry within a polygon and then clip it en masse.
  7411. function polygonStart() {
  7412. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  7413. }
  7414. function polygonEnd() {
  7415. var startInside = polygonInside(),
  7416. cleanInside = clean && startInside,
  7417. visible = (segments = merge(segments)).length;
  7418. if (cleanInside || visible) {
  7419. stream.polygonStart();
  7420. if (cleanInside) {
  7421. stream.lineStart();
  7422. interpolate(null, null, 1, stream);
  7423. stream.lineEnd();
  7424. }
  7425. if (visible) {
  7426. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  7427. }
  7428. stream.polygonEnd();
  7429. }
  7430. activeStream = stream, segments = polygon = ring = null;
  7431. }
  7432. function lineStart() {
  7433. clipStream.point = linePoint;
  7434. if (polygon) polygon.push(ring = []);
  7435. first = true;
  7436. v_ = false;
  7437. x_ = y_ = NaN;
  7438. }
  7439. // TODO rather than special-case polygons, simply handle them separately.
  7440. // Ideally, coincident intersection points should be jittered to avoid
  7441. // clipping issues.
  7442. function lineEnd() {
  7443. if (segments) {
  7444. linePoint(x__, y__);
  7445. if (v__ && v_) bufferStream.rejoin();
  7446. segments.push(bufferStream.result());
  7447. }
  7448. clipStream.point = point;
  7449. if (v_) activeStream.lineEnd();
  7450. }
  7451. function linePoint(x, y) {
  7452. var v = visible(x, y);
  7453. if (polygon) ring.push([x, y]);
  7454. if (first) {
  7455. x__ = x, y__ = y, v__ = v;
  7456. first = false;
  7457. if (v) {
  7458. activeStream.lineStart();
  7459. activeStream.point(x, y);
  7460. }
  7461. } else {
  7462. if (v && v_) activeStream.point(x, y);
  7463. else {
  7464. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7465. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7466. if (clipLine(a, b, x0, y0, x1, y1)) {
  7467. if (!v_) {
  7468. activeStream.lineStart();
  7469. activeStream.point(a[0], a[1]);
  7470. }
  7471. activeStream.point(b[0], b[1]);
  7472. if (!v) activeStream.lineEnd();
  7473. clean = false;
  7474. } else if (v) {
  7475. activeStream.lineStart();
  7476. activeStream.point(x, y);
  7477. clean = false;
  7478. }
  7479. }
  7480. }
  7481. x_ = x, y_ = y, v_ = v;
  7482. }
  7483. return clipStream;
  7484. };
  7485. }
  7486. function extent$1() {
  7487. var x0 = 0,
  7488. y0 = 0,
  7489. x1 = 960,
  7490. y1 = 500,
  7491. cache,
  7492. cacheStream,
  7493. clip;
  7494. return clip = {
  7495. stream: function(stream) {
  7496. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7497. },
  7498. extent: function(_) {
  7499. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7500. }
  7501. };
  7502. }
  7503. var lengthSum = adder(),
  7504. lambda0$2,
  7505. sinPhi0$1,
  7506. cosPhi0$1;
  7507. var lengthStream = {
  7508. sphere: noop$2,
  7509. point: noop$2,
  7510. lineStart: lengthLineStart,
  7511. lineEnd: noop$2,
  7512. polygonStart: noop$2,
  7513. polygonEnd: noop$2
  7514. };
  7515. function lengthLineStart() {
  7516. lengthStream.point = lengthPointFirst;
  7517. lengthStream.lineEnd = lengthLineEnd;
  7518. }
  7519. function lengthLineEnd() {
  7520. lengthStream.point = lengthStream.lineEnd = noop$2;
  7521. }
  7522. function lengthPointFirst(lambda, phi) {
  7523. lambda *= radians, phi *= radians;
  7524. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7525. lengthStream.point = lengthPoint;
  7526. }
  7527. function lengthPoint(lambda, phi) {
  7528. lambda *= radians, phi *= radians;
  7529. var sinPhi = sin$1(phi),
  7530. cosPhi = cos$1(phi),
  7531. delta = abs(lambda - lambda0$2),
  7532. cosDelta = cos$1(delta),
  7533. sinDelta = sin$1(delta),
  7534. x = cosPhi * sinDelta,
  7535. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7536. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7537. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7538. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7539. }
  7540. function length$1(object) {
  7541. lengthSum.reset();
  7542. geoStream(object, lengthStream);
  7543. return +lengthSum;
  7544. }
  7545. var coordinates = [null, null],
  7546. object$1 = {type: "LineString", coordinates: coordinates};
  7547. function distance(a, b) {
  7548. coordinates[0] = a;
  7549. coordinates[1] = b;
  7550. return length$1(object$1);
  7551. }
  7552. var containsObjectType = {
  7553. Feature: function(object, point) {
  7554. return containsGeometry(object.geometry, point);
  7555. },
  7556. FeatureCollection: function(object, point) {
  7557. var features = object.features, i = -1, n = features.length;
  7558. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7559. return false;
  7560. }
  7561. };
  7562. var containsGeometryType = {
  7563. Sphere: function() {
  7564. return true;
  7565. },
  7566. Point: function(object, point) {
  7567. return containsPoint(object.coordinates, point);
  7568. },
  7569. MultiPoint: function(object, point) {
  7570. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7571. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7572. return false;
  7573. },
  7574. LineString: function(object, point) {
  7575. return containsLine(object.coordinates, point);
  7576. },
  7577. MultiLineString: function(object, point) {
  7578. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7579. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7580. return false;
  7581. },
  7582. Polygon: function(object, point) {
  7583. return containsPolygon(object.coordinates, point);
  7584. },
  7585. MultiPolygon: function(object, point) {
  7586. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7587. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7588. return false;
  7589. },
  7590. GeometryCollection: function(object, point) {
  7591. var geometries = object.geometries, i = -1, n = geometries.length;
  7592. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7593. return false;
  7594. }
  7595. };
  7596. function containsGeometry(geometry, point) {
  7597. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7598. ? containsGeometryType[geometry.type](geometry, point)
  7599. : false;
  7600. }
  7601. function containsPoint(coordinates, point) {
  7602. return distance(coordinates, point) === 0;
  7603. }
  7604. function containsLine(coordinates, point) {
  7605. var ab = distance(coordinates[0], coordinates[1]),
  7606. ao = distance(coordinates[0], point),
  7607. ob = distance(point, coordinates[1]);
  7608. return ao + ob <= ab + epsilon$2;
  7609. }
  7610. function containsPolygon(coordinates, point) {
  7611. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7612. }
  7613. function ringRadians(ring) {
  7614. return ring = ring.map(pointRadians), ring.pop(), ring;
  7615. }
  7616. function pointRadians(point) {
  7617. return [point[0] * radians, point[1] * radians];
  7618. }
  7619. function contains$1(object, point) {
  7620. return (object && containsObjectType.hasOwnProperty(object.type)
  7621. ? containsObjectType[object.type]
  7622. : containsGeometry)(object, point);
  7623. }
  7624. function graticuleX(y0, y1, dy) {
  7625. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7626. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7627. }
  7628. function graticuleY(x0, x1, dx) {
  7629. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7630. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7631. }
  7632. function graticule() {
  7633. var x1, x0, X1, X0,
  7634. y1, y0, Y1, Y0,
  7635. dx = 10, dy = dx, DX = 90, DY = 360,
  7636. x, y, X, Y,
  7637. precision = 2.5;
  7638. function graticule() {
  7639. return {type: "MultiLineString", coordinates: lines()};
  7640. }
  7641. function lines() {
  7642. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7643. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7644. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7645. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7646. }
  7647. graticule.lines = function() {
  7648. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7649. };
  7650. graticule.outline = function() {
  7651. return {
  7652. type: "Polygon",
  7653. coordinates: [
  7654. X(X0).concat(
  7655. Y(Y1).slice(1),
  7656. X(X1).reverse().slice(1),
  7657. Y(Y0).reverse().slice(1))
  7658. ]
  7659. };
  7660. };
  7661. graticule.extent = function(_) {
  7662. if (!arguments.length) return graticule.extentMinor();
  7663. return graticule.extentMajor(_).extentMinor(_);
  7664. };
  7665. graticule.extentMajor = function(_) {
  7666. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7667. X0 = +_[0][0], X1 = +_[1][0];
  7668. Y0 = +_[0][1], Y1 = +_[1][1];
  7669. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7670. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7671. return graticule.precision(precision);
  7672. };
  7673. graticule.extentMinor = function(_) {
  7674. if (!arguments.length) return [[x0, y0], [x1, y1]];
  7675. x0 = +_[0][0], x1 = +_[1][0];
  7676. y0 = +_[0][1], y1 = +_[1][1];
  7677. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  7678. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  7679. return graticule.precision(precision);
  7680. };
  7681. graticule.step = function(_) {
  7682. if (!arguments.length) return graticule.stepMinor();
  7683. return graticule.stepMajor(_).stepMinor(_);
  7684. };
  7685. graticule.stepMajor = function(_) {
  7686. if (!arguments.length) return [DX, DY];
  7687. DX = +_[0], DY = +_[1];
  7688. return graticule;
  7689. };
  7690. graticule.stepMinor = function(_) {
  7691. if (!arguments.length) return [dx, dy];
  7692. dx = +_[0], dy = +_[1];
  7693. return graticule;
  7694. };
  7695. graticule.precision = function(_) {
  7696. if (!arguments.length) return precision;
  7697. precision = +_;
  7698. x = graticuleX(y0, y1, 90);
  7699. y = graticuleY(x0, x1, precision);
  7700. X = graticuleX(Y0, Y1, 90);
  7701. Y = graticuleY(X0, X1, precision);
  7702. return graticule;
  7703. };
  7704. return graticule
  7705. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7706. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7707. }
  7708. function graticule10() {
  7709. return graticule()();
  7710. }
  7711. function interpolate$1(a, b) {
  7712. var x0 = a[0] * radians,
  7713. y0 = a[1] * radians,
  7714. x1 = b[0] * radians,
  7715. y1 = b[1] * radians,
  7716. cy0 = cos$1(y0),
  7717. sy0 = sin$1(y0),
  7718. cy1 = cos$1(y1),
  7719. sy1 = sin$1(y1),
  7720. kx0 = cy0 * cos$1(x0),
  7721. ky0 = cy0 * sin$1(x0),
  7722. kx1 = cy1 * cos$1(x1),
  7723. ky1 = cy1 * sin$1(x1),
  7724. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  7725. k = sin$1(d);
  7726. var interpolate = d ? function(t) {
  7727. var B = sin$1(t *= d) / k,
  7728. A = sin$1(d - t) / k,
  7729. x = A * kx0 + B * kx1,
  7730. y = A * ky0 + B * ky1,
  7731. z = A * sy0 + B * sy1;
  7732. return [
  7733. atan2(y, x) * degrees$1,
  7734. atan2(z, sqrt(x * x + y * y)) * degrees$1
  7735. ];
  7736. } : function() {
  7737. return [x0 * degrees$1, y0 * degrees$1];
  7738. };
  7739. interpolate.distance = d;
  7740. return interpolate;
  7741. }
  7742. function identity$4(x) {
  7743. return x;
  7744. }
  7745. var areaSum$1 = adder(),
  7746. areaRingSum$1 = adder(),
  7747. x00,
  7748. y00,
  7749. x0$1,
  7750. y0$1;
  7751. var areaStream$1 = {
  7752. point: noop$2,
  7753. lineStart: noop$2,
  7754. lineEnd: noop$2,
  7755. polygonStart: function() {
  7756. areaStream$1.lineStart = areaRingStart$1;
  7757. areaStream$1.lineEnd = areaRingEnd$1;
  7758. },
  7759. polygonEnd: function() {
  7760. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  7761. areaSum$1.add(abs(areaRingSum$1));
  7762. areaRingSum$1.reset();
  7763. },
  7764. result: function() {
  7765. var area = areaSum$1 / 2;
  7766. areaSum$1.reset();
  7767. return area;
  7768. }
  7769. };
  7770. function areaRingStart$1() {
  7771. areaStream$1.point = areaPointFirst$1;
  7772. }
  7773. function areaPointFirst$1(x, y) {
  7774. areaStream$1.point = areaPoint$1;
  7775. x00 = x0$1 = x, y00 = y0$1 = y;
  7776. }
  7777. function areaPoint$1(x, y) {
  7778. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  7779. x0$1 = x, y0$1 = y;
  7780. }
  7781. function areaRingEnd$1() {
  7782. areaPoint$1(x00, y00);
  7783. }
  7784. var x0$2 = Infinity,
  7785. y0$2 = x0$2,
  7786. x1 = -x0$2,
  7787. y1 = x1;
  7788. var boundsStream$1 = {
  7789. point: boundsPoint$1,
  7790. lineStart: noop$2,
  7791. lineEnd: noop$2,
  7792. polygonStart: noop$2,
  7793. polygonEnd: noop$2,
  7794. result: function() {
  7795. var bounds = [[x0$2, y0$2], [x1, y1]];
  7796. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  7797. return bounds;
  7798. }
  7799. };
  7800. function boundsPoint$1(x, y) {
  7801. if (x < x0$2) x0$2 = x;
  7802. if (x > x1) x1 = x;
  7803. if (y < y0$2) y0$2 = y;
  7804. if (y > y1) y1 = y;
  7805. }
  7806. // TODO Enforce positive area for exterior, negative area for interior?
  7807. var X0$1 = 0,
  7808. Y0$1 = 0,
  7809. Z0$1 = 0,
  7810. X1$1 = 0,
  7811. Y1$1 = 0,
  7812. Z1$1 = 0,
  7813. X2$1 = 0,
  7814. Y2$1 = 0,
  7815. Z2$1 = 0,
  7816. x00$1,
  7817. y00$1,
  7818. x0$3,
  7819. y0$3;
  7820. var centroidStream$1 = {
  7821. point: centroidPoint$1,
  7822. lineStart: centroidLineStart$1,
  7823. lineEnd: centroidLineEnd$1,
  7824. polygonStart: function() {
  7825. centroidStream$1.lineStart = centroidRingStart$1;
  7826. centroidStream$1.lineEnd = centroidRingEnd$1;
  7827. },
  7828. polygonEnd: function() {
  7829. centroidStream$1.point = centroidPoint$1;
  7830. centroidStream$1.lineStart = centroidLineStart$1;
  7831. centroidStream$1.lineEnd = centroidLineEnd$1;
  7832. },
  7833. result: function() {
  7834. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  7835. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  7836. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  7837. : [NaN, NaN];
  7838. X0$1 = Y0$1 = Z0$1 =
  7839. X1$1 = Y1$1 = Z1$1 =
  7840. X2$1 = Y2$1 = Z2$1 = 0;
  7841. return centroid;
  7842. }
  7843. };
  7844. function centroidPoint$1(x, y) {
  7845. X0$1 += x;
  7846. Y0$1 += y;
  7847. ++Z0$1;
  7848. }
  7849. function centroidLineStart$1() {
  7850. centroidStream$1.point = centroidPointFirstLine;
  7851. }
  7852. function centroidPointFirstLine(x, y) {
  7853. centroidStream$1.point = centroidPointLine;
  7854. centroidPoint$1(x0$3 = x, y0$3 = y);
  7855. }
  7856. function centroidPointLine(x, y) {
  7857. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  7858. X1$1 += z * (x0$3 + x) / 2;
  7859. Y1$1 += z * (y0$3 + y) / 2;
  7860. Z1$1 += z;
  7861. centroidPoint$1(x0$3 = x, y0$3 = y);
  7862. }
  7863. function centroidLineEnd$1() {
  7864. centroidStream$1.point = centroidPoint$1;
  7865. }
  7866. function centroidRingStart$1() {
  7867. centroidStream$1.point = centroidPointFirstRing;
  7868. }
  7869. function centroidRingEnd$1() {
  7870. centroidPointRing(x00$1, y00$1);
  7871. }
  7872. function centroidPointFirstRing(x, y) {
  7873. centroidStream$1.point = centroidPointRing;
  7874. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  7875. }
  7876. function centroidPointRing(x, y) {
  7877. var dx = x - x0$3,
  7878. dy = y - y0$3,
  7879. z = sqrt(dx * dx + dy * dy);
  7880. X1$1 += z * (x0$3 + x) / 2;
  7881. Y1$1 += z * (y0$3 + y) / 2;
  7882. Z1$1 += z;
  7883. z = y0$3 * x - x0$3 * y;
  7884. X2$1 += z * (x0$3 + x);
  7885. Y2$1 += z * (y0$3 + y);
  7886. Z2$1 += z * 3;
  7887. centroidPoint$1(x0$3 = x, y0$3 = y);
  7888. }
  7889. function PathContext(context) {
  7890. this._context = context;
  7891. }
  7892. PathContext.prototype = {
  7893. _radius: 4.5,
  7894. pointRadius: function(_) {
  7895. return this._radius = _, this;
  7896. },
  7897. polygonStart: function() {
  7898. this._line = 0;
  7899. },
  7900. polygonEnd: function() {
  7901. this._line = NaN;
  7902. },
  7903. lineStart: function() {
  7904. this._point = 0;
  7905. },
  7906. lineEnd: function() {
  7907. if (this._line === 0) this._context.closePath();
  7908. this._point = NaN;
  7909. },
  7910. point: function(x, y) {
  7911. switch (this._point) {
  7912. case 0: {
  7913. this._context.moveTo(x, y);
  7914. this._point = 1;
  7915. break;
  7916. }
  7917. case 1: {
  7918. this._context.lineTo(x, y);
  7919. break;
  7920. }
  7921. default: {
  7922. this._context.moveTo(x + this._radius, y);
  7923. this._context.arc(x, y, this._radius, 0, tau$3);
  7924. break;
  7925. }
  7926. }
  7927. },
  7928. result: noop$2
  7929. };
  7930. var lengthSum$1 = adder(),
  7931. lengthRing,
  7932. x00$2,
  7933. y00$2,
  7934. x0$4,
  7935. y0$4;
  7936. var lengthStream$1 = {
  7937. point: noop$2,
  7938. lineStart: function() {
  7939. lengthStream$1.point = lengthPointFirst$1;
  7940. },
  7941. lineEnd: function() {
  7942. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  7943. lengthStream$1.point = noop$2;
  7944. },
  7945. polygonStart: function() {
  7946. lengthRing = true;
  7947. },
  7948. polygonEnd: function() {
  7949. lengthRing = null;
  7950. },
  7951. result: function() {
  7952. var length = +lengthSum$1;
  7953. lengthSum$1.reset();
  7954. return length;
  7955. }
  7956. };
  7957. function lengthPointFirst$1(x, y) {
  7958. lengthStream$1.point = lengthPoint$1;
  7959. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  7960. }
  7961. function lengthPoint$1(x, y) {
  7962. x0$4 -= x, y0$4 -= y;
  7963. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  7964. x0$4 = x, y0$4 = y;
  7965. }
  7966. function PathString() {
  7967. this._string = [];
  7968. }
  7969. PathString.prototype = {
  7970. _radius: 4.5,
  7971. _circle: circle$1(4.5),
  7972. pointRadius: function(_) {
  7973. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  7974. return this;
  7975. },
  7976. polygonStart: function() {
  7977. this._line = 0;
  7978. },
  7979. polygonEnd: function() {
  7980. this._line = NaN;
  7981. },
  7982. lineStart: function() {
  7983. this._point = 0;
  7984. },
  7985. lineEnd: function() {
  7986. if (this._line === 0) this._string.push("Z");
  7987. this._point = NaN;
  7988. },
  7989. point: function(x, y) {
  7990. switch (this._point) {
  7991. case 0: {
  7992. this._string.push("M", x, ",", y);
  7993. this._point = 1;
  7994. break;
  7995. }
  7996. case 1: {
  7997. this._string.push("L", x, ",", y);
  7998. break;
  7999. }
  8000. default: {
  8001. if (this._circle == null) this._circle = circle$1(this._radius);
  8002. this._string.push("M", x, ",", y, this._circle);
  8003. break;
  8004. }
  8005. }
  8006. },
  8007. result: function() {
  8008. if (this._string.length) {
  8009. var result = this._string.join("");
  8010. this._string = [];
  8011. return result;
  8012. } else {
  8013. return null;
  8014. }
  8015. }
  8016. };
  8017. function circle$1(radius) {
  8018. return "m0," + radius
  8019. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  8020. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  8021. + "z";
  8022. }
  8023. function index$1(projection, context) {
  8024. var pointRadius = 4.5,
  8025. projectionStream,
  8026. contextStream;
  8027. function path(object) {
  8028. if (object) {
  8029. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  8030. geoStream(object, projectionStream(contextStream));
  8031. }
  8032. return contextStream.result();
  8033. }
  8034. path.area = function(object) {
  8035. geoStream(object, projectionStream(areaStream$1));
  8036. return areaStream$1.result();
  8037. };
  8038. path.measure = function(object) {
  8039. geoStream(object, projectionStream(lengthStream$1));
  8040. return lengthStream$1.result();
  8041. };
  8042. path.bounds = function(object) {
  8043. geoStream(object, projectionStream(boundsStream$1));
  8044. return boundsStream$1.result();
  8045. };
  8046. path.centroid = function(object) {
  8047. geoStream(object, projectionStream(centroidStream$1));
  8048. return centroidStream$1.result();
  8049. };
  8050. path.projection = function(_) {
  8051. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  8052. };
  8053. path.context = function(_) {
  8054. if (!arguments.length) return context;
  8055. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  8056. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  8057. return path;
  8058. };
  8059. path.pointRadius = function(_) {
  8060. if (!arguments.length) return pointRadius;
  8061. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  8062. return path;
  8063. };
  8064. return path.projection(projection).context(context);
  8065. }
  8066. function transform(methods) {
  8067. return {
  8068. stream: transformer(methods)
  8069. };
  8070. }
  8071. function transformer(methods) {
  8072. return function(stream) {
  8073. var s = new TransformStream;
  8074. for (var key in methods) s[key] = methods[key];
  8075. s.stream = stream;
  8076. return s;
  8077. };
  8078. }
  8079. function TransformStream() {}
  8080. TransformStream.prototype = {
  8081. constructor: TransformStream,
  8082. point: function(x, y) { this.stream.point(x, y); },
  8083. sphere: function() { this.stream.sphere(); },
  8084. lineStart: function() { this.stream.lineStart(); },
  8085. lineEnd: function() { this.stream.lineEnd(); },
  8086. polygonStart: function() { this.stream.polygonStart(); },
  8087. polygonEnd: function() { this.stream.polygonEnd(); }
  8088. };
  8089. function fit(projection, fitBounds, object) {
  8090. var clip = projection.clipExtent && projection.clipExtent();
  8091. projection.scale(150).translate([0, 0]);
  8092. if (clip != null) projection.clipExtent(null);
  8093. geoStream(object, projection.stream(boundsStream$1));
  8094. fitBounds(boundsStream$1.result());
  8095. if (clip != null) projection.clipExtent(clip);
  8096. return projection;
  8097. }
  8098. function fitExtent(projection, extent, object) {
  8099. return fit(projection, function(b) {
  8100. var w = extent[1][0] - extent[0][0],
  8101. h = extent[1][1] - extent[0][1],
  8102. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  8103. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  8104. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  8105. projection.scale(150 * k).translate([x, y]);
  8106. }, object);
  8107. }
  8108. function fitSize(projection, size, object) {
  8109. return fitExtent(projection, [[0, 0], size], object);
  8110. }
  8111. function fitWidth(projection, width, object) {
  8112. return fit(projection, function(b) {
  8113. var w = +width,
  8114. k = w / (b[1][0] - b[0][0]),
  8115. x = (w - k * (b[1][0] + b[0][0])) / 2,
  8116. y = -k * b[0][1];
  8117. projection.scale(150 * k).translate([x, y]);
  8118. }, object);
  8119. }
  8120. function fitHeight(projection, height, object) {
  8121. return fit(projection, function(b) {
  8122. var h = +height,
  8123. k = h / (b[1][1] - b[0][1]),
  8124. x = -k * b[0][0],
  8125. y = (h - k * (b[1][1] + b[0][1])) / 2;
  8126. projection.scale(150 * k).translate([x, y]);
  8127. }, object);
  8128. }
  8129. var maxDepth = 16, // maximum depth of subdivision
  8130. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  8131. function resample(project, delta2) {
  8132. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  8133. }
  8134. function resampleNone(project) {
  8135. return transformer({
  8136. point: function(x, y) {
  8137. x = project(x, y);
  8138. this.stream.point(x[0], x[1]);
  8139. }
  8140. });
  8141. }
  8142. function resample$1(project, delta2) {
  8143. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  8144. var dx = x1 - x0,
  8145. dy = y1 - y0,
  8146. d2 = dx * dx + dy * dy;
  8147. if (d2 > 4 * delta2 && depth--) {
  8148. var a = a0 + a1,
  8149. b = b0 + b1,
  8150. c = c0 + c1,
  8151. m = sqrt(a * a + b * b + c * c),
  8152. phi2 = asin(c /= m),
  8153. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  8154. p = project(lambda2, phi2),
  8155. x2 = p[0],
  8156. y2 = p[1],
  8157. dx2 = x2 - x0,
  8158. dy2 = y2 - y0,
  8159. dz = dy * dx2 - dx * dy2;
  8160. if (dz * dz / d2 > delta2 // perpendicular projected distance
  8161. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  8162. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  8163. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  8164. stream.point(x2, y2);
  8165. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  8166. }
  8167. }
  8168. }
  8169. return function(stream) {
  8170. var lambda00, x00, y00, a00, b00, c00, // first point
  8171. lambda0, x0, y0, a0, b0, c0; // previous point
  8172. var resampleStream = {
  8173. point: point,
  8174. lineStart: lineStart,
  8175. lineEnd: lineEnd,
  8176. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  8177. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  8178. };
  8179. function point(x, y) {
  8180. x = project(x, y);
  8181. stream.point(x[0], x[1]);
  8182. }
  8183. function lineStart() {
  8184. x0 = NaN;
  8185. resampleStream.point = linePoint;
  8186. stream.lineStart();
  8187. }
  8188. function linePoint(lambda, phi) {
  8189. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  8190. 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);
  8191. stream.point(x0, y0);
  8192. }
  8193. function lineEnd() {
  8194. resampleStream.point = point;
  8195. stream.lineEnd();
  8196. }
  8197. function ringStart() {
  8198. lineStart();
  8199. resampleStream.point = ringPoint;
  8200. resampleStream.lineEnd = ringEnd;
  8201. }
  8202. function ringPoint(lambda, phi) {
  8203. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  8204. resampleStream.point = linePoint;
  8205. }
  8206. function ringEnd() {
  8207. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  8208. resampleStream.lineEnd = lineEnd;
  8209. lineEnd();
  8210. }
  8211. return resampleStream;
  8212. };
  8213. }
  8214. var transformRadians = transformer({
  8215. point: function(x, y) {
  8216. this.stream.point(x * radians, y * radians);
  8217. }
  8218. });
  8219. function transformRotate(rotate) {
  8220. return transformer({
  8221. point: function(x, y) {
  8222. var r = rotate(x, y);
  8223. return this.stream.point(r[0], r[1]);
  8224. }
  8225. });
  8226. }
  8227. function scaleTranslate(k, dx, dy) {
  8228. function transform$$1(x, y) {
  8229. return [dx + k * x, dy - k * y];
  8230. }
  8231. transform$$1.invert = function(x, y) {
  8232. return [(x - dx) / k, (dy - y) / k];
  8233. };
  8234. return transform$$1;
  8235. }
  8236. function scaleTranslateRotate(k, dx, dy, alpha) {
  8237. var cosAlpha = cos$1(alpha),
  8238. sinAlpha = sin$1(alpha),
  8239. a = cosAlpha * k,
  8240. b = sinAlpha * k,
  8241. ai = cosAlpha / k,
  8242. bi = sinAlpha / k,
  8243. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  8244. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  8245. function transform$$1(x, y) {
  8246. return [a * x - b * y + dx, dy - b * x - a * y];
  8247. }
  8248. transform$$1.invert = function(x, y) {
  8249. return [ai * x - bi * y + ci, fi - bi * x - ai * y];
  8250. };
  8251. return transform$$1;
  8252. }
  8253. function projection(project) {
  8254. return projectionMutator(function() { return project; })();
  8255. }
  8256. function projectionMutator(projectAt) {
  8257. var project,
  8258. k = 150, // scale
  8259. x = 480, y = 250, // translate
  8260. lambda = 0, phi = 0, // center
  8261. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  8262. alpha = 0, // post-rotate
  8263. theta = null, preclip = clipAntimeridian, // pre-clip angle
  8264. x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
  8265. delta2 = 0.5, // precision
  8266. projectResample,
  8267. projectTransform,
  8268. projectRotateTransform,
  8269. cache,
  8270. cacheStream;
  8271. function projection(point) {
  8272. return projectRotateTransform(point[0] * radians, point[1] * radians);
  8273. }
  8274. function invert(point) {
  8275. point = projectRotateTransform.invert(point[0], point[1]);
  8276. return point && [point[0] * degrees$1, point[1] * degrees$1];
  8277. }
  8278. projection.stream = function(stream) {
  8279. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  8280. };
  8281. projection.preclip = function(_) {
  8282. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  8283. };
  8284. projection.postclip = function(_) {
  8285. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8286. };
  8287. projection.clipAngle = function(_) {
  8288. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  8289. };
  8290. projection.clipExtent = function(_) {
  8291. 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]];
  8292. };
  8293. projection.scale = function(_) {
  8294. return arguments.length ? (k = +_, recenter()) : k;
  8295. };
  8296. projection.translate = function(_) {
  8297. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  8298. };
  8299. projection.center = function(_) {
  8300. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  8301. };
  8302. projection.rotate = function(_) {
  8303. 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];
  8304. };
  8305. projection.angle = function(_) {
  8306. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
  8307. };
  8308. projection.precision = function(_) {
  8309. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  8310. };
  8311. projection.fitExtent = function(extent, object) {
  8312. return fitExtent(projection, extent, object);
  8313. };
  8314. projection.fitSize = function(size, object) {
  8315. return fitSize(projection, size, object);
  8316. };
  8317. projection.fitWidth = function(width, object) {
  8318. return fitWidth(projection, width, object);
  8319. };
  8320. projection.fitHeight = function(height, object) {
  8321. return fitHeight(projection, height, object);
  8322. };
  8323. function recenter() {
  8324. var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
  8325. transform$$1 = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
  8326. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  8327. projectTransform = compose(project, transform$$1);
  8328. projectRotateTransform = compose(rotate, projectTransform);
  8329. projectResample = resample(projectTransform, delta2);
  8330. return reset();
  8331. }
  8332. function reset() {
  8333. cache = cacheStream = null;
  8334. return projection;
  8335. }
  8336. return function() {
  8337. project = projectAt.apply(this, arguments);
  8338. projection.invert = project.invert && invert;
  8339. return recenter();
  8340. };
  8341. }
  8342. function conicProjection(projectAt) {
  8343. var phi0 = 0,
  8344. phi1 = pi$3 / 3,
  8345. m = projectionMutator(projectAt),
  8346. p = m(phi0, phi1);
  8347. p.parallels = function(_) {
  8348. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  8349. };
  8350. return p;
  8351. }
  8352. function cylindricalEqualAreaRaw(phi0) {
  8353. var cosPhi0 = cos$1(phi0);
  8354. function forward(lambda, phi) {
  8355. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  8356. }
  8357. forward.invert = function(x, y) {
  8358. return [x / cosPhi0, asin(y * cosPhi0)];
  8359. };
  8360. return forward;
  8361. }
  8362. function conicEqualAreaRaw(y0, y1) {
  8363. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  8364. // Are the parallels symmetrical around the Equator?
  8365. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  8366. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  8367. function project(x, y) {
  8368. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  8369. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  8370. }
  8371. project.invert = function(x, y) {
  8372. var r0y = r0 - y;
  8373. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  8374. };
  8375. return project;
  8376. }
  8377. function conicEqualArea() {
  8378. return conicProjection(conicEqualAreaRaw)
  8379. .scale(155.424)
  8380. .center([0, 33.6442]);
  8381. }
  8382. function albers() {
  8383. return conicEqualArea()
  8384. .parallels([29.5, 45.5])
  8385. .scale(1070)
  8386. .translate([480, 250])
  8387. .rotate([96, 0])
  8388. .center([-0.6, 38.7]);
  8389. }
  8390. // The projections must have mutually exclusive clip regions on the sphere,
  8391. // as this will avoid emitting interleaving lines and polygons.
  8392. function multiplex(streams) {
  8393. var n = streams.length;
  8394. return {
  8395. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  8396. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  8397. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  8398. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  8399. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  8400. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  8401. };
  8402. }
  8403. // A composite projection for the United States, configured by default for
  8404. // 960×500. The projection also works quite well at 960×600 if you change the
  8405. // scale to 1285 and adjust the translate accordingly. The set of standard
  8406. // parallels for each region comes from USGS, which is published here:
  8407. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  8408. function albersUsa() {
  8409. var cache,
  8410. cacheStream,
  8411. lower48 = albers(), lower48Point,
  8412. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  8413. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  8414. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  8415. function albersUsa(coordinates) {
  8416. var x = coordinates[0], y = coordinates[1];
  8417. return point = null, (lower48Point.point(x, y), point)
  8418. || (alaskaPoint.point(x, y), point)
  8419. || (hawaiiPoint.point(x, y), point);
  8420. }
  8421. albersUsa.invert = function(coordinates) {
  8422. var k = lower48.scale(),
  8423. t = lower48.translate(),
  8424. x = (coordinates[0] - t[0]) / k,
  8425. y = (coordinates[1] - t[1]) / k;
  8426. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  8427. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  8428. : lower48).invert(coordinates);
  8429. };
  8430. albersUsa.stream = function(stream) {
  8431. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  8432. };
  8433. albersUsa.precision = function(_) {
  8434. if (!arguments.length) return lower48.precision();
  8435. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  8436. return reset();
  8437. };
  8438. albersUsa.scale = function(_) {
  8439. if (!arguments.length) return lower48.scale();
  8440. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  8441. return albersUsa.translate(lower48.translate());
  8442. };
  8443. albersUsa.translate = function(_) {
  8444. if (!arguments.length) return lower48.translate();
  8445. var k = lower48.scale(), x = +_[0], y = +_[1];
  8446. lower48Point = lower48
  8447. .translate(_)
  8448. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  8449. .stream(pointStream);
  8450. alaskaPoint = alaska
  8451. .translate([x - 0.307 * k, y + 0.201 * k])
  8452. .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]])
  8453. .stream(pointStream);
  8454. hawaiiPoint = hawaii
  8455. .translate([x - 0.205 * k, y + 0.212 * k])
  8456. .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]])
  8457. .stream(pointStream);
  8458. return reset();
  8459. };
  8460. albersUsa.fitExtent = function(extent, object) {
  8461. return fitExtent(albersUsa, extent, object);
  8462. };
  8463. albersUsa.fitSize = function(size, object) {
  8464. return fitSize(albersUsa, size, object);
  8465. };
  8466. albersUsa.fitWidth = function(width, object) {
  8467. return fitWidth(albersUsa, width, object);
  8468. };
  8469. albersUsa.fitHeight = function(height, object) {
  8470. return fitHeight(albersUsa, height, object);
  8471. };
  8472. function reset() {
  8473. cache = cacheStream = null;
  8474. return albersUsa;
  8475. }
  8476. return albersUsa.scale(1070);
  8477. }
  8478. function azimuthalRaw(scale) {
  8479. return function(x, y) {
  8480. var cx = cos$1(x),
  8481. cy = cos$1(y),
  8482. k = scale(cx * cy);
  8483. return [
  8484. k * cy * sin$1(x),
  8485. k * sin$1(y)
  8486. ];
  8487. }
  8488. }
  8489. function azimuthalInvert(angle) {
  8490. return function(x, y) {
  8491. var z = sqrt(x * x + y * y),
  8492. c = angle(z),
  8493. sc = sin$1(c),
  8494. cc = cos$1(c);
  8495. return [
  8496. atan2(x * sc, z * cc),
  8497. asin(z && y * sc / z)
  8498. ];
  8499. }
  8500. }
  8501. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8502. return sqrt(2 / (1 + cxcy));
  8503. });
  8504. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8505. return 2 * asin(z / 2);
  8506. });
  8507. function azimuthalEqualArea() {
  8508. return projection(azimuthalEqualAreaRaw)
  8509. .scale(124.75)
  8510. .clipAngle(180 - 1e-3);
  8511. }
  8512. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8513. return (c = acos(c)) && c / sin$1(c);
  8514. });
  8515. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8516. return z;
  8517. });
  8518. function azimuthalEquidistant() {
  8519. return projection(azimuthalEquidistantRaw)
  8520. .scale(79.4188)
  8521. .clipAngle(180 - 1e-3);
  8522. }
  8523. function mercatorRaw(lambda, phi) {
  8524. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8525. }
  8526. mercatorRaw.invert = function(x, y) {
  8527. return [x, 2 * atan(exp(y)) - halfPi$2];
  8528. };
  8529. function mercator() {
  8530. return mercatorProjection(mercatorRaw)
  8531. .scale(961 / tau$3);
  8532. }
  8533. function mercatorProjection(project) {
  8534. var m = projection(project),
  8535. center = m.center,
  8536. scale = m.scale,
  8537. translate = m.translate,
  8538. clipExtent = m.clipExtent,
  8539. x0 = null, y0, x1, y1; // clip extent
  8540. m.scale = function(_) {
  8541. return arguments.length ? (scale(_), reclip()) : scale();
  8542. };
  8543. m.translate = function(_) {
  8544. return arguments.length ? (translate(_), reclip()) : translate();
  8545. };
  8546. m.center = function(_) {
  8547. return arguments.length ? (center(_), reclip()) : center();
  8548. };
  8549. m.clipExtent = function(_) {
  8550. 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]];
  8551. };
  8552. function reclip() {
  8553. var k = pi$3 * scale(),
  8554. t = m(rotation(m.rotate()).invert([0, 0]));
  8555. return clipExtent(x0 == null
  8556. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8557. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8558. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8559. }
  8560. return reclip();
  8561. }
  8562. function tany(y) {
  8563. return tan((halfPi$2 + y) / 2);
  8564. }
  8565. function conicConformalRaw(y0, y1) {
  8566. var cy0 = cos$1(y0),
  8567. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8568. f = cy0 * pow(tany(y0), n) / n;
  8569. if (!n) return mercatorRaw;
  8570. function project(x, y) {
  8571. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8572. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8573. var r = f / pow(tany(y), n);
  8574. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8575. }
  8576. project.invert = function(x, y) {
  8577. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8578. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8579. };
  8580. return project;
  8581. }
  8582. function conicConformal() {
  8583. return conicProjection(conicConformalRaw)
  8584. .scale(109.5)
  8585. .parallels([30, 30]);
  8586. }
  8587. function equirectangularRaw(lambda, phi) {
  8588. return [lambda, phi];
  8589. }
  8590. equirectangularRaw.invert = equirectangularRaw;
  8591. function equirectangular() {
  8592. return projection(equirectangularRaw)
  8593. .scale(152.63);
  8594. }
  8595. function conicEquidistantRaw(y0, y1) {
  8596. var cy0 = cos$1(y0),
  8597. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8598. g = cy0 / n + y0;
  8599. if (abs(n) < epsilon$2) return equirectangularRaw;
  8600. function project(x, y) {
  8601. var gy = g - y, nx = n * x;
  8602. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8603. }
  8604. project.invert = function(x, y) {
  8605. var gy = g - y;
  8606. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8607. };
  8608. return project;
  8609. }
  8610. function conicEquidistant() {
  8611. return conicProjection(conicEquidistantRaw)
  8612. .scale(131.154)
  8613. .center([0, 13.9389]);
  8614. }
  8615. function gnomonicRaw(x, y) {
  8616. var cy = cos$1(y), k = cos$1(x) * cy;
  8617. return [cy * sin$1(x) / k, sin$1(y) / k];
  8618. }
  8619. gnomonicRaw.invert = azimuthalInvert(atan);
  8620. function gnomonic() {
  8621. return projection(gnomonicRaw)
  8622. .scale(144.049)
  8623. .clipAngle(60);
  8624. }
  8625. function scaleTranslate$1(kx, ky, tx, ty) {
  8626. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8627. point: function(x, y) {
  8628. this.stream.point(x * kx + tx, y * ky + ty);
  8629. }
  8630. });
  8631. }
  8632. function identity$5() {
  8633. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
  8634. x0 = null, y0, x1, y1, // clip extent
  8635. postclip = identity$4,
  8636. cache,
  8637. cacheStream,
  8638. projection;
  8639. function reset() {
  8640. cache = cacheStream = null;
  8641. return projection;
  8642. }
  8643. return projection = {
  8644. stream: function(stream) {
  8645. return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
  8646. },
  8647. postclip: function(_) {
  8648. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8649. },
  8650. clipExtent: function(_) {
  8651. 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]];
  8652. },
  8653. scale: function(_) {
  8654. return arguments.length ? (transform$$1 = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8655. },
  8656. translate: function(_) {
  8657. return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8658. },
  8659. reflectX: function(_) {
  8660. return arguments.length ? (transform$$1 = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8661. },
  8662. reflectY: function(_) {
  8663. return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8664. },
  8665. fitExtent: function(extent, object) {
  8666. return fitExtent(projection, extent, object);
  8667. },
  8668. fitSize: function(size, object) {
  8669. return fitSize(projection, size, object);
  8670. },
  8671. fitWidth: function(width, object) {
  8672. return fitWidth(projection, width, object);
  8673. },
  8674. fitHeight: function(height, object) {
  8675. return fitHeight(projection, height, object);
  8676. }
  8677. };
  8678. }
  8679. function naturalEarth1Raw(lambda, phi) {
  8680. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8681. return [
  8682. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  8683. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  8684. ];
  8685. }
  8686. naturalEarth1Raw.invert = function(x, y) {
  8687. var phi = y, i = 25, delta;
  8688. do {
  8689. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8690. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  8691. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  8692. } while (abs(delta) > epsilon$2 && --i > 0);
  8693. return [
  8694. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  8695. phi
  8696. ];
  8697. };
  8698. function naturalEarth1() {
  8699. return projection(naturalEarth1Raw)
  8700. .scale(175.295);
  8701. }
  8702. function orthographicRaw(x, y) {
  8703. return [cos$1(y) * sin$1(x), sin$1(y)];
  8704. }
  8705. orthographicRaw.invert = azimuthalInvert(asin);
  8706. function orthographic() {
  8707. return projection(orthographicRaw)
  8708. .scale(249.5)
  8709. .clipAngle(90 + epsilon$2);
  8710. }
  8711. function stereographicRaw(x, y) {
  8712. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  8713. return [cy * sin$1(x) / k, sin$1(y) / k];
  8714. }
  8715. stereographicRaw.invert = azimuthalInvert(function(z) {
  8716. return 2 * atan(z);
  8717. });
  8718. function stereographic() {
  8719. return projection(stereographicRaw)
  8720. .scale(250)
  8721. .clipAngle(142);
  8722. }
  8723. function transverseMercatorRaw(lambda, phi) {
  8724. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  8725. }
  8726. transverseMercatorRaw.invert = function(x, y) {
  8727. return [-y, 2 * atan(exp(x)) - halfPi$2];
  8728. };
  8729. function transverseMercator() {
  8730. var m = mercatorProjection(transverseMercatorRaw),
  8731. center = m.center,
  8732. rotate = m.rotate;
  8733. m.center = function(_) {
  8734. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  8735. };
  8736. m.rotate = function(_) {
  8737. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  8738. };
  8739. return rotate([0, 0, 90])
  8740. .scale(159.155);
  8741. }
  8742. function defaultSeparation(a, b) {
  8743. return a.parent === b.parent ? 1 : 2;
  8744. }
  8745. function meanX(children) {
  8746. return children.reduce(meanXReduce, 0) / children.length;
  8747. }
  8748. function meanXReduce(x, c) {
  8749. return x + c.x;
  8750. }
  8751. function maxY(children) {
  8752. return 1 + children.reduce(maxYReduce, 0);
  8753. }
  8754. function maxYReduce(y, c) {
  8755. return Math.max(y, c.y);
  8756. }
  8757. function leafLeft(node) {
  8758. var children;
  8759. while (children = node.children) node = children[0];
  8760. return node;
  8761. }
  8762. function leafRight(node) {
  8763. var children;
  8764. while (children = node.children) node = children[children.length - 1];
  8765. return node;
  8766. }
  8767. function cluster() {
  8768. var separation = defaultSeparation,
  8769. dx = 1,
  8770. dy = 1,
  8771. nodeSize = false;
  8772. function cluster(root) {
  8773. var previousNode,
  8774. x = 0;
  8775. // First walk, computing the initial x & y values.
  8776. root.eachAfter(function(node) {
  8777. var children = node.children;
  8778. if (children) {
  8779. node.x = meanX(children);
  8780. node.y = maxY(children);
  8781. } else {
  8782. node.x = previousNode ? x += separation(node, previousNode) : 0;
  8783. node.y = 0;
  8784. previousNode = node;
  8785. }
  8786. });
  8787. var left = leafLeft(root),
  8788. right = leafRight(root),
  8789. x0 = left.x - separation(left, right) / 2,
  8790. x1 = right.x + separation(right, left) / 2;
  8791. // Second walk, normalizing x & y to the desired size.
  8792. return root.eachAfter(nodeSize ? function(node) {
  8793. node.x = (node.x - root.x) * dx;
  8794. node.y = (root.y - node.y) * dy;
  8795. } : function(node) {
  8796. node.x = (node.x - x0) / (x1 - x0) * dx;
  8797. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  8798. });
  8799. }
  8800. cluster.separation = function(x) {
  8801. return arguments.length ? (separation = x, cluster) : separation;
  8802. };
  8803. cluster.size = function(x) {
  8804. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  8805. };
  8806. cluster.nodeSize = function(x) {
  8807. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  8808. };
  8809. return cluster;
  8810. }
  8811. function count(node) {
  8812. var sum = 0,
  8813. children = node.children,
  8814. i = children && children.length;
  8815. if (!i) sum = 1;
  8816. else while (--i >= 0) sum += children[i].value;
  8817. node.value = sum;
  8818. }
  8819. function node_count() {
  8820. return this.eachAfter(count);
  8821. }
  8822. function node_each(callback) {
  8823. var node = this, current, next = [node], children, i, n;
  8824. do {
  8825. current = next.reverse(), next = [];
  8826. while (node = current.pop()) {
  8827. callback(node), children = node.children;
  8828. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8829. next.push(children[i]);
  8830. }
  8831. }
  8832. } while (next.length);
  8833. return this;
  8834. }
  8835. function node_eachBefore(callback) {
  8836. var node = this, nodes = [node], children, i;
  8837. while (node = nodes.pop()) {
  8838. callback(node), children = node.children;
  8839. if (children) for (i = children.length - 1; i >= 0; --i) {
  8840. nodes.push(children[i]);
  8841. }
  8842. }
  8843. return this;
  8844. }
  8845. function node_eachAfter(callback) {
  8846. var node = this, nodes = [node], next = [], children, i, n;
  8847. while (node = nodes.pop()) {
  8848. next.push(node), children = node.children;
  8849. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8850. nodes.push(children[i]);
  8851. }
  8852. }
  8853. while (node = next.pop()) {
  8854. callback(node);
  8855. }
  8856. return this;
  8857. }
  8858. function node_sum(value) {
  8859. return this.eachAfter(function(node) {
  8860. var sum = +value(node.data) || 0,
  8861. children = node.children,
  8862. i = children && children.length;
  8863. while (--i >= 0) sum += children[i].value;
  8864. node.value = sum;
  8865. });
  8866. }
  8867. function node_sort(compare) {
  8868. return this.eachBefore(function(node) {
  8869. if (node.children) {
  8870. node.children.sort(compare);
  8871. }
  8872. });
  8873. }
  8874. function node_path(end) {
  8875. var start = this,
  8876. ancestor = leastCommonAncestor(start, end),
  8877. nodes = [start];
  8878. while (start !== ancestor) {
  8879. start = start.parent;
  8880. nodes.push(start);
  8881. }
  8882. var k = nodes.length;
  8883. while (end !== ancestor) {
  8884. nodes.splice(k, 0, end);
  8885. end = end.parent;
  8886. }
  8887. return nodes;
  8888. }
  8889. function leastCommonAncestor(a, b) {
  8890. if (a === b) return a;
  8891. var aNodes = a.ancestors(),
  8892. bNodes = b.ancestors(),
  8893. c = null;
  8894. a = aNodes.pop();
  8895. b = bNodes.pop();
  8896. while (a === b) {
  8897. c = a;
  8898. a = aNodes.pop();
  8899. b = bNodes.pop();
  8900. }
  8901. return c;
  8902. }
  8903. function node_ancestors() {
  8904. var node = this, nodes = [node];
  8905. while (node = node.parent) {
  8906. nodes.push(node);
  8907. }
  8908. return nodes;
  8909. }
  8910. function node_descendants() {
  8911. var nodes = [];
  8912. this.each(function(node) {
  8913. nodes.push(node);
  8914. });
  8915. return nodes;
  8916. }
  8917. function node_leaves() {
  8918. var leaves = [];
  8919. this.eachBefore(function(node) {
  8920. if (!node.children) {
  8921. leaves.push(node);
  8922. }
  8923. });
  8924. return leaves;
  8925. }
  8926. function node_links() {
  8927. var root = this, links = [];
  8928. root.each(function(node) {
  8929. if (node !== root) { // Don’t include the root’s parent, if any.
  8930. links.push({source: node.parent, target: node});
  8931. }
  8932. });
  8933. return links;
  8934. }
  8935. function hierarchy(data, children) {
  8936. var root = new Node(data),
  8937. valued = +data.value && (root.value = data.value),
  8938. node,
  8939. nodes = [root],
  8940. child,
  8941. childs,
  8942. i,
  8943. n;
  8944. if (children == null) children = defaultChildren;
  8945. while (node = nodes.pop()) {
  8946. if (valued) node.value = +node.data.value;
  8947. if ((childs = children(node.data)) && (n = childs.length)) {
  8948. node.children = new Array(n);
  8949. for (i = n - 1; i >= 0; --i) {
  8950. nodes.push(child = node.children[i] = new Node(childs[i]));
  8951. child.parent = node;
  8952. child.depth = node.depth + 1;
  8953. }
  8954. }
  8955. }
  8956. return root.eachBefore(computeHeight);
  8957. }
  8958. function node_copy() {
  8959. return hierarchy(this).eachBefore(copyData);
  8960. }
  8961. function defaultChildren(d) {
  8962. return d.children;
  8963. }
  8964. function copyData(node) {
  8965. node.data = node.data.data;
  8966. }
  8967. function computeHeight(node) {
  8968. var height = 0;
  8969. do node.height = height;
  8970. while ((node = node.parent) && (node.height < ++height));
  8971. }
  8972. function Node(data) {
  8973. this.data = data;
  8974. this.depth =
  8975. this.height = 0;
  8976. this.parent = null;
  8977. }
  8978. Node.prototype = hierarchy.prototype = {
  8979. constructor: Node,
  8980. count: node_count,
  8981. each: node_each,
  8982. eachAfter: node_eachAfter,
  8983. eachBefore: node_eachBefore,
  8984. sum: node_sum,
  8985. sort: node_sort,
  8986. path: node_path,
  8987. ancestors: node_ancestors,
  8988. descendants: node_descendants,
  8989. leaves: node_leaves,
  8990. links: node_links,
  8991. copy: node_copy
  8992. };
  8993. var slice$4 = Array.prototype.slice;
  8994. function shuffle$1(array) {
  8995. var m = array.length,
  8996. t,
  8997. i;
  8998. while (m) {
  8999. i = Math.random() * m-- | 0;
  9000. t = array[m];
  9001. array[m] = array[i];
  9002. array[i] = t;
  9003. }
  9004. return array;
  9005. }
  9006. function enclose(circles) {
  9007. var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
  9008. while (i < n) {
  9009. p = circles[i];
  9010. if (e && enclosesWeak(e, p)) ++i;
  9011. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  9012. }
  9013. return e;
  9014. }
  9015. function extendBasis(B, p) {
  9016. var i, j;
  9017. if (enclosesWeakAll(p, B)) return [p];
  9018. // If we get here then B must have at least one element.
  9019. for (i = 0; i < B.length; ++i) {
  9020. if (enclosesNot(p, B[i])
  9021. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  9022. return [B[i], p];
  9023. }
  9024. }
  9025. // If we get here then B must have at least two elements.
  9026. for (i = 0; i < B.length - 1; ++i) {
  9027. for (j = i + 1; j < B.length; ++j) {
  9028. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  9029. && enclosesNot(encloseBasis2(B[i], p), B[j])
  9030. && enclosesNot(encloseBasis2(B[j], p), B[i])
  9031. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  9032. return [B[i], B[j], p];
  9033. }
  9034. }
  9035. }
  9036. // If we get here then something is very wrong.
  9037. throw new Error;
  9038. }
  9039. function enclosesNot(a, b) {
  9040. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  9041. return dr < 0 || dr * dr < dx * dx + dy * dy;
  9042. }
  9043. function enclosesWeak(a, b) {
  9044. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9045. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9046. }
  9047. function enclosesWeakAll(a, B) {
  9048. for (var i = 0; i < B.length; ++i) {
  9049. if (!enclosesWeak(a, B[i])) {
  9050. return false;
  9051. }
  9052. }
  9053. return true;
  9054. }
  9055. function encloseBasis(B) {
  9056. switch (B.length) {
  9057. case 1: return encloseBasis1(B[0]);
  9058. case 2: return encloseBasis2(B[0], B[1]);
  9059. case 3: return encloseBasis3(B[0], B[1], B[2]);
  9060. }
  9061. }
  9062. function encloseBasis1(a) {
  9063. return {
  9064. x: a.x,
  9065. y: a.y,
  9066. r: a.r
  9067. };
  9068. }
  9069. function encloseBasis2(a, b) {
  9070. var x1 = a.x, y1 = a.y, r1 = a.r,
  9071. x2 = b.x, y2 = b.y, r2 = b.r,
  9072. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  9073. l = Math.sqrt(x21 * x21 + y21 * y21);
  9074. return {
  9075. x: (x1 + x2 + x21 / l * r21) / 2,
  9076. y: (y1 + y2 + y21 / l * r21) / 2,
  9077. r: (l + r1 + r2) / 2
  9078. };
  9079. }
  9080. function encloseBasis3(a, b, c) {
  9081. var x1 = a.x, y1 = a.y, r1 = a.r,
  9082. x2 = b.x, y2 = b.y, r2 = b.r,
  9083. x3 = c.x, y3 = c.y, r3 = c.r,
  9084. a2 = x1 - x2,
  9085. a3 = x1 - x3,
  9086. b2 = y1 - y2,
  9087. b3 = y1 - y3,
  9088. c2 = r2 - r1,
  9089. c3 = r3 - r1,
  9090. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  9091. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  9092. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  9093. ab = a3 * b2 - a2 * b3,
  9094. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  9095. xb = (b3 * c2 - b2 * c3) / ab,
  9096. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  9097. yb = (a2 * c3 - a3 * c2) / ab,
  9098. A = xb * xb + yb * yb - 1,
  9099. B = 2 * (r1 + xa * xb + ya * yb),
  9100. C = xa * xa + ya * ya - r1 * r1,
  9101. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  9102. return {
  9103. x: x1 + xa + xb * r,
  9104. y: y1 + ya + yb * r,
  9105. r: r
  9106. };
  9107. }
  9108. function place(b, a, c) {
  9109. var dx = b.x - a.x, x, a2,
  9110. dy = b.y - a.y, y, b2,
  9111. d2 = dx * dx + dy * dy;
  9112. if (d2) {
  9113. a2 = a.r + c.r, a2 *= a2;
  9114. b2 = b.r + c.r, b2 *= b2;
  9115. if (a2 > b2) {
  9116. x = (d2 + b2 - a2) / (2 * d2);
  9117. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  9118. c.x = b.x - x * dx - y * dy;
  9119. c.y = b.y - x * dy + y * dx;
  9120. } else {
  9121. x = (d2 + a2 - b2) / (2 * d2);
  9122. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  9123. c.x = a.x + x * dx - y * dy;
  9124. c.y = a.y + x * dy + y * dx;
  9125. }
  9126. } else {
  9127. c.x = a.x + c.r;
  9128. c.y = a.y;
  9129. }
  9130. }
  9131. function intersects(a, b) {
  9132. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9133. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9134. }
  9135. function score(node) {
  9136. var a = node._,
  9137. b = node.next._,
  9138. ab = a.r + b.r,
  9139. dx = (a.x * b.r + b.x * a.r) / ab,
  9140. dy = (a.y * b.r + b.y * a.r) / ab;
  9141. return dx * dx + dy * dy;
  9142. }
  9143. function Node$1(circle) {
  9144. this._ = circle;
  9145. this.next = null;
  9146. this.previous = null;
  9147. }
  9148. function packEnclose(circles) {
  9149. if (!(n = circles.length)) return 0;
  9150. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  9151. // Place the first circle.
  9152. a = circles[0], a.x = 0, a.y = 0;
  9153. if (!(n > 1)) return a.r;
  9154. // Place the second circle.
  9155. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  9156. if (!(n > 2)) return a.r + b.r;
  9157. // Place the third circle.
  9158. place(b, a, c = circles[2]);
  9159. // Initialize the front-chain using the first three circles a, b and c.
  9160. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  9161. a.next = c.previous = b;
  9162. b.next = a.previous = c;
  9163. c.next = b.previous = a;
  9164. // Attempt to place each remaining circle…
  9165. pack: for (i = 3; i < n; ++i) {
  9166. place(a._, b._, c = circles[i]), c = new Node$1(c);
  9167. // Find the closest intersecting circle on the front-chain, if any.
  9168. // “Closeness” is determined by linear distance along the front-chain.
  9169. // “Ahead” or “behind” is likewise determined by linear distance.
  9170. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  9171. do {
  9172. if (sj <= sk) {
  9173. if (intersects(j._, c._)) {
  9174. b = j, a.next = b, b.previous = a, --i;
  9175. continue pack;
  9176. }
  9177. sj += j._.r, j = j.next;
  9178. } else {
  9179. if (intersects(k._, c._)) {
  9180. a = k, a.next = b, b.previous = a, --i;
  9181. continue pack;
  9182. }
  9183. sk += k._.r, k = k.previous;
  9184. }
  9185. } while (j !== k.next);
  9186. // Success! Insert the new circle c between a and b.
  9187. c.previous = a, c.next = b, a.next = b.previous = b = c;
  9188. // Compute the new closest circle pair to the centroid.
  9189. aa = score(a);
  9190. while ((c = c.next) !== b) {
  9191. if ((ca = score(c)) < aa) {
  9192. a = c, aa = ca;
  9193. }
  9194. }
  9195. b = a.next;
  9196. }
  9197. // Compute the enclosing circle of the front chain.
  9198. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  9199. // Translate the circles to put the enclosing circle around the origin.
  9200. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  9201. return c.r;
  9202. }
  9203. function siblings(circles) {
  9204. packEnclose(circles);
  9205. return circles;
  9206. }
  9207. function optional(f) {
  9208. return f == null ? null : required(f);
  9209. }
  9210. function required(f) {
  9211. if (typeof f !== "function") throw new Error;
  9212. return f;
  9213. }
  9214. function constantZero() {
  9215. return 0;
  9216. }
  9217. function constant$9(x) {
  9218. return function() {
  9219. return x;
  9220. };
  9221. }
  9222. function defaultRadius$1(d) {
  9223. return Math.sqrt(d.value);
  9224. }
  9225. function index$2() {
  9226. var radius = null,
  9227. dx = 1,
  9228. dy = 1,
  9229. padding = constantZero;
  9230. function pack(root) {
  9231. root.x = dx / 2, root.y = dy / 2;
  9232. if (radius) {
  9233. root.eachBefore(radiusLeaf(radius))
  9234. .eachAfter(packChildren(padding, 0.5))
  9235. .eachBefore(translateChild(1));
  9236. } else {
  9237. root.eachBefore(radiusLeaf(defaultRadius$1))
  9238. .eachAfter(packChildren(constantZero, 1))
  9239. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  9240. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  9241. }
  9242. return root;
  9243. }
  9244. pack.radius = function(x) {
  9245. return arguments.length ? (radius = optional(x), pack) : radius;
  9246. };
  9247. pack.size = function(x) {
  9248. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  9249. };
  9250. pack.padding = function(x) {
  9251. return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
  9252. };
  9253. return pack;
  9254. }
  9255. function radiusLeaf(radius) {
  9256. return function(node) {
  9257. if (!node.children) {
  9258. node.r = Math.max(0, +radius(node) || 0);
  9259. }
  9260. };
  9261. }
  9262. function packChildren(padding, k) {
  9263. return function(node) {
  9264. if (children = node.children) {
  9265. var children,
  9266. i,
  9267. n = children.length,
  9268. r = padding(node) * k || 0,
  9269. e;
  9270. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  9271. e = packEnclose(children);
  9272. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  9273. node.r = e + r;
  9274. }
  9275. };
  9276. }
  9277. function translateChild(k) {
  9278. return function(node) {
  9279. var parent = node.parent;
  9280. node.r *= k;
  9281. if (parent) {
  9282. node.x = parent.x + k * node.x;
  9283. node.y = parent.y + k * node.y;
  9284. }
  9285. };
  9286. }
  9287. function roundNode(node) {
  9288. node.x0 = Math.round(node.x0);
  9289. node.y0 = Math.round(node.y0);
  9290. node.x1 = Math.round(node.x1);
  9291. node.y1 = Math.round(node.y1);
  9292. }
  9293. function treemapDice(parent, x0, y0, x1, y1) {
  9294. var nodes = parent.children,
  9295. node,
  9296. i = -1,
  9297. n = nodes.length,
  9298. k = parent.value && (x1 - x0) / parent.value;
  9299. while (++i < n) {
  9300. node = nodes[i], node.y0 = y0, node.y1 = y1;
  9301. node.x0 = x0, node.x1 = x0 += node.value * k;
  9302. }
  9303. }
  9304. function partition() {
  9305. var dx = 1,
  9306. dy = 1,
  9307. padding = 0,
  9308. round = false;
  9309. function partition(root) {
  9310. var n = root.height + 1;
  9311. root.x0 =
  9312. root.y0 = padding;
  9313. root.x1 = dx;
  9314. root.y1 = dy / n;
  9315. root.eachBefore(positionNode(dy, n));
  9316. if (round) root.eachBefore(roundNode);
  9317. return root;
  9318. }
  9319. function positionNode(dy, n) {
  9320. return function(node) {
  9321. if (node.children) {
  9322. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  9323. }
  9324. var x0 = node.x0,
  9325. y0 = node.y0,
  9326. x1 = node.x1 - padding,
  9327. y1 = node.y1 - padding;
  9328. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9329. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9330. node.x0 = x0;
  9331. node.y0 = y0;
  9332. node.x1 = x1;
  9333. node.y1 = y1;
  9334. };
  9335. }
  9336. partition.round = function(x) {
  9337. return arguments.length ? (round = !!x, partition) : round;
  9338. };
  9339. partition.size = function(x) {
  9340. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  9341. };
  9342. partition.padding = function(x) {
  9343. return arguments.length ? (padding = +x, partition) : padding;
  9344. };
  9345. return partition;
  9346. }
  9347. var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
  9348. preroot = {depth: -1},
  9349. ambiguous = {};
  9350. function defaultId(d) {
  9351. return d.id;
  9352. }
  9353. function defaultParentId(d) {
  9354. return d.parentId;
  9355. }
  9356. function stratify() {
  9357. var id = defaultId,
  9358. parentId = defaultParentId;
  9359. function stratify(data) {
  9360. var d,
  9361. i,
  9362. n = data.length,
  9363. root,
  9364. parent,
  9365. node,
  9366. nodes = new Array(n),
  9367. nodeId,
  9368. nodeKey,
  9369. nodeByKey = {};
  9370. for (i = 0; i < n; ++i) {
  9371. d = data[i], node = nodes[i] = new Node(d);
  9372. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  9373. nodeKey = keyPrefix$1 + (node.id = nodeId);
  9374. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  9375. }
  9376. }
  9377. for (i = 0; i < n; ++i) {
  9378. node = nodes[i], nodeId = parentId(data[i], i, data);
  9379. if (nodeId == null || !(nodeId += "")) {
  9380. if (root) throw new Error("multiple roots");
  9381. root = node;
  9382. } else {
  9383. parent = nodeByKey[keyPrefix$1 + nodeId];
  9384. if (!parent) throw new Error("missing: " + nodeId);
  9385. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  9386. if (parent.children) parent.children.push(node);
  9387. else parent.children = [node];
  9388. node.parent = parent;
  9389. }
  9390. }
  9391. if (!root) throw new Error("no root");
  9392. root.parent = preroot;
  9393. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  9394. root.parent = null;
  9395. if (n > 0) throw new Error("cycle");
  9396. return root;
  9397. }
  9398. stratify.id = function(x) {
  9399. return arguments.length ? (id = required(x), stratify) : id;
  9400. };
  9401. stratify.parentId = function(x) {
  9402. return arguments.length ? (parentId = required(x), stratify) : parentId;
  9403. };
  9404. return stratify;
  9405. }
  9406. function defaultSeparation$1(a, b) {
  9407. return a.parent === b.parent ? 1 : 2;
  9408. }
  9409. // function radialSeparation(a, b) {
  9410. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  9411. // }
  9412. // This function is used to traverse the left contour of a subtree (or
  9413. // subforest). It returns the successor of v on this contour. This successor is
  9414. // either given by the leftmost child of v or by the thread of v. The function
  9415. // returns null if and only if v is on the highest level of its subtree.
  9416. function nextLeft(v) {
  9417. var children = v.children;
  9418. return children ? children[0] : v.t;
  9419. }
  9420. // This function works analogously to nextLeft.
  9421. function nextRight(v) {
  9422. var children = v.children;
  9423. return children ? children[children.length - 1] : v.t;
  9424. }
  9425. // Shifts the current subtree rooted at w+. This is done by increasing
  9426. // prelim(w+) and mod(w+) by shift.
  9427. function moveSubtree(wm, wp, shift) {
  9428. var change = shift / (wp.i - wm.i);
  9429. wp.c -= change;
  9430. wp.s += shift;
  9431. wm.c += change;
  9432. wp.z += shift;
  9433. wp.m += shift;
  9434. }
  9435. // All other shifts, applied to the smaller subtrees between w- and w+, are
  9436. // performed by this function. To prepare the shifts, we have to adjust
  9437. // change(w+), shift(w+), and change(w-).
  9438. function executeShifts(v) {
  9439. var shift = 0,
  9440. change = 0,
  9441. children = v.children,
  9442. i = children.length,
  9443. w;
  9444. while (--i >= 0) {
  9445. w = children[i];
  9446. w.z += shift;
  9447. w.m += shift;
  9448. shift += w.s + (change += w.c);
  9449. }
  9450. }
  9451. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  9452. // returns the specified (default) ancestor.
  9453. function nextAncestor(vim, v, ancestor) {
  9454. return vim.a.parent === v.parent ? vim.a : ancestor;
  9455. }
  9456. function TreeNode(node, i) {
  9457. this._ = node;
  9458. this.parent = null;
  9459. this.children = null;
  9460. this.A = null; // default ancestor
  9461. this.a = this; // ancestor
  9462. this.z = 0; // prelim
  9463. this.m = 0; // mod
  9464. this.c = 0; // change
  9465. this.s = 0; // shift
  9466. this.t = null; // thread
  9467. this.i = i; // number
  9468. }
  9469. TreeNode.prototype = Object.create(Node.prototype);
  9470. function treeRoot(root) {
  9471. var tree = new TreeNode(root, 0),
  9472. node,
  9473. nodes = [tree],
  9474. child,
  9475. children,
  9476. i,
  9477. n;
  9478. while (node = nodes.pop()) {
  9479. if (children = node._.children) {
  9480. node.children = new Array(n = children.length);
  9481. for (i = n - 1; i >= 0; --i) {
  9482. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  9483. child.parent = node;
  9484. }
  9485. }
  9486. }
  9487. (tree.parent = new TreeNode(null, 0)).children = [tree];
  9488. return tree;
  9489. }
  9490. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  9491. function tree() {
  9492. var separation = defaultSeparation$1,
  9493. dx = 1,
  9494. dy = 1,
  9495. nodeSize = null;
  9496. function tree(root) {
  9497. var t = treeRoot(root);
  9498. // Compute the layout using Buchheim et al.’s algorithm.
  9499. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9500. t.eachBefore(secondWalk);
  9501. // If a fixed node size is specified, scale x and y.
  9502. if (nodeSize) root.eachBefore(sizeNode);
  9503. // If a fixed tree size is specified, scale x and y based on the extent.
  9504. // Compute the left-most, right-most, and depth-most nodes for extents.
  9505. else {
  9506. var left = root,
  9507. right = root,
  9508. bottom = root;
  9509. root.eachBefore(function(node) {
  9510. if (node.x < left.x) left = node;
  9511. if (node.x > right.x) right = node;
  9512. if (node.depth > bottom.depth) bottom = node;
  9513. });
  9514. var s = left === right ? 1 : separation(left, right) / 2,
  9515. tx = s - left.x,
  9516. kx = dx / (right.x + s + tx),
  9517. ky = dy / (bottom.depth || 1);
  9518. root.eachBefore(function(node) {
  9519. node.x = (node.x + tx) * kx;
  9520. node.y = node.depth * ky;
  9521. });
  9522. }
  9523. return root;
  9524. }
  9525. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9526. // applied recursively to the children of v, as well as the function
  9527. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9528. // node v is placed to the midpoint of its outermost children.
  9529. function firstWalk(v) {
  9530. var children = v.children,
  9531. siblings = v.parent.children,
  9532. w = v.i ? siblings[v.i - 1] : null;
  9533. if (children) {
  9534. executeShifts(v);
  9535. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9536. if (w) {
  9537. v.z = w.z + separation(v._, w._);
  9538. v.m = v.z - midpoint;
  9539. } else {
  9540. v.z = midpoint;
  9541. }
  9542. } else if (w) {
  9543. v.z = w.z + separation(v._, w._);
  9544. }
  9545. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9546. }
  9547. // Computes all real x-coordinates by summing up the modifiers recursively.
  9548. function secondWalk(v) {
  9549. v._.x = v.z + v.parent.m;
  9550. v.m += v.parent.m;
  9551. }
  9552. // The core of the algorithm. Here, a new subtree is combined with the
  9553. // previous subtrees. Threads are used to traverse the inside and outside
  9554. // contours of the left and right subtree up to the highest common level. The
  9555. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9556. // superscript o means outside and i means inside, the subscript - means left
  9557. // subtree and + means right subtree. For summing up the modifiers along the
  9558. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9559. // nodes of the inside contours conflict, we compute the left one of the
  9560. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9561. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9562. // Finally, we add a new thread (if necessary).
  9563. function apportion(v, w, ancestor) {
  9564. if (w) {
  9565. var vip = v,
  9566. vop = v,
  9567. vim = w,
  9568. vom = vip.parent.children[0],
  9569. sip = vip.m,
  9570. sop = vop.m,
  9571. sim = vim.m,
  9572. som = vom.m,
  9573. shift;
  9574. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9575. vom = nextLeft(vom);
  9576. vop = nextRight(vop);
  9577. vop.a = v;
  9578. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9579. if (shift > 0) {
  9580. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9581. sip += shift;
  9582. sop += shift;
  9583. }
  9584. sim += vim.m;
  9585. sip += vip.m;
  9586. som += vom.m;
  9587. sop += vop.m;
  9588. }
  9589. if (vim && !nextRight(vop)) {
  9590. vop.t = vim;
  9591. vop.m += sim - sop;
  9592. }
  9593. if (vip && !nextLeft(vom)) {
  9594. vom.t = vip;
  9595. vom.m += sip - som;
  9596. ancestor = v;
  9597. }
  9598. }
  9599. return ancestor;
  9600. }
  9601. function sizeNode(node) {
  9602. node.x *= dx;
  9603. node.y = node.depth * dy;
  9604. }
  9605. tree.separation = function(x) {
  9606. return arguments.length ? (separation = x, tree) : separation;
  9607. };
  9608. tree.size = function(x) {
  9609. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9610. };
  9611. tree.nodeSize = function(x) {
  9612. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9613. };
  9614. return tree;
  9615. }
  9616. function treemapSlice(parent, x0, y0, x1, y1) {
  9617. var nodes = parent.children,
  9618. node,
  9619. i = -1,
  9620. n = nodes.length,
  9621. k = parent.value && (y1 - y0) / parent.value;
  9622. while (++i < n) {
  9623. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9624. node.y0 = y0, node.y1 = y0 += node.value * k;
  9625. }
  9626. }
  9627. var phi = (1 + Math.sqrt(5)) / 2;
  9628. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9629. var rows = [],
  9630. nodes = parent.children,
  9631. row,
  9632. nodeValue,
  9633. i0 = 0,
  9634. i1 = 0,
  9635. n = nodes.length,
  9636. dx, dy,
  9637. value = parent.value,
  9638. sumValue,
  9639. minValue,
  9640. maxValue,
  9641. newRatio,
  9642. minRatio,
  9643. alpha,
  9644. beta;
  9645. while (i0 < n) {
  9646. dx = x1 - x0, dy = y1 - y0;
  9647. // Find the next non-empty node.
  9648. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9649. minValue = maxValue = sumValue;
  9650. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9651. beta = sumValue * sumValue * alpha;
  9652. minRatio = Math.max(maxValue / beta, beta / minValue);
  9653. // Keep adding nodes while the aspect ratio maintains or improves.
  9654. for (; i1 < n; ++i1) {
  9655. sumValue += nodeValue = nodes[i1].value;
  9656. if (nodeValue < minValue) minValue = nodeValue;
  9657. if (nodeValue > maxValue) maxValue = nodeValue;
  9658. beta = sumValue * sumValue * alpha;
  9659. newRatio = Math.max(maxValue / beta, beta / minValue);
  9660. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9661. minRatio = newRatio;
  9662. }
  9663. // Position and record the row orientation.
  9664. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9665. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9666. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9667. value -= sumValue, i0 = i1;
  9668. }
  9669. return rows;
  9670. }
  9671. var squarify = (function custom(ratio) {
  9672. function squarify(parent, x0, y0, x1, y1) {
  9673. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9674. }
  9675. squarify.ratio = function(x) {
  9676. return custom((x = +x) > 1 ? x : 1);
  9677. };
  9678. return squarify;
  9679. })(phi);
  9680. function index$3() {
  9681. var tile = squarify,
  9682. round = false,
  9683. dx = 1,
  9684. dy = 1,
  9685. paddingStack = [0],
  9686. paddingInner = constantZero,
  9687. paddingTop = constantZero,
  9688. paddingRight = constantZero,
  9689. paddingBottom = constantZero,
  9690. paddingLeft = constantZero;
  9691. function treemap(root) {
  9692. root.x0 =
  9693. root.y0 = 0;
  9694. root.x1 = dx;
  9695. root.y1 = dy;
  9696. root.eachBefore(positionNode);
  9697. paddingStack = [0];
  9698. if (round) root.eachBefore(roundNode);
  9699. return root;
  9700. }
  9701. function positionNode(node) {
  9702. var p = paddingStack[node.depth],
  9703. x0 = node.x0 + p,
  9704. y0 = node.y0 + p,
  9705. x1 = node.x1 - p,
  9706. y1 = node.y1 - p;
  9707. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9708. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9709. node.x0 = x0;
  9710. node.y0 = y0;
  9711. node.x1 = x1;
  9712. node.y1 = y1;
  9713. if (node.children) {
  9714. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  9715. x0 += paddingLeft(node) - p;
  9716. y0 += paddingTop(node) - p;
  9717. x1 -= paddingRight(node) - p;
  9718. y1 -= paddingBottom(node) - p;
  9719. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9720. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9721. tile(node, x0, y0, x1, y1);
  9722. }
  9723. }
  9724. treemap.round = function(x) {
  9725. return arguments.length ? (round = !!x, treemap) : round;
  9726. };
  9727. treemap.size = function(x) {
  9728. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  9729. };
  9730. treemap.tile = function(x) {
  9731. return arguments.length ? (tile = required(x), treemap) : tile;
  9732. };
  9733. treemap.padding = function(x) {
  9734. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  9735. };
  9736. treemap.paddingInner = function(x) {
  9737. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
  9738. };
  9739. treemap.paddingOuter = function(x) {
  9740. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  9741. };
  9742. treemap.paddingTop = function(x) {
  9743. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
  9744. };
  9745. treemap.paddingRight = function(x) {
  9746. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
  9747. };
  9748. treemap.paddingBottom = function(x) {
  9749. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
  9750. };
  9751. treemap.paddingLeft = function(x) {
  9752. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
  9753. };
  9754. return treemap;
  9755. }
  9756. function binary(parent, x0, y0, x1, y1) {
  9757. var nodes = parent.children,
  9758. i, n = nodes.length,
  9759. sum, sums = new Array(n + 1);
  9760. for (sums[0] = sum = i = 0; i < n; ++i) {
  9761. sums[i + 1] = sum += nodes[i].value;
  9762. }
  9763. partition(0, n, parent.value, x0, y0, x1, y1);
  9764. function partition(i, j, value, x0, y0, x1, y1) {
  9765. if (i >= j - 1) {
  9766. var node = nodes[i];
  9767. node.x0 = x0, node.y0 = y0;
  9768. node.x1 = x1, node.y1 = y1;
  9769. return;
  9770. }
  9771. var valueOffset = sums[i],
  9772. valueTarget = (value / 2) + valueOffset,
  9773. k = i + 1,
  9774. hi = j - 1;
  9775. while (k < hi) {
  9776. var mid = k + hi >>> 1;
  9777. if (sums[mid] < valueTarget) k = mid + 1;
  9778. else hi = mid;
  9779. }
  9780. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  9781. var valueLeft = sums[k] - valueOffset,
  9782. valueRight = value - valueLeft;
  9783. if ((x1 - x0) > (y1 - y0)) {
  9784. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  9785. partition(i, k, valueLeft, x0, y0, xk, y1);
  9786. partition(k, j, valueRight, xk, y0, x1, y1);
  9787. } else {
  9788. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  9789. partition(i, k, valueLeft, x0, y0, x1, yk);
  9790. partition(k, j, valueRight, x0, yk, x1, y1);
  9791. }
  9792. }
  9793. }
  9794. function sliceDice(parent, x0, y0, x1, y1) {
  9795. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  9796. }
  9797. var resquarify = (function custom(ratio) {
  9798. function resquarify(parent, x0, y0, x1, y1) {
  9799. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  9800. var rows,
  9801. row,
  9802. nodes,
  9803. i,
  9804. j = -1,
  9805. n,
  9806. m = rows.length,
  9807. value = parent.value;
  9808. while (++j < m) {
  9809. row = rows[j], nodes = row.children;
  9810. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  9811. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  9812. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  9813. value -= row.value;
  9814. }
  9815. } else {
  9816. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9817. rows.ratio = ratio;
  9818. }
  9819. }
  9820. resquarify.ratio = function(x) {
  9821. return custom((x = +x) > 1 ? x : 1);
  9822. };
  9823. return resquarify;
  9824. })(phi);
  9825. function area$2(polygon) {
  9826. var i = -1,
  9827. n = polygon.length,
  9828. a,
  9829. b = polygon[n - 1],
  9830. area = 0;
  9831. while (++i < n) {
  9832. a = b;
  9833. b = polygon[i];
  9834. area += a[1] * b[0] - a[0] * b[1];
  9835. }
  9836. return area / 2;
  9837. }
  9838. function centroid$1(polygon) {
  9839. var i = -1,
  9840. n = polygon.length,
  9841. x = 0,
  9842. y = 0,
  9843. a,
  9844. b = polygon[n - 1],
  9845. c,
  9846. k = 0;
  9847. while (++i < n) {
  9848. a = b;
  9849. b = polygon[i];
  9850. k += c = a[0] * b[1] - b[0] * a[1];
  9851. x += (a[0] + b[0]) * c;
  9852. y += (a[1] + b[1]) * c;
  9853. }
  9854. return k *= 3, [x / k, y / k];
  9855. }
  9856. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  9857. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  9858. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  9859. // negative if clockwise, and zero if the points are collinear.
  9860. function cross$1(a, b, c) {
  9861. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  9862. }
  9863. function lexicographicOrder(a, b) {
  9864. return a[0] - b[0] || a[1] - b[1];
  9865. }
  9866. // Computes the upper convex hull per the monotone chain algorithm.
  9867. // Assumes points.length >= 3, is sorted by x, unique in y.
  9868. // Returns an array of indices into points in left-to-right order.
  9869. function computeUpperHullIndexes(points) {
  9870. var n = points.length,
  9871. indexes = [0, 1],
  9872. size = 2;
  9873. for (var i = 2; i < n; ++i) {
  9874. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  9875. indexes[size++] = i;
  9876. }
  9877. return indexes.slice(0, size); // remove popped points
  9878. }
  9879. function hull(points) {
  9880. if ((n = points.length) < 3) return null;
  9881. var i,
  9882. n,
  9883. sortedPoints = new Array(n),
  9884. flippedPoints = new Array(n);
  9885. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  9886. sortedPoints.sort(lexicographicOrder);
  9887. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  9888. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  9889. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  9890. // Construct the hull polygon, removing possible duplicate endpoints.
  9891. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  9892. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  9893. hull = [];
  9894. // Add upper hull in right-to-l order.
  9895. // Then add lower hull in left-to-right order.
  9896. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  9897. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  9898. return hull;
  9899. }
  9900. function contains$2(polygon, point) {
  9901. var n = polygon.length,
  9902. p = polygon[n - 1],
  9903. x = point[0], y = point[1],
  9904. x0 = p[0], y0 = p[1],
  9905. x1, y1,
  9906. inside = false;
  9907. for (var i = 0; i < n; ++i) {
  9908. p = polygon[i], x1 = p[0], y1 = p[1];
  9909. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  9910. x0 = x1, y0 = y1;
  9911. }
  9912. return inside;
  9913. }
  9914. function length$2(polygon) {
  9915. var i = -1,
  9916. n = polygon.length,
  9917. b = polygon[n - 1],
  9918. xa,
  9919. ya,
  9920. xb = b[0],
  9921. yb = b[1],
  9922. perimeter = 0;
  9923. while (++i < n) {
  9924. xa = xb;
  9925. ya = yb;
  9926. b = polygon[i];
  9927. xb = b[0];
  9928. yb = b[1];
  9929. xa -= xb;
  9930. ya -= yb;
  9931. perimeter += Math.sqrt(xa * xa + ya * ya);
  9932. }
  9933. return perimeter;
  9934. }
  9935. function defaultSource$1() {
  9936. return Math.random();
  9937. }
  9938. var uniform = (function sourceRandomUniform(source) {
  9939. function randomUniform(min, max) {
  9940. min = min == null ? 0 : +min;
  9941. max = max == null ? 1 : +max;
  9942. if (arguments.length === 1) max = min, min = 0;
  9943. else max -= min;
  9944. return function() {
  9945. return source() * max + min;
  9946. };
  9947. }
  9948. randomUniform.source = sourceRandomUniform;
  9949. return randomUniform;
  9950. })(defaultSource$1);
  9951. var normal = (function sourceRandomNormal(source) {
  9952. function randomNormal(mu, sigma) {
  9953. var x, r;
  9954. mu = mu == null ? 0 : +mu;
  9955. sigma = sigma == null ? 1 : +sigma;
  9956. return function() {
  9957. var y;
  9958. // If available, use the second previously-generated uniform random.
  9959. if (x != null) y = x, x = null;
  9960. // Otherwise, generate a new x and y.
  9961. else do {
  9962. x = source() * 2 - 1;
  9963. y = source() * 2 - 1;
  9964. r = x * x + y * y;
  9965. } while (!r || r > 1);
  9966. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  9967. };
  9968. }
  9969. randomNormal.source = sourceRandomNormal;
  9970. return randomNormal;
  9971. })(defaultSource$1);
  9972. var logNormal = (function sourceRandomLogNormal(source) {
  9973. function randomLogNormal() {
  9974. var randomNormal = normal.source(source).apply(this, arguments);
  9975. return function() {
  9976. return Math.exp(randomNormal());
  9977. };
  9978. }
  9979. randomLogNormal.source = sourceRandomLogNormal;
  9980. return randomLogNormal;
  9981. })(defaultSource$1);
  9982. var irwinHall = (function sourceRandomIrwinHall(source) {
  9983. function randomIrwinHall(n) {
  9984. return function() {
  9985. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  9986. return sum;
  9987. };
  9988. }
  9989. randomIrwinHall.source = sourceRandomIrwinHall;
  9990. return randomIrwinHall;
  9991. })(defaultSource$1);
  9992. var bates = (function sourceRandomBates(source) {
  9993. function randomBates(n) {
  9994. var randomIrwinHall = irwinHall.source(source)(n);
  9995. return function() {
  9996. return randomIrwinHall() / n;
  9997. };
  9998. }
  9999. randomBates.source = sourceRandomBates;
  10000. return randomBates;
  10001. })(defaultSource$1);
  10002. var exponential$1 = (function sourceRandomExponential(source) {
  10003. function randomExponential(lambda) {
  10004. return function() {
  10005. return -Math.log(1 - source()) / lambda;
  10006. };
  10007. }
  10008. randomExponential.source = sourceRandomExponential;
  10009. return randomExponential;
  10010. })(defaultSource$1);
  10011. var array$3 = Array.prototype;
  10012. var map$2 = array$3.map;
  10013. var slice$5 = array$3.slice;
  10014. var implicit = {name: "implicit"};
  10015. function ordinal(range) {
  10016. var index = map$1(),
  10017. domain = [],
  10018. unknown = implicit;
  10019. range = range == null ? [] : slice$5.call(range);
  10020. function scale(d) {
  10021. var key = d + "", i = index.get(key);
  10022. if (!i) {
  10023. if (unknown !== implicit) return unknown;
  10024. index.set(key, i = domain.push(d));
  10025. }
  10026. return range[(i - 1) % range.length];
  10027. }
  10028. scale.domain = function(_) {
  10029. if (!arguments.length) return domain.slice();
  10030. domain = [], index = map$1();
  10031. var i = -1, n = _.length, d, key;
  10032. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  10033. return scale;
  10034. };
  10035. scale.range = function(_) {
  10036. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  10037. };
  10038. scale.unknown = function(_) {
  10039. return arguments.length ? (unknown = _, scale) : unknown;
  10040. };
  10041. scale.copy = function() {
  10042. return ordinal()
  10043. .domain(domain)
  10044. .range(range)
  10045. .unknown(unknown);
  10046. };
  10047. return scale;
  10048. }
  10049. function band() {
  10050. var scale = ordinal().unknown(undefined),
  10051. domain = scale.domain,
  10052. ordinalRange = scale.range,
  10053. range$$1 = [0, 1],
  10054. step,
  10055. bandwidth,
  10056. round = false,
  10057. paddingInner = 0,
  10058. paddingOuter = 0,
  10059. align = 0.5;
  10060. delete scale.unknown;
  10061. function rescale() {
  10062. var n = domain().length,
  10063. reverse = range$$1[1] < range$$1[0],
  10064. start = range$$1[reverse - 0],
  10065. stop = range$$1[1 - reverse];
  10066. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  10067. if (round) step = Math.floor(step);
  10068. start += (stop - start - step * (n - paddingInner)) * align;
  10069. bandwidth = step * (1 - paddingInner);
  10070. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  10071. var values = sequence(n).map(function(i) { return start + step * i; });
  10072. return ordinalRange(reverse ? values.reverse() : values);
  10073. }
  10074. scale.domain = function(_) {
  10075. return arguments.length ? (domain(_), rescale()) : domain();
  10076. };
  10077. scale.range = function(_) {
  10078. return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
  10079. };
  10080. scale.rangeRound = function(_) {
  10081. return range$$1 = [+_[0], +_[1]], round = true, rescale();
  10082. };
  10083. scale.bandwidth = function() {
  10084. return bandwidth;
  10085. };
  10086. scale.step = function() {
  10087. return step;
  10088. };
  10089. scale.round = function(_) {
  10090. return arguments.length ? (round = !!_, rescale()) : round;
  10091. };
  10092. scale.padding = function(_) {
  10093. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  10094. };
  10095. scale.paddingInner = function(_) {
  10096. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  10097. };
  10098. scale.paddingOuter = function(_) {
  10099. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  10100. };
  10101. scale.align = function(_) {
  10102. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  10103. };
  10104. scale.copy = function() {
  10105. return band()
  10106. .domain(domain())
  10107. .range(range$$1)
  10108. .round(round)
  10109. .paddingInner(paddingInner)
  10110. .paddingOuter(paddingOuter)
  10111. .align(align);
  10112. };
  10113. return rescale();
  10114. }
  10115. function pointish(scale) {
  10116. var copy = scale.copy;
  10117. scale.padding = scale.paddingOuter;
  10118. delete scale.paddingInner;
  10119. delete scale.paddingOuter;
  10120. scale.copy = function() {
  10121. return pointish(copy());
  10122. };
  10123. return scale;
  10124. }
  10125. function point$1() {
  10126. return pointish(band().paddingInner(1));
  10127. }
  10128. function constant$10(x) {
  10129. return function() {
  10130. return x;
  10131. };
  10132. }
  10133. function number$2(x) {
  10134. return +x;
  10135. }
  10136. var unit = [0, 1];
  10137. function deinterpolateLinear(a, b) {
  10138. return (b -= (a = +a))
  10139. ? function(x) { return (x - a) / b; }
  10140. : constant$10(b);
  10141. }
  10142. function deinterpolateClamp(deinterpolate) {
  10143. return function(a, b) {
  10144. var d = deinterpolate(a = +a, b = +b);
  10145. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  10146. };
  10147. }
  10148. function reinterpolateClamp(reinterpolate$$1) {
  10149. return function(a, b) {
  10150. var r = reinterpolate$$1(a = +a, b = +b);
  10151. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  10152. };
  10153. }
  10154. function bimap(domain, range, deinterpolate, reinterpolate$$1) {
  10155. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  10156. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate$$1(r1, r0);
  10157. else d0 = deinterpolate(d0, d1), r0 = reinterpolate$$1(r0, r1);
  10158. return function(x) { return r0(d0(x)); };
  10159. }
  10160. function polymap(domain, range, deinterpolate, reinterpolate$$1) {
  10161. var j = Math.min(domain.length, range.length) - 1,
  10162. d = new Array(j),
  10163. r = new Array(j),
  10164. i = -1;
  10165. // Reverse descending domains.
  10166. if (domain[j] < domain[0]) {
  10167. domain = domain.slice().reverse();
  10168. range = range.slice().reverse();
  10169. }
  10170. while (++i < j) {
  10171. d[i] = deinterpolate(domain[i], domain[i + 1]);
  10172. r[i] = reinterpolate$$1(range[i], range[i + 1]);
  10173. }
  10174. return function(x) {
  10175. var i = bisectRight(domain, x, 1, j) - 1;
  10176. return r[i](d[i](x));
  10177. };
  10178. }
  10179. function copy(source, target) {
  10180. return target
  10181. .domain(source.domain())
  10182. .range(source.range())
  10183. .interpolate(source.interpolate())
  10184. .clamp(source.clamp());
  10185. }
  10186. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  10187. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  10188. function continuous(deinterpolate, reinterpolate$$1) {
  10189. var domain = unit,
  10190. range = unit,
  10191. interpolate$$1 = interpolateValue,
  10192. clamp = false,
  10193. piecewise,
  10194. output,
  10195. input;
  10196. function rescale() {
  10197. piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  10198. output = input = null;
  10199. return scale;
  10200. }
  10201. function scale(x) {
  10202. return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  10203. }
  10204. scale.invert = function(y) {
  10205. return (input || (input = piecewise(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate$$1) : reinterpolate$$1)))(+y);
  10206. };
  10207. scale.domain = function(_) {
  10208. return arguments.length ? (domain = map$2.call(_, number$2), rescale()) : domain.slice();
  10209. };
  10210. scale.range = function(_) {
  10211. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10212. };
  10213. scale.rangeRound = function(_) {
  10214. return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
  10215. };
  10216. scale.clamp = function(_) {
  10217. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  10218. };
  10219. scale.interpolate = function(_) {
  10220. return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
  10221. };
  10222. return rescale();
  10223. }
  10224. function tickFormat(domain, count, specifier) {
  10225. var start = domain[0],
  10226. stop = domain[domain.length - 1],
  10227. step = tickStep(start, stop, count == null ? 10 : count),
  10228. precision;
  10229. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10230. switch (specifier.type) {
  10231. case "s": {
  10232. var value = Math.max(Math.abs(start), Math.abs(stop));
  10233. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10234. return exports.formatPrefix(specifier, value);
  10235. }
  10236. case "":
  10237. case "e":
  10238. case "g":
  10239. case "p":
  10240. case "r": {
  10241. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10242. break;
  10243. }
  10244. case "f":
  10245. case "%": {
  10246. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10247. break;
  10248. }
  10249. }
  10250. return exports.format(specifier);
  10251. }
  10252. function linearish(scale) {
  10253. var domain = scale.domain;
  10254. scale.ticks = function(count) {
  10255. var d = domain();
  10256. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10257. };
  10258. scale.tickFormat = function(count, specifier) {
  10259. return tickFormat(domain(), count, specifier);
  10260. };
  10261. scale.nice = function(count) {
  10262. if (count == null) count = 10;
  10263. var d = domain(),
  10264. i0 = 0,
  10265. i1 = d.length - 1,
  10266. start = d[i0],
  10267. stop = d[i1],
  10268. step;
  10269. if (stop < start) {
  10270. step = start, start = stop, stop = step;
  10271. step = i0, i0 = i1, i1 = step;
  10272. }
  10273. step = tickIncrement(start, stop, count);
  10274. if (step > 0) {
  10275. start = Math.floor(start / step) * step;
  10276. stop = Math.ceil(stop / step) * step;
  10277. step = tickIncrement(start, stop, count);
  10278. } else if (step < 0) {
  10279. start = Math.ceil(start * step) / step;
  10280. stop = Math.floor(stop * step) / step;
  10281. step = tickIncrement(start, stop, count);
  10282. }
  10283. if (step > 0) {
  10284. d[i0] = Math.floor(start / step) * step;
  10285. d[i1] = Math.ceil(stop / step) * step;
  10286. domain(d);
  10287. } else if (step < 0) {
  10288. d[i0] = Math.ceil(start * step) / step;
  10289. d[i1] = Math.floor(stop * step) / step;
  10290. domain(d);
  10291. }
  10292. return scale;
  10293. };
  10294. return scale;
  10295. }
  10296. function linear$2() {
  10297. var scale = continuous(deinterpolateLinear, reinterpolate);
  10298. scale.copy = function() {
  10299. return copy(scale, linear$2());
  10300. };
  10301. return linearish(scale);
  10302. }
  10303. function identity$6() {
  10304. var domain = [0, 1];
  10305. function scale(x) {
  10306. return +x;
  10307. }
  10308. scale.invert = scale;
  10309. scale.domain = scale.range = function(_) {
  10310. return arguments.length ? (domain = map$2.call(_, number$2), scale) : domain.slice();
  10311. };
  10312. scale.copy = function() {
  10313. return identity$6().domain(domain);
  10314. };
  10315. return linearish(scale);
  10316. }
  10317. function nice(domain, interval) {
  10318. domain = domain.slice();
  10319. var i0 = 0,
  10320. i1 = domain.length - 1,
  10321. x0 = domain[i0],
  10322. x1 = domain[i1],
  10323. t;
  10324. if (x1 < x0) {
  10325. t = i0, i0 = i1, i1 = t;
  10326. t = x0, x0 = x1, x1 = t;
  10327. }
  10328. domain[i0] = interval.floor(x0);
  10329. domain[i1] = interval.ceil(x1);
  10330. return domain;
  10331. }
  10332. function deinterpolate(a, b) {
  10333. return (b = Math.log(b / a))
  10334. ? function(x) { return Math.log(x / a) / b; }
  10335. : constant$10(b);
  10336. }
  10337. function reinterpolate$1(a, b) {
  10338. return a < 0
  10339. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  10340. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  10341. }
  10342. function pow10(x) {
  10343. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10344. }
  10345. function powp(base) {
  10346. return base === 10 ? pow10
  10347. : base === Math.E ? Math.exp
  10348. : function(x) { return Math.pow(base, x); };
  10349. }
  10350. function logp(base) {
  10351. return base === Math.E ? Math.log
  10352. : base === 10 && Math.log10
  10353. || base === 2 && Math.log2
  10354. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10355. }
  10356. function reflect(f) {
  10357. return function(x) {
  10358. return -f(-x);
  10359. };
  10360. }
  10361. function log$1() {
  10362. var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
  10363. domain = scale.domain,
  10364. base = 10,
  10365. logs = logp(10),
  10366. pows = powp(10);
  10367. function rescale() {
  10368. logs = logp(base), pows = powp(base);
  10369. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  10370. return scale;
  10371. }
  10372. scale.base = function(_) {
  10373. return arguments.length ? (base = +_, rescale()) : base;
  10374. };
  10375. scale.domain = function(_) {
  10376. return arguments.length ? (domain(_), rescale()) : domain();
  10377. };
  10378. scale.ticks = function(count) {
  10379. var d = domain(),
  10380. u = d[0],
  10381. v = d[d.length - 1],
  10382. r;
  10383. if (r = v < u) i = u, u = v, v = i;
  10384. var i = logs(u),
  10385. j = logs(v),
  10386. p,
  10387. k,
  10388. t,
  10389. n = count == null ? 10 : +count,
  10390. z = [];
  10391. if (!(base % 1) && j - i < n) {
  10392. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10393. if (u > 0) for (; i < j; ++i) {
  10394. for (k = 1, p = pows(i); k < base; ++k) {
  10395. t = p * k;
  10396. if (t < u) continue;
  10397. if (t > v) break;
  10398. z.push(t);
  10399. }
  10400. } else for (; i < j; ++i) {
  10401. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10402. t = p * k;
  10403. if (t < u) continue;
  10404. if (t > v) break;
  10405. z.push(t);
  10406. }
  10407. }
  10408. } else {
  10409. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10410. }
  10411. return r ? z.reverse() : z;
  10412. };
  10413. scale.tickFormat = function(count, specifier) {
  10414. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10415. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10416. if (count === Infinity) return specifier;
  10417. if (count == null) count = 10;
  10418. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10419. return function(d) {
  10420. var i = d / pows(Math.round(logs(d)));
  10421. if (i * base < base - 0.5) i *= base;
  10422. return i <= k ? specifier(d) : "";
  10423. };
  10424. };
  10425. scale.nice = function() {
  10426. return domain(nice(domain(), {
  10427. floor: function(x) { return pows(Math.floor(logs(x))); },
  10428. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10429. }));
  10430. };
  10431. scale.copy = function() {
  10432. return copy(scale, log$1().base(base));
  10433. };
  10434. return scale;
  10435. }
  10436. function raise$1(x, exponent) {
  10437. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10438. }
  10439. function pow$1() {
  10440. var exponent = 1,
  10441. scale = continuous(deinterpolate, reinterpolate),
  10442. domain = scale.domain;
  10443. function deinterpolate(a, b) {
  10444. return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
  10445. ? function(x) { return (raise$1(x, exponent) - a) / b; }
  10446. : constant$10(b);
  10447. }
  10448. function reinterpolate(a, b) {
  10449. b = raise$1(b, exponent) - (a = raise$1(a, exponent));
  10450. return function(t) { return raise$1(a + b * t, 1 / exponent); };
  10451. }
  10452. scale.exponent = function(_) {
  10453. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  10454. };
  10455. scale.copy = function() {
  10456. return copy(scale, pow$1().exponent(exponent));
  10457. };
  10458. return linearish(scale);
  10459. }
  10460. function sqrt$1() {
  10461. return pow$1().exponent(0.5);
  10462. }
  10463. function quantile$$1() {
  10464. var domain = [],
  10465. range = [],
  10466. thresholds = [];
  10467. function rescale() {
  10468. var i = 0, n = Math.max(1, range.length);
  10469. thresholds = new Array(n - 1);
  10470. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10471. return scale;
  10472. }
  10473. function scale(x) {
  10474. if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
  10475. }
  10476. scale.invertExtent = function(y) {
  10477. var i = range.indexOf(y);
  10478. return i < 0 ? [NaN, NaN] : [
  10479. i > 0 ? thresholds[i - 1] : domain[0],
  10480. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10481. ];
  10482. };
  10483. scale.domain = function(_) {
  10484. if (!arguments.length) return domain.slice();
  10485. domain = [];
  10486. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10487. domain.sort(ascending);
  10488. return rescale();
  10489. };
  10490. scale.range = function(_) {
  10491. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10492. };
  10493. scale.quantiles = function() {
  10494. return thresholds.slice();
  10495. };
  10496. scale.copy = function() {
  10497. return quantile$$1()
  10498. .domain(domain)
  10499. .range(range);
  10500. };
  10501. return scale;
  10502. }
  10503. function quantize$1() {
  10504. var x0 = 0,
  10505. x1 = 1,
  10506. n = 1,
  10507. domain = [0.5],
  10508. range = [0, 1];
  10509. function scale(x) {
  10510. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10511. }
  10512. function rescale() {
  10513. var i = -1;
  10514. domain = new Array(n);
  10515. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10516. return scale;
  10517. }
  10518. scale.domain = function(_) {
  10519. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10520. };
  10521. scale.range = function(_) {
  10522. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10523. };
  10524. scale.invertExtent = function(y) {
  10525. var i = range.indexOf(y);
  10526. return i < 0 ? [NaN, NaN]
  10527. : i < 1 ? [x0, domain[0]]
  10528. : i >= n ? [domain[n - 1], x1]
  10529. : [domain[i - 1], domain[i]];
  10530. };
  10531. scale.copy = function() {
  10532. return quantize$1()
  10533. .domain([x0, x1])
  10534. .range(range);
  10535. };
  10536. return linearish(scale);
  10537. }
  10538. function threshold$1() {
  10539. var domain = [0.5],
  10540. range = [0, 1],
  10541. n = 1;
  10542. function scale(x) {
  10543. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10544. }
  10545. scale.domain = function(_) {
  10546. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10547. };
  10548. scale.range = function(_) {
  10549. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10550. };
  10551. scale.invertExtent = function(y) {
  10552. var i = range.indexOf(y);
  10553. return [domain[i - 1], domain[i]];
  10554. };
  10555. scale.copy = function() {
  10556. return threshold$1()
  10557. .domain(domain)
  10558. .range(range);
  10559. };
  10560. return scale;
  10561. }
  10562. var t0$1 = new Date,
  10563. t1$1 = new Date;
  10564. function newInterval(floori, offseti, count, field) {
  10565. function interval(date) {
  10566. return floori(date = new Date(+date)), date;
  10567. }
  10568. interval.floor = interval;
  10569. interval.ceil = function(date) {
  10570. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10571. };
  10572. interval.round = function(date) {
  10573. var d0 = interval(date),
  10574. d1 = interval.ceil(date);
  10575. return date - d0 < d1 - date ? d0 : d1;
  10576. };
  10577. interval.offset = function(date, step) {
  10578. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10579. };
  10580. interval.range = function(start, stop, step) {
  10581. var range = [], previous;
  10582. start = interval.ceil(start);
  10583. step = step == null ? 1 : Math.floor(step);
  10584. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10585. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  10586. while (previous < start && start < stop);
  10587. return range;
  10588. };
  10589. interval.filter = function(test) {
  10590. return newInterval(function(date) {
  10591. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10592. }, function(date, step) {
  10593. if (date >= date) {
  10594. if (step < 0) while (++step <= 0) {
  10595. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10596. } else while (--step >= 0) {
  10597. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10598. }
  10599. }
  10600. });
  10601. };
  10602. if (count) {
  10603. interval.count = function(start, end) {
  10604. t0$1.setTime(+start), t1$1.setTime(+end);
  10605. floori(t0$1), floori(t1$1);
  10606. return Math.floor(count(t0$1, t1$1));
  10607. };
  10608. interval.every = function(step) {
  10609. step = Math.floor(step);
  10610. return !isFinite(step) || !(step > 0) ? null
  10611. : !(step > 1) ? interval
  10612. : interval.filter(field
  10613. ? function(d) { return field(d) % step === 0; }
  10614. : function(d) { return interval.count(0, d) % step === 0; });
  10615. };
  10616. }
  10617. return interval;
  10618. }
  10619. var millisecond = newInterval(function() {
  10620. // noop
  10621. }, function(date, step) {
  10622. date.setTime(+date + step);
  10623. }, function(start, end) {
  10624. return end - start;
  10625. });
  10626. // An optimized implementation for this simple case.
  10627. millisecond.every = function(k) {
  10628. k = Math.floor(k);
  10629. if (!isFinite(k) || !(k > 0)) return null;
  10630. if (!(k > 1)) return millisecond;
  10631. return newInterval(function(date) {
  10632. date.setTime(Math.floor(date / k) * k);
  10633. }, function(date, step) {
  10634. date.setTime(+date + step * k);
  10635. }, function(start, end) {
  10636. return (end - start) / k;
  10637. });
  10638. };
  10639. var milliseconds = millisecond.range;
  10640. var durationSecond = 1e3;
  10641. var durationMinute = 6e4;
  10642. var durationHour = 36e5;
  10643. var durationDay = 864e5;
  10644. var durationWeek = 6048e5;
  10645. var second = newInterval(function(date) {
  10646. date.setTime(Math.floor(date / durationSecond) * durationSecond);
  10647. }, function(date, step) {
  10648. date.setTime(+date + step * durationSecond);
  10649. }, function(start, end) {
  10650. return (end - start) / durationSecond;
  10651. }, function(date) {
  10652. return date.getUTCSeconds();
  10653. });
  10654. var seconds = second.range;
  10655. var minute = newInterval(function(date) {
  10656. date.setTime(Math.floor(date / durationMinute) * durationMinute);
  10657. }, function(date, step) {
  10658. date.setTime(+date + step * durationMinute);
  10659. }, function(start, end) {
  10660. return (end - start) / durationMinute;
  10661. }, function(date) {
  10662. return date.getMinutes();
  10663. });
  10664. var minutes = minute.range;
  10665. var hour = newInterval(function(date) {
  10666. var offset = date.getTimezoneOffset() * durationMinute % durationHour;
  10667. if (offset < 0) offset += durationHour;
  10668. date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
  10669. }, function(date, step) {
  10670. date.setTime(+date + step * durationHour);
  10671. }, function(start, end) {
  10672. return (end - start) / durationHour;
  10673. }, function(date) {
  10674. return date.getHours();
  10675. });
  10676. var hours = hour.range;
  10677. var day = newInterval(function(date) {
  10678. date.setHours(0, 0, 0, 0);
  10679. }, function(date, step) {
  10680. date.setDate(date.getDate() + step);
  10681. }, function(start, end) {
  10682. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  10683. }, function(date) {
  10684. return date.getDate() - 1;
  10685. });
  10686. var days = day.range;
  10687. function weekday(i) {
  10688. return newInterval(function(date) {
  10689. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  10690. date.setHours(0, 0, 0, 0);
  10691. }, function(date, step) {
  10692. date.setDate(date.getDate() + step * 7);
  10693. }, function(start, end) {
  10694. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  10695. });
  10696. }
  10697. var sunday = weekday(0);
  10698. var monday = weekday(1);
  10699. var tuesday = weekday(2);
  10700. var wednesday = weekday(3);
  10701. var thursday = weekday(4);
  10702. var friday = weekday(5);
  10703. var saturday = weekday(6);
  10704. var sundays = sunday.range;
  10705. var mondays = monday.range;
  10706. var tuesdays = tuesday.range;
  10707. var wednesdays = wednesday.range;
  10708. var thursdays = thursday.range;
  10709. var fridays = friday.range;
  10710. var saturdays = saturday.range;
  10711. var month = newInterval(function(date) {
  10712. date.setDate(1);
  10713. date.setHours(0, 0, 0, 0);
  10714. }, function(date, step) {
  10715. date.setMonth(date.getMonth() + step);
  10716. }, function(start, end) {
  10717. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  10718. }, function(date) {
  10719. return date.getMonth();
  10720. });
  10721. var months = month.range;
  10722. var year = newInterval(function(date) {
  10723. date.setMonth(0, 1);
  10724. date.setHours(0, 0, 0, 0);
  10725. }, function(date, step) {
  10726. date.setFullYear(date.getFullYear() + step);
  10727. }, function(start, end) {
  10728. return end.getFullYear() - start.getFullYear();
  10729. }, function(date) {
  10730. return date.getFullYear();
  10731. });
  10732. // An optimized implementation for this simple case.
  10733. year.every = function(k) {
  10734. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10735. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  10736. date.setMonth(0, 1);
  10737. date.setHours(0, 0, 0, 0);
  10738. }, function(date, step) {
  10739. date.setFullYear(date.getFullYear() + step * k);
  10740. });
  10741. };
  10742. var years = year.range;
  10743. var utcMinute = newInterval(function(date) {
  10744. date.setUTCSeconds(0, 0);
  10745. }, function(date, step) {
  10746. date.setTime(+date + step * durationMinute);
  10747. }, function(start, end) {
  10748. return (end - start) / durationMinute;
  10749. }, function(date) {
  10750. return date.getUTCMinutes();
  10751. });
  10752. var utcMinutes = utcMinute.range;
  10753. var utcHour = newInterval(function(date) {
  10754. date.setUTCMinutes(0, 0, 0);
  10755. }, function(date, step) {
  10756. date.setTime(+date + step * durationHour);
  10757. }, function(start, end) {
  10758. return (end - start) / durationHour;
  10759. }, function(date) {
  10760. return date.getUTCHours();
  10761. });
  10762. var utcHours = utcHour.range;
  10763. var utcDay = newInterval(function(date) {
  10764. date.setUTCHours(0, 0, 0, 0);
  10765. }, function(date, step) {
  10766. date.setUTCDate(date.getUTCDate() + step);
  10767. }, function(start, end) {
  10768. return (end - start) / durationDay;
  10769. }, function(date) {
  10770. return date.getUTCDate() - 1;
  10771. });
  10772. var utcDays = utcDay.range;
  10773. function utcWeekday(i) {
  10774. return newInterval(function(date) {
  10775. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  10776. date.setUTCHours(0, 0, 0, 0);
  10777. }, function(date, step) {
  10778. date.setUTCDate(date.getUTCDate() + step * 7);
  10779. }, function(start, end) {
  10780. return (end - start) / durationWeek;
  10781. });
  10782. }
  10783. var utcSunday = utcWeekday(0);
  10784. var utcMonday = utcWeekday(1);
  10785. var utcTuesday = utcWeekday(2);
  10786. var utcWednesday = utcWeekday(3);
  10787. var utcThursday = utcWeekday(4);
  10788. var utcFriday = utcWeekday(5);
  10789. var utcSaturday = utcWeekday(6);
  10790. var utcSundays = utcSunday.range;
  10791. var utcMondays = utcMonday.range;
  10792. var utcTuesdays = utcTuesday.range;
  10793. var utcWednesdays = utcWednesday.range;
  10794. var utcThursdays = utcThursday.range;
  10795. var utcFridays = utcFriday.range;
  10796. var utcSaturdays = utcSaturday.range;
  10797. var utcMonth = newInterval(function(date) {
  10798. date.setUTCDate(1);
  10799. date.setUTCHours(0, 0, 0, 0);
  10800. }, function(date, step) {
  10801. date.setUTCMonth(date.getUTCMonth() + step);
  10802. }, function(start, end) {
  10803. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  10804. }, function(date) {
  10805. return date.getUTCMonth();
  10806. });
  10807. var utcMonths = utcMonth.range;
  10808. var utcYear = newInterval(function(date) {
  10809. date.setUTCMonth(0, 1);
  10810. date.setUTCHours(0, 0, 0, 0);
  10811. }, function(date, step) {
  10812. date.setUTCFullYear(date.getUTCFullYear() + step);
  10813. }, function(start, end) {
  10814. return end.getUTCFullYear() - start.getUTCFullYear();
  10815. }, function(date) {
  10816. return date.getUTCFullYear();
  10817. });
  10818. // An optimized implementation for this simple case.
  10819. utcYear.every = function(k) {
  10820. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10821. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  10822. date.setUTCMonth(0, 1);
  10823. date.setUTCHours(0, 0, 0, 0);
  10824. }, function(date, step) {
  10825. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  10826. });
  10827. };
  10828. var utcYears = utcYear.range;
  10829. function localDate(d) {
  10830. if (0 <= d.y && d.y < 100) {
  10831. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  10832. date.setFullYear(d.y);
  10833. return date;
  10834. }
  10835. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  10836. }
  10837. function utcDate(d) {
  10838. if (0 <= d.y && d.y < 100) {
  10839. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  10840. date.setUTCFullYear(d.y);
  10841. return date;
  10842. }
  10843. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  10844. }
  10845. function newYear(y) {
  10846. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  10847. }
  10848. function formatLocale$1(locale) {
  10849. var locale_dateTime = locale.dateTime,
  10850. locale_date = locale.date,
  10851. locale_time = locale.time,
  10852. locale_periods = locale.periods,
  10853. locale_weekdays = locale.days,
  10854. locale_shortWeekdays = locale.shortDays,
  10855. locale_months = locale.months,
  10856. locale_shortMonths = locale.shortMonths;
  10857. var periodRe = formatRe(locale_periods),
  10858. periodLookup = formatLookup(locale_periods),
  10859. weekdayRe = formatRe(locale_weekdays),
  10860. weekdayLookup = formatLookup(locale_weekdays),
  10861. shortWeekdayRe = formatRe(locale_shortWeekdays),
  10862. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  10863. monthRe = formatRe(locale_months),
  10864. monthLookup = formatLookup(locale_months),
  10865. shortMonthRe = formatRe(locale_shortMonths),
  10866. shortMonthLookup = formatLookup(locale_shortMonths);
  10867. var formats = {
  10868. "a": formatShortWeekday,
  10869. "A": formatWeekday,
  10870. "b": formatShortMonth,
  10871. "B": formatMonth,
  10872. "c": null,
  10873. "d": formatDayOfMonth,
  10874. "e": formatDayOfMonth,
  10875. "f": formatMicroseconds,
  10876. "H": formatHour24,
  10877. "I": formatHour12,
  10878. "j": formatDayOfYear,
  10879. "L": formatMilliseconds,
  10880. "m": formatMonthNumber,
  10881. "M": formatMinutes,
  10882. "p": formatPeriod,
  10883. "Q": formatUnixTimestamp,
  10884. "s": formatUnixTimestampSeconds,
  10885. "S": formatSeconds,
  10886. "u": formatWeekdayNumberMonday,
  10887. "U": formatWeekNumberSunday,
  10888. "V": formatWeekNumberISO,
  10889. "w": formatWeekdayNumberSunday,
  10890. "W": formatWeekNumberMonday,
  10891. "x": null,
  10892. "X": null,
  10893. "y": formatYear,
  10894. "Y": formatFullYear,
  10895. "Z": formatZone,
  10896. "%": formatLiteralPercent
  10897. };
  10898. var utcFormats = {
  10899. "a": formatUTCShortWeekday,
  10900. "A": formatUTCWeekday,
  10901. "b": formatUTCShortMonth,
  10902. "B": formatUTCMonth,
  10903. "c": null,
  10904. "d": formatUTCDayOfMonth,
  10905. "e": formatUTCDayOfMonth,
  10906. "f": formatUTCMicroseconds,
  10907. "H": formatUTCHour24,
  10908. "I": formatUTCHour12,
  10909. "j": formatUTCDayOfYear,
  10910. "L": formatUTCMilliseconds,
  10911. "m": formatUTCMonthNumber,
  10912. "M": formatUTCMinutes,
  10913. "p": formatUTCPeriod,
  10914. "Q": formatUnixTimestamp,
  10915. "s": formatUnixTimestampSeconds,
  10916. "S": formatUTCSeconds,
  10917. "u": formatUTCWeekdayNumberMonday,
  10918. "U": formatUTCWeekNumberSunday,
  10919. "V": formatUTCWeekNumberISO,
  10920. "w": formatUTCWeekdayNumberSunday,
  10921. "W": formatUTCWeekNumberMonday,
  10922. "x": null,
  10923. "X": null,
  10924. "y": formatUTCYear,
  10925. "Y": formatUTCFullYear,
  10926. "Z": formatUTCZone,
  10927. "%": formatLiteralPercent
  10928. };
  10929. var parses = {
  10930. "a": parseShortWeekday,
  10931. "A": parseWeekday,
  10932. "b": parseShortMonth,
  10933. "B": parseMonth,
  10934. "c": parseLocaleDateTime,
  10935. "d": parseDayOfMonth,
  10936. "e": parseDayOfMonth,
  10937. "f": parseMicroseconds,
  10938. "H": parseHour24,
  10939. "I": parseHour24,
  10940. "j": parseDayOfYear,
  10941. "L": parseMilliseconds,
  10942. "m": parseMonthNumber,
  10943. "M": parseMinutes,
  10944. "p": parsePeriod,
  10945. "Q": parseUnixTimestamp,
  10946. "s": parseUnixTimestampSeconds,
  10947. "S": parseSeconds,
  10948. "u": parseWeekdayNumberMonday,
  10949. "U": parseWeekNumberSunday,
  10950. "V": parseWeekNumberISO,
  10951. "w": parseWeekdayNumberSunday,
  10952. "W": parseWeekNumberMonday,
  10953. "x": parseLocaleDate,
  10954. "X": parseLocaleTime,
  10955. "y": parseYear,
  10956. "Y": parseFullYear,
  10957. "Z": parseZone,
  10958. "%": parseLiteralPercent
  10959. };
  10960. // These recursive directive definitions must be deferred.
  10961. formats.x = newFormat(locale_date, formats);
  10962. formats.X = newFormat(locale_time, formats);
  10963. formats.c = newFormat(locale_dateTime, formats);
  10964. utcFormats.x = newFormat(locale_date, utcFormats);
  10965. utcFormats.X = newFormat(locale_time, utcFormats);
  10966. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  10967. function newFormat(specifier, formats) {
  10968. return function(date) {
  10969. var string = [],
  10970. i = -1,
  10971. j = 0,
  10972. n = specifier.length,
  10973. c,
  10974. pad,
  10975. format;
  10976. if (!(date instanceof Date)) date = new Date(+date);
  10977. while (++i < n) {
  10978. if (specifier.charCodeAt(i) === 37) {
  10979. string.push(specifier.slice(j, i));
  10980. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  10981. else pad = c === "e" ? " " : "0";
  10982. if (format = formats[c]) c = format(date, pad);
  10983. string.push(c);
  10984. j = i + 1;
  10985. }
  10986. }
  10987. string.push(specifier.slice(j, i));
  10988. return string.join("");
  10989. };
  10990. }
  10991. function newParse(specifier, newDate) {
  10992. return function(string) {
  10993. var d = newYear(1900),
  10994. i = parseSpecifier(d, specifier, string += "", 0),
  10995. week, day$$1;
  10996. if (i != string.length) return null;
  10997. // If a UNIX timestamp is specified, return it.
  10998. if ("Q" in d) return new Date(d.Q);
  10999. // The am-pm flag is 0 for AM, and 1 for PM.
  11000. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  11001. // Convert day-of-week and week-of-year to day-of-year.
  11002. if ("V" in d) {
  11003. if (d.V < 1 || d.V > 53) return null;
  11004. if (!("w" in d)) d.w = 1;
  11005. if ("Z" in d) {
  11006. week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
  11007. week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  11008. week = utcDay.offset(week, (d.V - 1) * 7);
  11009. d.y = week.getUTCFullYear();
  11010. d.m = week.getUTCMonth();
  11011. d.d = week.getUTCDate() + (d.w + 6) % 7;
  11012. } else {
  11013. week = newDate(newYear(d.y)), day$$1 = week.getDay();
  11014. week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
  11015. week = day.offset(week, (d.V - 1) * 7);
  11016. d.y = week.getFullYear();
  11017. d.m = week.getMonth();
  11018. d.d = week.getDate() + (d.w + 6) % 7;
  11019. }
  11020. } else if ("W" in d || "U" in d) {
  11021. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  11022. day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  11023. d.m = 0;
  11024. 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;
  11025. }
  11026. // If a time zone is specified, all fields are interpreted as UTC and then
  11027. // offset according to the specified time zone.
  11028. if ("Z" in d) {
  11029. d.H += d.Z / 100 | 0;
  11030. d.M += d.Z % 100;
  11031. return utcDate(d);
  11032. }
  11033. // Otherwise, all fields are in local time.
  11034. return newDate(d);
  11035. };
  11036. }
  11037. function parseSpecifier(d, specifier, string, j) {
  11038. var i = 0,
  11039. n = specifier.length,
  11040. m = string.length,
  11041. c,
  11042. parse;
  11043. while (i < n) {
  11044. if (j >= m) return -1;
  11045. c = specifier.charCodeAt(i++);
  11046. if (c === 37) {
  11047. c = specifier.charAt(i++);
  11048. parse = parses[c in pads ? specifier.charAt(i++) : c];
  11049. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  11050. } else if (c != string.charCodeAt(j++)) {
  11051. return -1;
  11052. }
  11053. }
  11054. return j;
  11055. }
  11056. function parsePeriod(d, string, i) {
  11057. var n = periodRe.exec(string.slice(i));
  11058. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11059. }
  11060. function parseShortWeekday(d, string, i) {
  11061. var n = shortWeekdayRe.exec(string.slice(i));
  11062. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11063. }
  11064. function parseWeekday(d, string, i) {
  11065. var n = weekdayRe.exec(string.slice(i));
  11066. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11067. }
  11068. function parseShortMonth(d, string, i) {
  11069. var n = shortMonthRe.exec(string.slice(i));
  11070. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11071. }
  11072. function parseMonth(d, string, i) {
  11073. var n = monthRe.exec(string.slice(i));
  11074. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11075. }
  11076. function parseLocaleDateTime(d, string, i) {
  11077. return parseSpecifier(d, locale_dateTime, string, i);
  11078. }
  11079. function parseLocaleDate(d, string, i) {
  11080. return parseSpecifier(d, locale_date, string, i);
  11081. }
  11082. function parseLocaleTime(d, string, i) {
  11083. return parseSpecifier(d, locale_time, string, i);
  11084. }
  11085. function formatShortWeekday(d) {
  11086. return locale_shortWeekdays[d.getDay()];
  11087. }
  11088. function formatWeekday(d) {
  11089. return locale_weekdays[d.getDay()];
  11090. }
  11091. function formatShortMonth(d) {
  11092. return locale_shortMonths[d.getMonth()];
  11093. }
  11094. function formatMonth(d) {
  11095. return locale_months[d.getMonth()];
  11096. }
  11097. function formatPeriod(d) {
  11098. return locale_periods[+(d.getHours() >= 12)];
  11099. }
  11100. function formatUTCShortWeekday(d) {
  11101. return locale_shortWeekdays[d.getUTCDay()];
  11102. }
  11103. function formatUTCWeekday(d) {
  11104. return locale_weekdays[d.getUTCDay()];
  11105. }
  11106. function formatUTCShortMonth(d) {
  11107. return locale_shortMonths[d.getUTCMonth()];
  11108. }
  11109. function formatUTCMonth(d) {
  11110. return locale_months[d.getUTCMonth()];
  11111. }
  11112. function formatUTCPeriod(d) {
  11113. return locale_periods[+(d.getUTCHours() >= 12)];
  11114. }
  11115. return {
  11116. format: function(specifier) {
  11117. var f = newFormat(specifier += "", formats);
  11118. f.toString = function() { return specifier; };
  11119. return f;
  11120. },
  11121. parse: function(specifier) {
  11122. var p = newParse(specifier += "", localDate);
  11123. p.toString = function() { return specifier; };
  11124. return p;
  11125. },
  11126. utcFormat: function(specifier) {
  11127. var f = newFormat(specifier += "", utcFormats);
  11128. f.toString = function() { return specifier; };
  11129. return f;
  11130. },
  11131. utcParse: function(specifier) {
  11132. var p = newParse(specifier, utcDate);
  11133. p.toString = function() { return specifier; };
  11134. return p;
  11135. }
  11136. };
  11137. }
  11138. var pads = {"-": "", "_": " ", "0": "0"},
  11139. numberRe = /^\s*\d+/, // note: ignores next directive
  11140. percentRe = /^%/,
  11141. requoteRe = /[\\^$*+?|[\]().{}]/g;
  11142. function pad(value, fill, width) {
  11143. var sign = value < 0 ? "-" : "",
  11144. string = (sign ? -value : value) + "",
  11145. length = string.length;
  11146. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  11147. }
  11148. function requote(s) {
  11149. return s.replace(requoteRe, "\\$&");
  11150. }
  11151. function formatRe(names) {
  11152. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  11153. }
  11154. function formatLookup(names) {
  11155. var map = {}, i = -1, n = names.length;
  11156. while (++i < n) map[names[i].toLowerCase()] = i;
  11157. return map;
  11158. }
  11159. function parseWeekdayNumberSunday(d, string, i) {
  11160. var n = numberRe.exec(string.slice(i, i + 1));
  11161. return n ? (d.w = +n[0], i + n[0].length) : -1;
  11162. }
  11163. function parseWeekdayNumberMonday(d, string, i) {
  11164. var n = numberRe.exec(string.slice(i, i + 1));
  11165. return n ? (d.u = +n[0], i + n[0].length) : -1;
  11166. }
  11167. function parseWeekNumberSunday(d, string, i) {
  11168. var n = numberRe.exec(string.slice(i, i + 2));
  11169. return n ? (d.U = +n[0], i + n[0].length) : -1;
  11170. }
  11171. function parseWeekNumberISO(d, string, i) {
  11172. var n = numberRe.exec(string.slice(i, i + 2));
  11173. return n ? (d.V = +n[0], i + n[0].length) : -1;
  11174. }
  11175. function parseWeekNumberMonday(d, string, i) {
  11176. var n = numberRe.exec(string.slice(i, i + 2));
  11177. return n ? (d.W = +n[0], i + n[0].length) : -1;
  11178. }
  11179. function parseFullYear(d, string, i) {
  11180. var n = numberRe.exec(string.slice(i, i + 4));
  11181. return n ? (d.y = +n[0], i + n[0].length) : -1;
  11182. }
  11183. function parseYear(d, string, i) {
  11184. var n = numberRe.exec(string.slice(i, i + 2));
  11185. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  11186. }
  11187. function parseZone(d, string, i) {
  11188. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  11189. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  11190. }
  11191. function parseMonthNumber(d, string, i) {
  11192. var n = numberRe.exec(string.slice(i, i + 2));
  11193. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  11194. }
  11195. function parseDayOfMonth(d, string, i) {
  11196. var n = numberRe.exec(string.slice(i, i + 2));
  11197. return n ? (d.d = +n[0], i + n[0].length) : -1;
  11198. }
  11199. function parseDayOfYear(d, string, i) {
  11200. var n = numberRe.exec(string.slice(i, i + 3));
  11201. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  11202. }
  11203. function parseHour24(d, string, i) {
  11204. var n = numberRe.exec(string.slice(i, i + 2));
  11205. return n ? (d.H = +n[0], i + n[0].length) : -1;
  11206. }
  11207. function parseMinutes(d, string, i) {
  11208. var n = numberRe.exec(string.slice(i, i + 2));
  11209. return n ? (d.M = +n[0], i + n[0].length) : -1;
  11210. }
  11211. function parseSeconds(d, string, i) {
  11212. var n = numberRe.exec(string.slice(i, i + 2));
  11213. return n ? (d.S = +n[0], i + n[0].length) : -1;
  11214. }
  11215. function parseMilliseconds(d, string, i) {
  11216. var n = numberRe.exec(string.slice(i, i + 3));
  11217. return n ? (d.L = +n[0], i + n[0].length) : -1;
  11218. }
  11219. function parseMicroseconds(d, string, i) {
  11220. var n = numberRe.exec(string.slice(i, i + 6));
  11221. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  11222. }
  11223. function parseLiteralPercent(d, string, i) {
  11224. var n = percentRe.exec(string.slice(i, i + 1));
  11225. return n ? i + n[0].length : -1;
  11226. }
  11227. function parseUnixTimestamp(d, string, i) {
  11228. var n = numberRe.exec(string.slice(i));
  11229. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  11230. }
  11231. function parseUnixTimestampSeconds(d, string, i) {
  11232. var n = numberRe.exec(string.slice(i));
  11233. return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
  11234. }
  11235. function formatDayOfMonth(d, p) {
  11236. return pad(d.getDate(), p, 2);
  11237. }
  11238. function formatHour24(d, p) {
  11239. return pad(d.getHours(), p, 2);
  11240. }
  11241. function formatHour12(d, p) {
  11242. return pad(d.getHours() % 12 || 12, p, 2);
  11243. }
  11244. function formatDayOfYear(d, p) {
  11245. return pad(1 + day.count(year(d), d), p, 3);
  11246. }
  11247. function formatMilliseconds(d, p) {
  11248. return pad(d.getMilliseconds(), p, 3);
  11249. }
  11250. function formatMicroseconds(d, p) {
  11251. return formatMilliseconds(d, p) + "000";
  11252. }
  11253. function formatMonthNumber(d, p) {
  11254. return pad(d.getMonth() + 1, p, 2);
  11255. }
  11256. function formatMinutes(d, p) {
  11257. return pad(d.getMinutes(), p, 2);
  11258. }
  11259. function formatSeconds(d, p) {
  11260. return pad(d.getSeconds(), p, 2);
  11261. }
  11262. function formatWeekdayNumberMonday(d) {
  11263. var day$$1 = d.getDay();
  11264. return day$$1 === 0 ? 7 : day$$1;
  11265. }
  11266. function formatWeekNumberSunday(d, p) {
  11267. return pad(sunday.count(year(d), d), p, 2);
  11268. }
  11269. function formatWeekNumberISO(d, p) {
  11270. var day$$1 = d.getDay();
  11271. d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
  11272. return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  11273. }
  11274. function formatWeekdayNumberSunday(d) {
  11275. return d.getDay();
  11276. }
  11277. function formatWeekNumberMonday(d, p) {
  11278. return pad(monday.count(year(d), d), p, 2);
  11279. }
  11280. function formatYear(d, p) {
  11281. return pad(d.getFullYear() % 100, p, 2);
  11282. }
  11283. function formatFullYear(d, p) {
  11284. return pad(d.getFullYear() % 10000, p, 4);
  11285. }
  11286. function formatZone(d) {
  11287. var z = d.getTimezoneOffset();
  11288. return (z > 0 ? "-" : (z *= -1, "+"))
  11289. + pad(z / 60 | 0, "0", 2)
  11290. + pad(z % 60, "0", 2);
  11291. }
  11292. function formatUTCDayOfMonth(d, p) {
  11293. return pad(d.getUTCDate(), p, 2);
  11294. }
  11295. function formatUTCHour24(d, p) {
  11296. return pad(d.getUTCHours(), p, 2);
  11297. }
  11298. function formatUTCHour12(d, p) {
  11299. return pad(d.getUTCHours() % 12 || 12, p, 2);
  11300. }
  11301. function formatUTCDayOfYear(d, p) {
  11302. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  11303. }
  11304. function formatUTCMilliseconds(d, p) {
  11305. return pad(d.getUTCMilliseconds(), p, 3);
  11306. }
  11307. function formatUTCMicroseconds(d, p) {
  11308. return formatUTCMilliseconds(d, p) + "000";
  11309. }
  11310. function formatUTCMonthNumber(d, p) {
  11311. return pad(d.getUTCMonth() + 1, p, 2);
  11312. }
  11313. function formatUTCMinutes(d, p) {
  11314. return pad(d.getUTCMinutes(), p, 2);
  11315. }
  11316. function formatUTCSeconds(d, p) {
  11317. return pad(d.getUTCSeconds(), p, 2);
  11318. }
  11319. function formatUTCWeekdayNumberMonday(d) {
  11320. var dow = d.getUTCDay();
  11321. return dow === 0 ? 7 : dow;
  11322. }
  11323. function formatUTCWeekNumberSunday(d, p) {
  11324. return pad(utcSunday.count(utcYear(d), d), p, 2);
  11325. }
  11326. function formatUTCWeekNumberISO(d, p) {
  11327. var day$$1 = d.getUTCDay();
  11328. d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
  11329. return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  11330. }
  11331. function formatUTCWeekdayNumberSunday(d) {
  11332. return d.getUTCDay();
  11333. }
  11334. function formatUTCWeekNumberMonday(d, p) {
  11335. return pad(utcMonday.count(utcYear(d), d), p, 2);
  11336. }
  11337. function formatUTCYear(d, p) {
  11338. return pad(d.getUTCFullYear() % 100, p, 2);
  11339. }
  11340. function formatUTCFullYear(d, p) {
  11341. return pad(d.getUTCFullYear() % 10000, p, 4);
  11342. }
  11343. function formatUTCZone() {
  11344. return "+0000";
  11345. }
  11346. function formatLiteralPercent() {
  11347. return "%";
  11348. }
  11349. function formatUnixTimestamp(d) {
  11350. return +d;
  11351. }
  11352. function formatUnixTimestampSeconds(d) {
  11353. return Math.floor(+d / 1000);
  11354. }
  11355. var locale$1;
  11356. defaultLocale$1({
  11357. dateTime: "%x, %X",
  11358. date: "%-m/%-d/%Y",
  11359. time: "%-I:%M:%S %p",
  11360. periods: ["AM", "PM"],
  11361. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11362. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11363. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11364. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11365. });
  11366. function defaultLocale$1(definition) {
  11367. locale$1 = formatLocale$1(definition);
  11368. exports.timeFormat = locale$1.format;
  11369. exports.timeParse = locale$1.parse;
  11370. exports.utcFormat = locale$1.utcFormat;
  11371. exports.utcParse = locale$1.utcParse;
  11372. return locale$1;
  11373. }
  11374. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11375. function formatIsoNative(date) {
  11376. return date.toISOString();
  11377. }
  11378. var formatIso = Date.prototype.toISOString
  11379. ? formatIsoNative
  11380. : exports.utcFormat(isoSpecifier);
  11381. function parseIsoNative(string) {
  11382. var date = new Date(string);
  11383. return isNaN(date) ? null : date;
  11384. }
  11385. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11386. ? parseIsoNative
  11387. : exports.utcParse(isoSpecifier);
  11388. var durationSecond$1 = 1000,
  11389. durationMinute$1 = durationSecond$1 * 60,
  11390. durationHour$1 = durationMinute$1 * 60,
  11391. durationDay$1 = durationHour$1 * 24,
  11392. durationWeek$1 = durationDay$1 * 7,
  11393. durationMonth = durationDay$1 * 30,
  11394. durationYear = durationDay$1 * 365;
  11395. function date$1(t) {
  11396. return new Date(t);
  11397. }
  11398. function number$3(t) {
  11399. return t instanceof Date ? +t : +new Date(+t);
  11400. }
  11401. function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
  11402. var scale = continuous(deinterpolateLinear, reinterpolate),
  11403. invert = scale.invert,
  11404. domain = scale.domain;
  11405. var formatMillisecond = format(".%L"),
  11406. formatSecond = format(":%S"),
  11407. formatMinute = format("%I:%M"),
  11408. formatHour = format("%I %p"),
  11409. formatDay = format("%a %d"),
  11410. formatWeek = format("%b %d"),
  11411. formatMonth = format("%B"),
  11412. formatYear = format("%Y");
  11413. var tickIntervals = [
  11414. [second$$1, 1, durationSecond$1],
  11415. [second$$1, 5, 5 * durationSecond$1],
  11416. [second$$1, 15, 15 * durationSecond$1],
  11417. [second$$1, 30, 30 * durationSecond$1],
  11418. [minute$$1, 1, durationMinute$1],
  11419. [minute$$1, 5, 5 * durationMinute$1],
  11420. [minute$$1, 15, 15 * durationMinute$1],
  11421. [minute$$1, 30, 30 * durationMinute$1],
  11422. [ hour$$1, 1, durationHour$1 ],
  11423. [ hour$$1, 3, 3 * durationHour$1 ],
  11424. [ hour$$1, 6, 6 * durationHour$1 ],
  11425. [ hour$$1, 12, 12 * durationHour$1 ],
  11426. [ day$$1, 1, durationDay$1 ],
  11427. [ day$$1, 2, 2 * durationDay$1 ],
  11428. [ week, 1, durationWeek$1 ],
  11429. [ month$$1, 1, durationMonth ],
  11430. [ month$$1, 3, 3 * durationMonth ],
  11431. [ year$$1, 1, durationYear ]
  11432. ];
  11433. function tickFormat(date$$1) {
  11434. return (second$$1(date$$1) < date$$1 ? formatMillisecond
  11435. : minute$$1(date$$1) < date$$1 ? formatSecond
  11436. : hour$$1(date$$1) < date$$1 ? formatMinute
  11437. : day$$1(date$$1) < date$$1 ? formatHour
  11438. : month$$1(date$$1) < date$$1 ? (week(date$$1) < date$$1 ? formatDay : formatWeek)
  11439. : year$$1(date$$1) < date$$1 ? formatMonth
  11440. : formatYear)(date$$1);
  11441. }
  11442. function tickInterval(interval, start, stop, step) {
  11443. if (interval == null) interval = 10;
  11444. // If a desired tick count is specified, pick a reasonable tick interval
  11445. // based on the extent of the domain and a rough estimate of tick size.
  11446. // Otherwise, assume interval is already a time interval and use it.
  11447. if (typeof interval === "number") {
  11448. var target = Math.abs(stop - start) / interval,
  11449. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11450. if (i === tickIntervals.length) {
  11451. step = tickStep(start / durationYear, stop / durationYear, interval);
  11452. interval = year$$1;
  11453. } else if (i) {
  11454. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11455. step = i[1];
  11456. interval = i[0];
  11457. } else {
  11458. step = Math.max(tickStep(start, stop, interval), 1);
  11459. interval = millisecond$$1;
  11460. }
  11461. }
  11462. return step == null ? interval : interval.every(step);
  11463. }
  11464. scale.invert = function(y) {
  11465. return new Date(invert(y));
  11466. };
  11467. scale.domain = function(_) {
  11468. return arguments.length ? domain(map$2.call(_, number$3)) : domain().map(date$1);
  11469. };
  11470. scale.ticks = function(interval, step) {
  11471. var d = domain(),
  11472. t0 = d[0],
  11473. t1 = d[d.length - 1],
  11474. r = t1 < t0,
  11475. t;
  11476. if (r) t = t0, t0 = t1, t1 = t;
  11477. t = tickInterval(interval, t0, t1, step);
  11478. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11479. return r ? t.reverse() : t;
  11480. };
  11481. scale.tickFormat = function(count, specifier) {
  11482. return specifier == null ? tickFormat : format(specifier);
  11483. };
  11484. scale.nice = function(interval, step) {
  11485. var d = domain();
  11486. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11487. ? domain(nice(d, interval))
  11488. : scale;
  11489. };
  11490. scale.copy = function() {
  11491. return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
  11492. };
  11493. return scale;
  11494. }
  11495. function time() {
  11496. return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  11497. }
  11498. function utcTime() {
  11499. return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  11500. }
  11501. function sequential(interpolator) {
  11502. var x0 = 0,
  11503. x1 = 1,
  11504. clamp = false;
  11505. function scale(x) {
  11506. var t = (x - x0) / (x1 - x0);
  11507. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11508. }
  11509. scale.domain = function(_) {
  11510. return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
  11511. };
  11512. scale.clamp = function(_) {
  11513. return arguments.length ? (clamp = !!_, scale) : clamp;
  11514. };
  11515. scale.interpolator = function(_) {
  11516. return arguments.length ? (interpolator = _, scale) : interpolator;
  11517. };
  11518. scale.copy = function() {
  11519. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  11520. };
  11521. return linearish(scale);
  11522. }
  11523. function colors(specifier) {
  11524. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  11525. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  11526. return colors;
  11527. }
  11528. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  11529. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  11530. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  11531. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  11532. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  11533. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  11534. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  11535. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  11536. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  11537. function ramp(scheme) {
  11538. return rgbBasis(scheme[scheme.length - 1]);
  11539. }
  11540. var scheme = new Array(3).concat(
  11541. "d8b365f5f5f55ab4ac",
  11542. "a6611adfc27d80cdc1018571",
  11543. "a6611adfc27df5f5f580cdc1018571",
  11544. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  11545. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  11546. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  11547. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  11548. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  11549. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  11550. ).map(colors);
  11551. var BrBG = ramp(scheme);
  11552. var scheme$1 = new Array(3).concat(
  11553. "af8dc3f7f7f77fbf7b",
  11554. "7b3294c2a5cfa6dba0008837",
  11555. "7b3294c2a5cff7f7f7a6dba0008837",
  11556. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  11557. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  11558. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  11559. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  11560. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  11561. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  11562. ).map(colors);
  11563. var PRGn = ramp(scheme$1);
  11564. var scheme$2 = new Array(3).concat(
  11565. "e9a3c9f7f7f7a1d76a",
  11566. "d01c8bf1b6dab8e1864dac26",
  11567. "d01c8bf1b6daf7f7f7b8e1864dac26",
  11568. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  11569. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  11570. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  11571. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  11572. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  11573. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  11574. ).map(colors);
  11575. var PiYG = ramp(scheme$2);
  11576. var scheme$3 = new Array(3).concat(
  11577. "998ec3f7f7f7f1a340",
  11578. "5e3c99b2abd2fdb863e66101",
  11579. "5e3c99b2abd2f7f7f7fdb863e66101",
  11580. "542788998ec3d8daebfee0b6f1a340b35806",
  11581. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  11582. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  11583. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  11584. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  11585. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  11586. ).map(colors);
  11587. var PuOr = ramp(scheme$3);
  11588. var scheme$4 = new Array(3).concat(
  11589. "ef8a62f7f7f767a9cf",
  11590. "ca0020f4a58292c5de0571b0",
  11591. "ca0020f4a582f7f7f792c5de0571b0",
  11592. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  11593. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  11594. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  11595. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  11596. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  11597. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  11598. ).map(colors);
  11599. var RdBu = ramp(scheme$4);
  11600. var scheme$5 = new Array(3).concat(
  11601. "ef8a62ffffff999999",
  11602. "ca0020f4a582bababa404040",
  11603. "ca0020f4a582ffffffbababa404040",
  11604. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  11605. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  11606. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  11607. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  11608. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  11609. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  11610. ).map(colors);
  11611. var RdGy = ramp(scheme$5);
  11612. var scheme$6 = new Array(3).concat(
  11613. "fc8d59ffffbf91bfdb",
  11614. "d7191cfdae61abd9e92c7bb6",
  11615. "d7191cfdae61ffffbfabd9e92c7bb6",
  11616. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  11617. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  11618. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  11619. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  11620. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  11621. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  11622. ).map(colors);
  11623. var RdYlBu = ramp(scheme$6);
  11624. var scheme$7 = new Array(3).concat(
  11625. "fc8d59ffffbf91cf60",
  11626. "d7191cfdae61a6d96a1a9641",
  11627. "d7191cfdae61ffffbfa6d96a1a9641",
  11628. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  11629. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  11630. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  11631. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  11632. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  11633. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  11634. ).map(colors);
  11635. var RdYlGn = ramp(scheme$7);
  11636. var scheme$8 = new Array(3).concat(
  11637. "fc8d59ffffbf99d594",
  11638. "d7191cfdae61abdda42b83ba",
  11639. "d7191cfdae61ffffbfabdda42b83ba",
  11640. "d53e4ffc8d59fee08be6f59899d5943288bd",
  11641. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  11642. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  11643. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  11644. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  11645. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  11646. ).map(colors);
  11647. var Spectral = ramp(scheme$8);
  11648. var scheme$9 = new Array(3).concat(
  11649. "e5f5f999d8c92ca25f",
  11650. "edf8fbb2e2e266c2a4238b45",
  11651. "edf8fbb2e2e266c2a42ca25f006d2c",
  11652. "edf8fbccece699d8c966c2a42ca25f006d2c",
  11653. "edf8fbccece699d8c966c2a441ae76238b45005824",
  11654. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  11655. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  11656. ).map(colors);
  11657. var BuGn = ramp(scheme$9);
  11658. var scheme$10 = new Array(3).concat(
  11659. "e0ecf49ebcda8856a7",
  11660. "edf8fbb3cde38c96c688419d",
  11661. "edf8fbb3cde38c96c68856a7810f7c",
  11662. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  11663. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  11664. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  11665. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  11666. ).map(colors);
  11667. var BuPu = ramp(scheme$10);
  11668. var scheme$11 = new Array(3).concat(
  11669. "e0f3dba8ddb543a2ca",
  11670. "f0f9e8bae4bc7bccc42b8cbe",
  11671. "f0f9e8bae4bc7bccc443a2ca0868ac",
  11672. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  11673. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  11674. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  11675. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  11676. ).map(colors);
  11677. var GnBu = ramp(scheme$11);
  11678. var scheme$12 = new Array(3).concat(
  11679. "fee8c8fdbb84e34a33",
  11680. "fef0d9fdcc8afc8d59d7301f",
  11681. "fef0d9fdcc8afc8d59e34a33b30000",
  11682. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  11683. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  11684. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  11685. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  11686. ).map(colors);
  11687. var OrRd = ramp(scheme$12);
  11688. var scheme$13 = new Array(3).concat(
  11689. "ece2f0a6bddb1c9099",
  11690. "f6eff7bdc9e167a9cf02818a",
  11691. "f6eff7bdc9e167a9cf1c9099016c59",
  11692. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  11693. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  11694. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  11695. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  11696. ).map(colors);
  11697. var PuBuGn = ramp(scheme$13);
  11698. var scheme$14 = new Array(3).concat(
  11699. "ece7f2a6bddb2b8cbe",
  11700. "f1eef6bdc9e174a9cf0570b0",
  11701. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  11702. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  11703. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  11704. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  11705. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  11706. ).map(colors);
  11707. var PuBu = ramp(scheme$14);
  11708. var scheme$15 = new Array(3).concat(
  11709. "e7e1efc994c7dd1c77",
  11710. "f1eef6d7b5d8df65b0ce1256",
  11711. "f1eef6d7b5d8df65b0dd1c77980043",
  11712. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  11713. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  11714. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  11715. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  11716. ).map(colors);
  11717. var PuRd = ramp(scheme$15);
  11718. var scheme$16 = new Array(3).concat(
  11719. "fde0ddfa9fb5c51b8a",
  11720. "feebe2fbb4b9f768a1ae017e",
  11721. "feebe2fbb4b9f768a1c51b8a7a0177",
  11722. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  11723. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  11724. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  11725. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  11726. ).map(colors);
  11727. var RdPu = ramp(scheme$16);
  11728. var scheme$17 = new Array(3).concat(
  11729. "edf8b17fcdbb2c7fb8",
  11730. "ffffcca1dab441b6c4225ea8",
  11731. "ffffcca1dab441b6c42c7fb8253494",
  11732. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  11733. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  11734. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  11735. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  11736. ).map(colors);
  11737. var YlGnBu = ramp(scheme$17);
  11738. var scheme$18 = new Array(3).concat(
  11739. "f7fcb9addd8e31a354",
  11740. "ffffccc2e69978c679238443",
  11741. "ffffccc2e69978c67931a354006837",
  11742. "ffffccd9f0a3addd8e78c67931a354006837",
  11743. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  11744. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  11745. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  11746. ).map(colors);
  11747. var YlGn = ramp(scheme$18);
  11748. var scheme$19 = new Array(3).concat(
  11749. "fff7bcfec44fd95f0e",
  11750. "ffffd4fed98efe9929cc4c02",
  11751. "ffffd4fed98efe9929d95f0e993404",
  11752. "ffffd4fee391fec44ffe9929d95f0e993404",
  11753. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  11754. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  11755. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  11756. ).map(colors);
  11757. var YlOrBr = ramp(scheme$19);
  11758. var scheme$20 = new Array(3).concat(
  11759. "ffeda0feb24cf03b20",
  11760. "ffffb2fecc5cfd8d3ce31a1c",
  11761. "ffffb2fecc5cfd8d3cf03b20bd0026",
  11762. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  11763. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  11764. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  11765. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  11766. ).map(colors);
  11767. var YlOrRd = ramp(scheme$20);
  11768. var scheme$21 = new Array(3).concat(
  11769. "deebf79ecae13182bd",
  11770. "eff3ffbdd7e76baed62171b5",
  11771. "eff3ffbdd7e76baed63182bd08519c",
  11772. "eff3ffc6dbef9ecae16baed63182bd08519c",
  11773. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  11774. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  11775. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  11776. ).map(colors);
  11777. var Blues = ramp(scheme$21);
  11778. var scheme$22 = new Array(3).concat(
  11779. "e5f5e0a1d99b31a354",
  11780. "edf8e9bae4b374c476238b45",
  11781. "edf8e9bae4b374c47631a354006d2c",
  11782. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  11783. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  11784. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  11785. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  11786. ).map(colors);
  11787. var Greens = ramp(scheme$22);
  11788. var scheme$23 = new Array(3).concat(
  11789. "f0f0f0bdbdbd636363",
  11790. "f7f7f7cccccc969696525252",
  11791. "f7f7f7cccccc969696636363252525",
  11792. "f7f7f7d9d9d9bdbdbd969696636363252525",
  11793. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  11794. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  11795. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  11796. ).map(colors);
  11797. var Greys = ramp(scheme$23);
  11798. var scheme$24 = new Array(3).concat(
  11799. "efedf5bcbddc756bb1",
  11800. "f2f0f7cbc9e29e9ac86a51a3",
  11801. "f2f0f7cbc9e29e9ac8756bb154278f",
  11802. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  11803. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  11804. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  11805. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  11806. ).map(colors);
  11807. var Purples = ramp(scheme$24);
  11808. var scheme$25 = new Array(3).concat(
  11809. "fee0d2fc9272de2d26",
  11810. "fee5d9fcae91fb6a4acb181d",
  11811. "fee5d9fcae91fb6a4ade2d26a50f15",
  11812. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  11813. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  11814. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  11815. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  11816. ).map(colors);
  11817. var Reds = ramp(scheme$25);
  11818. var scheme$26 = new Array(3).concat(
  11819. "fee6cefdae6be6550d",
  11820. "feeddefdbe85fd8d3cd94701",
  11821. "feeddefdbe85fd8d3ce6550da63603",
  11822. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  11823. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  11824. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  11825. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  11826. ).map(colors);
  11827. var Oranges = ramp(scheme$26);
  11828. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  11829. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11830. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11831. var rainbow = cubehelix();
  11832. function rainbow$1(t) {
  11833. if (t < 0 || t > 1) t -= Math.floor(t);
  11834. var ts = Math.abs(t - 0.5);
  11835. rainbow.h = 360 * t - 100;
  11836. rainbow.s = 1.5 - 1.5 * ts;
  11837. rainbow.l = 0.8 - 0.9 * ts;
  11838. return rainbow + "";
  11839. }
  11840. function ramp$1(range) {
  11841. var n = range.length;
  11842. return function(t) {
  11843. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  11844. };
  11845. }
  11846. var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  11847. var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  11848. var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  11849. var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  11850. function constant$11(x) {
  11851. return function constant() {
  11852. return x;
  11853. };
  11854. }
  11855. var abs$1 = Math.abs;
  11856. var atan2$1 = Math.atan2;
  11857. var cos$2 = Math.cos;
  11858. var max$2 = Math.max;
  11859. var min$1 = Math.min;
  11860. var sin$2 = Math.sin;
  11861. var sqrt$2 = Math.sqrt;
  11862. var epsilon$3 = 1e-12;
  11863. var pi$4 = Math.PI;
  11864. var halfPi$3 = pi$4 / 2;
  11865. var tau$4 = 2 * pi$4;
  11866. function acos$1(x) {
  11867. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  11868. }
  11869. function asin$1(x) {
  11870. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  11871. }
  11872. function arcInnerRadius(d) {
  11873. return d.innerRadius;
  11874. }
  11875. function arcOuterRadius(d) {
  11876. return d.outerRadius;
  11877. }
  11878. function arcStartAngle(d) {
  11879. return d.startAngle;
  11880. }
  11881. function arcEndAngle(d) {
  11882. return d.endAngle;
  11883. }
  11884. function arcPadAngle(d) {
  11885. return d && d.padAngle; // Note: optional!
  11886. }
  11887. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  11888. var x10 = x1 - x0, y10 = y1 - y0,
  11889. x32 = x3 - x2, y32 = y3 - y2,
  11890. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  11891. return [x0 + t * x10, y0 + t * y10];
  11892. }
  11893. // Compute perpendicular offset line of length rc.
  11894. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  11895. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  11896. var x01 = x0 - x1,
  11897. y01 = y0 - y1,
  11898. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  11899. ox = lo * y01,
  11900. oy = -lo * x01,
  11901. x11 = x0 + ox,
  11902. y11 = y0 + oy,
  11903. x10 = x1 + ox,
  11904. y10 = y1 + oy,
  11905. x00 = (x11 + x10) / 2,
  11906. y00 = (y11 + y10) / 2,
  11907. dx = x10 - x11,
  11908. dy = y10 - y11,
  11909. d2 = dx * dx + dy * dy,
  11910. r = r1 - rc,
  11911. D = x11 * y10 - x10 * y11,
  11912. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  11913. cx0 = (D * dy - dx * d) / d2,
  11914. cy0 = (-D * dx - dy * d) / d2,
  11915. cx1 = (D * dy + dx * d) / d2,
  11916. cy1 = (-D * dx + dy * d) / d2,
  11917. dx0 = cx0 - x00,
  11918. dy0 = cy0 - y00,
  11919. dx1 = cx1 - x00,
  11920. dy1 = cy1 - y00;
  11921. // Pick the closer of the two intersection points.
  11922. // TODO Is there a faster way to determine which intersection to use?
  11923. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  11924. return {
  11925. cx: cx0,
  11926. cy: cy0,
  11927. x01: -ox,
  11928. y01: -oy,
  11929. x11: cx0 * (r1 / r - 1),
  11930. y11: cy0 * (r1 / r - 1)
  11931. };
  11932. }
  11933. function arc() {
  11934. var innerRadius = arcInnerRadius,
  11935. outerRadius = arcOuterRadius,
  11936. cornerRadius = constant$11(0),
  11937. padRadius = null,
  11938. startAngle = arcStartAngle,
  11939. endAngle = arcEndAngle,
  11940. padAngle = arcPadAngle,
  11941. context = null;
  11942. function arc() {
  11943. var buffer,
  11944. r,
  11945. r0 = +innerRadius.apply(this, arguments),
  11946. r1 = +outerRadius.apply(this, arguments),
  11947. a0 = startAngle.apply(this, arguments) - halfPi$3,
  11948. a1 = endAngle.apply(this, arguments) - halfPi$3,
  11949. da = abs$1(a1 - a0),
  11950. cw = a1 > a0;
  11951. if (!context) context = buffer = path();
  11952. // Ensure that the outer radius is always larger than the inner radius.
  11953. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  11954. // Is it a point?
  11955. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  11956. // Or is it a circle or annulus?
  11957. else if (da > tau$4 - epsilon$3) {
  11958. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  11959. context.arc(0, 0, r1, a0, a1, !cw);
  11960. if (r0 > epsilon$3) {
  11961. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  11962. context.arc(0, 0, r0, a1, a0, cw);
  11963. }
  11964. }
  11965. // Or is it a circular or annular sector?
  11966. else {
  11967. var a01 = a0,
  11968. a11 = a1,
  11969. a00 = a0,
  11970. a10 = a1,
  11971. da0 = da,
  11972. da1 = da,
  11973. ap = padAngle.apply(this, arguments) / 2,
  11974. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  11975. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  11976. rc0 = rc,
  11977. rc1 = rc,
  11978. t0,
  11979. t1;
  11980. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  11981. if (rp > epsilon$3) {
  11982. var p0 = asin$1(rp / r0 * sin$2(ap)),
  11983. p1 = asin$1(rp / r1 * sin$2(ap));
  11984. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  11985. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  11986. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  11987. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  11988. }
  11989. var x01 = r1 * cos$2(a01),
  11990. y01 = r1 * sin$2(a01),
  11991. x10 = r0 * cos$2(a10),
  11992. y10 = r0 * sin$2(a10);
  11993. // Apply rounded corners?
  11994. if (rc > epsilon$3) {
  11995. var x11 = r1 * cos$2(a11),
  11996. y11 = r1 * sin$2(a11),
  11997. x00 = r0 * cos$2(a00),
  11998. y00 = r0 * sin$2(a00);
  11999. // Restrict the corner radius according to the sector angle.
  12000. if (da < pi$4) {
  12001. var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  12002. ax = x01 - oc[0],
  12003. ay = y01 - oc[1],
  12004. bx = x11 - oc[0],
  12005. by = y11 - oc[1],
  12006. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  12007. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  12008. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  12009. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  12010. }
  12011. }
  12012. // Is the sector collapsed to a line?
  12013. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  12014. // Does the sector’s outer ring have rounded corners?
  12015. else if (rc1 > epsilon$3) {
  12016. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  12017. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  12018. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12019. // Have the corners merged?
  12020. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12021. // Otherwise, draw the two corners and the ring.
  12022. else {
  12023. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12024. 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);
  12025. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12026. }
  12027. }
  12028. // Or is the outer ring just a circular arc?
  12029. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  12030. // Is there no inner ring, and it’s a circular sector?
  12031. // Or perhaps it’s an annular sector collapsed due to padding?
  12032. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  12033. // Does the sector’s inner ring (or point) have rounded corners?
  12034. else if (rc0 > epsilon$3) {
  12035. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  12036. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  12037. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12038. // Have the corners merged?
  12039. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12040. // Otherwise, draw the two corners and the ring.
  12041. else {
  12042. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12043. 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);
  12044. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12045. }
  12046. }
  12047. // Or is the inner ring just a circular arc?
  12048. else context.arc(0, 0, r0, a10, a00, cw);
  12049. }
  12050. context.closePath();
  12051. if (buffer) return context = null, buffer + "" || null;
  12052. }
  12053. arc.centroid = function() {
  12054. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  12055. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  12056. return [cos$2(a) * r, sin$2(a) * r];
  12057. };
  12058. arc.innerRadius = function(_) {
  12059. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : innerRadius;
  12060. };
  12061. arc.outerRadius = function(_) {
  12062. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : outerRadius;
  12063. };
  12064. arc.cornerRadius = function(_) {
  12065. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : cornerRadius;
  12066. };
  12067. arc.padRadius = function(_) {
  12068. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), arc) : padRadius;
  12069. };
  12070. arc.startAngle = function(_) {
  12071. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : startAngle;
  12072. };
  12073. arc.endAngle = function(_) {
  12074. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : endAngle;
  12075. };
  12076. arc.padAngle = function(_) {
  12077. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : padAngle;
  12078. };
  12079. arc.context = function(_) {
  12080. return arguments.length ? (context = _ == null ? null : _, arc) : context;
  12081. };
  12082. return arc;
  12083. }
  12084. function Linear(context) {
  12085. this._context = context;
  12086. }
  12087. Linear.prototype = {
  12088. areaStart: function() {
  12089. this._line = 0;
  12090. },
  12091. areaEnd: function() {
  12092. this._line = NaN;
  12093. },
  12094. lineStart: function() {
  12095. this._point = 0;
  12096. },
  12097. lineEnd: function() {
  12098. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12099. this._line = 1 - this._line;
  12100. },
  12101. point: function(x, y) {
  12102. x = +x, y = +y;
  12103. switch (this._point) {
  12104. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12105. case 1: this._point = 2; // proceed
  12106. default: this._context.lineTo(x, y); break;
  12107. }
  12108. }
  12109. };
  12110. function curveLinear(context) {
  12111. return new Linear(context);
  12112. }
  12113. function x$3(p) {
  12114. return p[0];
  12115. }
  12116. function y$3(p) {
  12117. return p[1];
  12118. }
  12119. function line() {
  12120. var x$$1 = x$3,
  12121. y$$1 = y$3,
  12122. defined = constant$11(true),
  12123. context = null,
  12124. curve = curveLinear,
  12125. output = null;
  12126. function line(data) {
  12127. var i,
  12128. n = data.length,
  12129. d,
  12130. defined0 = false,
  12131. buffer;
  12132. if (context == null) output = curve(buffer = path());
  12133. for (i = 0; i <= n; ++i) {
  12134. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12135. if (defined0 = !defined0) output.lineStart();
  12136. else output.lineEnd();
  12137. }
  12138. if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
  12139. }
  12140. if (buffer) return output = null, buffer + "" || null;
  12141. }
  12142. line.x = function(_) {
  12143. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), line) : x$$1;
  12144. };
  12145. line.y = function(_) {
  12146. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), line) : y$$1;
  12147. };
  12148. line.defined = function(_) {
  12149. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$11(!!_), line) : defined;
  12150. };
  12151. line.curve = function(_) {
  12152. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  12153. };
  12154. line.context = function(_) {
  12155. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  12156. };
  12157. return line;
  12158. }
  12159. function area$3() {
  12160. var x0 = x$3,
  12161. x1 = null,
  12162. y0 = constant$11(0),
  12163. y1 = y$3,
  12164. defined = constant$11(true),
  12165. context = null,
  12166. curve = curveLinear,
  12167. output = null;
  12168. function area(data) {
  12169. var i,
  12170. j,
  12171. k,
  12172. n = data.length,
  12173. d,
  12174. defined0 = false,
  12175. buffer,
  12176. x0z = new Array(n),
  12177. y0z = new Array(n);
  12178. if (context == null) output = curve(buffer = path());
  12179. for (i = 0; i <= n; ++i) {
  12180. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12181. if (defined0 = !defined0) {
  12182. j = i;
  12183. output.areaStart();
  12184. output.lineStart();
  12185. } else {
  12186. output.lineEnd();
  12187. output.lineStart();
  12188. for (k = i - 1; k >= j; --k) {
  12189. output.point(x0z[k], y0z[k]);
  12190. }
  12191. output.lineEnd();
  12192. output.areaEnd();
  12193. }
  12194. }
  12195. if (defined0) {
  12196. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  12197. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  12198. }
  12199. }
  12200. if (buffer) return output = null, buffer + "" || null;
  12201. }
  12202. function arealine() {
  12203. return line().defined(defined).curve(curve).context(context);
  12204. }
  12205. area.x = function(_) {
  12206. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$11(+_), x1 = null, area) : x0;
  12207. };
  12208. area.x0 = function(_) {
  12209. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$11(+_), area) : x0;
  12210. };
  12211. area.x1 = function(_) {
  12212. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), area) : x1;
  12213. };
  12214. area.y = function(_) {
  12215. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$11(+_), y1 = null, area) : y0;
  12216. };
  12217. area.y0 = function(_) {
  12218. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$11(+_), area) : y0;
  12219. };
  12220. area.y1 = function(_) {
  12221. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), area) : y1;
  12222. };
  12223. area.lineX0 =
  12224. area.lineY0 = function() {
  12225. return arealine().x(x0).y(y0);
  12226. };
  12227. area.lineY1 = function() {
  12228. return arealine().x(x0).y(y1);
  12229. };
  12230. area.lineX1 = function() {
  12231. return arealine().x(x1).y(y0);
  12232. };
  12233. area.defined = function(_) {
  12234. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$11(!!_), area) : defined;
  12235. };
  12236. area.curve = function(_) {
  12237. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  12238. };
  12239. area.context = function(_) {
  12240. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  12241. };
  12242. return area;
  12243. }
  12244. function descending$1(a, b) {
  12245. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  12246. }
  12247. function identity$7(d) {
  12248. return d;
  12249. }
  12250. function pie() {
  12251. var value = identity$7,
  12252. sortValues = descending$1,
  12253. sort = null,
  12254. startAngle = constant$11(0),
  12255. endAngle = constant$11(tau$4),
  12256. padAngle = constant$11(0);
  12257. function pie(data) {
  12258. var i,
  12259. n = data.length,
  12260. j,
  12261. k,
  12262. sum = 0,
  12263. index = new Array(n),
  12264. arcs = new Array(n),
  12265. a0 = +startAngle.apply(this, arguments),
  12266. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  12267. a1,
  12268. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  12269. pa = p * (da < 0 ? -1 : 1),
  12270. v;
  12271. for (i = 0; i < n; ++i) {
  12272. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  12273. sum += v;
  12274. }
  12275. }
  12276. // Optionally sort the arcs by previously-computed values or by data.
  12277. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  12278. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  12279. // Compute the arcs! They are stored in the original data's order.
  12280. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  12281. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  12282. data: data[j],
  12283. index: i,
  12284. value: v,
  12285. startAngle: a0,
  12286. endAngle: a1,
  12287. padAngle: p
  12288. };
  12289. }
  12290. return arcs;
  12291. }
  12292. pie.value = function(_) {
  12293. return arguments.length ? (value = typeof _ === "function" ? _ : constant$11(+_), pie) : value;
  12294. };
  12295. pie.sortValues = function(_) {
  12296. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  12297. };
  12298. pie.sort = function(_) {
  12299. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  12300. };
  12301. pie.startAngle = function(_) {
  12302. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : startAngle;
  12303. };
  12304. pie.endAngle = function(_) {
  12305. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : endAngle;
  12306. };
  12307. pie.padAngle = function(_) {
  12308. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : padAngle;
  12309. };
  12310. return pie;
  12311. }
  12312. var curveRadialLinear = curveRadial(curveLinear);
  12313. function Radial(curve) {
  12314. this._curve = curve;
  12315. }
  12316. Radial.prototype = {
  12317. areaStart: function() {
  12318. this._curve.areaStart();
  12319. },
  12320. areaEnd: function() {
  12321. this._curve.areaEnd();
  12322. },
  12323. lineStart: function() {
  12324. this._curve.lineStart();
  12325. },
  12326. lineEnd: function() {
  12327. this._curve.lineEnd();
  12328. },
  12329. point: function(a, r) {
  12330. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  12331. }
  12332. };
  12333. function curveRadial(curve) {
  12334. function radial(context) {
  12335. return new Radial(curve(context));
  12336. }
  12337. radial._curve = curve;
  12338. return radial;
  12339. }
  12340. function lineRadial(l) {
  12341. var c = l.curve;
  12342. l.angle = l.x, delete l.x;
  12343. l.radius = l.y, delete l.y;
  12344. l.curve = function(_) {
  12345. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12346. };
  12347. return l;
  12348. }
  12349. function lineRadial$1() {
  12350. return lineRadial(line().curve(curveRadialLinear));
  12351. }
  12352. function areaRadial() {
  12353. var a = area$3().curve(curveRadialLinear),
  12354. c = a.curve,
  12355. x0 = a.lineX0,
  12356. x1 = a.lineX1,
  12357. y0 = a.lineY0,
  12358. y1 = a.lineY1;
  12359. a.angle = a.x, delete a.x;
  12360. a.startAngle = a.x0, delete a.x0;
  12361. a.endAngle = a.x1, delete a.x1;
  12362. a.radius = a.y, delete a.y;
  12363. a.innerRadius = a.y0, delete a.y0;
  12364. a.outerRadius = a.y1, delete a.y1;
  12365. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  12366. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  12367. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  12368. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  12369. a.curve = function(_) {
  12370. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12371. };
  12372. return a;
  12373. }
  12374. function pointRadial(x, y) {
  12375. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  12376. }
  12377. var slice$6 = Array.prototype.slice;
  12378. function linkSource(d) {
  12379. return d.source;
  12380. }
  12381. function linkTarget(d) {
  12382. return d.target;
  12383. }
  12384. function link$2(curve) {
  12385. var source = linkSource,
  12386. target = linkTarget,
  12387. x$$1 = x$3,
  12388. y$$1 = y$3,
  12389. context = null;
  12390. function link() {
  12391. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  12392. if (!context) context = buffer = path();
  12393. 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));
  12394. if (buffer) return context = null, buffer + "" || null;
  12395. }
  12396. link.source = function(_) {
  12397. return arguments.length ? (source = _, link) : source;
  12398. };
  12399. link.target = function(_) {
  12400. return arguments.length ? (target = _, link) : target;
  12401. };
  12402. link.x = function(_) {
  12403. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), link) : x$$1;
  12404. };
  12405. link.y = function(_) {
  12406. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), link) : y$$1;
  12407. };
  12408. link.context = function(_) {
  12409. return arguments.length ? (context = _ == null ? null : _, link) : context;
  12410. };
  12411. return link;
  12412. }
  12413. function curveHorizontal(context, x0, y0, x1, y1) {
  12414. context.moveTo(x0, y0);
  12415. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  12416. }
  12417. function curveVertical(context, x0, y0, x1, y1) {
  12418. context.moveTo(x0, y0);
  12419. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  12420. }
  12421. function curveRadial$1(context, x0, y0, x1, y1) {
  12422. var p0 = pointRadial(x0, y0),
  12423. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  12424. p2 = pointRadial(x1, y0),
  12425. p3 = pointRadial(x1, y1);
  12426. context.moveTo(p0[0], p0[1]);
  12427. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  12428. }
  12429. function linkHorizontal() {
  12430. return link$2(curveHorizontal);
  12431. }
  12432. function linkVertical() {
  12433. return link$2(curveVertical);
  12434. }
  12435. function linkRadial() {
  12436. var l = link$2(curveRadial$1);
  12437. l.angle = l.x, delete l.x;
  12438. l.radius = l.y, delete l.y;
  12439. return l;
  12440. }
  12441. var circle$2 = {
  12442. draw: function(context, size) {
  12443. var r = Math.sqrt(size / pi$4);
  12444. context.moveTo(r, 0);
  12445. context.arc(0, 0, r, 0, tau$4);
  12446. }
  12447. };
  12448. var cross$2 = {
  12449. draw: function(context, size) {
  12450. var r = Math.sqrt(size / 5) / 2;
  12451. context.moveTo(-3 * r, -r);
  12452. context.lineTo(-r, -r);
  12453. context.lineTo(-r, -3 * r);
  12454. context.lineTo(r, -3 * r);
  12455. context.lineTo(r, -r);
  12456. context.lineTo(3 * r, -r);
  12457. context.lineTo(3 * r, r);
  12458. context.lineTo(r, r);
  12459. context.lineTo(r, 3 * r);
  12460. context.lineTo(-r, 3 * r);
  12461. context.lineTo(-r, r);
  12462. context.lineTo(-3 * r, r);
  12463. context.closePath();
  12464. }
  12465. };
  12466. var tan30 = Math.sqrt(1 / 3),
  12467. tan30_2 = tan30 * 2;
  12468. var diamond = {
  12469. draw: function(context, size) {
  12470. var y = Math.sqrt(size / tan30_2),
  12471. x = y * tan30;
  12472. context.moveTo(0, -y);
  12473. context.lineTo(x, 0);
  12474. context.lineTo(0, y);
  12475. context.lineTo(-x, 0);
  12476. context.closePath();
  12477. }
  12478. };
  12479. var ka = 0.89081309152928522810,
  12480. kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
  12481. kx = Math.sin(tau$4 / 10) * kr,
  12482. ky = -Math.cos(tau$4 / 10) * kr;
  12483. var star = {
  12484. draw: function(context, size) {
  12485. var r = Math.sqrt(size * ka),
  12486. x = kx * r,
  12487. y = ky * r;
  12488. context.moveTo(0, -r);
  12489. context.lineTo(x, y);
  12490. for (var i = 1; i < 5; ++i) {
  12491. var a = tau$4 * i / 5,
  12492. c = Math.cos(a),
  12493. s = Math.sin(a);
  12494. context.lineTo(s * r, -c * r);
  12495. context.lineTo(c * x - s * y, s * x + c * y);
  12496. }
  12497. context.closePath();
  12498. }
  12499. };
  12500. var square = {
  12501. draw: function(context, size) {
  12502. var w = Math.sqrt(size),
  12503. x = -w / 2;
  12504. context.rect(x, x, w, w);
  12505. }
  12506. };
  12507. var sqrt3 = Math.sqrt(3);
  12508. var triangle = {
  12509. draw: function(context, size) {
  12510. var y = -Math.sqrt(size / (sqrt3 * 3));
  12511. context.moveTo(0, y * 2);
  12512. context.lineTo(-sqrt3 * y, -y);
  12513. context.lineTo(sqrt3 * y, -y);
  12514. context.closePath();
  12515. }
  12516. };
  12517. var c = -0.5,
  12518. s = Math.sqrt(3) / 2,
  12519. k = 1 / Math.sqrt(12),
  12520. a = (k / 2 + 1) * 3;
  12521. var wye = {
  12522. draw: function(context, size) {
  12523. var r = Math.sqrt(size / a),
  12524. x0 = r / 2,
  12525. y0 = r * k,
  12526. x1 = x0,
  12527. y1 = r * k + r,
  12528. x2 = -x1,
  12529. y2 = y1;
  12530. context.moveTo(x0, y0);
  12531. context.lineTo(x1, y1);
  12532. context.lineTo(x2, y2);
  12533. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  12534. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  12535. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  12536. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  12537. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  12538. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  12539. context.closePath();
  12540. }
  12541. };
  12542. var symbols = [
  12543. circle$2,
  12544. cross$2,
  12545. diamond,
  12546. square,
  12547. star,
  12548. triangle,
  12549. wye
  12550. ];
  12551. function symbol() {
  12552. var type = constant$11(circle$2),
  12553. size = constant$11(64),
  12554. context = null;
  12555. function symbol() {
  12556. var buffer;
  12557. if (!context) context = buffer = path();
  12558. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  12559. if (buffer) return context = null, buffer + "" || null;
  12560. }
  12561. symbol.type = function(_) {
  12562. return arguments.length ? (type = typeof _ === "function" ? _ : constant$11(_), symbol) : type;
  12563. };
  12564. symbol.size = function(_) {
  12565. return arguments.length ? (size = typeof _ === "function" ? _ : constant$11(+_), symbol) : size;
  12566. };
  12567. symbol.context = function(_) {
  12568. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  12569. };
  12570. return symbol;
  12571. }
  12572. function noop$3() {}
  12573. function point$2(that, x, y) {
  12574. that._context.bezierCurveTo(
  12575. (2 * that._x0 + that._x1) / 3,
  12576. (2 * that._y0 + that._y1) / 3,
  12577. (that._x0 + 2 * that._x1) / 3,
  12578. (that._y0 + 2 * that._y1) / 3,
  12579. (that._x0 + 4 * that._x1 + x) / 6,
  12580. (that._y0 + 4 * that._y1 + y) / 6
  12581. );
  12582. }
  12583. function Basis(context) {
  12584. this._context = context;
  12585. }
  12586. Basis.prototype = {
  12587. areaStart: function() {
  12588. this._line = 0;
  12589. },
  12590. areaEnd: function() {
  12591. this._line = NaN;
  12592. },
  12593. lineStart: function() {
  12594. this._x0 = this._x1 =
  12595. this._y0 = this._y1 = NaN;
  12596. this._point = 0;
  12597. },
  12598. lineEnd: function() {
  12599. switch (this._point) {
  12600. case 3: point$2(this, this._x1, this._y1); // proceed
  12601. case 2: this._context.lineTo(this._x1, this._y1); break;
  12602. }
  12603. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12604. this._line = 1 - this._line;
  12605. },
  12606. point: function(x, y) {
  12607. x = +x, y = +y;
  12608. switch (this._point) {
  12609. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12610. case 1: this._point = 2; break;
  12611. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  12612. default: point$2(this, x, y); break;
  12613. }
  12614. this._x0 = this._x1, this._x1 = x;
  12615. this._y0 = this._y1, this._y1 = y;
  12616. }
  12617. };
  12618. function basis$2(context) {
  12619. return new Basis(context);
  12620. }
  12621. function BasisClosed(context) {
  12622. this._context = context;
  12623. }
  12624. BasisClosed.prototype = {
  12625. areaStart: noop$3,
  12626. areaEnd: noop$3,
  12627. lineStart: function() {
  12628. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  12629. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  12630. this._point = 0;
  12631. },
  12632. lineEnd: function() {
  12633. switch (this._point) {
  12634. case 1: {
  12635. this._context.moveTo(this._x2, this._y2);
  12636. this._context.closePath();
  12637. break;
  12638. }
  12639. case 2: {
  12640. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  12641. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  12642. this._context.closePath();
  12643. break;
  12644. }
  12645. case 3: {
  12646. this.point(this._x2, this._y2);
  12647. this.point(this._x3, this._y3);
  12648. this.point(this._x4, this._y4);
  12649. break;
  12650. }
  12651. }
  12652. },
  12653. point: function(x, y) {
  12654. x = +x, y = +y;
  12655. switch (this._point) {
  12656. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  12657. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  12658. 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;
  12659. default: point$2(this, x, y); break;
  12660. }
  12661. this._x0 = this._x1, this._x1 = x;
  12662. this._y0 = this._y1, this._y1 = y;
  12663. }
  12664. };
  12665. function basisClosed$1(context) {
  12666. return new BasisClosed(context);
  12667. }
  12668. function BasisOpen(context) {
  12669. this._context = context;
  12670. }
  12671. BasisOpen.prototype = {
  12672. areaStart: function() {
  12673. this._line = 0;
  12674. },
  12675. areaEnd: function() {
  12676. this._line = NaN;
  12677. },
  12678. lineStart: function() {
  12679. this._x0 = this._x1 =
  12680. this._y0 = this._y1 = NaN;
  12681. this._point = 0;
  12682. },
  12683. lineEnd: function() {
  12684. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12685. this._line = 1 - this._line;
  12686. },
  12687. point: function(x, y) {
  12688. x = +x, y = +y;
  12689. switch (this._point) {
  12690. case 0: this._point = 1; break;
  12691. case 1: this._point = 2; break;
  12692. 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;
  12693. case 3: this._point = 4; // proceed
  12694. default: point$2(this, x, y); break;
  12695. }
  12696. this._x0 = this._x1, this._x1 = x;
  12697. this._y0 = this._y1, this._y1 = y;
  12698. }
  12699. };
  12700. function basisOpen(context) {
  12701. return new BasisOpen(context);
  12702. }
  12703. function Bundle(context, beta) {
  12704. this._basis = new Basis(context);
  12705. this._beta = beta;
  12706. }
  12707. Bundle.prototype = {
  12708. lineStart: function() {
  12709. this._x = [];
  12710. this._y = [];
  12711. this._basis.lineStart();
  12712. },
  12713. lineEnd: function() {
  12714. var x = this._x,
  12715. y = this._y,
  12716. j = x.length - 1;
  12717. if (j > 0) {
  12718. var x0 = x[0],
  12719. y0 = y[0],
  12720. dx = x[j] - x0,
  12721. dy = y[j] - y0,
  12722. i = -1,
  12723. t;
  12724. while (++i <= j) {
  12725. t = i / j;
  12726. this._basis.point(
  12727. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  12728. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  12729. );
  12730. }
  12731. }
  12732. this._x = this._y = null;
  12733. this._basis.lineEnd();
  12734. },
  12735. point: function(x, y) {
  12736. this._x.push(+x);
  12737. this._y.push(+y);
  12738. }
  12739. };
  12740. var bundle = (function custom(beta) {
  12741. function bundle(context) {
  12742. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  12743. }
  12744. bundle.beta = function(beta) {
  12745. return custom(+beta);
  12746. };
  12747. return bundle;
  12748. })(0.85);
  12749. function point$3(that, x, y) {
  12750. that._context.bezierCurveTo(
  12751. that._x1 + that._k * (that._x2 - that._x0),
  12752. that._y1 + that._k * (that._y2 - that._y0),
  12753. that._x2 + that._k * (that._x1 - x),
  12754. that._y2 + that._k * (that._y1 - y),
  12755. that._x2,
  12756. that._y2
  12757. );
  12758. }
  12759. function Cardinal(context, tension) {
  12760. this._context = context;
  12761. this._k = (1 - tension) / 6;
  12762. }
  12763. Cardinal.prototype = {
  12764. areaStart: function() {
  12765. this._line = 0;
  12766. },
  12767. areaEnd: function() {
  12768. this._line = NaN;
  12769. },
  12770. lineStart: function() {
  12771. this._x0 = this._x1 = this._x2 =
  12772. this._y0 = this._y1 = this._y2 = NaN;
  12773. this._point = 0;
  12774. },
  12775. lineEnd: function() {
  12776. switch (this._point) {
  12777. case 2: this._context.lineTo(this._x2, this._y2); break;
  12778. case 3: point$3(this, this._x1, this._y1); break;
  12779. }
  12780. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12781. this._line = 1 - this._line;
  12782. },
  12783. point: function(x, y) {
  12784. x = +x, y = +y;
  12785. switch (this._point) {
  12786. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12787. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  12788. case 2: this._point = 3; // proceed
  12789. default: point$3(this, x, y); break;
  12790. }
  12791. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12792. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12793. }
  12794. };
  12795. var cardinal = (function custom(tension) {
  12796. function cardinal(context) {
  12797. return new Cardinal(context, tension);
  12798. }
  12799. cardinal.tension = function(tension) {
  12800. return custom(+tension);
  12801. };
  12802. return cardinal;
  12803. })(0);
  12804. function CardinalClosed(context, tension) {
  12805. this._context = context;
  12806. this._k = (1 - tension) / 6;
  12807. }
  12808. CardinalClosed.prototype = {
  12809. areaStart: noop$3,
  12810. areaEnd: noop$3,
  12811. lineStart: function() {
  12812. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12813. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12814. this._point = 0;
  12815. },
  12816. lineEnd: function() {
  12817. switch (this._point) {
  12818. case 1: {
  12819. this._context.moveTo(this._x3, this._y3);
  12820. this._context.closePath();
  12821. break;
  12822. }
  12823. case 2: {
  12824. this._context.lineTo(this._x3, this._y3);
  12825. this._context.closePath();
  12826. break;
  12827. }
  12828. case 3: {
  12829. this.point(this._x3, this._y3);
  12830. this.point(this._x4, this._y4);
  12831. this.point(this._x5, this._y5);
  12832. break;
  12833. }
  12834. }
  12835. },
  12836. point: function(x, y) {
  12837. x = +x, y = +y;
  12838. switch (this._point) {
  12839. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12840. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12841. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12842. default: point$3(this, x, y); break;
  12843. }
  12844. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12845. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12846. }
  12847. };
  12848. var cardinalClosed = (function custom(tension) {
  12849. function cardinal$$1(context) {
  12850. return new CardinalClosed(context, tension);
  12851. }
  12852. cardinal$$1.tension = function(tension) {
  12853. return custom(+tension);
  12854. };
  12855. return cardinal$$1;
  12856. })(0);
  12857. function CardinalOpen(context, tension) {
  12858. this._context = context;
  12859. this._k = (1 - tension) / 6;
  12860. }
  12861. CardinalOpen.prototype = {
  12862. areaStart: function() {
  12863. this._line = 0;
  12864. },
  12865. areaEnd: function() {
  12866. this._line = NaN;
  12867. },
  12868. lineStart: function() {
  12869. this._x0 = this._x1 = this._x2 =
  12870. this._y0 = this._y1 = this._y2 = NaN;
  12871. this._point = 0;
  12872. },
  12873. lineEnd: function() {
  12874. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12875. this._line = 1 - this._line;
  12876. },
  12877. point: function(x, y) {
  12878. x = +x, y = +y;
  12879. switch (this._point) {
  12880. case 0: this._point = 1; break;
  12881. case 1: this._point = 2; break;
  12882. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12883. case 3: this._point = 4; // proceed
  12884. default: point$3(this, x, y); break;
  12885. }
  12886. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12887. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12888. }
  12889. };
  12890. var cardinalOpen = (function custom(tension) {
  12891. function cardinal$$1(context) {
  12892. return new CardinalOpen(context, tension);
  12893. }
  12894. cardinal$$1.tension = function(tension) {
  12895. return custom(+tension);
  12896. };
  12897. return cardinal$$1;
  12898. })(0);
  12899. function point$4(that, x, y) {
  12900. var x1 = that._x1,
  12901. y1 = that._y1,
  12902. x2 = that._x2,
  12903. y2 = that._y2;
  12904. if (that._l01_a > epsilon$3) {
  12905. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  12906. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  12907. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  12908. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  12909. }
  12910. if (that._l23_a > epsilon$3) {
  12911. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  12912. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  12913. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  12914. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  12915. }
  12916. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  12917. }
  12918. function CatmullRom(context, alpha) {
  12919. this._context = context;
  12920. this._alpha = alpha;
  12921. }
  12922. CatmullRom.prototype = {
  12923. areaStart: function() {
  12924. this._line = 0;
  12925. },
  12926. areaEnd: function() {
  12927. this._line = NaN;
  12928. },
  12929. lineStart: function() {
  12930. this._x0 = this._x1 = this._x2 =
  12931. this._y0 = this._y1 = this._y2 = NaN;
  12932. this._l01_a = this._l12_a = this._l23_a =
  12933. this._l01_2a = this._l12_2a = this._l23_2a =
  12934. this._point = 0;
  12935. },
  12936. lineEnd: function() {
  12937. switch (this._point) {
  12938. case 2: this._context.lineTo(this._x2, this._y2); break;
  12939. case 3: this.point(this._x2, this._y2); break;
  12940. }
  12941. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12942. this._line = 1 - this._line;
  12943. },
  12944. point: function(x, y) {
  12945. x = +x, y = +y;
  12946. if (this._point) {
  12947. var x23 = this._x2 - x,
  12948. y23 = this._y2 - y;
  12949. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12950. }
  12951. switch (this._point) {
  12952. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12953. case 1: this._point = 2; break;
  12954. case 2: this._point = 3; // proceed
  12955. default: point$4(this, x, y); break;
  12956. }
  12957. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12958. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12959. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12960. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12961. }
  12962. };
  12963. var catmullRom = (function custom(alpha) {
  12964. function catmullRom(context) {
  12965. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  12966. }
  12967. catmullRom.alpha = function(alpha) {
  12968. return custom(+alpha);
  12969. };
  12970. return catmullRom;
  12971. })(0.5);
  12972. function CatmullRomClosed(context, alpha) {
  12973. this._context = context;
  12974. this._alpha = alpha;
  12975. }
  12976. CatmullRomClosed.prototype = {
  12977. areaStart: noop$3,
  12978. areaEnd: noop$3,
  12979. lineStart: function() {
  12980. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12981. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12982. this._l01_a = this._l12_a = this._l23_a =
  12983. this._l01_2a = this._l12_2a = this._l23_2a =
  12984. this._point = 0;
  12985. },
  12986. lineEnd: function() {
  12987. switch (this._point) {
  12988. case 1: {
  12989. this._context.moveTo(this._x3, this._y3);
  12990. this._context.closePath();
  12991. break;
  12992. }
  12993. case 2: {
  12994. this._context.lineTo(this._x3, this._y3);
  12995. this._context.closePath();
  12996. break;
  12997. }
  12998. case 3: {
  12999. this.point(this._x3, this._y3);
  13000. this.point(this._x4, this._y4);
  13001. this.point(this._x5, this._y5);
  13002. break;
  13003. }
  13004. }
  13005. },
  13006. point: function(x, y) {
  13007. x = +x, y = +y;
  13008. if (this._point) {
  13009. var x23 = this._x2 - x,
  13010. y23 = this._y2 - y;
  13011. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13012. }
  13013. switch (this._point) {
  13014. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13015. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13016. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13017. default: point$4(this, x, y); break;
  13018. }
  13019. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13020. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13021. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13022. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13023. }
  13024. };
  13025. var catmullRomClosed = (function custom(alpha) {
  13026. function catmullRom$$1(context) {
  13027. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  13028. }
  13029. catmullRom$$1.alpha = function(alpha) {
  13030. return custom(+alpha);
  13031. };
  13032. return catmullRom$$1;
  13033. })(0.5);
  13034. function CatmullRomOpen(context, alpha) {
  13035. this._context = context;
  13036. this._alpha = alpha;
  13037. }
  13038. CatmullRomOpen.prototype = {
  13039. areaStart: function() {
  13040. this._line = 0;
  13041. },
  13042. areaEnd: function() {
  13043. this._line = NaN;
  13044. },
  13045. lineStart: function() {
  13046. this._x0 = this._x1 = this._x2 =
  13047. this._y0 = this._y1 = this._y2 = NaN;
  13048. this._l01_a = this._l12_a = this._l23_a =
  13049. this._l01_2a = this._l12_2a = this._l23_2a =
  13050. this._point = 0;
  13051. },
  13052. lineEnd: function() {
  13053. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13054. this._line = 1 - this._line;
  13055. },
  13056. point: function(x, y) {
  13057. x = +x, y = +y;
  13058. if (this._point) {
  13059. var x23 = this._x2 - x,
  13060. y23 = this._y2 - y;
  13061. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13062. }
  13063. switch (this._point) {
  13064. case 0: this._point = 1; break;
  13065. case 1: this._point = 2; break;
  13066. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13067. case 3: this._point = 4; // proceed
  13068. default: point$4(this, x, y); break;
  13069. }
  13070. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13071. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13072. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13073. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13074. }
  13075. };
  13076. var catmullRomOpen = (function custom(alpha) {
  13077. function catmullRom$$1(context) {
  13078. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  13079. }
  13080. catmullRom$$1.alpha = function(alpha) {
  13081. return custom(+alpha);
  13082. };
  13083. return catmullRom$$1;
  13084. })(0.5);
  13085. function LinearClosed(context) {
  13086. this._context = context;
  13087. }
  13088. LinearClosed.prototype = {
  13089. areaStart: noop$3,
  13090. areaEnd: noop$3,
  13091. lineStart: function() {
  13092. this._point = 0;
  13093. },
  13094. lineEnd: function() {
  13095. if (this._point) this._context.closePath();
  13096. },
  13097. point: function(x, y) {
  13098. x = +x, y = +y;
  13099. if (this._point) this._context.lineTo(x, y);
  13100. else this._point = 1, this._context.moveTo(x, y);
  13101. }
  13102. };
  13103. function linearClosed(context) {
  13104. return new LinearClosed(context);
  13105. }
  13106. function sign$1(x) {
  13107. return x < 0 ? -1 : 1;
  13108. }
  13109. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  13110. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  13111. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  13112. // NOV(II), P. 443, 1990.
  13113. function slope3(that, x2, y2) {
  13114. var h0 = that._x1 - that._x0,
  13115. h1 = x2 - that._x1,
  13116. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  13117. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  13118. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  13119. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  13120. }
  13121. // Calculate a one-sided slope.
  13122. function slope2(that, t) {
  13123. var h = that._x1 - that._x0;
  13124. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  13125. }
  13126. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  13127. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  13128. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  13129. function point$5(that, t0, t1) {
  13130. var x0 = that._x0,
  13131. y0 = that._y0,
  13132. x1 = that._x1,
  13133. y1 = that._y1,
  13134. dx = (x1 - x0) / 3;
  13135. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  13136. }
  13137. function MonotoneX(context) {
  13138. this._context = context;
  13139. }
  13140. MonotoneX.prototype = {
  13141. areaStart: function() {
  13142. this._line = 0;
  13143. },
  13144. areaEnd: function() {
  13145. this._line = NaN;
  13146. },
  13147. lineStart: function() {
  13148. this._x0 = this._x1 =
  13149. this._y0 = this._y1 =
  13150. this._t0 = NaN;
  13151. this._point = 0;
  13152. },
  13153. lineEnd: function() {
  13154. switch (this._point) {
  13155. case 2: this._context.lineTo(this._x1, this._y1); break;
  13156. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  13157. }
  13158. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13159. this._line = 1 - this._line;
  13160. },
  13161. point: function(x, y) {
  13162. var t1 = NaN;
  13163. x = +x, y = +y;
  13164. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  13165. switch (this._point) {
  13166. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13167. case 1: this._point = 2; break;
  13168. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  13169. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  13170. }
  13171. this._x0 = this._x1, this._x1 = x;
  13172. this._y0 = this._y1, this._y1 = y;
  13173. this._t0 = t1;
  13174. }
  13175. };
  13176. function MonotoneY(context) {
  13177. this._context = new ReflectContext(context);
  13178. }
  13179. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  13180. MonotoneX.prototype.point.call(this, y, x);
  13181. };
  13182. function ReflectContext(context) {
  13183. this._context = context;
  13184. }
  13185. ReflectContext.prototype = {
  13186. moveTo: function(x, y) { this._context.moveTo(y, x); },
  13187. closePath: function() { this._context.closePath(); },
  13188. lineTo: function(x, y) { this._context.lineTo(y, x); },
  13189. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  13190. };
  13191. function monotoneX(context) {
  13192. return new MonotoneX(context);
  13193. }
  13194. function monotoneY(context) {
  13195. return new MonotoneY(context);
  13196. }
  13197. function Natural(context) {
  13198. this._context = context;
  13199. }
  13200. Natural.prototype = {
  13201. areaStart: function() {
  13202. this._line = 0;
  13203. },
  13204. areaEnd: function() {
  13205. this._line = NaN;
  13206. },
  13207. lineStart: function() {
  13208. this._x = [];
  13209. this._y = [];
  13210. },
  13211. lineEnd: function() {
  13212. var x = this._x,
  13213. y = this._y,
  13214. n = x.length;
  13215. if (n) {
  13216. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  13217. if (n === 2) {
  13218. this._context.lineTo(x[1], y[1]);
  13219. } else {
  13220. var px = controlPoints(x),
  13221. py = controlPoints(y);
  13222. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  13223. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  13224. }
  13225. }
  13226. }
  13227. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  13228. this._line = 1 - this._line;
  13229. this._x = this._y = null;
  13230. },
  13231. point: function(x, y) {
  13232. this._x.push(+x);
  13233. this._y.push(+y);
  13234. }
  13235. };
  13236. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  13237. function controlPoints(x) {
  13238. var i,
  13239. n = x.length - 1,
  13240. m,
  13241. a = new Array(n),
  13242. b = new Array(n),
  13243. r = new Array(n);
  13244. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  13245. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  13246. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  13247. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  13248. a[n - 1] = r[n - 1] / b[n - 1];
  13249. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  13250. b[n - 1] = (x[n] + a[n - 1]) / 2;
  13251. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  13252. return [a, b];
  13253. }
  13254. function natural(context) {
  13255. return new Natural(context);
  13256. }
  13257. function Step(context, t) {
  13258. this._context = context;
  13259. this._t = t;
  13260. }
  13261. Step.prototype = {
  13262. areaStart: function() {
  13263. this._line = 0;
  13264. },
  13265. areaEnd: function() {
  13266. this._line = NaN;
  13267. },
  13268. lineStart: function() {
  13269. this._x = this._y = NaN;
  13270. this._point = 0;
  13271. },
  13272. lineEnd: function() {
  13273. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  13274. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13275. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  13276. },
  13277. point: function(x, y) {
  13278. x = +x, y = +y;
  13279. switch (this._point) {
  13280. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13281. case 1: this._point = 2; // proceed
  13282. default: {
  13283. if (this._t <= 0) {
  13284. this._context.lineTo(this._x, y);
  13285. this._context.lineTo(x, y);
  13286. } else {
  13287. var x1 = this._x * (1 - this._t) + x * this._t;
  13288. this._context.lineTo(x1, this._y);
  13289. this._context.lineTo(x1, y);
  13290. }
  13291. break;
  13292. }
  13293. }
  13294. this._x = x, this._y = y;
  13295. }
  13296. };
  13297. function step(context) {
  13298. return new Step(context, 0.5);
  13299. }
  13300. function stepBefore(context) {
  13301. return new Step(context, 0);
  13302. }
  13303. function stepAfter(context) {
  13304. return new Step(context, 1);
  13305. }
  13306. function none$1(series, order) {
  13307. if (!((n = series.length) > 1)) return;
  13308. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  13309. s0 = s1, s1 = series[order[i]];
  13310. for (j = 0; j < m; ++j) {
  13311. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  13312. }
  13313. }
  13314. }
  13315. function none$2(series) {
  13316. var n = series.length, o = new Array(n);
  13317. while (--n >= 0) o[n] = n;
  13318. return o;
  13319. }
  13320. function stackValue(d, key) {
  13321. return d[key];
  13322. }
  13323. function stack() {
  13324. var keys = constant$11([]),
  13325. order = none$2,
  13326. offset = none$1,
  13327. value = stackValue;
  13328. function stack(data) {
  13329. var kz = keys.apply(this, arguments),
  13330. i,
  13331. m = data.length,
  13332. n = kz.length,
  13333. sz = new Array(n),
  13334. oz;
  13335. for (i = 0; i < n; ++i) {
  13336. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  13337. si[j] = sij = [0, +value(data[j], ki, j, data)];
  13338. sij.data = data[j];
  13339. }
  13340. si.key = ki;
  13341. }
  13342. for (i = 0, oz = order(sz); i < n; ++i) {
  13343. sz[oz[i]].index = i;
  13344. }
  13345. offset(sz, oz);
  13346. return sz;
  13347. }
  13348. stack.keys = function(_) {
  13349. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$11(slice$6.call(_)), stack) : keys;
  13350. };
  13351. stack.value = function(_) {
  13352. return arguments.length ? (value = typeof _ === "function" ? _ : constant$11(+_), stack) : value;
  13353. };
  13354. stack.order = function(_) {
  13355. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$11(slice$6.call(_)), stack) : order;
  13356. };
  13357. stack.offset = function(_) {
  13358. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  13359. };
  13360. return stack;
  13361. }
  13362. function expand(series, order) {
  13363. if (!((n = series.length) > 0)) return;
  13364. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  13365. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  13366. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  13367. }
  13368. none$1(series, order);
  13369. }
  13370. function diverging(series, order) {
  13371. if (!((n = series.length) > 1)) return;
  13372. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  13373. for (yp = yn = 0, i = 0; i < n; ++i) {
  13374. if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
  13375. d[0] = yp, d[1] = yp += dy;
  13376. } else if (dy < 0) {
  13377. d[1] = yn, d[0] = yn += dy;
  13378. } else {
  13379. d[0] = yp;
  13380. }
  13381. }
  13382. }
  13383. }
  13384. function silhouette(series, order) {
  13385. if (!((n = series.length) > 0)) return;
  13386. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  13387. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  13388. s0[j][1] += s0[j][0] = -y / 2;
  13389. }
  13390. none$1(series, order);
  13391. }
  13392. function wiggle(series, order) {
  13393. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  13394. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  13395. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  13396. var si = series[order[i]],
  13397. sij0 = si[j][1] || 0,
  13398. sij1 = si[j - 1][1] || 0,
  13399. s3 = (sij0 - sij1) / 2;
  13400. for (var k = 0; k < i; ++k) {
  13401. var sk = series[order[k]],
  13402. skj0 = sk[j][1] || 0,
  13403. skj1 = sk[j - 1][1] || 0;
  13404. s3 += skj0 - skj1;
  13405. }
  13406. s1 += sij0, s2 += s3 * sij0;
  13407. }
  13408. s0[j - 1][1] += s0[j - 1][0] = y;
  13409. if (s1) y -= s2 / s1;
  13410. }
  13411. s0[j - 1][1] += s0[j - 1][0] = y;
  13412. none$1(series, order);
  13413. }
  13414. function ascending$3(series) {
  13415. var sums = series.map(sum$2);
  13416. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  13417. }
  13418. function sum$2(series) {
  13419. var s = 0, i = -1, n = series.length, v;
  13420. while (++i < n) if (v = +series[i][1]) s += v;
  13421. return s;
  13422. }
  13423. function descending$2(series) {
  13424. return ascending$3(series).reverse();
  13425. }
  13426. function insideOut(series) {
  13427. var n = series.length,
  13428. i,
  13429. j,
  13430. sums = series.map(sum$2),
  13431. order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  13432. top = 0,
  13433. bottom = 0,
  13434. tops = [],
  13435. bottoms = [];
  13436. for (i = 0; i < n; ++i) {
  13437. j = order[i];
  13438. if (top < bottom) {
  13439. top += sums[j];
  13440. tops.push(j);
  13441. } else {
  13442. bottom += sums[j];
  13443. bottoms.push(j);
  13444. }
  13445. }
  13446. return bottoms.reverse().concat(tops);
  13447. }
  13448. function reverse(series) {
  13449. return none$2(series).reverse();
  13450. }
  13451. function constant$12(x) {
  13452. return function() {
  13453. return x;
  13454. };
  13455. }
  13456. function x$4(d) {
  13457. return d[0];
  13458. }
  13459. function y$4(d) {
  13460. return d[1];
  13461. }
  13462. function RedBlackTree() {
  13463. this._ = null; // root node
  13464. }
  13465. function RedBlackNode(node) {
  13466. node.U = // parent node
  13467. node.C = // color - true for red, false for black
  13468. node.L = // left node
  13469. node.R = // right node
  13470. node.P = // previous node
  13471. node.N = null; // next node
  13472. }
  13473. RedBlackTree.prototype = {
  13474. constructor: RedBlackTree,
  13475. insert: function(after, node) {
  13476. var parent, grandpa, uncle;
  13477. if (after) {
  13478. node.P = after;
  13479. node.N = after.N;
  13480. if (after.N) after.N.P = node;
  13481. after.N = node;
  13482. if (after.R) {
  13483. after = after.R;
  13484. while (after.L) after = after.L;
  13485. after.L = node;
  13486. } else {
  13487. after.R = node;
  13488. }
  13489. parent = after;
  13490. } else if (this._) {
  13491. after = RedBlackFirst(this._);
  13492. node.P = null;
  13493. node.N = after;
  13494. after.P = after.L = node;
  13495. parent = after;
  13496. } else {
  13497. node.P = node.N = null;
  13498. this._ = node;
  13499. parent = null;
  13500. }
  13501. node.L = node.R = null;
  13502. node.U = parent;
  13503. node.C = true;
  13504. after = node;
  13505. while (parent && parent.C) {
  13506. grandpa = parent.U;
  13507. if (parent === grandpa.L) {
  13508. uncle = grandpa.R;
  13509. if (uncle && uncle.C) {
  13510. parent.C = uncle.C = false;
  13511. grandpa.C = true;
  13512. after = grandpa;
  13513. } else {
  13514. if (after === parent.R) {
  13515. RedBlackRotateLeft(this, parent);
  13516. after = parent;
  13517. parent = after.U;
  13518. }
  13519. parent.C = false;
  13520. grandpa.C = true;
  13521. RedBlackRotateRight(this, grandpa);
  13522. }
  13523. } else {
  13524. uncle = grandpa.L;
  13525. if (uncle && uncle.C) {
  13526. parent.C = uncle.C = false;
  13527. grandpa.C = true;
  13528. after = grandpa;
  13529. } else {
  13530. if (after === parent.L) {
  13531. RedBlackRotateRight(this, parent);
  13532. after = parent;
  13533. parent = after.U;
  13534. }
  13535. parent.C = false;
  13536. grandpa.C = true;
  13537. RedBlackRotateLeft(this, grandpa);
  13538. }
  13539. }
  13540. parent = after.U;
  13541. }
  13542. this._.C = false;
  13543. },
  13544. remove: function(node) {
  13545. if (node.N) node.N.P = node.P;
  13546. if (node.P) node.P.N = node.N;
  13547. node.N = node.P = null;
  13548. var parent = node.U,
  13549. sibling,
  13550. left = node.L,
  13551. right = node.R,
  13552. next,
  13553. red;
  13554. if (!left) next = right;
  13555. else if (!right) next = left;
  13556. else next = RedBlackFirst(right);
  13557. if (parent) {
  13558. if (parent.L === node) parent.L = next;
  13559. else parent.R = next;
  13560. } else {
  13561. this._ = next;
  13562. }
  13563. if (left && right) {
  13564. red = next.C;
  13565. next.C = node.C;
  13566. next.L = left;
  13567. left.U = next;
  13568. if (next !== right) {
  13569. parent = next.U;
  13570. next.U = node.U;
  13571. node = next.R;
  13572. parent.L = node;
  13573. next.R = right;
  13574. right.U = next;
  13575. } else {
  13576. next.U = parent;
  13577. parent = next;
  13578. node = next.R;
  13579. }
  13580. } else {
  13581. red = node.C;
  13582. node = next;
  13583. }
  13584. if (node) node.U = parent;
  13585. if (red) return;
  13586. if (node && node.C) { node.C = false; return; }
  13587. do {
  13588. if (node === this._) break;
  13589. if (node === parent.L) {
  13590. sibling = parent.R;
  13591. if (sibling.C) {
  13592. sibling.C = false;
  13593. parent.C = true;
  13594. RedBlackRotateLeft(this, parent);
  13595. sibling = parent.R;
  13596. }
  13597. if ((sibling.L && sibling.L.C)
  13598. || (sibling.R && sibling.R.C)) {
  13599. if (!sibling.R || !sibling.R.C) {
  13600. sibling.L.C = false;
  13601. sibling.C = true;
  13602. RedBlackRotateRight(this, sibling);
  13603. sibling = parent.R;
  13604. }
  13605. sibling.C = parent.C;
  13606. parent.C = sibling.R.C = false;
  13607. RedBlackRotateLeft(this, parent);
  13608. node = this._;
  13609. break;
  13610. }
  13611. } else {
  13612. sibling = parent.L;
  13613. if (sibling.C) {
  13614. sibling.C = false;
  13615. parent.C = true;
  13616. RedBlackRotateRight(this, parent);
  13617. sibling = parent.L;
  13618. }
  13619. if ((sibling.L && sibling.L.C)
  13620. || (sibling.R && sibling.R.C)) {
  13621. if (!sibling.L || !sibling.L.C) {
  13622. sibling.R.C = false;
  13623. sibling.C = true;
  13624. RedBlackRotateLeft(this, sibling);
  13625. sibling = parent.L;
  13626. }
  13627. sibling.C = parent.C;
  13628. parent.C = sibling.L.C = false;
  13629. RedBlackRotateRight(this, parent);
  13630. node = this._;
  13631. break;
  13632. }
  13633. }
  13634. sibling.C = true;
  13635. node = parent;
  13636. parent = parent.U;
  13637. } while (!node.C);
  13638. if (node) node.C = false;
  13639. }
  13640. };
  13641. function RedBlackRotateLeft(tree, node) {
  13642. var p = node,
  13643. q = node.R,
  13644. parent = p.U;
  13645. if (parent) {
  13646. if (parent.L === p) parent.L = q;
  13647. else parent.R = q;
  13648. } else {
  13649. tree._ = q;
  13650. }
  13651. q.U = parent;
  13652. p.U = q;
  13653. p.R = q.L;
  13654. if (p.R) p.R.U = p;
  13655. q.L = p;
  13656. }
  13657. function RedBlackRotateRight(tree, node) {
  13658. var p = node,
  13659. q = node.L,
  13660. parent = p.U;
  13661. if (parent) {
  13662. if (parent.L === p) parent.L = q;
  13663. else parent.R = q;
  13664. } else {
  13665. tree._ = q;
  13666. }
  13667. q.U = parent;
  13668. p.U = q;
  13669. p.L = q.R;
  13670. if (p.L) p.L.U = p;
  13671. q.R = p;
  13672. }
  13673. function RedBlackFirst(node) {
  13674. while (node.L) node = node.L;
  13675. return node;
  13676. }
  13677. function createEdge(left, right, v0, v1) {
  13678. var edge = [null, null],
  13679. index = edges.push(edge) - 1;
  13680. edge.left = left;
  13681. edge.right = right;
  13682. if (v0) setEdgeEnd(edge, left, right, v0);
  13683. if (v1) setEdgeEnd(edge, right, left, v1);
  13684. cells[left.index].halfedges.push(index);
  13685. cells[right.index].halfedges.push(index);
  13686. return edge;
  13687. }
  13688. function createBorderEdge(left, v0, v1) {
  13689. var edge = [v0, v1];
  13690. edge.left = left;
  13691. return edge;
  13692. }
  13693. function setEdgeEnd(edge, left, right, vertex) {
  13694. if (!edge[0] && !edge[1]) {
  13695. edge[0] = vertex;
  13696. edge.left = left;
  13697. edge.right = right;
  13698. } else if (edge.left === right) {
  13699. edge[1] = vertex;
  13700. } else {
  13701. edge[0] = vertex;
  13702. }
  13703. }
  13704. // Liang–Barsky line clipping.
  13705. function clipEdge(edge, x0, y0, x1, y1) {
  13706. var a = edge[0],
  13707. b = edge[1],
  13708. ax = a[0],
  13709. ay = a[1],
  13710. bx = b[0],
  13711. by = b[1],
  13712. t0 = 0,
  13713. t1 = 1,
  13714. dx = bx - ax,
  13715. dy = by - ay,
  13716. r;
  13717. r = x0 - ax;
  13718. if (!dx && r > 0) return;
  13719. r /= dx;
  13720. if (dx < 0) {
  13721. if (r < t0) return;
  13722. if (r < t1) t1 = r;
  13723. } else if (dx > 0) {
  13724. if (r > t1) return;
  13725. if (r > t0) t0 = r;
  13726. }
  13727. r = x1 - ax;
  13728. if (!dx && r < 0) return;
  13729. r /= dx;
  13730. if (dx < 0) {
  13731. if (r > t1) return;
  13732. if (r > t0) t0 = r;
  13733. } else if (dx > 0) {
  13734. if (r < t0) return;
  13735. if (r < t1) t1 = r;
  13736. }
  13737. r = y0 - ay;
  13738. if (!dy && r > 0) return;
  13739. r /= dy;
  13740. if (dy < 0) {
  13741. if (r < t0) return;
  13742. if (r < t1) t1 = r;
  13743. } else if (dy > 0) {
  13744. if (r > t1) return;
  13745. if (r > t0) t0 = r;
  13746. }
  13747. r = y1 - ay;
  13748. if (!dy && r < 0) return;
  13749. r /= dy;
  13750. if (dy < 0) {
  13751. if (r > t1) return;
  13752. if (r > t0) t0 = r;
  13753. } else if (dy > 0) {
  13754. if (r < t0) return;
  13755. if (r < t1) t1 = r;
  13756. }
  13757. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  13758. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  13759. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  13760. return true;
  13761. }
  13762. function connectEdge(edge, x0, y0, x1, y1) {
  13763. var v1 = edge[1];
  13764. if (v1) return true;
  13765. var v0 = edge[0],
  13766. left = edge.left,
  13767. right = edge.right,
  13768. lx = left[0],
  13769. ly = left[1],
  13770. rx = right[0],
  13771. ry = right[1],
  13772. fx = (lx + rx) / 2,
  13773. fy = (ly + ry) / 2,
  13774. fm,
  13775. fb;
  13776. if (ry === ly) {
  13777. if (fx < x0 || fx >= x1) return;
  13778. if (lx > rx) {
  13779. if (!v0) v0 = [fx, y0];
  13780. else if (v0[1] >= y1) return;
  13781. v1 = [fx, y1];
  13782. } else {
  13783. if (!v0) v0 = [fx, y1];
  13784. else if (v0[1] < y0) return;
  13785. v1 = [fx, y0];
  13786. }
  13787. } else {
  13788. fm = (lx - rx) / (ry - ly);
  13789. fb = fy - fm * fx;
  13790. if (fm < -1 || fm > 1) {
  13791. if (lx > rx) {
  13792. if (!v0) v0 = [(y0 - fb) / fm, y0];
  13793. else if (v0[1] >= y1) return;
  13794. v1 = [(y1 - fb) / fm, y1];
  13795. } else {
  13796. if (!v0) v0 = [(y1 - fb) / fm, y1];
  13797. else if (v0[1] < y0) return;
  13798. v1 = [(y0 - fb) / fm, y0];
  13799. }
  13800. } else {
  13801. if (ly < ry) {
  13802. if (!v0) v0 = [x0, fm * x0 + fb];
  13803. else if (v0[0] >= x1) return;
  13804. v1 = [x1, fm * x1 + fb];
  13805. } else {
  13806. if (!v0) v0 = [x1, fm * x1 + fb];
  13807. else if (v0[0] < x0) return;
  13808. v1 = [x0, fm * x0 + fb];
  13809. }
  13810. }
  13811. }
  13812. edge[0] = v0;
  13813. edge[1] = v1;
  13814. return true;
  13815. }
  13816. function clipEdges(x0, y0, x1, y1) {
  13817. var i = edges.length,
  13818. edge;
  13819. while (i--) {
  13820. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  13821. || !clipEdge(edge, x0, y0, x1, y1)
  13822. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  13823. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  13824. delete edges[i];
  13825. }
  13826. }
  13827. }
  13828. function createCell(site) {
  13829. return cells[site.index] = {
  13830. site: site,
  13831. halfedges: []
  13832. };
  13833. }
  13834. function cellHalfedgeAngle(cell, edge) {
  13835. var site = cell.site,
  13836. va = edge.left,
  13837. vb = edge.right;
  13838. if (site === vb) vb = va, va = site;
  13839. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  13840. if (site === va) va = edge[1], vb = edge[0];
  13841. else va = edge[0], vb = edge[1];
  13842. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  13843. }
  13844. function cellHalfedgeStart(cell, edge) {
  13845. return edge[+(edge.left !== cell.site)];
  13846. }
  13847. function cellHalfedgeEnd(cell, edge) {
  13848. return edge[+(edge.left === cell.site)];
  13849. }
  13850. function sortCellHalfedges() {
  13851. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  13852. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  13853. var index = new Array(m),
  13854. array = new Array(m);
  13855. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  13856. index.sort(function(i, j) { return array[j] - array[i]; });
  13857. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  13858. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  13859. }
  13860. }
  13861. }
  13862. function clipCells(x0, y0, x1, y1) {
  13863. var nCells = cells.length,
  13864. iCell,
  13865. cell,
  13866. site,
  13867. iHalfedge,
  13868. halfedges,
  13869. nHalfedges,
  13870. start,
  13871. startX,
  13872. startY,
  13873. end,
  13874. endX,
  13875. endY,
  13876. cover = true;
  13877. for (iCell = 0; iCell < nCells; ++iCell) {
  13878. if (cell = cells[iCell]) {
  13879. site = cell.site;
  13880. halfedges = cell.halfedges;
  13881. iHalfedge = halfedges.length;
  13882. // Remove any dangling clipped edges.
  13883. while (iHalfedge--) {
  13884. if (!edges[halfedges[iHalfedge]]) {
  13885. halfedges.splice(iHalfedge, 1);
  13886. }
  13887. }
  13888. // Insert any border edges as necessary.
  13889. iHalfedge = 0, nHalfedges = halfedges.length;
  13890. while (iHalfedge < nHalfedges) {
  13891. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  13892. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  13893. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  13894. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  13895. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  13896. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  13897. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  13898. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  13899. : null)) - 1);
  13900. ++nHalfedges;
  13901. }
  13902. }
  13903. if (nHalfedges) cover = false;
  13904. }
  13905. }
  13906. // If there weren’t any edges, have the closest site cover the extent.
  13907. // It doesn’t matter which corner of the extent we measure!
  13908. if (cover) {
  13909. var dx, dy, d2, dc = Infinity;
  13910. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  13911. if (cell = cells[iCell]) {
  13912. site = cell.site;
  13913. dx = site[0] - x0;
  13914. dy = site[1] - y0;
  13915. d2 = dx * dx + dy * dy;
  13916. if (d2 < dc) dc = d2, cover = cell;
  13917. }
  13918. }
  13919. if (cover) {
  13920. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  13921. cover.halfedges.push(
  13922. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  13923. edges.push(createBorderEdge(site, v01, v11)) - 1,
  13924. edges.push(createBorderEdge(site, v11, v10)) - 1,
  13925. edges.push(createBorderEdge(site, v10, v00)) - 1
  13926. );
  13927. }
  13928. }
  13929. // Lastly delete any cells with no edges; these were entirely clipped.
  13930. for (iCell = 0; iCell < nCells; ++iCell) {
  13931. if (cell = cells[iCell]) {
  13932. if (!cell.halfedges.length) {
  13933. delete cells[iCell];
  13934. }
  13935. }
  13936. }
  13937. }
  13938. var circlePool = [];
  13939. var firstCircle;
  13940. function Circle() {
  13941. RedBlackNode(this);
  13942. this.x =
  13943. this.y =
  13944. this.arc =
  13945. this.site =
  13946. this.cy = null;
  13947. }
  13948. function attachCircle(arc) {
  13949. var lArc = arc.P,
  13950. rArc = arc.N;
  13951. if (!lArc || !rArc) return;
  13952. var lSite = lArc.site,
  13953. cSite = arc.site,
  13954. rSite = rArc.site;
  13955. if (lSite === rSite) return;
  13956. var bx = cSite[0],
  13957. by = cSite[1],
  13958. ax = lSite[0] - bx,
  13959. ay = lSite[1] - by,
  13960. cx = rSite[0] - bx,
  13961. cy = rSite[1] - by;
  13962. var d = 2 * (ax * cy - ay * cx);
  13963. if (d >= -epsilon2$2) return;
  13964. var ha = ax * ax + ay * ay,
  13965. hc = cx * cx + cy * cy,
  13966. x = (cy * ha - ay * hc) / d,
  13967. y = (ax * hc - cx * ha) / d;
  13968. var circle = circlePool.pop() || new Circle;
  13969. circle.arc = arc;
  13970. circle.site = cSite;
  13971. circle.x = x + bx;
  13972. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  13973. arc.circle = circle;
  13974. var before = null,
  13975. node = circles._;
  13976. while (node) {
  13977. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  13978. if (node.L) node = node.L;
  13979. else { before = node.P; break; }
  13980. } else {
  13981. if (node.R) node = node.R;
  13982. else { before = node; break; }
  13983. }
  13984. }
  13985. circles.insert(before, circle);
  13986. if (!before) firstCircle = circle;
  13987. }
  13988. function detachCircle(arc) {
  13989. var circle = arc.circle;
  13990. if (circle) {
  13991. if (!circle.P) firstCircle = circle.N;
  13992. circles.remove(circle);
  13993. circlePool.push(circle);
  13994. RedBlackNode(circle);
  13995. arc.circle = null;
  13996. }
  13997. }
  13998. var beachPool = [];
  13999. function Beach() {
  14000. RedBlackNode(this);
  14001. this.edge =
  14002. this.site =
  14003. this.circle = null;
  14004. }
  14005. function createBeach(site) {
  14006. var beach = beachPool.pop() || new Beach;
  14007. beach.site = site;
  14008. return beach;
  14009. }
  14010. function detachBeach(beach) {
  14011. detachCircle(beach);
  14012. beaches.remove(beach);
  14013. beachPool.push(beach);
  14014. RedBlackNode(beach);
  14015. }
  14016. function removeBeach(beach) {
  14017. var circle = beach.circle,
  14018. x = circle.x,
  14019. y = circle.cy,
  14020. vertex = [x, y],
  14021. previous = beach.P,
  14022. next = beach.N,
  14023. disappearing = [beach];
  14024. detachBeach(beach);
  14025. var lArc = previous;
  14026. while (lArc.circle
  14027. && Math.abs(x - lArc.circle.x) < epsilon$4
  14028. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  14029. previous = lArc.P;
  14030. disappearing.unshift(lArc);
  14031. detachBeach(lArc);
  14032. lArc = previous;
  14033. }
  14034. disappearing.unshift(lArc);
  14035. detachCircle(lArc);
  14036. var rArc = next;
  14037. while (rArc.circle
  14038. && Math.abs(x - rArc.circle.x) < epsilon$4
  14039. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  14040. next = rArc.N;
  14041. disappearing.push(rArc);
  14042. detachBeach(rArc);
  14043. rArc = next;
  14044. }
  14045. disappearing.push(rArc);
  14046. detachCircle(rArc);
  14047. var nArcs = disappearing.length,
  14048. iArc;
  14049. for (iArc = 1; iArc < nArcs; ++iArc) {
  14050. rArc = disappearing[iArc];
  14051. lArc = disappearing[iArc - 1];
  14052. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  14053. }
  14054. lArc = disappearing[0];
  14055. rArc = disappearing[nArcs - 1];
  14056. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  14057. attachCircle(lArc);
  14058. attachCircle(rArc);
  14059. }
  14060. function addBeach(site) {
  14061. var x = site[0],
  14062. directrix = site[1],
  14063. lArc,
  14064. rArc,
  14065. dxl,
  14066. dxr,
  14067. node = beaches._;
  14068. while (node) {
  14069. dxl = leftBreakPoint(node, directrix) - x;
  14070. if (dxl > epsilon$4) node = node.L; else {
  14071. dxr = x - rightBreakPoint(node, directrix);
  14072. if (dxr > epsilon$4) {
  14073. if (!node.R) {
  14074. lArc = node;
  14075. break;
  14076. }
  14077. node = node.R;
  14078. } else {
  14079. if (dxl > -epsilon$4) {
  14080. lArc = node.P;
  14081. rArc = node;
  14082. } else if (dxr > -epsilon$4) {
  14083. lArc = node;
  14084. rArc = node.N;
  14085. } else {
  14086. lArc = rArc = node;
  14087. }
  14088. break;
  14089. }
  14090. }
  14091. }
  14092. createCell(site);
  14093. var newArc = createBeach(site);
  14094. beaches.insert(lArc, newArc);
  14095. if (!lArc && !rArc) return;
  14096. if (lArc === rArc) {
  14097. detachCircle(lArc);
  14098. rArc = createBeach(lArc.site);
  14099. beaches.insert(newArc, rArc);
  14100. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  14101. attachCircle(lArc);
  14102. attachCircle(rArc);
  14103. return;
  14104. }
  14105. if (!rArc) { // && lArc
  14106. newArc.edge = createEdge(lArc.site, newArc.site);
  14107. return;
  14108. }
  14109. // else lArc !== rArc
  14110. detachCircle(lArc);
  14111. detachCircle(rArc);
  14112. var lSite = lArc.site,
  14113. ax = lSite[0],
  14114. ay = lSite[1],
  14115. bx = site[0] - ax,
  14116. by = site[1] - ay,
  14117. rSite = rArc.site,
  14118. cx = rSite[0] - ax,
  14119. cy = rSite[1] - ay,
  14120. d = 2 * (bx * cy - by * cx),
  14121. hb = bx * bx + by * by,
  14122. hc = cx * cx + cy * cy,
  14123. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  14124. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  14125. newArc.edge = createEdge(lSite, site, null, vertex);
  14126. rArc.edge = createEdge(site, rSite, null, vertex);
  14127. attachCircle(lArc);
  14128. attachCircle(rArc);
  14129. }
  14130. function leftBreakPoint(arc, directrix) {
  14131. var site = arc.site,
  14132. rfocx = site[0],
  14133. rfocy = site[1],
  14134. pby2 = rfocy - directrix;
  14135. if (!pby2) return rfocx;
  14136. var lArc = arc.P;
  14137. if (!lArc) return -Infinity;
  14138. site = lArc.site;
  14139. var lfocx = site[0],
  14140. lfocy = site[1],
  14141. plby2 = lfocy - directrix;
  14142. if (!plby2) return lfocx;
  14143. var hl = lfocx - rfocx,
  14144. aby2 = 1 / pby2 - 1 / plby2,
  14145. b = hl / plby2;
  14146. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  14147. return (rfocx + lfocx) / 2;
  14148. }
  14149. function rightBreakPoint(arc, directrix) {
  14150. var rArc = arc.N;
  14151. if (rArc) return leftBreakPoint(rArc, directrix);
  14152. var site = arc.site;
  14153. return site[1] === directrix ? site[0] : Infinity;
  14154. }
  14155. var epsilon$4 = 1e-6;
  14156. var epsilon2$2 = 1e-12;
  14157. var beaches;
  14158. var cells;
  14159. var circles;
  14160. var edges;
  14161. function triangleArea(a, b, c) {
  14162. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  14163. }
  14164. function lexicographic(a, b) {
  14165. return b[1] - a[1]
  14166. || b[0] - a[0];
  14167. }
  14168. function Diagram(sites, extent) {
  14169. var site = sites.sort(lexicographic).pop(),
  14170. x,
  14171. y,
  14172. circle;
  14173. edges = [];
  14174. cells = new Array(sites.length);
  14175. beaches = new RedBlackTree;
  14176. circles = new RedBlackTree;
  14177. while (true) {
  14178. circle = firstCircle;
  14179. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  14180. if (site[0] !== x || site[1] !== y) {
  14181. addBeach(site);
  14182. x = site[0], y = site[1];
  14183. }
  14184. site = sites.pop();
  14185. } else if (circle) {
  14186. removeBeach(circle.arc);
  14187. } else {
  14188. break;
  14189. }
  14190. }
  14191. sortCellHalfedges();
  14192. if (extent) {
  14193. var x0 = +extent[0][0],
  14194. y0 = +extent[0][1],
  14195. x1 = +extent[1][0],
  14196. y1 = +extent[1][1];
  14197. clipEdges(x0, y0, x1, y1);
  14198. clipCells(x0, y0, x1, y1);
  14199. }
  14200. this.edges = edges;
  14201. this.cells = cells;
  14202. beaches =
  14203. circles =
  14204. edges =
  14205. cells = null;
  14206. }
  14207. Diagram.prototype = {
  14208. constructor: Diagram,
  14209. polygons: function() {
  14210. var edges = this.edges;
  14211. return this.cells.map(function(cell) {
  14212. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  14213. polygon.data = cell.site.data;
  14214. return polygon;
  14215. });
  14216. },
  14217. triangles: function() {
  14218. var triangles = [],
  14219. edges = this.edges;
  14220. this.cells.forEach(function(cell, i) {
  14221. if (!(m = (halfedges = cell.halfedges).length)) return;
  14222. var site = cell.site,
  14223. halfedges,
  14224. j = -1,
  14225. m,
  14226. s0,
  14227. e1 = edges[halfedges[m - 1]],
  14228. s1 = e1.left === site ? e1.right : e1.left;
  14229. while (++j < m) {
  14230. s0 = s1;
  14231. e1 = edges[halfedges[j]];
  14232. s1 = e1.left === site ? e1.right : e1.left;
  14233. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  14234. triangles.push([site.data, s0.data, s1.data]);
  14235. }
  14236. }
  14237. });
  14238. return triangles;
  14239. },
  14240. links: function() {
  14241. return this.edges.filter(function(edge) {
  14242. return edge.right;
  14243. }).map(function(edge) {
  14244. return {
  14245. source: edge.left.data,
  14246. target: edge.right.data
  14247. };
  14248. });
  14249. },
  14250. find: function(x, y, radius) {
  14251. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  14252. // Use the previously-found cell, or start with an arbitrary one.
  14253. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  14254. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  14255. // Traverse the half-edges to find a closer cell, if any.
  14256. do {
  14257. cell = that.cells[i0 = i1], i1 = null;
  14258. cell.halfedges.forEach(function(e) {
  14259. var edge = that.edges[e], v = edge.left;
  14260. if ((v === cell.site || !v) && !(v = edge.right)) return;
  14261. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  14262. if (v2 < d2) d2 = v2, i1 = v.index;
  14263. });
  14264. } while (i1 !== null);
  14265. that._found = i0;
  14266. return radius == null || d2 <= radius * radius ? cell.site : null;
  14267. }
  14268. };
  14269. function voronoi() {
  14270. var x$$1 = x$4,
  14271. y$$1 = y$4,
  14272. extent = null;
  14273. function voronoi(data) {
  14274. return new Diagram(data.map(function(d, i) {
  14275. var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
  14276. s.index = i;
  14277. s.data = d;
  14278. return s;
  14279. }), extent);
  14280. }
  14281. voronoi.polygons = function(data) {
  14282. return voronoi(data).polygons();
  14283. };
  14284. voronoi.links = function(data) {
  14285. return voronoi(data).links();
  14286. };
  14287. voronoi.triangles = function(data) {
  14288. return voronoi(data).triangles();
  14289. };
  14290. voronoi.x = function(_) {
  14291. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$12(+_), voronoi) : x$$1;
  14292. };
  14293. voronoi.y = function(_) {
  14294. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$12(+_), voronoi) : y$$1;
  14295. };
  14296. voronoi.extent = function(_) {
  14297. 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]]];
  14298. };
  14299. voronoi.size = function(_) {
  14300. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  14301. };
  14302. return voronoi;
  14303. }
  14304. function constant$13(x) {
  14305. return function() {
  14306. return x;
  14307. };
  14308. }
  14309. function ZoomEvent(target, type, transform) {
  14310. this.target = target;
  14311. this.type = type;
  14312. this.transform = transform;
  14313. }
  14314. function Transform(k, x, y) {
  14315. this.k = k;
  14316. this.x = x;
  14317. this.y = y;
  14318. }
  14319. Transform.prototype = {
  14320. constructor: Transform,
  14321. scale: function(k) {
  14322. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  14323. },
  14324. translate: function(x, y) {
  14325. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  14326. },
  14327. apply: function(point) {
  14328. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  14329. },
  14330. applyX: function(x) {
  14331. return x * this.k + this.x;
  14332. },
  14333. applyY: function(y) {
  14334. return y * this.k + this.y;
  14335. },
  14336. invert: function(location) {
  14337. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  14338. },
  14339. invertX: function(x) {
  14340. return (x - this.x) / this.k;
  14341. },
  14342. invertY: function(y) {
  14343. return (y - this.y) / this.k;
  14344. },
  14345. rescaleX: function(x) {
  14346. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  14347. },
  14348. rescaleY: function(y) {
  14349. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  14350. },
  14351. toString: function() {
  14352. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  14353. }
  14354. };
  14355. var identity$8 = new Transform(1, 0, 0);
  14356. transform$1.prototype = Transform.prototype;
  14357. function transform$1(node) {
  14358. return node.__zoom || identity$8;
  14359. }
  14360. function nopropagation$2() {
  14361. exports.event.stopImmediatePropagation();
  14362. }
  14363. function noevent$2() {
  14364. exports.event.preventDefault();
  14365. exports.event.stopImmediatePropagation();
  14366. }
  14367. // Ignore right-click, since that should open the context menu.
  14368. function defaultFilter$2() {
  14369. return !exports.event.button;
  14370. }
  14371. function defaultExtent$1() {
  14372. var e = this, w, h;
  14373. if (e instanceof SVGElement) {
  14374. e = e.ownerSVGElement || e;
  14375. w = e.width.baseVal.value;
  14376. h = e.height.baseVal.value;
  14377. } else {
  14378. w = e.clientWidth;
  14379. h = e.clientHeight;
  14380. }
  14381. return [[0, 0], [w, h]];
  14382. }
  14383. function defaultTransform() {
  14384. return this.__zoom || identity$8;
  14385. }
  14386. function defaultWheelDelta() {
  14387. return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
  14388. }
  14389. function defaultTouchable$1() {
  14390. return "ontouchstart" in this;
  14391. }
  14392. function defaultConstrain(transform, extent, translateExtent) {
  14393. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  14394. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  14395. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  14396. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  14397. return transform.translate(
  14398. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  14399. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  14400. );
  14401. }
  14402. function zoom() {
  14403. var filter = defaultFilter$2,
  14404. extent = defaultExtent$1,
  14405. constrain = defaultConstrain,
  14406. wheelDelta = defaultWheelDelta,
  14407. touchable = defaultTouchable$1,
  14408. scaleExtent = [0, Infinity],
  14409. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  14410. duration = 250,
  14411. interpolate = interpolateZoom,
  14412. gestures = [],
  14413. listeners = dispatch("start", "zoom", "end"),
  14414. touchstarting,
  14415. touchending,
  14416. touchDelay = 500,
  14417. wheelDelay = 150,
  14418. clickDistance2 = 0;
  14419. function zoom(selection$$1) {
  14420. selection$$1
  14421. .property("__zoom", defaultTransform)
  14422. .on("wheel.zoom", wheeled)
  14423. .on("mousedown.zoom", mousedowned)
  14424. .on("dblclick.zoom", dblclicked)
  14425. .filter(touchable)
  14426. .on("touchstart.zoom", touchstarted)
  14427. .on("touchmove.zoom", touchmoved)
  14428. .on("touchend.zoom touchcancel.zoom", touchended)
  14429. .style("touch-action", "none")
  14430. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  14431. }
  14432. zoom.transform = function(collection, transform) {
  14433. var selection$$1 = collection.selection ? collection.selection() : collection;
  14434. selection$$1.property("__zoom", defaultTransform);
  14435. if (collection !== selection$$1) {
  14436. schedule(collection, transform);
  14437. } else {
  14438. selection$$1.interrupt().each(function() {
  14439. gesture(this, arguments)
  14440. .start()
  14441. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  14442. .end();
  14443. });
  14444. }
  14445. };
  14446. zoom.scaleBy = function(selection$$1, k) {
  14447. zoom.scaleTo(selection$$1, function() {
  14448. var k0 = this.__zoom.k,
  14449. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14450. return k0 * k1;
  14451. });
  14452. };
  14453. zoom.scaleTo = function(selection$$1, k) {
  14454. zoom.transform(selection$$1, function() {
  14455. var e = extent.apply(this, arguments),
  14456. t0 = this.__zoom,
  14457. p0 = centroid(e),
  14458. p1 = t0.invert(p0),
  14459. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14460. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  14461. });
  14462. };
  14463. zoom.translateBy = function(selection$$1, x, y) {
  14464. zoom.transform(selection$$1, function() {
  14465. return constrain(this.__zoom.translate(
  14466. typeof x === "function" ? x.apply(this, arguments) : x,
  14467. typeof y === "function" ? y.apply(this, arguments) : y
  14468. ), extent.apply(this, arguments), translateExtent);
  14469. });
  14470. };
  14471. zoom.translateTo = function(selection$$1, x, y) {
  14472. zoom.transform(selection$$1, function() {
  14473. var e = extent.apply(this, arguments),
  14474. t = this.__zoom,
  14475. p = centroid(e);
  14476. return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
  14477. typeof x === "function" ? -x.apply(this, arguments) : -x,
  14478. typeof y === "function" ? -y.apply(this, arguments) : -y
  14479. ), e, translateExtent);
  14480. });
  14481. };
  14482. function scale(transform, k) {
  14483. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  14484. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  14485. }
  14486. function translate(transform, p0, p1) {
  14487. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  14488. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  14489. }
  14490. function centroid(extent) {
  14491. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  14492. }
  14493. function schedule(transition$$1, transform, center) {
  14494. transition$$1
  14495. .on("start.zoom", function() { gesture(this, arguments).start(); })
  14496. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  14497. .tween("zoom", function() {
  14498. var that = this,
  14499. args = arguments,
  14500. g = gesture(that, args),
  14501. e = extent.apply(that, args),
  14502. p = center || centroid(e),
  14503. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  14504. a = that.__zoom,
  14505. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  14506. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  14507. return function(t) {
  14508. if (t === 1) t = b; // Avoid rounding error on end.
  14509. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  14510. g.zoom(null, t);
  14511. };
  14512. });
  14513. }
  14514. function gesture(that, args) {
  14515. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  14516. if ((g = gestures[i]).that === that) {
  14517. return g;
  14518. }
  14519. }
  14520. return new Gesture(that, args);
  14521. }
  14522. function Gesture(that, args) {
  14523. this.that = that;
  14524. this.args = args;
  14525. this.index = -1;
  14526. this.active = 0;
  14527. this.extent = extent.apply(that, args);
  14528. }
  14529. Gesture.prototype = {
  14530. start: function() {
  14531. if (++this.active === 1) {
  14532. this.index = gestures.push(this) - 1;
  14533. this.emit("start");
  14534. }
  14535. return this;
  14536. },
  14537. zoom: function(key, transform) {
  14538. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  14539. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  14540. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  14541. this.that.__zoom = transform;
  14542. this.emit("zoom");
  14543. return this;
  14544. },
  14545. end: function() {
  14546. if (--this.active === 0) {
  14547. gestures.splice(this.index, 1);
  14548. this.index = -1;
  14549. this.emit("end");
  14550. }
  14551. return this;
  14552. },
  14553. emit: function(type) {
  14554. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  14555. }
  14556. };
  14557. function wheeled() {
  14558. if (!filter.apply(this, arguments)) return;
  14559. var g = gesture(this, arguments),
  14560. t = this.__zoom,
  14561. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  14562. p = mouse(this);
  14563. // If the mouse is in the same location as before, reuse it.
  14564. // If there were recent wheel events, reset the wheel idle timeout.
  14565. if (g.wheel) {
  14566. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  14567. g.mouse[1] = t.invert(g.mouse[0] = p);
  14568. }
  14569. clearTimeout(g.wheel);
  14570. }
  14571. // If this wheel event won’t trigger a transform change, ignore it.
  14572. else if (t.k === k) return;
  14573. // Otherwise, capture the mouse point and location at the start.
  14574. else {
  14575. g.mouse = [p, t.invert(p)];
  14576. interrupt(this);
  14577. g.start();
  14578. }
  14579. noevent$2();
  14580. g.wheel = setTimeout(wheelidled, wheelDelay);
  14581. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  14582. function wheelidled() {
  14583. g.wheel = null;
  14584. g.end();
  14585. }
  14586. }
  14587. function mousedowned() {
  14588. if (touchending || !filter.apply(this, arguments)) return;
  14589. var g = gesture(this, arguments),
  14590. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  14591. p = mouse(this),
  14592. x0 = exports.event.clientX,
  14593. y0 = exports.event.clientY;
  14594. dragDisable(exports.event.view);
  14595. nopropagation$2();
  14596. g.mouse = [p, this.__zoom.invert(p)];
  14597. interrupt(this);
  14598. g.start();
  14599. function mousemoved() {
  14600. noevent$2();
  14601. if (!g.moved) {
  14602. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  14603. g.moved = dx * dx + dy * dy > clickDistance2;
  14604. }
  14605. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  14606. }
  14607. function mouseupped() {
  14608. v.on("mousemove.zoom mouseup.zoom", null);
  14609. yesdrag(exports.event.view, g.moved);
  14610. noevent$2();
  14611. g.end();
  14612. }
  14613. }
  14614. function dblclicked() {
  14615. if (!filter.apply(this, arguments)) return;
  14616. var t0 = this.__zoom,
  14617. p0 = mouse(this),
  14618. p1 = t0.invert(p0),
  14619. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  14620. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  14621. noevent$2();
  14622. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  14623. else select(this).call(zoom.transform, t1);
  14624. }
  14625. function touchstarted() {
  14626. if (!filter.apply(this, arguments)) return;
  14627. var g = gesture(this, arguments),
  14628. touches$$1 = exports.event.changedTouches,
  14629. started,
  14630. n = touches$$1.length, i, t, p;
  14631. nopropagation$2();
  14632. for (i = 0; i < n; ++i) {
  14633. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  14634. p = [p, this.__zoom.invert(p), t.identifier];
  14635. if (!g.touch0) g.touch0 = p, started = true;
  14636. else if (!g.touch1) g.touch1 = p;
  14637. }
  14638. // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
  14639. if (touchstarting) {
  14640. touchstarting = clearTimeout(touchstarting);
  14641. if (!g.touch1) {
  14642. g.end();
  14643. p = select(this).on("dblclick.zoom");
  14644. if (p) p.apply(this, arguments);
  14645. return;
  14646. }
  14647. }
  14648. if (started) {
  14649. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  14650. interrupt(this);
  14651. g.start();
  14652. }
  14653. }
  14654. function touchmoved() {
  14655. var g = gesture(this, arguments),
  14656. touches$$1 = exports.event.changedTouches,
  14657. n = touches$$1.length, i, t, p, l;
  14658. noevent$2();
  14659. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  14660. for (i = 0; i < n; ++i) {
  14661. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  14662. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  14663. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  14664. }
  14665. t = g.that.__zoom;
  14666. if (g.touch1) {
  14667. var p0 = g.touch0[0], l0 = g.touch0[1],
  14668. p1 = g.touch1[0], l1 = g.touch1[1],
  14669. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  14670. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  14671. t = scale(t, Math.sqrt(dp / dl));
  14672. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  14673. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  14674. }
  14675. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  14676. else return;
  14677. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  14678. }
  14679. function touchended() {
  14680. var g = gesture(this, arguments),
  14681. touches$$1 = exports.event.changedTouches,
  14682. n = touches$$1.length, i, t;
  14683. nopropagation$2();
  14684. if (touchending) clearTimeout(touchending);
  14685. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  14686. for (i = 0; i < n; ++i) {
  14687. t = touches$$1[i];
  14688. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  14689. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  14690. }
  14691. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  14692. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  14693. else g.end();
  14694. }
  14695. zoom.wheelDelta = function(_) {
  14696. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$13(+_), zoom) : wheelDelta;
  14697. };
  14698. zoom.filter = function(_) {
  14699. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$13(!!_), zoom) : filter;
  14700. };
  14701. zoom.touchable = function(_) {
  14702. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$13(!!_), zoom) : touchable;
  14703. };
  14704. zoom.extent = function(_) {
  14705. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$13([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  14706. };
  14707. zoom.scaleExtent = function(_) {
  14708. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  14709. };
  14710. zoom.translateExtent = function(_) {
  14711. 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]]];
  14712. };
  14713. zoom.constrain = function(_) {
  14714. return arguments.length ? (constrain = _, zoom) : constrain;
  14715. };
  14716. zoom.duration = function(_) {
  14717. return arguments.length ? (duration = +_, zoom) : duration;
  14718. };
  14719. zoom.interpolate = function(_) {
  14720. return arguments.length ? (interpolate = _, zoom) : interpolate;
  14721. };
  14722. zoom.on = function() {
  14723. var value = listeners.on.apply(listeners, arguments);
  14724. return value === listeners ? zoom : value;
  14725. };
  14726. zoom.clickDistance = function(_) {
  14727. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  14728. };
  14729. return zoom;
  14730. }
  14731. exports.version = version;
  14732. exports.bisect = bisectRight;
  14733. exports.bisectRight = bisectRight;
  14734. exports.bisectLeft = bisectLeft;
  14735. exports.ascending = ascending;
  14736. exports.bisector = bisector;
  14737. exports.cross = cross;
  14738. exports.descending = descending;
  14739. exports.deviation = deviation;
  14740. exports.extent = extent;
  14741. exports.histogram = histogram;
  14742. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  14743. exports.thresholdScott = scott;
  14744. exports.thresholdSturges = thresholdSturges;
  14745. exports.max = max;
  14746. exports.mean = mean;
  14747. exports.median = median;
  14748. exports.merge = merge;
  14749. exports.min = min;
  14750. exports.pairs = pairs;
  14751. exports.permute = permute;
  14752. exports.quantile = threshold;
  14753. exports.range = sequence;
  14754. exports.scan = scan;
  14755. exports.shuffle = shuffle;
  14756. exports.sum = sum;
  14757. exports.ticks = ticks;
  14758. exports.tickIncrement = tickIncrement;
  14759. exports.tickStep = tickStep;
  14760. exports.transpose = transpose;
  14761. exports.variance = variance;
  14762. exports.zip = zip;
  14763. exports.axisTop = axisTop;
  14764. exports.axisRight = axisRight;
  14765. exports.axisBottom = axisBottom;
  14766. exports.axisLeft = axisLeft;
  14767. exports.brush = brush;
  14768. exports.brushX = brushX;
  14769. exports.brushY = brushY;
  14770. exports.brushSelection = brushSelection;
  14771. exports.chord = chord;
  14772. exports.ribbon = ribbon;
  14773. exports.nest = nest;
  14774. exports.set = set$2;
  14775. exports.map = map$1;
  14776. exports.keys = keys;
  14777. exports.values = values;
  14778. exports.entries = entries;
  14779. exports.color = color;
  14780. exports.rgb = rgb;
  14781. exports.hsl = hsl;
  14782. exports.lab = lab;
  14783. exports.hcl = hcl;
  14784. exports.lch = lch;
  14785. exports.gray = gray;
  14786. exports.cubehelix = cubehelix;
  14787. exports.contours = contours;
  14788. exports.contourDensity = density;
  14789. exports.dispatch = dispatch;
  14790. exports.drag = drag;
  14791. exports.dragDisable = dragDisable;
  14792. exports.dragEnable = yesdrag;
  14793. exports.dsvFormat = dsvFormat;
  14794. exports.csvParse = csvParse;
  14795. exports.csvParseRows = csvParseRows;
  14796. exports.csvFormat = csvFormat;
  14797. exports.csvFormatRows = csvFormatRows;
  14798. exports.tsvParse = tsvParse;
  14799. exports.tsvParseRows = tsvParseRows;
  14800. exports.tsvFormat = tsvFormat;
  14801. exports.tsvFormatRows = tsvFormatRows;
  14802. exports.easeLinear = linear$1;
  14803. exports.easeQuad = quadInOut;
  14804. exports.easeQuadIn = quadIn;
  14805. exports.easeQuadOut = quadOut;
  14806. exports.easeQuadInOut = quadInOut;
  14807. exports.easeCubic = cubicInOut;
  14808. exports.easeCubicIn = cubicIn;
  14809. exports.easeCubicOut = cubicOut;
  14810. exports.easeCubicInOut = cubicInOut;
  14811. exports.easePoly = polyInOut;
  14812. exports.easePolyIn = polyIn;
  14813. exports.easePolyOut = polyOut;
  14814. exports.easePolyInOut = polyInOut;
  14815. exports.easeSin = sinInOut;
  14816. exports.easeSinIn = sinIn;
  14817. exports.easeSinOut = sinOut;
  14818. exports.easeSinInOut = sinInOut;
  14819. exports.easeExp = expInOut;
  14820. exports.easeExpIn = expIn;
  14821. exports.easeExpOut = expOut;
  14822. exports.easeExpInOut = expInOut;
  14823. exports.easeCircle = circleInOut;
  14824. exports.easeCircleIn = circleIn;
  14825. exports.easeCircleOut = circleOut;
  14826. exports.easeCircleInOut = circleInOut;
  14827. exports.easeBounce = bounceOut;
  14828. exports.easeBounceIn = bounceIn;
  14829. exports.easeBounceOut = bounceOut;
  14830. exports.easeBounceInOut = bounceInOut;
  14831. exports.easeBack = backInOut;
  14832. exports.easeBackIn = backIn;
  14833. exports.easeBackOut = backOut;
  14834. exports.easeBackInOut = backInOut;
  14835. exports.easeElastic = elasticOut;
  14836. exports.easeElasticIn = elasticIn;
  14837. exports.easeElasticOut = elasticOut;
  14838. exports.easeElasticInOut = elasticInOut;
  14839. exports.blob = blob;
  14840. exports.buffer = buffer;
  14841. exports.dsv = dsv;
  14842. exports.csv = csv$1;
  14843. exports.tsv = tsv$1;
  14844. exports.image = image;
  14845. exports.json = json;
  14846. exports.text = text;
  14847. exports.xml = xml;
  14848. exports.html = html;
  14849. exports.svg = svg;
  14850. exports.forceCenter = center$1;
  14851. exports.forceCollide = collide;
  14852. exports.forceLink = link;
  14853. exports.forceManyBody = manyBody;
  14854. exports.forceRadial = radial;
  14855. exports.forceSimulation = simulation;
  14856. exports.forceX = x$2;
  14857. exports.forceY = y$2;
  14858. exports.formatDefaultLocale = defaultLocale;
  14859. exports.formatLocale = formatLocale;
  14860. exports.formatSpecifier = formatSpecifier;
  14861. exports.precisionFixed = precisionFixed;
  14862. exports.precisionPrefix = precisionPrefix;
  14863. exports.precisionRound = precisionRound;
  14864. exports.geoArea = area$1;
  14865. exports.geoBounds = bounds;
  14866. exports.geoCentroid = centroid;
  14867. exports.geoCircle = circle;
  14868. exports.geoClipAntimeridian = clipAntimeridian;
  14869. exports.geoClipCircle = clipCircle;
  14870. exports.geoClipExtent = extent$1;
  14871. exports.geoClipRectangle = clipRectangle;
  14872. exports.geoContains = contains$1;
  14873. exports.geoDistance = distance;
  14874. exports.geoGraticule = graticule;
  14875. exports.geoGraticule10 = graticule10;
  14876. exports.geoInterpolate = interpolate$1;
  14877. exports.geoLength = length$1;
  14878. exports.geoPath = index$1;
  14879. exports.geoAlbers = albers;
  14880. exports.geoAlbersUsa = albersUsa;
  14881. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  14882. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  14883. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  14884. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  14885. exports.geoConicConformal = conicConformal;
  14886. exports.geoConicConformalRaw = conicConformalRaw;
  14887. exports.geoConicEqualArea = conicEqualArea;
  14888. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  14889. exports.geoConicEquidistant = conicEquidistant;
  14890. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  14891. exports.geoEquirectangular = equirectangular;
  14892. exports.geoEquirectangularRaw = equirectangularRaw;
  14893. exports.geoGnomonic = gnomonic;
  14894. exports.geoGnomonicRaw = gnomonicRaw;
  14895. exports.geoIdentity = identity$5;
  14896. exports.geoProjection = projection;
  14897. exports.geoProjectionMutator = projectionMutator;
  14898. exports.geoMercator = mercator;
  14899. exports.geoMercatorRaw = mercatorRaw;
  14900. exports.geoNaturalEarth1 = naturalEarth1;
  14901. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  14902. exports.geoOrthographic = orthographic;
  14903. exports.geoOrthographicRaw = orthographicRaw;
  14904. exports.geoStereographic = stereographic;
  14905. exports.geoStereographicRaw = stereographicRaw;
  14906. exports.geoTransverseMercator = transverseMercator;
  14907. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  14908. exports.geoRotation = rotation;
  14909. exports.geoStream = geoStream;
  14910. exports.geoTransform = transform;
  14911. exports.cluster = cluster;
  14912. exports.hierarchy = hierarchy;
  14913. exports.pack = index$2;
  14914. exports.packSiblings = siblings;
  14915. exports.packEnclose = enclose;
  14916. exports.partition = partition;
  14917. exports.stratify = stratify;
  14918. exports.tree = tree;
  14919. exports.treemap = index$3;
  14920. exports.treemapBinary = binary;
  14921. exports.treemapDice = treemapDice;
  14922. exports.treemapSlice = treemapSlice;
  14923. exports.treemapSliceDice = sliceDice;
  14924. exports.treemapSquarify = squarify;
  14925. exports.treemapResquarify = resquarify;
  14926. exports.interpolate = interpolateValue;
  14927. exports.interpolateArray = array$1;
  14928. exports.interpolateBasis = basis$1;
  14929. exports.interpolateBasisClosed = basisClosed;
  14930. exports.interpolateDate = date;
  14931. exports.interpolateNumber = reinterpolate;
  14932. exports.interpolateObject = object;
  14933. exports.interpolateRound = interpolateRound;
  14934. exports.interpolateString = interpolateString;
  14935. exports.interpolateTransformCss = interpolateTransformCss;
  14936. exports.interpolateTransformSvg = interpolateTransformSvg;
  14937. exports.interpolateZoom = interpolateZoom;
  14938. exports.interpolateRgb = interpolateRgb;
  14939. exports.interpolateRgbBasis = rgbBasis;
  14940. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  14941. exports.interpolateHsl = hsl$2;
  14942. exports.interpolateHslLong = hslLong;
  14943. exports.interpolateLab = lab$1;
  14944. exports.interpolateHcl = hcl$2;
  14945. exports.interpolateHclLong = hclLong;
  14946. exports.interpolateCubehelix = cubehelix$2;
  14947. exports.interpolateCubehelixLong = cubehelixLong;
  14948. exports.quantize = quantize;
  14949. exports.path = path;
  14950. exports.polygonArea = area$2;
  14951. exports.polygonCentroid = centroid$1;
  14952. exports.polygonHull = hull;
  14953. exports.polygonContains = contains$2;
  14954. exports.polygonLength = length$2;
  14955. exports.quadtree = quadtree;
  14956. exports.randomUniform = uniform;
  14957. exports.randomNormal = normal;
  14958. exports.randomLogNormal = logNormal;
  14959. exports.randomBates = bates;
  14960. exports.randomIrwinHall = irwinHall;
  14961. exports.randomExponential = exponential$1;
  14962. exports.scaleBand = band;
  14963. exports.scalePoint = point$1;
  14964. exports.scaleIdentity = identity$6;
  14965. exports.scaleLinear = linear$2;
  14966. exports.scaleLog = log$1;
  14967. exports.scaleOrdinal = ordinal;
  14968. exports.scaleImplicit = implicit;
  14969. exports.scalePow = pow$1;
  14970. exports.scaleSqrt = sqrt$1;
  14971. exports.scaleQuantile = quantile$$1;
  14972. exports.scaleQuantize = quantize$1;
  14973. exports.scaleThreshold = threshold$1;
  14974. exports.scaleTime = time;
  14975. exports.scaleUtc = utcTime;
  14976. exports.scaleSequential = sequential;
  14977. exports.schemeCategory10 = category10;
  14978. exports.schemeAccent = Accent;
  14979. exports.schemeDark2 = Dark2;
  14980. exports.schemePaired = Paired;
  14981. exports.schemePastel1 = Pastel1;
  14982. exports.schemePastel2 = Pastel2;
  14983. exports.schemeSet1 = Set1;
  14984. exports.schemeSet2 = Set2;
  14985. exports.schemeSet3 = Set3;
  14986. exports.interpolateBrBG = BrBG;
  14987. exports.schemeBrBG = scheme;
  14988. exports.interpolatePRGn = PRGn;
  14989. exports.schemePRGn = scheme$1;
  14990. exports.interpolatePiYG = PiYG;
  14991. exports.schemePiYG = scheme$2;
  14992. exports.interpolatePuOr = PuOr;
  14993. exports.schemePuOr = scheme$3;
  14994. exports.interpolateRdBu = RdBu;
  14995. exports.schemeRdBu = scheme$4;
  14996. exports.interpolateRdGy = RdGy;
  14997. exports.schemeRdGy = scheme$5;
  14998. exports.interpolateRdYlBu = RdYlBu;
  14999. exports.schemeRdYlBu = scheme$6;
  15000. exports.interpolateRdYlGn = RdYlGn;
  15001. exports.schemeRdYlGn = scheme$7;
  15002. exports.interpolateSpectral = Spectral;
  15003. exports.schemeSpectral = scheme$8;
  15004. exports.interpolateBuGn = BuGn;
  15005. exports.schemeBuGn = scheme$9;
  15006. exports.interpolateBuPu = BuPu;
  15007. exports.schemeBuPu = scheme$10;
  15008. exports.interpolateGnBu = GnBu;
  15009. exports.schemeGnBu = scheme$11;
  15010. exports.interpolateOrRd = OrRd;
  15011. exports.schemeOrRd = scheme$12;
  15012. exports.interpolatePuBuGn = PuBuGn;
  15013. exports.schemePuBuGn = scheme$13;
  15014. exports.interpolatePuBu = PuBu;
  15015. exports.schemePuBu = scheme$14;
  15016. exports.interpolatePuRd = PuRd;
  15017. exports.schemePuRd = scheme$15;
  15018. exports.interpolateRdPu = RdPu;
  15019. exports.schemeRdPu = scheme$16;
  15020. exports.interpolateYlGnBu = YlGnBu;
  15021. exports.schemeYlGnBu = scheme$17;
  15022. exports.interpolateYlGn = YlGn;
  15023. exports.schemeYlGn = scheme$18;
  15024. exports.interpolateYlOrBr = YlOrBr;
  15025. exports.schemeYlOrBr = scheme$19;
  15026. exports.interpolateYlOrRd = YlOrRd;
  15027. exports.schemeYlOrRd = scheme$20;
  15028. exports.interpolateBlues = Blues;
  15029. exports.schemeBlues = scheme$21;
  15030. exports.interpolateGreens = Greens;
  15031. exports.schemeGreens = scheme$22;
  15032. exports.interpolateGreys = Greys;
  15033. exports.schemeGreys = scheme$23;
  15034. exports.interpolatePurples = Purples;
  15035. exports.schemePurples = scheme$24;
  15036. exports.interpolateReds = Reds;
  15037. exports.schemeReds = scheme$25;
  15038. exports.interpolateOranges = Oranges;
  15039. exports.schemeOranges = scheme$26;
  15040. exports.interpolateCubehelixDefault = cubehelix$3;
  15041. exports.interpolateRainbow = rainbow$1;
  15042. exports.interpolateWarm = warm;
  15043. exports.interpolateCool = cool;
  15044. exports.interpolateViridis = viridis;
  15045. exports.interpolateMagma = magma;
  15046. exports.interpolateInferno = inferno;
  15047. exports.interpolatePlasma = plasma;
  15048. exports.create = create;
  15049. exports.creator = creator;
  15050. exports.local = local;
  15051. exports.matcher = matcher$1;
  15052. exports.mouse = mouse;
  15053. exports.namespace = namespace;
  15054. exports.namespaces = namespaces;
  15055. exports.clientPoint = point;
  15056. exports.select = select;
  15057. exports.selectAll = selectAll;
  15058. exports.selection = selection;
  15059. exports.selector = selector;
  15060. exports.selectorAll = selectorAll;
  15061. exports.style = styleValue;
  15062. exports.touch = touch;
  15063. exports.touches = touches;
  15064. exports.window = defaultView;
  15065. exports.customEvent = customEvent;
  15066. exports.arc = arc;
  15067. exports.area = area$3;
  15068. exports.line = line;
  15069. exports.pie = pie;
  15070. exports.areaRadial = areaRadial;
  15071. exports.radialArea = areaRadial;
  15072. exports.lineRadial = lineRadial$1;
  15073. exports.radialLine = lineRadial$1;
  15074. exports.pointRadial = pointRadial;
  15075. exports.linkHorizontal = linkHorizontal;
  15076. exports.linkVertical = linkVertical;
  15077. exports.linkRadial = linkRadial;
  15078. exports.symbol = symbol;
  15079. exports.symbols = symbols;
  15080. exports.symbolCircle = circle$2;
  15081. exports.symbolCross = cross$2;
  15082. exports.symbolDiamond = diamond;
  15083. exports.symbolSquare = square;
  15084. exports.symbolStar = star;
  15085. exports.symbolTriangle = triangle;
  15086. exports.symbolWye = wye;
  15087. exports.curveBasisClosed = basisClosed$1;
  15088. exports.curveBasisOpen = basisOpen;
  15089. exports.curveBasis = basis$2;
  15090. exports.curveBundle = bundle;
  15091. exports.curveCardinalClosed = cardinalClosed;
  15092. exports.curveCardinalOpen = cardinalOpen;
  15093. exports.curveCardinal = cardinal;
  15094. exports.curveCatmullRomClosed = catmullRomClosed;
  15095. exports.curveCatmullRomOpen = catmullRomOpen;
  15096. exports.curveCatmullRom = catmullRom;
  15097. exports.curveLinearClosed = linearClosed;
  15098. exports.curveLinear = curveLinear;
  15099. exports.curveMonotoneX = monotoneX;
  15100. exports.curveMonotoneY = monotoneY;
  15101. exports.curveNatural = natural;
  15102. exports.curveStep = step;
  15103. exports.curveStepAfter = stepAfter;
  15104. exports.curveStepBefore = stepBefore;
  15105. exports.stack = stack;
  15106. exports.stackOffsetExpand = expand;
  15107. exports.stackOffsetDiverging = diverging;
  15108. exports.stackOffsetNone = none$1;
  15109. exports.stackOffsetSilhouette = silhouette;
  15110. exports.stackOffsetWiggle = wiggle;
  15111. exports.stackOrderAscending = ascending$3;
  15112. exports.stackOrderDescending = descending$2;
  15113. exports.stackOrderInsideOut = insideOut;
  15114. exports.stackOrderNone = none$2;
  15115. exports.stackOrderReverse = reverse;
  15116. exports.timeInterval = newInterval;
  15117. exports.timeMillisecond = millisecond;
  15118. exports.timeMilliseconds = milliseconds;
  15119. exports.utcMillisecond = millisecond;
  15120. exports.utcMilliseconds = milliseconds;
  15121. exports.timeSecond = second;
  15122. exports.timeSeconds = seconds;
  15123. exports.utcSecond = second;
  15124. exports.utcSeconds = seconds;
  15125. exports.timeMinute = minute;
  15126. exports.timeMinutes = minutes;
  15127. exports.timeHour = hour;
  15128. exports.timeHours = hours;
  15129. exports.timeDay = day;
  15130. exports.timeDays = days;
  15131. exports.timeWeek = sunday;
  15132. exports.timeWeeks = sundays;
  15133. exports.timeSunday = sunday;
  15134. exports.timeSundays = sundays;
  15135. exports.timeMonday = monday;
  15136. exports.timeMondays = mondays;
  15137. exports.timeTuesday = tuesday;
  15138. exports.timeTuesdays = tuesdays;
  15139. exports.timeWednesday = wednesday;
  15140. exports.timeWednesdays = wednesdays;
  15141. exports.timeThursday = thursday;
  15142. exports.timeThursdays = thursdays;
  15143. exports.timeFriday = friday;
  15144. exports.timeFridays = fridays;
  15145. exports.timeSaturday = saturday;
  15146. exports.timeSaturdays = saturdays;
  15147. exports.timeMonth = month;
  15148. exports.timeMonths = months;
  15149. exports.timeYear = year;
  15150. exports.timeYears = years;
  15151. exports.utcMinute = utcMinute;
  15152. exports.utcMinutes = utcMinutes;
  15153. exports.utcHour = utcHour;
  15154. exports.utcHours = utcHours;
  15155. exports.utcDay = utcDay;
  15156. exports.utcDays = utcDays;
  15157. exports.utcWeek = utcSunday;
  15158. exports.utcWeeks = utcSundays;
  15159. exports.utcSunday = utcSunday;
  15160. exports.utcSundays = utcSundays;
  15161. exports.utcMonday = utcMonday;
  15162. exports.utcMondays = utcMondays;
  15163. exports.utcTuesday = utcTuesday;
  15164. exports.utcTuesdays = utcTuesdays;
  15165. exports.utcWednesday = utcWednesday;
  15166. exports.utcWednesdays = utcWednesdays;
  15167. exports.utcThursday = utcThursday;
  15168. exports.utcThursdays = utcThursdays;
  15169. exports.utcFriday = utcFriday;
  15170. exports.utcFridays = utcFridays;
  15171. exports.utcSaturday = utcSaturday;
  15172. exports.utcSaturdays = utcSaturdays;
  15173. exports.utcMonth = utcMonth;
  15174. exports.utcMonths = utcMonths;
  15175. exports.utcYear = utcYear;
  15176. exports.utcYears = utcYears;
  15177. exports.timeFormatDefaultLocale = defaultLocale$1;
  15178. exports.timeFormatLocale = formatLocale$1;
  15179. exports.isoFormat = formatIso;
  15180. exports.isoParse = parseIso;
  15181. exports.now = now;
  15182. exports.timer = timer;
  15183. exports.timerFlush = timerFlush;
  15184. exports.timeout = timeout$1;
  15185. exports.interval = interval$1;
  15186. exports.transition = transition;
  15187. exports.active = active;
  15188. exports.interrupt = interrupt;
  15189. exports.voronoi = voronoi;
  15190. exports.zoom = zoom;
  15191. exports.zoomTransform = transform$1;
  15192. exports.zoomIdentity = identity$8;
  15193. Object.defineProperty(exports, '__esModule', { value: true });
  15194. })));