d3.js 502 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524
  1. // https://d3js.org v5.15.0 Copyright 2019 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = global || self, factory(global.d3 = global.d3 || {}));
  6. }(this, function (exports) { 'use strict';
  7. var version = "5.15.0";
  8. function ascending(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function bisector(compare) {
  12. if (compare.length === 1) compare = ascendingComparator(compare);
  13. return {
  14. left: function(a, x, lo, hi) {
  15. if (lo == null) lo = 0;
  16. if (hi == null) hi = a.length;
  17. while (lo < hi) {
  18. var mid = lo + hi >>> 1;
  19. if (compare(a[mid], x) < 0) lo = mid + 1;
  20. else hi = mid;
  21. }
  22. return lo;
  23. },
  24. right: function(a, x, lo, hi) {
  25. if (lo == null) lo = 0;
  26. if (hi == null) hi = a.length;
  27. while (lo < hi) {
  28. var mid = lo + hi >>> 1;
  29. if (compare(a[mid], x) > 0) hi = mid;
  30. else lo = mid + 1;
  31. }
  32. return lo;
  33. }
  34. };
  35. }
  36. function ascendingComparator(f) {
  37. return function(d, x) {
  38. return ascending(f(d), x);
  39. };
  40. }
  41. var ascendingBisect = bisector(ascending);
  42. var bisectRight = ascendingBisect.right;
  43. var bisectLeft = ascendingBisect.left;
  44. function pairs(array, f) {
  45. if (f == null) f = pair;
  46. var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
  47. while (i < n) pairs[i] = f(p, p = array[++i]);
  48. return pairs;
  49. }
  50. function pair(a, b) {
  51. return [a, b];
  52. }
  53. function cross(values0, values1, reduce) {
  54. var n0 = values0.length,
  55. n1 = values1.length,
  56. values = new Array(n0 * n1),
  57. i0,
  58. i1,
  59. i,
  60. value0;
  61. if (reduce == null) reduce = pair;
  62. for (i0 = i = 0; i0 < n0; ++i0) {
  63. for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
  64. values[i] = reduce(value0, values1[i1]);
  65. }
  66. }
  67. return values;
  68. }
  69. function descending(a, b) {
  70. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  71. }
  72. function number(x) {
  73. return x === null ? NaN : +x;
  74. }
  75. function variance(values, valueof) {
  76. var n = values.length,
  77. m = 0,
  78. i = -1,
  79. mean = 0,
  80. value,
  81. delta,
  82. sum = 0;
  83. if (valueof == null) {
  84. while (++i < n) {
  85. if (!isNaN(value = number(values[i]))) {
  86. delta = value - mean;
  87. mean += delta / ++m;
  88. sum += delta * (value - mean);
  89. }
  90. }
  91. }
  92. else {
  93. while (++i < n) {
  94. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  95. delta = value - mean;
  96. mean += delta / ++m;
  97. sum += delta * (value - mean);
  98. }
  99. }
  100. }
  101. if (m > 1) return sum / (m - 1);
  102. }
  103. function deviation(array, f) {
  104. var v = variance(array, f);
  105. return v ? Math.sqrt(v) : v;
  106. }
  107. function extent(values, valueof) {
  108. var n = values.length,
  109. i = -1,
  110. value,
  111. min,
  112. max;
  113. if (valueof == null) {
  114. while (++i < n) { // Find the first comparable value.
  115. if ((value = values[i]) != null && value >= value) {
  116. min = max = value;
  117. while (++i < n) { // Compare the remaining values.
  118. if ((value = values[i]) != null) {
  119. if (min > value) min = value;
  120. if (max < value) max = value;
  121. }
  122. }
  123. }
  124. }
  125. }
  126. else {
  127. while (++i < n) { // Find the first comparable value.
  128. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  129. min = max = value;
  130. while (++i < n) { // Compare the remaining values.
  131. if ((value = valueof(values[i], i, values)) != null) {
  132. if (min > value) min = value;
  133. if (max < value) max = value;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. return [min, max];
  140. }
  141. var array = Array.prototype;
  142. var slice = array.slice;
  143. var map = array.map;
  144. function constant(x) {
  145. return function() {
  146. return x;
  147. };
  148. }
  149. function identity(x) {
  150. return x;
  151. }
  152. function sequence(start, stop, step) {
  153. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  154. var i = -1,
  155. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  156. range = new Array(n);
  157. while (++i < n) {
  158. range[i] = start + i * step;
  159. }
  160. return range;
  161. }
  162. var e10 = Math.sqrt(50),
  163. e5 = Math.sqrt(10),
  164. e2 = Math.sqrt(2);
  165. function ticks(start, stop, count) {
  166. var reverse,
  167. i = -1,
  168. n,
  169. ticks,
  170. step;
  171. stop = +stop, start = +start, count = +count;
  172. if (start === stop && count > 0) return [start];
  173. if (reverse = stop < start) n = start, start = stop, stop = n;
  174. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  175. if (step > 0) {
  176. start = Math.ceil(start / step);
  177. stop = Math.floor(stop / step);
  178. ticks = new Array(n = Math.ceil(stop - start + 1));
  179. while (++i < n) ticks[i] = (start + i) * step;
  180. } else {
  181. start = Math.floor(start * step);
  182. stop = Math.ceil(stop * step);
  183. ticks = new Array(n = Math.ceil(start - stop + 1));
  184. while (++i < n) ticks[i] = (start - i) / step;
  185. }
  186. if (reverse) ticks.reverse();
  187. return ticks;
  188. }
  189. function tickIncrement(start, stop, count) {
  190. var step = (stop - start) / Math.max(0, count),
  191. power = Math.floor(Math.log(step) / Math.LN10),
  192. error = step / Math.pow(10, power);
  193. return power >= 0
  194. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  195. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  196. }
  197. function tickStep(start, stop, count) {
  198. var step0 = Math.abs(stop - start) / Math.max(0, count),
  199. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  200. error = step0 / step1;
  201. if (error >= e10) step1 *= 10;
  202. else if (error >= e5) step1 *= 5;
  203. else if (error >= e2) step1 *= 2;
  204. return stop < start ? -step1 : step1;
  205. }
  206. function thresholdSturges(values) {
  207. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  208. }
  209. function histogram() {
  210. var value = identity,
  211. domain = extent,
  212. threshold = thresholdSturges;
  213. function histogram(data) {
  214. var i,
  215. n = data.length,
  216. x,
  217. values = new Array(n);
  218. for (i = 0; i < n; ++i) {
  219. values[i] = value(data[i], i, data);
  220. }
  221. var xz = domain(values),
  222. x0 = xz[0],
  223. x1 = xz[1],
  224. tz = threshold(values, x0, x1);
  225. // Convert number of thresholds into uniform thresholds.
  226. if (!Array.isArray(tz)) {
  227. tz = tickStep(x0, x1, tz);
  228. tz = sequence(Math.ceil(x0 / tz) * tz, x1, tz); // exclusive
  229. }
  230. // Remove any thresholds outside the domain.
  231. var m = tz.length;
  232. while (tz[0] <= x0) tz.shift(), --m;
  233. while (tz[m - 1] > x1) tz.pop(), --m;
  234. var bins = new Array(m + 1),
  235. bin;
  236. // Initialize bins.
  237. for (i = 0; i <= m; ++i) {
  238. bin = bins[i] = [];
  239. bin.x0 = i > 0 ? tz[i - 1] : x0;
  240. bin.x1 = i < m ? tz[i] : x1;
  241. }
  242. // Assign data to bins by value, ignoring any outside the domain.
  243. for (i = 0; i < n; ++i) {
  244. x = values[i];
  245. if (x0 <= x && x <= x1) {
  246. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  247. }
  248. }
  249. return bins;
  250. }
  251. histogram.value = function(_) {
  252. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  253. };
  254. histogram.domain = function(_) {
  255. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  256. };
  257. histogram.thresholds = function(_) {
  258. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  259. };
  260. return histogram;
  261. }
  262. function threshold(values, p, valueof) {
  263. if (valueof == null) valueof = number;
  264. if (!(n = values.length)) return;
  265. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  266. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  267. var n,
  268. i = (n - 1) * p,
  269. i0 = Math.floor(i),
  270. value0 = +valueof(values[i0], i0, values),
  271. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  272. return value0 + (value1 - value0) * (i - i0);
  273. }
  274. function freedmanDiaconis(values, min, max) {
  275. values = map.call(values, number).sort(ascending);
  276. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  277. }
  278. function scott(values, min, max) {
  279. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  280. }
  281. function max(values, valueof) {
  282. var n = values.length,
  283. i = -1,
  284. value,
  285. max;
  286. if (valueof == null) {
  287. while (++i < n) { // Find the first comparable value.
  288. if ((value = values[i]) != null && value >= value) {
  289. max = value;
  290. while (++i < n) { // Compare the remaining values.
  291. if ((value = values[i]) != null && value > max) {
  292. max = value;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. else {
  299. while (++i < n) { // Find the first comparable value.
  300. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  301. max = value;
  302. while (++i < n) { // Compare the remaining values.
  303. if ((value = valueof(values[i], i, values)) != null && value > max) {
  304. max = value;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. return max;
  311. }
  312. function mean(values, valueof) {
  313. var n = values.length,
  314. m = n,
  315. i = -1,
  316. value,
  317. sum = 0;
  318. if (valueof == null) {
  319. while (++i < n) {
  320. if (!isNaN(value = number(values[i]))) sum += value;
  321. else --m;
  322. }
  323. }
  324. else {
  325. while (++i < n) {
  326. if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
  327. else --m;
  328. }
  329. }
  330. if (m) return sum / m;
  331. }
  332. function median(values, valueof) {
  333. var n = values.length,
  334. i = -1,
  335. value,
  336. numbers = [];
  337. if (valueof == null) {
  338. while (++i < n) {
  339. if (!isNaN(value = number(values[i]))) {
  340. numbers.push(value);
  341. }
  342. }
  343. }
  344. else {
  345. while (++i < n) {
  346. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  347. numbers.push(value);
  348. }
  349. }
  350. }
  351. return threshold(numbers.sort(ascending), 0.5);
  352. }
  353. function merge(arrays) {
  354. var n = arrays.length,
  355. m,
  356. i = -1,
  357. j = 0,
  358. merged,
  359. array;
  360. while (++i < n) j += arrays[i].length;
  361. merged = new Array(j);
  362. while (--n >= 0) {
  363. array = arrays[n];
  364. m = array.length;
  365. while (--m >= 0) {
  366. merged[--j] = array[m];
  367. }
  368. }
  369. return merged;
  370. }
  371. function min(values, valueof) {
  372. var n = values.length,
  373. i = -1,
  374. value,
  375. min;
  376. if (valueof == null) {
  377. while (++i < n) { // Find the first comparable value.
  378. if ((value = values[i]) != null && value >= value) {
  379. min = value;
  380. while (++i < n) { // Compare the remaining values.
  381. if ((value = values[i]) != null && min > value) {
  382. min = value;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. else {
  389. while (++i < n) { // Find the first comparable value.
  390. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  391. min = value;
  392. while (++i < n) { // Compare the remaining values.
  393. if ((value = valueof(values[i], i, values)) != null && min > value) {
  394. min = value;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. return min;
  401. }
  402. function permute(array, indexes) {
  403. var i = indexes.length, permutes = new Array(i);
  404. while (i--) permutes[i] = array[indexes[i]];
  405. return permutes;
  406. }
  407. function scan(values, compare) {
  408. if (!(n = values.length)) return;
  409. var n,
  410. i = 0,
  411. j = 0,
  412. xi,
  413. xj = values[j];
  414. if (compare == null) compare = ascending;
  415. while (++i < n) {
  416. if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
  417. xj = xi, j = i;
  418. }
  419. }
  420. if (compare(xj, xj) === 0) return j;
  421. }
  422. function shuffle(array, i0, i1) {
  423. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  424. t,
  425. i;
  426. while (m) {
  427. i = Math.random() * m-- | 0;
  428. t = array[m + i0];
  429. array[m + i0] = array[i + i0];
  430. array[i + i0] = t;
  431. }
  432. return array;
  433. }
  434. function sum(values, valueof) {
  435. var n = values.length,
  436. i = -1,
  437. value,
  438. sum = 0;
  439. if (valueof == null) {
  440. while (++i < n) {
  441. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  442. }
  443. }
  444. else {
  445. while (++i < n) {
  446. if (value = +valueof(values[i], i, values)) sum += value;
  447. }
  448. }
  449. return sum;
  450. }
  451. function transpose(matrix) {
  452. if (!(n = matrix.length)) return [];
  453. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  454. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  455. row[j] = matrix[j][i];
  456. }
  457. }
  458. return transpose;
  459. }
  460. function length(d) {
  461. return d.length;
  462. }
  463. function zip() {
  464. return transpose(arguments);
  465. }
  466. var slice$1 = Array.prototype.slice;
  467. function identity$1(x) {
  468. return x;
  469. }
  470. var top = 1,
  471. right = 2,
  472. bottom = 3,
  473. left = 4,
  474. epsilon = 1e-6;
  475. function translateX(x) {
  476. return "translate(" + (x + 0.5) + ",0)";
  477. }
  478. function translateY(y) {
  479. return "translate(0," + (y + 0.5) + ")";
  480. }
  481. function number$1(scale) {
  482. return function(d) {
  483. return +scale(d);
  484. };
  485. }
  486. function center(scale) {
  487. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  488. if (scale.round()) offset = Math.round(offset);
  489. return function(d) {
  490. return +scale(d) + offset;
  491. };
  492. }
  493. function entering() {
  494. return !this.__axis;
  495. }
  496. function axis(orient, scale) {
  497. var tickArguments = [],
  498. tickValues = null,
  499. tickFormat = null,
  500. tickSizeInner = 6,
  501. tickSizeOuter = 6,
  502. tickPadding = 3,
  503. k = orient === top || orient === left ? -1 : 1,
  504. x = orient === left || orient === right ? "x" : "y",
  505. transform = orient === top || orient === bottom ? translateX : translateY;
  506. function axis(context) {
  507. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  508. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  509. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  510. range = scale.range(),
  511. range0 = +range[0] + 0.5,
  512. range1 = +range[range.length - 1] + 0.5,
  513. position = (scale.bandwidth ? center : number$1)(scale.copy()),
  514. selection = context.selection ? context.selection() : context,
  515. path = selection.selectAll(".domain").data([null]),
  516. tick = selection.selectAll(".tick").data(values, scale).order(),
  517. tickExit = tick.exit(),
  518. tickEnter = tick.enter().append("g").attr("class", "tick"),
  519. line = tick.select("line"),
  520. text = tick.select("text");
  521. path = path.merge(path.enter().insert("path", ".tick")
  522. .attr("class", "domain")
  523. .attr("stroke", "currentColor"));
  524. tick = tick.merge(tickEnter);
  525. line = line.merge(tickEnter.append("line")
  526. .attr("stroke", "currentColor")
  527. .attr(x + "2", k * tickSizeInner));
  528. text = text.merge(tickEnter.append("text")
  529. .attr("fill", "currentColor")
  530. .attr(x, k * spacing)
  531. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  532. if (context !== selection) {
  533. path = path.transition(context);
  534. tick = tick.transition(context);
  535. line = line.transition(context);
  536. text = text.transition(context);
  537. tickExit = tickExit.transition(context)
  538. .attr("opacity", epsilon)
  539. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  540. tickEnter
  541. .attr("opacity", epsilon)
  542. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  543. }
  544. tickExit.remove();
  545. path
  546. .attr("d", orient === left || orient == right
  547. ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter : "M0.5," + range0 + "V" + range1)
  548. : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + ",0.5H" + range1));
  549. tick
  550. .attr("opacity", 1)
  551. .attr("transform", function(d) { return transform(position(d)); });
  552. line
  553. .attr(x + "2", k * tickSizeInner);
  554. text
  555. .attr(x, k * spacing)
  556. .text(format);
  557. selection.filter(entering)
  558. .attr("fill", "none")
  559. .attr("font-size", 10)
  560. .attr("font-family", "sans-serif")
  561. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  562. selection
  563. .each(function() { this.__axis = position; });
  564. }
  565. axis.scale = function(_) {
  566. return arguments.length ? (scale = _, axis) : scale;
  567. };
  568. axis.ticks = function() {
  569. return tickArguments = slice$1.call(arguments), axis;
  570. };
  571. axis.tickArguments = function(_) {
  572. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  573. };
  574. axis.tickValues = function(_) {
  575. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  576. };
  577. axis.tickFormat = function(_) {
  578. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  579. };
  580. axis.tickSize = function(_) {
  581. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  582. };
  583. axis.tickSizeInner = function(_) {
  584. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  585. };
  586. axis.tickSizeOuter = function(_) {
  587. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  588. };
  589. axis.tickPadding = function(_) {
  590. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  591. };
  592. return axis;
  593. }
  594. function axisTop(scale) {
  595. return axis(top, scale);
  596. }
  597. function axisRight(scale) {
  598. return axis(right, scale);
  599. }
  600. function axisBottom(scale) {
  601. return axis(bottom, scale);
  602. }
  603. function axisLeft(scale) {
  604. return axis(left, scale);
  605. }
  606. var noop = {value: function() {}};
  607. function dispatch() {
  608. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  609. if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
  610. _[t] = [];
  611. }
  612. return new Dispatch(_);
  613. }
  614. function Dispatch(_) {
  615. this._ = _;
  616. }
  617. function parseTypenames(typenames, types) {
  618. return typenames.trim().split(/^|\s+/).map(function(t) {
  619. var name = "", i = t.indexOf(".");
  620. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  621. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  622. return {type: t, name: name};
  623. });
  624. }
  625. Dispatch.prototype = dispatch.prototype = {
  626. constructor: Dispatch,
  627. on: function(typename, callback) {
  628. var _ = this._,
  629. T = parseTypenames(typename + "", _),
  630. t,
  631. i = -1,
  632. n = T.length;
  633. // If no callback was specified, return the callback of the given type and name.
  634. if (arguments.length < 2) {
  635. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  636. return;
  637. }
  638. // If a type was specified, set the callback for the given type and name.
  639. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  640. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  641. while (++i < n) {
  642. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  643. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  644. }
  645. return this;
  646. },
  647. copy: function() {
  648. var copy = {}, _ = this._;
  649. for (var t in _) copy[t] = _[t].slice();
  650. return new Dispatch(copy);
  651. },
  652. call: function(type, that) {
  653. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  654. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  655. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  656. },
  657. apply: function(type, that, args) {
  658. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  659. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  660. }
  661. };
  662. function get(type, name) {
  663. for (var i = 0, n = type.length, c; i < n; ++i) {
  664. if ((c = type[i]).name === name) {
  665. return c.value;
  666. }
  667. }
  668. }
  669. function set(type, name, callback) {
  670. for (var i = 0, n = type.length; i < n; ++i) {
  671. if (type[i].name === name) {
  672. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  673. break;
  674. }
  675. }
  676. if (callback != null) type.push({name: name, value: callback});
  677. return type;
  678. }
  679. var xhtml = "http://www.w3.org/1999/xhtml";
  680. var namespaces = {
  681. svg: "http://www.w3.org/2000/svg",
  682. xhtml: xhtml,
  683. xlink: "http://www.w3.org/1999/xlink",
  684. xml: "http://www.w3.org/XML/1998/namespace",
  685. xmlns: "http://www.w3.org/2000/xmlns/"
  686. };
  687. function namespace(name) {
  688. var prefix = name += "", i = prefix.indexOf(":");
  689. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  690. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  691. }
  692. function creatorInherit(name) {
  693. return function() {
  694. var document = this.ownerDocument,
  695. uri = this.namespaceURI;
  696. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  697. ? document.createElement(name)
  698. : document.createElementNS(uri, name);
  699. };
  700. }
  701. function creatorFixed(fullname) {
  702. return function() {
  703. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  704. };
  705. }
  706. function creator(name) {
  707. var fullname = namespace(name);
  708. return (fullname.local
  709. ? creatorFixed
  710. : creatorInherit)(fullname);
  711. }
  712. function none() {}
  713. function selector(selector) {
  714. return selector == null ? none : function() {
  715. return this.querySelector(selector);
  716. };
  717. }
  718. function selection_select(select) {
  719. if (typeof select !== "function") select = selector(select);
  720. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  721. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  722. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  723. if ("__data__" in node) subnode.__data__ = node.__data__;
  724. subgroup[i] = subnode;
  725. }
  726. }
  727. }
  728. return new Selection(subgroups, this._parents);
  729. }
  730. function empty() {
  731. return [];
  732. }
  733. function selectorAll(selector) {
  734. return selector == null ? empty : function() {
  735. return this.querySelectorAll(selector);
  736. };
  737. }
  738. function selection_selectAll(select) {
  739. if (typeof select !== "function") select = selectorAll(select);
  740. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  741. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  742. if (node = group[i]) {
  743. subgroups.push(select.call(node, node.__data__, i, group));
  744. parents.push(node);
  745. }
  746. }
  747. }
  748. return new Selection(subgroups, parents);
  749. }
  750. function matcher(selector) {
  751. return function() {
  752. return this.matches(selector);
  753. };
  754. }
  755. function selection_filter(match) {
  756. if (typeof match !== "function") match = matcher(match);
  757. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  758. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  759. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  760. subgroup.push(node);
  761. }
  762. }
  763. }
  764. return new Selection(subgroups, this._parents);
  765. }
  766. function sparse(update) {
  767. return new Array(update.length);
  768. }
  769. function selection_enter() {
  770. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  771. }
  772. function EnterNode(parent, datum) {
  773. this.ownerDocument = parent.ownerDocument;
  774. this.namespaceURI = parent.namespaceURI;
  775. this._next = null;
  776. this._parent = parent;
  777. this.__data__ = datum;
  778. }
  779. EnterNode.prototype = {
  780. constructor: EnterNode,
  781. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  782. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  783. querySelector: function(selector) { return this._parent.querySelector(selector); },
  784. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  785. };
  786. function constant$1(x) {
  787. return function() {
  788. return x;
  789. };
  790. }
  791. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  792. function bindIndex(parent, group, enter, update, exit, data) {
  793. var i = 0,
  794. node,
  795. groupLength = group.length,
  796. dataLength = data.length;
  797. // Put any non-null nodes that fit into update.
  798. // Put any null nodes into enter.
  799. // Put any remaining data into enter.
  800. for (; i < dataLength; ++i) {
  801. if (node = group[i]) {
  802. node.__data__ = data[i];
  803. update[i] = node;
  804. } else {
  805. enter[i] = new EnterNode(parent, data[i]);
  806. }
  807. }
  808. // Put any non-null nodes that don’t fit into exit.
  809. for (; i < groupLength; ++i) {
  810. if (node = group[i]) {
  811. exit[i] = node;
  812. }
  813. }
  814. }
  815. function bindKey(parent, group, enter, update, exit, data, key) {
  816. var i,
  817. node,
  818. nodeByKeyValue = {},
  819. groupLength = group.length,
  820. dataLength = data.length,
  821. keyValues = new Array(groupLength),
  822. keyValue;
  823. // Compute the key for each node.
  824. // If multiple nodes have the same key, the duplicates are added to exit.
  825. for (i = 0; i < groupLength; ++i) {
  826. if (node = group[i]) {
  827. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  828. if (keyValue in nodeByKeyValue) {
  829. exit[i] = node;
  830. } else {
  831. nodeByKeyValue[keyValue] = node;
  832. }
  833. }
  834. }
  835. // Compute the key for each datum.
  836. // If there a node associated with this key, join and add it to update.
  837. // If there is not (or the key is a duplicate), add it to enter.
  838. for (i = 0; i < dataLength; ++i) {
  839. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  840. if (node = nodeByKeyValue[keyValue]) {
  841. update[i] = node;
  842. node.__data__ = data[i];
  843. nodeByKeyValue[keyValue] = null;
  844. } else {
  845. enter[i] = new EnterNode(parent, data[i]);
  846. }
  847. }
  848. // Add any remaining nodes that were not bound to data to exit.
  849. for (i = 0; i < groupLength; ++i) {
  850. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  851. exit[i] = node;
  852. }
  853. }
  854. }
  855. function selection_data(value, key) {
  856. if (!value) {
  857. data = new Array(this.size()), j = -1;
  858. this.each(function(d) { data[++j] = d; });
  859. return data;
  860. }
  861. var bind = key ? bindKey : bindIndex,
  862. parents = this._parents,
  863. groups = this._groups;
  864. if (typeof value !== "function") value = constant$1(value);
  865. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  866. var parent = parents[j],
  867. group = groups[j],
  868. groupLength = group.length,
  869. data = value.call(parent, parent && parent.__data__, j, parents),
  870. dataLength = data.length,
  871. enterGroup = enter[j] = new Array(dataLength),
  872. updateGroup = update[j] = new Array(dataLength),
  873. exitGroup = exit[j] = new Array(groupLength);
  874. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  875. // Now connect the enter nodes to their following update node, such that
  876. // appendChild can insert the materialized enter node before this node,
  877. // rather than at the end of the parent node.
  878. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  879. if (previous = enterGroup[i0]) {
  880. if (i0 >= i1) i1 = i0 + 1;
  881. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  882. previous._next = next || null;
  883. }
  884. }
  885. }
  886. update = new Selection(update, parents);
  887. update._enter = enter;
  888. update._exit = exit;
  889. return update;
  890. }
  891. function selection_exit() {
  892. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  893. }
  894. function selection_join(onenter, onupdate, onexit) {
  895. var enter = this.enter(), update = this, exit = this.exit();
  896. enter = typeof onenter === "function" ? onenter(enter) : enter.append(onenter + "");
  897. if (onupdate != null) update = onupdate(update);
  898. if (onexit == null) exit.remove(); else onexit(exit);
  899. return enter && update ? enter.merge(update).order() : update;
  900. }
  901. function selection_merge(selection) {
  902. for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  903. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  904. if (node = group0[i] || group1[i]) {
  905. merge[i] = node;
  906. }
  907. }
  908. }
  909. for (; j < m0; ++j) {
  910. merges[j] = groups0[j];
  911. }
  912. return new Selection(merges, this._parents);
  913. }
  914. function selection_order() {
  915. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  916. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  917. if (node = group[i]) {
  918. if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
  919. next = node;
  920. }
  921. }
  922. }
  923. return this;
  924. }
  925. function selection_sort(compare) {
  926. if (!compare) compare = ascending$1;
  927. function compareNode(a, b) {
  928. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  929. }
  930. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  931. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  932. if (node = group[i]) {
  933. sortgroup[i] = node;
  934. }
  935. }
  936. sortgroup.sort(compareNode);
  937. }
  938. return new Selection(sortgroups, this._parents).order();
  939. }
  940. function ascending$1(a, b) {
  941. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  942. }
  943. function selection_call() {
  944. var callback = arguments[0];
  945. arguments[0] = this;
  946. callback.apply(null, arguments);
  947. return this;
  948. }
  949. function selection_nodes() {
  950. var nodes = new Array(this.size()), i = -1;
  951. this.each(function() { nodes[++i] = this; });
  952. return nodes;
  953. }
  954. function selection_node() {
  955. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  956. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  957. var node = group[i];
  958. if (node) return node;
  959. }
  960. }
  961. return null;
  962. }
  963. function selection_size() {
  964. var size = 0;
  965. this.each(function() { ++size; });
  966. return size;
  967. }
  968. function selection_empty() {
  969. return !this.node();
  970. }
  971. function selection_each(callback) {
  972. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  973. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  974. if (node = group[i]) callback.call(node, node.__data__, i, group);
  975. }
  976. }
  977. return this;
  978. }
  979. function attrRemove(name) {
  980. return function() {
  981. this.removeAttribute(name);
  982. };
  983. }
  984. function attrRemoveNS(fullname) {
  985. return function() {
  986. this.removeAttributeNS(fullname.space, fullname.local);
  987. };
  988. }
  989. function attrConstant(name, value) {
  990. return function() {
  991. this.setAttribute(name, value);
  992. };
  993. }
  994. function attrConstantNS(fullname, value) {
  995. return function() {
  996. this.setAttributeNS(fullname.space, fullname.local, value);
  997. };
  998. }
  999. function attrFunction(name, value) {
  1000. return function() {
  1001. var v = value.apply(this, arguments);
  1002. if (v == null) this.removeAttribute(name);
  1003. else this.setAttribute(name, v);
  1004. };
  1005. }
  1006. function attrFunctionNS(fullname, value) {
  1007. return function() {
  1008. var v = value.apply(this, arguments);
  1009. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1010. else this.setAttributeNS(fullname.space, fullname.local, v);
  1011. };
  1012. }
  1013. function selection_attr(name, value) {
  1014. var fullname = namespace(name);
  1015. if (arguments.length < 2) {
  1016. var node = this.node();
  1017. return fullname.local
  1018. ? node.getAttributeNS(fullname.space, fullname.local)
  1019. : node.getAttribute(fullname);
  1020. }
  1021. return this.each((value == null
  1022. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1023. ? (fullname.local ? attrFunctionNS : attrFunction)
  1024. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1025. }
  1026. function defaultView(node) {
  1027. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1028. || (node.document && node) // node is a Window
  1029. || node.defaultView; // node is a Document
  1030. }
  1031. function styleRemove(name) {
  1032. return function() {
  1033. this.style.removeProperty(name);
  1034. };
  1035. }
  1036. function styleConstant(name, value, priority) {
  1037. return function() {
  1038. this.style.setProperty(name, value, priority);
  1039. };
  1040. }
  1041. function styleFunction(name, value, priority) {
  1042. return function() {
  1043. var v = value.apply(this, arguments);
  1044. if (v == null) this.style.removeProperty(name);
  1045. else this.style.setProperty(name, v, priority);
  1046. };
  1047. }
  1048. function selection_style(name, value, priority) {
  1049. return arguments.length > 1
  1050. ? this.each((value == null
  1051. ? styleRemove : typeof value === "function"
  1052. ? styleFunction
  1053. : styleConstant)(name, value, priority == null ? "" : priority))
  1054. : styleValue(this.node(), name);
  1055. }
  1056. function styleValue(node, name) {
  1057. return node.style.getPropertyValue(name)
  1058. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1059. }
  1060. function propertyRemove(name) {
  1061. return function() {
  1062. delete this[name];
  1063. };
  1064. }
  1065. function propertyConstant(name, value) {
  1066. return function() {
  1067. this[name] = value;
  1068. };
  1069. }
  1070. function propertyFunction(name, value) {
  1071. return function() {
  1072. var v = value.apply(this, arguments);
  1073. if (v == null) delete this[name];
  1074. else this[name] = v;
  1075. };
  1076. }
  1077. function selection_property(name, value) {
  1078. return arguments.length > 1
  1079. ? this.each((value == null
  1080. ? propertyRemove : typeof value === "function"
  1081. ? propertyFunction
  1082. : propertyConstant)(name, value))
  1083. : this.node()[name];
  1084. }
  1085. function classArray(string) {
  1086. return string.trim().split(/^|\s+/);
  1087. }
  1088. function classList(node) {
  1089. return node.classList || new ClassList(node);
  1090. }
  1091. function ClassList(node) {
  1092. this._node = node;
  1093. this._names = classArray(node.getAttribute("class") || "");
  1094. }
  1095. ClassList.prototype = {
  1096. add: function(name) {
  1097. var i = this._names.indexOf(name);
  1098. if (i < 0) {
  1099. this._names.push(name);
  1100. this._node.setAttribute("class", this._names.join(" "));
  1101. }
  1102. },
  1103. remove: function(name) {
  1104. var i = this._names.indexOf(name);
  1105. if (i >= 0) {
  1106. this._names.splice(i, 1);
  1107. this._node.setAttribute("class", this._names.join(" "));
  1108. }
  1109. },
  1110. contains: function(name) {
  1111. return this._names.indexOf(name) >= 0;
  1112. }
  1113. };
  1114. function classedAdd(node, names) {
  1115. var list = classList(node), i = -1, n = names.length;
  1116. while (++i < n) list.add(names[i]);
  1117. }
  1118. function classedRemove(node, names) {
  1119. var list = classList(node), i = -1, n = names.length;
  1120. while (++i < n) list.remove(names[i]);
  1121. }
  1122. function classedTrue(names) {
  1123. return function() {
  1124. classedAdd(this, names);
  1125. };
  1126. }
  1127. function classedFalse(names) {
  1128. return function() {
  1129. classedRemove(this, names);
  1130. };
  1131. }
  1132. function classedFunction(names, value) {
  1133. return function() {
  1134. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1135. };
  1136. }
  1137. function selection_classed(name, value) {
  1138. var names = classArray(name + "");
  1139. if (arguments.length < 2) {
  1140. var list = classList(this.node()), i = -1, n = names.length;
  1141. while (++i < n) if (!list.contains(names[i])) return false;
  1142. return true;
  1143. }
  1144. return this.each((typeof value === "function"
  1145. ? classedFunction : value
  1146. ? classedTrue
  1147. : classedFalse)(names, value));
  1148. }
  1149. function textRemove() {
  1150. this.textContent = "";
  1151. }
  1152. function textConstant(value) {
  1153. return function() {
  1154. this.textContent = value;
  1155. };
  1156. }
  1157. function textFunction(value) {
  1158. return function() {
  1159. var v = value.apply(this, arguments);
  1160. this.textContent = v == null ? "" : v;
  1161. };
  1162. }
  1163. function selection_text(value) {
  1164. return arguments.length
  1165. ? this.each(value == null
  1166. ? textRemove : (typeof value === "function"
  1167. ? textFunction
  1168. : textConstant)(value))
  1169. : this.node().textContent;
  1170. }
  1171. function htmlRemove() {
  1172. this.innerHTML = "";
  1173. }
  1174. function htmlConstant(value) {
  1175. return function() {
  1176. this.innerHTML = value;
  1177. };
  1178. }
  1179. function htmlFunction(value) {
  1180. return function() {
  1181. var v = value.apply(this, arguments);
  1182. this.innerHTML = v == null ? "" : v;
  1183. };
  1184. }
  1185. function selection_html(value) {
  1186. return arguments.length
  1187. ? this.each(value == null
  1188. ? htmlRemove : (typeof value === "function"
  1189. ? htmlFunction
  1190. : htmlConstant)(value))
  1191. : this.node().innerHTML;
  1192. }
  1193. function raise() {
  1194. if (this.nextSibling) this.parentNode.appendChild(this);
  1195. }
  1196. function selection_raise() {
  1197. return this.each(raise);
  1198. }
  1199. function lower() {
  1200. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1201. }
  1202. function selection_lower() {
  1203. return this.each(lower);
  1204. }
  1205. function selection_append(name) {
  1206. var create = typeof name === "function" ? name : creator(name);
  1207. return this.select(function() {
  1208. return this.appendChild(create.apply(this, arguments));
  1209. });
  1210. }
  1211. function constantNull() {
  1212. return null;
  1213. }
  1214. function selection_insert(name, before) {
  1215. var create = typeof name === "function" ? name : creator(name),
  1216. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1217. return this.select(function() {
  1218. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1219. });
  1220. }
  1221. function remove() {
  1222. var parent = this.parentNode;
  1223. if (parent) parent.removeChild(this);
  1224. }
  1225. function selection_remove() {
  1226. return this.each(remove);
  1227. }
  1228. function selection_cloneShallow() {
  1229. var clone = this.cloneNode(false), parent = this.parentNode;
  1230. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  1231. }
  1232. function selection_cloneDeep() {
  1233. var clone = this.cloneNode(true), parent = this.parentNode;
  1234. return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
  1235. }
  1236. function selection_clone(deep) {
  1237. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  1238. }
  1239. function selection_datum(value) {
  1240. return arguments.length
  1241. ? this.property("__data__", value)
  1242. : this.node().__data__;
  1243. }
  1244. var filterEvents = {};
  1245. exports.event = null;
  1246. if (typeof document !== "undefined") {
  1247. var element = document.documentElement;
  1248. if (!("onmouseenter" in element)) {
  1249. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  1250. }
  1251. }
  1252. function filterContextListener(listener, index, group) {
  1253. listener = contextListener(listener, index, group);
  1254. return function(event) {
  1255. var related = event.relatedTarget;
  1256. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  1257. listener.call(this, event);
  1258. }
  1259. };
  1260. }
  1261. function contextListener(listener, index, group) {
  1262. return function(event1) {
  1263. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  1264. exports.event = event1;
  1265. try {
  1266. listener.call(this, this.__data__, index, group);
  1267. } finally {
  1268. exports.event = event0;
  1269. }
  1270. };
  1271. }
  1272. function parseTypenames$1(typenames) {
  1273. return typenames.trim().split(/^|\s+/).map(function(t) {
  1274. var name = "", i = t.indexOf(".");
  1275. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1276. return {type: t, name: name};
  1277. });
  1278. }
  1279. function onRemove(typename) {
  1280. return function() {
  1281. var on = this.__on;
  1282. if (!on) return;
  1283. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  1284. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  1285. this.removeEventListener(o.type, o.listener, o.capture);
  1286. } else {
  1287. on[++i] = o;
  1288. }
  1289. }
  1290. if (++i) on.length = i;
  1291. else delete this.__on;
  1292. };
  1293. }
  1294. function onAdd(typename, value, capture) {
  1295. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  1296. return function(d, i, group) {
  1297. var on = this.__on, o, listener = wrap(value, i, group);
  1298. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  1299. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  1300. this.removeEventListener(o.type, o.listener, o.capture);
  1301. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  1302. o.value = value;
  1303. return;
  1304. }
  1305. }
  1306. this.addEventListener(typename.type, listener, capture);
  1307. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  1308. if (!on) this.__on = [o];
  1309. else on.push(o);
  1310. };
  1311. }
  1312. function selection_on(typename, value, capture) {
  1313. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  1314. if (arguments.length < 2) {
  1315. var on = this.node().__on;
  1316. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  1317. for (i = 0, o = on[j]; i < n; ++i) {
  1318. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  1319. return o.value;
  1320. }
  1321. }
  1322. }
  1323. return;
  1324. }
  1325. on = value ? onAdd : onRemove;
  1326. if (capture == null) capture = false;
  1327. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  1328. return this;
  1329. }
  1330. function customEvent(event1, listener, that, args) {
  1331. var event0 = exports.event;
  1332. event1.sourceEvent = exports.event;
  1333. exports.event = event1;
  1334. try {
  1335. return listener.apply(that, args);
  1336. } finally {
  1337. exports.event = event0;
  1338. }
  1339. }
  1340. function dispatchEvent(node, type, params) {
  1341. var window = defaultView(node),
  1342. event = window.CustomEvent;
  1343. if (typeof event === "function") {
  1344. event = new event(type, params);
  1345. } else {
  1346. event = window.document.createEvent("Event");
  1347. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1348. else event.initEvent(type, false, false);
  1349. }
  1350. node.dispatchEvent(event);
  1351. }
  1352. function dispatchConstant(type, params) {
  1353. return function() {
  1354. return dispatchEvent(this, type, params);
  1355. };
  1356. }
  1357. function dispatchFunction(type, params) {
  1358. return function() {
  1359. return dispatchEvent(this, type, params.apply(this, arguments));
  1360. };
  1361. }
  1362. function selection_dispatch(type, params) {
  1363. return this.each((typeof params === "function"
  1364. ? dispatchFunction
  1365. : dispatchConstant)(type, params));
  1366. }
  1367. var root = [null];
  1368. function Selection(groups, parents) {
  1369. this._groups = groups;
  1370. this._parents = parents;
  1371. }
  1372. function selection() {
  1373. return new Selection([[document.documentElement]], root);
  1374. }
  1375. Selection.prototype = selection.prototype = {
  1376. constructor: Selection,
  1377. select: selection_select,
  1378. selectAll: selection_selectAll,
  1379. filter: selection_filter,
  1380. data: selection_data,
  1381. enter: selection_enter,
  1382. exit: selection_exit,
  1383. join: selection_join,
  1384. merge: selection_merge,
  1385. order: selection_order,
  1386. sort: selection_sort,
  1387. call: selection_call,
  1388. nodes: selection_nodes,
  1389. node: selection_node,
  1390. size: selection_size,
  1391. empty: selection_empty,
  1392. each: selection_each,
  1393. attr: selection_attr,
  1394. style: selection_style,
  1395. property: selection_property,
  1396. classed: selection_classed,
  1397. text: selection_text,
  1398. html: selection_html,
  1399. raise: selection_raise,
  1400. lower: selection_lower,
  1401. append: selection_append,
  1402. insert: selection_insert,
  1403. remove: selection_remove,
  1404. clone: selection_clone,
  1405. datum: selection_datum,
  1406. on: selection_on,
  1407. dispatch: selection_dispatch
  1408. };
  1409. function select(selector) {
  1410. return typeof selector === "string"
  1411. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1412. : new Selection([[selector]], root);
  1413. }
  1414. function create(name) {
  1415. return select(creator(name).call(document.documentElement));
  1416. }
  1417. var nextId = 0;
  1418. function local() {
  1419. return new Local;
  1420. }
  1421. function Local() {
  1422. this._ = "@" + (++nextId).toString(36);
  1423. }
  1424. Local.prototype = local.prototype = {
  1425. constructor: Local,
  1426. get: function(node) {
  1427. var id = this._;
  1428. while (!(id in node)) if (!(node = node.parentNode)) return;
  1429. return node[id];
  1430. },
  1431. set: function(node, value) {
  1432. return node[this._] = value;
  1433. },
  1434. remove: function(node) {
  1435. return this._ in node && delete node[this._];
  1436. },
  1437. toString: function() {
  1438. return this._;
  1439. }
  1440. };
  1441. function sourceEvent() {
  1442. var current = exports.event, source;
  1443. while (source = current.sourceEvent) current = source;
  1444. return current;
  1445. }
  1446. function point(node, event) {
  1447. var svg = node.ownerSVGElement || node;
  1448. if (svg.createSVGPoint) {
  1449. var point = svg.createSVGPoint();
  1450. point.x = event.clientX, point.y = event.clientY;
  1451. point = point.matrixTransform(node.getScreenCTM().inverse());
  1452. return [point.x, point.y];
  1453. }
  1454. var rect = node.getBoundingClientRect();
  1455. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  1456. }
  1457. function mouse(node) {
  1458. var event = sourceEvent();
  1459. if (event.changedTouches) event = event.changedTouches[0];
  1460. return point(node, event);
  1461. }
  1462. function selectAll(selector) {
  1463. return typeof selector === "string"
  1464. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1465. : new Selection([selector == null ? [] : selector], root);
  1466. }
  1467. function touch(node, touches, identifier) {
  1468. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1469. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1470. if ((touch = touches[i]).identifier === identifier) {
  1471. return point(node, touch);
  1472. }
  1473. }
  1474. return null;
  1475. }
  1476. function touches(node, touches) {
  1477. if (touches == null) touches = sourceEvent().touches;
  1478. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1479. points[i] = point(node, touches[i]);
  1480. }
  1481. return points;
  1482. }
  1483. function nopropagation() {
  1484. exports.event.stopImmediatePropagation();
  1485. }
  1486. function noevent() {
  1487. exports.event.preventDefault();
  1488. exports.event.stopImmediatePropagation();
  1489. }
  1490. function dragDisable(view) {
  1491. var root = view.document.documentElement,
  1492. selection = select(view).on("dragstart.drag", noevent, true);
  1493. if ("onselectstart" in root) {
  1494. selection.on("selectstart.drag", noevent, true);
  1495. } else {
  1496. root.__noselect = root.style.MozUserSelect;
  1497. root.style.MozUserSelect = "none";
  1498. }
  1499. }
  1500. function yesdrag(view, noclick) {
  1501. var root = view.document.documentElement,
  1502. selection = select(view).on("dragstart.drag", null);
  1503. if (noclick) {
  1504. selection.on("click.drag", noevent, true);
  1505. setTimeout(function() { selection.on("click.drag", null); }, 0);
  1506. }
  1507. if ("onselectstart" in root) {
  1508. selection.on("selectstart.drag", null);
  1509. } else {
  1510. root.style.MozUserSelect = root.__noselect;
  1511. delete root.__noselect;
  1512. }
  1513. }
  1514. function constant$2(x) {
  1515. return function() {
  1516. return x;
  1517. };
  1518. }
  1519. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1520. this.target = target;
  1521. this.type = type;
  1522. this.subject = subject;
  1523. this.identifier = id;
  1524. this.active = active;
  1525. this.x = x;
  1526. this.y = y;
  1527. this.dx = dx;
  1528. this.dy = dy;
  1529. this._ = dispatch;
  1530. }
  1531. DragEvent.prototype.on = function() {
  1532. var value = this._.on.apply(this._, arguments);
  1533. return value === this._ ? this : value;
  1534. };
  1535. // Ignore right-click, since that should open the context menu.
  1536. function defaultFilter() {
  1537. return !exports.event.ctrlKey && !exports.event.button;
  1538. }
  1539. function defaultContainer() {
  1540. return this.parentNode;
  1541. }
  1542. function defaultSubject(d) {
  1543. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1544. }
  1545. function defaultTouchable() {
  1546. return navigator.maxTouchPoints || ("ontouchstart" in this);
  1547. }
  1548. function drag() {
  1549. var filter = defaultFilter,
  1550. container = defaultContainer,
  1551. subject = defaultSubject,
  1552. touchable = defaultTouchable,
  1553. gestures = {},
  1554. listeners = dispatch("start", "drag", "end"),
  1555. active = 0,
  1556. mousedownx,
  1557. mousedowny,
  1558. mousemoving,
  1559. touchending,
  1560. clickDistance2 = 0;
  1561. function drag(selection) {
  1562. selection
  1563. .on("mousedown.drag", mousedowned)
  1564. .filter(touchable)
  1565. .on("touchstart.drag", touchstarted)
  1566. .on("touchmove.drag", touchmoved)
  1567. .on("touchend.drag touchcancel.drag", touchended)
  1568. .style("touch-action", "none")
  1569. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1570. }
  1571. function mousedowned() {
  1572. if (touchending || !filter.apply(this, arguments)) return;
  1573. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1574. if (!gesture) return;
  1575. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1576. dragDisable(exports.event.view);
  1577. nopropagation();
  1578. mousemoving = false;
  1579. mousedownx = exports.event.clientX;
  1580. mousedowny = exports.event.clientY;
  1581. gesture("start");
  1582. }
  1583. function mousemoved() {
  1584. noevent();
  1585. if (!mousemoving) {
  1586. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1587. mousemoving = dx * dx + dy * dy > clickDistance2;
  1588. }
  1589. gestures.mouse("drag");
  1590. }
  1591. function mouseupped() {
  1592. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1593. yesdrag(exports.event.view, mousemoving);
  1594. noevent();
  1595. gestures.mouse("end");
  1596. }
  1597. function touchstarted() {
  1598. if (!filter.apply(this, arguments)) return;
  1599. var touches = exports.event.changedTouches,
  1600. c = container.apply(this, arguments),
  1601. n = touches.length, i, gesture;
  1602. for (i = 0; i < n; ++i) {
  1603. if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
  1604. nopropagation();
  1605. gesture("start");
  1606. }
  1607. }
  1608. }
  1609. function touchmoved() {
  1610. var touches = exports.event.changedTouches,
  1611. n = touches.length, i, gesture;
  1612. for (i = 0; i < n; ++i) {
  1613. if (gesture = gestures[touches[i].identifier]) {
  1614. noevent();
  1615. gesture("drag");
  1616. }
  1617. }
  1618. }
  1619. function touchended() {
  1620. var touches = exports.event.changedTouches,
  1621. n = touches.length, i, gesture;
  1622. if (touchending) clearTimeout(touchending);
  1623. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1624. for (i = 0; i < n; ++i) {
  1625. if (gesture = gestures[touches[i].identifier]) {
  1626. nopropagation();
  1627. gesture("end");
  1628. }
  1629. }
  1630. }
  1631. function beforestart(id, container, point, that, args) {
  1632. var p = point(container, id), s, dx, dy,
  1633. sublisteners = listeners.copy();
  1634. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1635. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1636. dx = s.x - p[0] || 0;
  1637. dy = s.y - p[1] || 0;
  1638. return true;
  1639. })) return;
  1640. return function gesture(type) {
  1641. var p0 = p, n;
  1642. switch (type) {
  1643. case "start": gestures[id] = gesture, n = active++; break;
  1644. case "end": delete gestures[id], --active; // nobreak
  1645. case "drag": p = point(container, id), n = active; break;
  1646. }
  1647. customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
  1648. };
  1649. }
  1650. drag.filter = function(_) {
  1651. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1652. };
  1653. drag.container = function(_) {
  1654. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1655. };
  1656. drag.subject = function(_) {
  1657. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1658. };
  1659. drag.touchable = function(_) {
  1660. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
  1661. };
  1662. drag.on = function() {
  1663. var value = listeners.on.apply(listeners, arguments);
  1664. return value === listeners ? drag : value;
  1665. };
  1666. drag.clickDistance = function(_) {
  1667. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1668. };
  1669. return drag;
  1670. }
  1671. function define(constructor, factory, prototype) {
  1672. constructor.prototype = factory.prototype = prototype;
  1673. prototype.constructor = constructor;
  1674. }
  1675. function extend(parent, definition) {
  1676. var prototype = Object.create(parent.prototype);
  1677. for (var key in definition) prototype[key] = definition[key];
  1678. return prototype;
  1679. }
  1680. function Color() {}
  1681. var darker = 0.7;
  1682. var brighter = 1 / darker;
  1683. var reI = "\\s*([+-]?\\d+)\\s*",
  1684. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  1685. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  1686. reHex = /^#([0-9a-f]{3,8})$/,
  1687. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  1688. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  1689. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  1690. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  1691. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  1692. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1693. var named = {
  1694. aliceblue: 0xf0f8ff,
  1695. antiquewhite: 0xfaebd7,
  1696. aqua: 0x00ffff,
  1697. aquamarine: 0x7fffd4,
  1698. azure: 0xf0ffff,
  1699. beige: 0xf5f5dc,
  1700. bisque: 0xffe4c4,
  1701. black: 0x000000,
  1702. blanchedalmond: 0xffebcd,
  1703. blue: 0x0000ff,
  1704. blueviolet: 0x8a2be2,
  1705. brown: 0xa52a2a,
  1706. burlywood: 0xdeb887,
  1707. cadetblue: 0x5f9ea0,
  1708. chartreuse: 0x7fff00,
  1709. chocolate: 0xd2691e,
  1710. coral: 0xff7f50,
  1711. cornflowerblue: 0x6495ed,
  1712. cornsilk: 0xfff8dc,
  1713. crimson: 0xdc143c,
  1714. cyan: 0x00ffff,
  1715. darkblue: 0x00008b,
  1716. darkcyan: 0x008b8b,
  1717. darkgoldenrod: 0xb8860b,
  1718. darkgray: 0xa9a9a9,
  1719. darkgreen: 0x006400,
  1720. darkgrey: 0xa9a9a9,
  1721. darkkhaki: 0xbdb76b,
  1722. darkmagenta: 0x8b008b,
  1723. darkolivegreen: 0x556b2f,
  1724. darkorange: 0xff8c00,
  1725. darkorchid: 0x9932cc,
  1726. darkred: 0x8b0000,
  1727. darksalmon: 0xe9967a,
  1728. darkseagreen: 0x8fbc8f,
  1729. darkslateblue: 0x483d8b,
  1730. darkslategray: 0x2f4f4f,
  1731. darkslategrey: 0x2f4f4f,
  1732. darkturquoise: 0x00ced1,
  1733. darkviolet: 0x9400d3,
  1734. deeppink: 0xff1493,
  1735. deepskyblue: 0x00bfff,
  1736. dimgray: 0x696969,
  1737. dimgrey: 0x696969,
  1738. dodgerblue: 0x1e90ff,
  1739. firebrick: 0xb22222,
  1740. floralwhite: 0xfffaf0,
  1741. forestgreen: 0x228b22,
  1742. fuchsia: 0xff00ff,
  1743. gainsboro: 0xdcdcdc,
  1744. ghostwhite: 0xf8f8ff,
  1745. gold: 0xffd700,
  1746. goldenrod: 0xdaa520,
  1747. gray: 0x808080,
  1748. green: 0x008000,
  1749. greenyellow: 0xadff2f,
  1750. grey: 0x808080,
  1751. honeydew: 0xf0fff0,
  1752. hotpink: 0xff69b4,
  1753. indianred: 0xcd5c5c,
  1754. indigo: 0x4b0082,
  1755. ivory: 0xfffff0,
  1756. khaki: 0xf0e68c,
  1757. lavender: 0xe6e6fa,
  1758. lavenderblush: 0xfff0f5,
  1759. lawngreen: 0x7cfc00,
  1760. lemonchiffon: 0xfffacd,
  1761. lightblue: 0xadd8e6,
  1762. lightcoral: 0xf08080,
  1763. lightcyan: 0xe0ffff,
  1764. lightgoldenrodyellow: 0xfafad2,
  1765. lightgray: 0xd3d3d3,
  1766. lightgreen: 0x90ee90,
  1767. lightgrey: 0xd3d3d3,
  1768. lightpink: 0xffb6c1,
  1769. lightsalmon: 0xffa07a,
  1770. lightseagreen: 0x20b2aa,
  1771. lightskyblue: 0x87cefa,
  1772. lightslategray: 0x778899,
  1773. lightslategrey: 0x778899,
  1774. lightsteelblue: 0xb0c4de,
  1775. lightyellow: 0xffffe0,
  1776. lime: 0x00ff00,
  1777. limegreen: 0x32cd32,
  1778. linen: 0xfaf0e6,
  1779. magenta: 0xff00ff,
  1780. maroon: 0x800000,
  1781. mediumaquamarine: 0x66cdaa,
  1782. mediumblue: 0x0000cd,
  1783. mediumorchid: 0xba55d3,
  1784. mediumpurple: 0x9370db,
  1785. mediumseagreen: 0x3cb371,
  1786. mediumslateblue: 0x7b68ee,
  1787. mediumspringgreen: 0x00fa9a,
  1788. mediumturquoise: 0x48d1cc,
  1789. mediumvioletred: 0xc71585,
  1790. midnightblue: 0x191970,
  1791. mintcream: 0xf5fffa,
  1792. mistyrose: 0xffe4e1,
  1793. moccasin: 0xffe4b5,
  1794. navajowhite: 0xffdead,
  1795. navy: 0x000080,
  1796. oldlace: 0xfdf5e6,
  1797. olive: 0x808000,
  1798. olivedrab: 0x6b8e23,
  1799. orange: 0xffa500,
  1800. orangered: 0xff4500,
  1801. orchid: 0xda70d6,
  1802. palegoldenrod: 0xeee8aa,
  1803. palegreen: 0x98fb98,
  1804. paleturquoise: 0xafeeee,
  1805. palevioletred: 0xdb7093,
  1806. papayawhip: 0xffefd5,
  1807. peachpuff: 0xffdab9,
  1808. peru: 0xcd853f,
  1809. pink: 0xffc0cb,
  1810. plum: 0xdda0dd,
  1811. powderblue: 0xb0e0e6,
  1812. purple: 0x800080,
  1813. rebeccapurple: 0x663399,
  1814. red: 0xff0000,
  1815. rosybrown: 0xbc8f8f,
  1816. royalblue: 0x4169e1,
  1817. saddlebrown: 0x8b4513,
  1818. salmon: 0xfa8072,
  1819. sandybrown: 0xf4a460,
  1820. seagreen: 0x2e8b57,
  1821. seashell: 0xfff5ee,
  1822. sienna: 0xa0522d,
  1823. silver: 0xc0c0c0,
  1824. skyblue: 0x87ceeb,
  1825. slateblue: 0x6a5acd,
  1826. slategray: 0x708090,
  1827. slategrey: 0x708090,
  1828. snow: 0xfffafa,
  1829. springgreen: 0x00ff7f,
  1830. steelblue: 0x4682b4,
  1831. tan: 0xd2b48c,
  1832. teal: 0x008080,
  1833. thistle: 0xd8bfd8,
  1834. tomato: 0xff6347,
  1835. turquoise: 0x40e0d0,
  1836. violet: 0xee82ee,
  1837. wheat: 0xf5deb3,
  1838. white: 0xffffff,
  1839. whitesmoke: 0xf5f5f5,
  1840. yellow: 0xffff00,
  1841. yellowgreen: 0x9acd32
  1842. };
  1843. define(Color, color, {
  1844. copy: function(channels) {
  1845. return Object.assign(new this.constructor, this, channels);
  1846. },
  1847. displayable: function() {
  1848. return this.rgb().displayable();
  1849. },
  1850. hex: color_formatHex, // Deprecated! Use color.formatHex.
  1851. formatHex: color_formatHex,
  1852. formatHsl: color_formatHsl,
  1853. formatRgb: color_formatRgb,
  1854. toString: color_formatRgb
  1855. });
  1856. function color_formatHex() {
  1857. return this.rgb().formatHex();
  1858. }
  1859. function color_formatHsl() {
  1860. return hslConvert(this).formatHsl();
  1861. }
  1862. function color_formatRgb() {
  1863. return this.rgb().formatRgb();
  1864. }
  1865. function color(format) {
  1866. var m, l;
  1867. format = (format + "").trim().toLowerCase();
  1868. return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
  1869. : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
  1870. : l === 8 ? new Rgb(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
  1871. : l === 4 ? new Rgb((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000
  1872. : null) // invalid hex
  1873. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1874. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1875. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1876. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1877. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1878. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1879. : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
  1880. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1881. : null;
  1882. }
  1883. function rgbn(n) {
  1884. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1885. }
  1886. function rgba(r, g, b, a) {
  1887. if (a <= 0) r = g = b = NaN;
  1888. return new Rgb(r, g, b, a);
  1889. }
  1890. function rgbConvert(o) {
  1891. if (!(o instanceof Color)) o = color(o);
  1892. if (!o) return new Rgb;
  1893. o = o.rgb();
  1894. return new Rgb(o.r, o.g, o.b, o.opacity);
  1895. }
  1896. function rgb(r, g, b, opacity) {
  1897. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1898. }
  1899. function Rgb(r, g, b, opacity) {
  1900. this.r = +r;
  1901. this.g = +g;
  1902. this.b = +b;
  1903. this.opacity = +opacity;
  1904. }
  1905. define(Rgb, rgb, extend(Color, {
  1906. brighter: function(k) {
  1907. k = k == null ? brighter : Math.pow(brighter, k);
  1908. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1909. },
  1910. darker: function(k) {
  1911. k = k == null ? darker : Math.pow(darker, k);
  1912. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1913. },
  1914. rgb: function() {
  1915. return this;
  1916. },
  1917. displayable: function() {
  1918. return (-0.5 <= this.r && this.r < 255.5)
  1919. && (-0.5 <= this.g && this.g < 255.5)
  1920. && (-0.5 <= this.b && this.b < 255.5)
  1921. && (0 <= this.opacity && this.opacity <= 1);
  1922. },
  1923. hex: rgb_formatHex, // Deprecated! Use color.formatHex.
  1924. formatHex: rgb_formatHex,
  1925. formatRgb: rgb_formatRgb,
  1926. toString: rgb_formatRgb
  1927. }));
  1928. function rgb_formatHex() {
  1929. return "#" + hex(this.r) + hex(this.g) + hex(this.b);
  1930. }
  1931. function rgb_formatRgb() {
  1932. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1933. return (a === 1 ? "rgb(" : "rgba(")
  1934. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1935. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1936. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1937. + (a === 1 ? ")" : ", " + a + ")");
  1938. }
  1939. function hex(value) {
  1940. value = Math.max(0, Math.min(255, Math.round(value) || 0));
  1941. return (value < 16 ? "0" : "") + value.toString(16);
  1942. }
  1943. function hsla(h, s, l, a) {
  1944. if (a <= 0) h = s = l = NaN;
  1945. else if (l <= 0 || l >= 1) h = s = NaN;
  1946. else if (s <= 0) h = NaN;
  1947. return new Hsl(h, s, l, a);
  1948. }
  1949. function hslConvert(o) {
  1950. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1951. if (!(o instanceof Color)) o = color(o);
  1952. if (!o) return new Hsl;
  1953. if (o instanceof Hsl) return o;
  1954. o = o.rgb();
  1955. var r = o.r / 255,
  1956. g = o.g / 255,
  1957. b = o.b / 255,
  1958. min = Math.min(r, g, b),
  1959. max = Math.max(r, g, b),
  1960. h = NaN,
  1961. s = max - min,
  1962. l = (max + min) / 2;
  1963. if (s) {
  1964. if (r === max) h = (g - b) / s + (g < b) * 6;
  1965. else if (g === max) h = (b - r) / s + 2;
  1966. else h = (r - g) / s + 4;
  1967. s /= l < 0.5 ? max + min : 2 - max - min;
  1968. h *= 60;
  1969. } else {
  1970. s = l > 0 && l < 1 ? 0 : h;
  1971. }
  1972. return new Hsl(h, s, l, o.opacity);
  1973. }
  1974. function hsl(h, s, l, opacity) {
  1975. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1976. }
  1977. function Hsl(h, s, l, opacity) {
  1978. this.h = +h;
  1979. this.s = +s;
  1980. this.l = +l;
  1981. this.opacity = +opacity;
  1982. }
  1983. define(Hsl, hsl, extend(Color, {
  1984. brighter: function(k) {
  1985. k = k == null ? brighter : Math.pow(brighter, k);
  1986. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1987. },
  1988. darker: function(k) {
  1989. k = k == null ? darker : Math.pow(darker, k);
  1990. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1991. },
  1992. rgb: function() {
  1993. var h = this.h % 360 + (this.h < 0) * 360,
  1994. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1995. l = this.l,
  1996. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1997. m1 = 2 * l - m2;
  1998. return new Rgb(
  1999. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  2000. hsl2rgb(h, m1, m2),
  2001. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  2002. this.opacity
  2003. );
  2004. },
  2005. displayable: function() {
  2006. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  2007. && (0 <= this.l && this.l <= 1)
  2008. && (0 <= this.opacity && this.opacity <= 1);
  2009. },
  2010. formatHsl: function() {
  2011. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  2012. return (a === 1 ? "hsl(" : "hsla(")
  2013. + (this.h || 0) + ", "
  2014. + (this.s || 0) * 100 + "%, "
  2015. + (this.l || 0) * 100 + "%"
  2016. + (a === 1 ? ")" : ", " + a + ")");
  2017. }
  2018. }));
  2019. /* From FvD 13.37, CSS Color Module Level 3 */
  2020. function hsl2rgb(h, m1, m2) {
  2021. return (h < 60 ? m1 + (m2 - m1) * h / 60
  2022. : h < 180 ? m2
  2023. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  2024. : m1) * 255;
  2025. }
  2026. var deg2rad = Math.PI / 180;
  2027. var rad2deg = 180 / Math.PI;
  2028. // https://observablehq.com/@mbostock/lab-and-rgb
  2029. var K = 18,
  2030. Xn = 0.96422,
  2031. Yn = 1,
  2032. Zn = 0.82521,
  2033. t0 = 4 / 29,
  2034. t1 = 6 / 29,
  2035. t2 = 3 * t1 * t1,
  2036. t3 = t1 * t1 * t1;
  2037. function labConvert(o) {
  2038. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2039. if (o instanceof Hcl) return hcl2lab(o);
  2040. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2041. var r = rgb2lrgb(o.r),
  2042. g = rgb2lrgb(o.g),
  2043. b = rgb2lrgb(o.b),
  2044. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2045. if (r === g && g === b) x = z = y; else {
  2046. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2047. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2048. }
  2049. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2050. }
  2051. function gray(l, opacity) {
  2052. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2053. }
  2054. function lab(l, a, b, opacity) {
  2055. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2056. }
  2057. function Lab(l, a, b, opacity) {
  2058. this.l = +l;
  2059. this.a = +a;
  2060. this.b = +b;
  2061. this.opacity = +opacity;
  2062. }
  2063. define(Lab, lab, extend(Color, {
  2064. brighter: function(k) {
  2065. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2066. },
  2067. darker: function(k) {
  2068. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2069. },
  2070. rgb: function() {
  2071. var y = (this.l + 16) / 116,
  2072. x = isNaN(this.a) ? y : y + this.a / 500,
  2073. z = isNaN(this.b) ? y : y - this.b / 200;
  2074. x = Xn * lab2xyz(x);
  2075. y = Yn * lab2xyz(y);
  2076. z = Zn * lab2xyz(z);
  2077. return new Rgb(
  2078. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2079. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2080. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2081. this.opacity
  2082. );
  2083. }
  2084. }));
  2085. function xyz2lab(t) {
  2086. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2087. }
  2088. function lab2xyz(t) {
  2089. return t > t1 ? t * t * t : t2 * (t - t0);
  2090. }
  2091. function lrgb2rgb(x) {
  2092. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2093. }
  2094. function rgb2lrgb(x) {
  2095. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2096. }
  2097. function hclConvert(o) {
  2098. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2099. if (!(o instanceof Lab)) o = labConvert(o);
  2100. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
  2101. var h = Math.atan2(o.b, o.a) * rad2deg;
  2102. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2103. }
  2104. function lch(l, c, h, opacity) {
  2105. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2106. }
  2107. function hcl(h, c, l, opacity) {
  2108. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2109. }
  2110. function Hcl(h, c, l, opacity) {
  2111. this.h = +h;
  2112. this.c = +c;
  2113. this.l = +l;
  2114. this.opacity = +opacity;
  2115. }
  2116. function hcl2lab(o) {
  2117. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2118. var h = o.h * deg2rad;
  2119. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2120. }
  2121. define(Hcl, hcl, extend(Color, {
  2122. brighter: function(k) {
  2123. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2124. },
  2125. darker: function(k) {
  2126. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2127. },
  2128. rgb: function() {
  2129. return hcl2lab(this).rgb();
  2130. }
  2131. }));
  2132. var A = -0.14861,
  2133. B = +1.78277,
  2134. C = -0.29227,
  2135. D = -0.90649,
  2136. E = +1.97294,
  2137. ED = E * D,
  2138. EB = E * B,
  2139. BC_DA = B * C - D * A;
  2140. function cubehelixConvert(o) {
  2141. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2142. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2143. var r = o.r / 255,
  2144. g = o.g / 255,
  2145. b = o.b / 255,
  2146. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2147. bl = b - l,
  2148. k = (E * (g - l) - C * bl) / D,
  2149. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2150. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2151. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2152. }
  2153. function cubehelix(h, s, l, opacity) {
  2154. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2155. }
  2156. function Cubehelix(h, s, l, opacity) {
  2157. this.h = +h;
  2158. this.s = +s;
  2159. this.l = +l;
  2160. this.opacity = +opacity;
  2161. }
  2162. define(Cubehelix, cubehelix, extend(Color, {
  2163. brighter: function(k) {
  2164. k = k == null ? brighter : Math.pow(brighter, k);
  2165. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2166. },
  2167. darker: function(k) {
  2168. k = k == null ? darker : Math.pow(darker, k);
  2169. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2170. },
  2171. rgb: function() {
  2172. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2173. l = +this.l,
  2174. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2175. cosh = Math.cos(h),
  2176. sinh = Math.sin(h);
  2177. return new Rgb(
  2178. 255 * (l + a * (A * cosh + B * sinh)),
  2179. 255 * (l + a * (C * cosh + D * sinh)),
  2180. 255 * (l + a * (E * cosh)),
  2181. this.opacity
  2182. );
  2183. }
  2184. }));
  2185. function basis(t1, v0, v1, v2, v3) {
  2186. var t2 = t1 * t1, t3 = t2 * t1;
  2187. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2188. + (4 - 6 * t2 + 3 * t3) * v1
  2189. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2190. + t3 * v3) / 6;
  2191. }
  2192. function basis$1(values) {
  2193. var n = values.length - 1;
  2194. return function(t) {
  2195. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2196. v1 = values[i],
  2197. v2 = values[i + 1],
  2198. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2199. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2200. return basis((t - i / n) * n, v0, v1, v2, v3);
  2201. };
  2202. }
  2203. function basisClosed(values) {
  2204. var n = values.length;
  2205. return function(t) {
  2206. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2207. v0 = values[(i + n - 1) % n],
  2208. v1 = values[i % n],
  2209. v2 = values[(i + 1) % n],
  2210. v3 = values[(i + 2) % n];
  2211. return basis((t - i / n) * n, v0, v1, v2, v3);
  2212. };
  2213. }
  2214. function constant$3(x) {
  2215. return function() {
  2216. return x;
  2217. };
  2218. }
  2219. function linear(a, d) {
  2220. return function(t) {
  2221. return a + t * d;
  2222. };
  2223. }
  2224. function exponential(a, b, y) {
  2225. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2226. return Math.pow(a + t * b, y);
  2227. };
  2228. }
  2229. function hue(a, b) {
  2230. var d = b - a;
  2231. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2232. }
  2233. function gamma(y) {
  2234. return (y = +y) === 1 ? nogamma : function(a, b) {
  2235. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2236. };
  2237. }
  2238. function nogamma(a, b) {
  2239. var d = b - a;
  2240. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2241. }
  2242. var interpolateRgb = (function rgbGamma(y) {
  2243. var color = gamma(y);
  2244. function rgb$1(start, end) {
  2245. var r = color((start = rgb(start)).r, (end = rgb(end)).r),
  2246. g = color(start.g, end.g),
  2247. b = color(start.b, end.b),
  2248. opacity = nogamma(start.opacity, end.opacity);
  2249. return function(t) {
  2250. start.r = r(t);
  2251. start.g = g(t);
  2252. start.b = b(t);
  2253. start.opacity = opacity(t);
  2254. return start + "";
  2255. };
  2256. }
  2257. rgb$1.gamma = rgbGamma;
  2258. return rgb$1;
  2259. })(1);
  2260. function rgbSpline(spline) {
  2261. return function(colors) {
  2262. var n = colors.length,
  2263. r = new Array(n),
  2264. g = new Array(n),
  2265. b = new Array(n),
  2266. i, color;
  2267. for (i = 0; i < n; ++i) {
  2268. color = rgb(colors[i]);
  2269. r[i] = color.r || 0;
  2270. g[i] = color.g || 0;
  2271. b[i] = color.b || 0;
  2272. }
  2273. r = spline(r);
  2274. g = spline(g);
  2275. b = spline(b);
  2276. color.opacity = 1;
  2277. return function(t) {
  2278. color.r = r(t);
  2279. color.g = g(t);
  2280. color.b = b(t);
  2281. return color + "";
  2282. };
  2283. };
  2284. }
  2285. var rgbBasis = rgbSpline(basis$1);
  2286. var rgbBasisClosed = rgbSpline(basisClosed);
  2287. function numberArray(a, b) {
  2288. if (!b) b = [];
  2289. var n = a ? Math.min(b.length, a.length) : 0,
  2290. c = b.slice(),
  2291. i;
  2292. return function(t) {
  2293. for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
  2294. return c;
  2295. };
  2296. }
  2297. function isNumberArray(x) {
  2298. return ArrayBuffer.isView(x) && !(x instanceof DataView);
  2299. }
  2300. function array$1(a, b) {
  2301. return (isNumberArray(b) ? numberArray : genericArray)(a, b);
  2302. }
  2303. function genericArray(a, b) {
  2304. var nb = b ? b.length : 0,
  2305. na = a ? Math.min(nb, a.length) : 0,
  2306. x = new Array(na),
  2307. c = new Array(nb),
  2308. i;
  2309. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2310. for (; i < nb; ++i) c[i] = b[i];
  2311. return function(t) {
  2312. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2313. return c;
  2314. };
  2315. }
  2316. function date(a, b) {
  2317. var d = new Date;
  2318. return a = +a, b = +b, function(t) {
  2319. return d.setTime(a * (1 - t) + b * t), d;
  2320. };
  2321. }
  2322. function interpolateNumber(a, b) {
  2323. return a = +a, b = +b, function(t) {
  2324. return a * (1 - t) + b * t;
  2325. };
  2326. }
  2327. function object(a, b) {
  2328. var i = {},
  2329. c = {},
  2330. k;
  2331. if (a === null || typeof a !== "object") a = {};
  2332. if (b === null || typeof b !== "object") b = {};
  2333. for (k in b) {
  2334. if (k in a) {
  2335. i[k] = interpolateValue(a[k], b[k]);
  2336. } else {
  2337. c[k] = b[k];
  2338. }
  2339. }
  2340. return function(t) {
  2341. for (k in i) c[k] = i[k](t);
  2342. return c;
  2343. };
  2344. }
  2345. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  2346. reB = new RegExp(reA.source, "g");
  2347. function zero(b) {
  2348. return function() {
  2349. return b;
  2350. };
  2351. }
  2352. function one(b) {
  2353. return function(t) {
  2354. return b(t) + "";
  2355. };
  2356. }
  2357. function interpolateString(a, b) {
  2358. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2359. am, // current match in a
  2360. bm, // current match in b
  2361. bs, // string preceding current number in b, if any
  2362. i = -1, // index in s
  2363. s = [], // string constants and placeholders
  2364. q = []; // number interpolators
  2365. // Coerce inputs to strings.
  2366. a = a + "", b = b + "";
  2367. // Interpolate pairs of numbers in a & b.
  2368. while ((am = reA.exec(a))
  2369. && (bm = reB.exec(b))) {
  2370. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2371. bs = b.slice(bi, bs);
  2372. if (s[i]) s[i] += bs; // coalesce with previous string
  2373. else s[++i] = bs;
  2374. }
  2375. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2376. if (s[i]) s[i] += bm; // coalesce with previous string
  2377. else s[++i] = bm;
  2378. } else { // interpolate non-matching numbers
  2379. s[++i] = null;
  2380. q.push({i: i, x: interpolateNumber(am, bm)});
  2381. }
  2382. bi = reB.lastIndex;
  2383. }
  2384. // Add remains of b.
  2385. if (bi < b.length) {
  2386. bs = b.slice(bi);
  2387. if (s[i]) s[i] += bs; // coalesce with previous string
  2388. else s[++i] = bs;
  2389. }
  2390. // Special optimization for only a single match.
  2391. // Otherwise, interpolate each of the numbers and rejoin the string.
  2392. return s.length < 2 ? (q[0]
  2393. ? one(q[0].x)
  2394. : zero(b))
  2395. : (b = q.length, function(t) {
  2396. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2397. return s.join("");
  2398. });
  2399. }
  2400. function interpolateValue(a, b) {
  2401. var t = typeof b, c;
  2402. return b == null || t === "boolean" ? constant$3(b)
  2403. : (t === "number" ? interpolateNumber
  2404. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2405. : b instanceof color ? interpolateRgb
  2406. : b instanceof Date ? date
  2407. : isNumberArray(b) ? numberArray
  2408. : Array.isArray(b) ? genericArray
  2409. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2410. : interpolateNumber)(a, b);
  2411. }
  2412. function discrete(range) {
  2413. var n = range.length;
  2414. return function(t) {
  2415. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  2416. };
  2417. }
  2418. function hue$1(a, b) {
  2419. var i = hue(+a, +b);
  2420. return function(t) {
  2421. var x = i(t);
  2422. return x - 360 * Math.floor(x / 360);
  2423. };
  2424. }
  2425. function interpolateRound(a, b) {
  2426. return a = +a, b = +b, function(t) {
  2427. return Math.round(a * (1 - t) + b * t);
  2428. };
  2429. }
  2430. var degrees = 180 / Math.PI;
  2431. var identity$2 = {
  2432. translateX: 0,
  2433. translateY: 0,
  2434. rotate: 0,
  2435. skewX: 0,
  2436. scaleX: 1,
  2437. scaleY: 1
  2438. };
  2439. function decompose(a, b, c, d, e, f) {
  2440. var scaleX, scaleY, skewX;
  2441. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2442. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2443. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2444. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2445. return {
  2446. translateX: e,
  2447. translateY: f,
  2448. rotate: Math.atan2(b, a) * degrees,
  2449. skewX: Math.atan(skewX) * degrees,
  2450. scaleX: scaleX,
  2451. scaleY: scaleY
  2452. };
  2453. }
  2454. var cssNode,
  2455. cssRoot,
  2456. cssView,
  2457. svgNode;
  2458. function parseCss(value) {
  2459. if (value === "none") return identity$2;
  2460. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2461. cssNode.style.transform = value;
  2462. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2463. cssRoot.removeChild(cssNode);
  2464. value = value.slice(7, -1).split(",");
  2465. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2466. }
  2467. function parseSvg(value) {
  2468. if (value == null) return identity$2;
  2469. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2470. svgNode.setAttribute("transform", value);
  2471. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2472. value = value.matrix;
  2473. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2474. }
  2475. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2476. function pop(s) {
  2477. return s.length ? s.pop() + " " : "";
  2478. }
  2479. function translate(xa, ya, xb, yb, s, q) {
  2480. if (xa !== xb || ya !== yb) {
  2481. var i = s.push("translate(", null, pxComma, null, pxParen);
  2482. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2483. } else if (xb || yb) {
  2484. s.push("translate(" + xb + pxComma + yb + pxParen);
  2485. }
  2486. }
  2487. function rotate(a, b, s, q) {
  2488. if (a !== b) {
  2489. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2490. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2491. } else if (b) {
  2492. s.push(pop(s) + "rotate(" + b + degParen);
  2493. }
  2494. }
  2495. function skewX(a, b, s, q) {
  2496. if (a !== b) {
  2497. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2498. } else if (b) {
  2499. s.push(pop(s) + "skewX(" + b + degParen);
  2500. }
  2501. }
  2502. function scale(xa, ya, xb, yb, s, q) {
  2503. if (xa !== xb || ya !== yb) {
  2504. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2505. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2506. } else if (xb !== 1 || yb !== 1) {
  2507. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2508. }
  2509. }
  2510. return function(a, b) {
  2511. var s = [], // string constants and placeholders
  2512. q = []; // number interpolators
  2513. a = parse(a), b = parse(b);
  2514. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2515. rotate(a.rotate, b.rotate, s, q);
  2516. skewX(a.skewX, b.skewX, s, q);
  2517. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2518. a = b = null; // gc
  2519. return function(t) {
  2520. var i = -1, n = q.length, o;
  2521. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2522. return s.join("");
  2523. };
  2524. };
  2525. }
  2526. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2527. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2528. var rho = Math.SQRT2,
  2529. rho2 = 2,
  2530. rho4 = 4,
  2531. epsilon2 = 1e-12;
  2532. function cosh(x) {
  2533. return ((x = Math.exp(x)) + 1 / x) / 2;
  2534. }
  2535. function sinh(x) {
  2536. return ((x = Math.exp(x)) - 1 / x) / 2;
  2537. }
  2538. function tanh(x) {
  2539. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2540. }
  2541. // p0 = [ux0, uy0, w0]
  2542. // p1 = [ux1, uy1, w1]
  2543. function interpolateZoom(p0, p1) {
  2544. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2545. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2546. dx = ux1 - ux0,
  2547. dy = uy1 - uy0,
  2548. d2 = dx * dx + dy * dy,
  2549. i,
  2550. S;
  2551. // Special case for u0 ≅ u1.
  2552. if (d2 < epsilon2) {
  2553. S = Math.log(w1 / w0) / rho;
  2554. i = function(t) {
  2555. return [
  2556. ux0 + t * dx,
  2557. uy0 + t * dy,
  2558. w0 * Math.exp(rho * t * S)
  2559. ];
  2560. };
  2561. }
  2562. // General case.
  2563. else {
  2564. var d1 = Math.sqrt(d2),
  2565. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2566. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2567. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2568. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2569. S = (r1 - r0) / rho;
  2570. i = function(t) {
  2571. var s = t * S,
  2572. coshr0 = cosh(r0),
  2573. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2574. return [
  2575. ux0 + u * dx,
  2576. uy0 + u * dy,
  2577. w0 * coshr0 / cosh(rho * s + r0)
  2578. ];
  2579. };
  2580. }
  2581. i.duration = S * 1000;
  2582. return i;
  2583. }
  2584. function hsl$1(hue) {
  2585. return function(start, end) {
  2586. var h = hue((start = hsl(start)).h, (end = hsl(end)).h),
  2587. s = nogamma(start.s, end.s),
  2588. l = nogamma(start.l, end.l),
  2589. opacity = nogamma(start.opacity, end.opacity);
  2590. return function(t) {
  2591. start.h = h(t);
  2592. start.s = s(t);
  2593. start.l = l(t);
  2594. start.opacity = opacity(t);
  2595. return start + "";
  2596. };
  2597. }
  2598. }
  2599. var hsl$2 = hsl$1(hue);
  2600. var hslLong = hsl$1(nogamma);
  2601. function lab$1(start, end) {
  2602. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2603. a = nogamma(start.a, end.a),
  2604. b = nogamma(start.b, end.b),
  2605. opacity = nogamma(start.opacity, end.opacity);
  2606. return function(t) {
  2607. start.l = l(t);
  2608. start.a = a(t);
  2609. start.b = b(t);
  2610. start.opacity = opacity(t);
  2611. return start + "";
  2612. };
  2613. }
  2614. function hcl$1(hue) {
  2615. return function(start, end) {
  2616. var h = hue((start = hcl(start)).h, (end = hcl(end)).h),
  2617. c = nogamma(start.c, end.c),
  2618. l = nogamma(start.l, end.l),
  2619. opacity = nogamma(start.opacity, end.opacity);
  2620. return function(t) {
  2621. start.h = h(t);
  2622. start.c = c(t);
  2623. start.l = l(t);
  2624. start.opacity = opacity(t);
  2625. return start + "";
  2626. };
  2627. }
  2628. }
  2629. var hcl$2 = hcl$1(hue);
  2630. var hclLong = hcl$1(nogamma);
  2631. function cubehelix$1(hue) {
  2632. return (function cubehelixGamma(y) {
  2633. y = +y;
  2634. function cubehelix$1(start, end) {
  2635. var h = hue((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2636. s = nogamma(start.s, end.s),
  2637. l = nogamma(start.l, end.l),
  2638. opacity = nogamma(start.opacity, end.opacity);
  2639. return function(t) {
  2640. start.h = h(t);
  2641. start.s = s(t);
  2642. start.l = l(Math.pow(t, y));
  2643. start.opacity = opacity(t);
  2644. return start + "";
  2645. };
  2646. }
  2647. cubehelix$1.gamma = cubehelixGamma;
  2648. return cubehelix$1;
  2649. })(1);
  2650. }
  2651. var cubehelix$2 = cubehelix$1(hue);
  2652. var cubehelixLong = cubehelix$1(nogamma);
  2653. function piecewise(interpolate, values) {
  2654. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  2655. while (i < n) I[i] = interpolate(v, v = values[++i]);
  2656. return function(t) {
  2657. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  2658. return I[i](t - i);
  2659. };
  2660. }
  2661. function quantize(interpolator, n) {
  2662. var samples = new Array(n);
  2663. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2664. return samples;
  2665. }
  2666. var frame = 0, // is an animation frame pending?
  2667. timeout = 0, // is a timeout pending?
  2668. interval = 0, // are any timers active?
  2669. pokeDelay = 1000, // how frequently we check for clock skew
  2670. taskHead,
  2671. taskTail,
  2672. clockLast = 0,
  2673. clockNow = 0,
  2674. clockSkew = 0,
  2675. clock = typeof performance === "object" && performance.now ? performance : Date,
  2676. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2677. function now() {
  2678. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2679. }
  2680. function clearNow() {
  2681. clockNow = 0;
  2682. }
  2683. function Timer() {
  2684. this._call =
  2685. this._time =
  2686. this._next = null;
  2687. }
  2688. Timer.prototype = timer.prototype = {
  2689. constructor: Timer,
  2690. restart: function(callback, delay, time) {
  2691. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2692. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2693. if (!this._next && taskTail !== this) {
  2694. if (taskTail) taskTail._next = this;
  2695. else taskHead = this;
  2696. taskTail = this;
  2697. }
  2698. this._call = callback;
  2699. this._time = time;
  2700. sleep();
  2701. },
  2702. stop: function() {
  2703. if (this._call) {
  2704. this._call = null;
  2705. this._time = Infinity;
  2706. sleep();
  2707. }
  2708. }
  2709. };
  2710. function timer(callback, delay, time) {
  2711. var t = new Timer;
  2712. t.restart(callback, delay, time);
  2713. return t;
  2714. }
  2715. function timerFlush() {
  2716. now(); // Get the current time, if not already set.
  2717. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2718. var t = taskHead, e;
  2719. while (t) {
  2720. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2721. t = t._next;
  2722. }
  2723. --frame;
  2724. }
  2725. function wake() {
  2726. clockNow = (clockLast = clock.now()) + clockSkew;
  2727. frame = timeout = 0;
  2728. try {
  2729. timerFlush();
  2730. } finally {
  2731. frame = 0;
  2732. nap();
  2733. clockNow = 0;
  2734. }
  2735. }
  2736. function poke() {
  2737. var now = clock.now(), delay = now - clockLast;
  2738. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2739. }
  2740. function nap() {
  2741. var t0, t1 = taskHead, t2, time = Infinity;
  2742. while (t1) {
  2743. if (t1._call) {
  2744. if (time > t1._time) time = t1._time;
  2745. t0 = t1, t1 = t1._next;
  2746. } else {
  2747. t2 = t1._next, t1._next = null;
  2748. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2749. }
  2750. }
  2751. taskTail = t0;
  2752. sleep(time);
  2753. }
  2754. function sleep(time) {
  2755. if (frame) return; // Soonest alarm already set, or will be.
  2756. if (timeout) timeout = clearTimeout(timeout);
  2757. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2758. if (delay > 24) {
  2759. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2760. if (interval) interval = clearInterval(interval);
  2761. } else {
  2762. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2763. frame = 1, setFrame(wake);
  2764. }
  2765. }
  2766. function timeout$1(callback, delay, time) {
  2767. var t = new Timer;
  2768. delay = delay == null ? 0 : +delay;
  2769. t.restart(function(elapsed) {
  2770. t.stop();
  2771. callback(elapsed + delay);
  2772. }, delay, time);
  2773. return t;
  2774. }
  2775. function interval$1(callback, delay, time) {
  2776. var t = new Timer, total = delay;
  2777. if (delay == null) return t.restart(callback, delay, time), t;
  2778. delay = +delay, time = time == null ? now() : +time;
  2779. t.restart(function tick(elapsed) {
  2780. elapsed += total;
  2781. t.restart(tick, total += delay, time);
  2782. callback(elapsed);
  2783. }, delay, time);
  2784. return t;
  2785. }
  2786. var emptyOn = dispatch("start", "end", "cancel", "interrupt");
  2787. var emptyTween = [];
  2788. var CREATED = 0;
  2789. var SCHEDULED = 1;
  2790. var STARTING = 2;
  2791. var STARTED = 3;
  2792. var RUNNING = 4;
  2793. var ENDING = 5;
  2794. var ENDED = 6;
  2795. function schedule(node, name, id, index, group, timing) {
  2796. var schedules = node.__transition;
  2797. if (!schedules) node.__transition = {};
  2798. else if (id in schedules) return;
  2799. create$1(node, id, {
  2800. name: name,
  2801. index: index, // For context during callback.
  2802. group: group, // For context during callback.
  2803. on: emptyOn,
  2804. tween: emptyTween,
  2805. time: timing.time,
  2806. delay: timing.delay,
  2807. duration: timing.duration,
  2808. ease: timing.ease,
  2809. timer: null,
  2810. state: CREATED
  2811. });
  2812. }
  2813. function init(node, id) {
  2814. var schedule = get$1(node, id);
  2815. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  2816. return schedule;
  2817. }
  2818. function set$1(node, id) {
  2819. var schedule = get$1(node, id);
  2820. if (schedule.state > STARTED) throw new Error("too late; already running");
  2821. return schedule;
  2822. }
  2823. function get$1(node, id) {
  2824. var schedule = node.__transition;
  2825. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  2826. return schedule;
  2827. }
  2828. function create$1(node, id, self) {
  2829. var schedules = node.__transition,
  2830. tween;
  2831. // Initialize the self timer when the transition is created.
  2832. // Note the actual delay is not known until the first callback!
  2833. schedules[id] = self;
  2834. self.timer = timer(schedule, 0, self.time);
  2835. function schedule(elapsed) {
  2836. self.state = SCHEDULED;
  2837. self.timer.restart(start, self.delay, self.time);
  2838. // If the elapsed delay is less than our first sleep, start immediately.
  2839. if (self.delay <= elapsed) start(elapsed - self.delay);
  2840. }
  2841. function start(elapsed) {
  2842. var i, j, n, o;
  2843. // If the state is not SCHEDULED, then we previously errored on start.
  2844. if (self.state !== SCHEDULED) return stop();
  2845. for (i in schedules) {
  2846. o = schedules[i];
  2847. if (o.name !== self.name) continue;
  2848. // While this element already has a starting transition during this frame,
  2849. // defer starting an interrupting transition until that transition has a
  2850. // chance to tick (and possibly end); see d3/d3-transition#54!
  2851. if (o.state === STARTED) return timeout$1(start);
  2852. // Interrupt the active transition, if any.
  2853. if (o.state === RUNNING) {
  2854. o.state = ENDED;
  2855. o.timer.stop();
  2856. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2857. delete schedules[i];
  2858. }
  2859. // Cancel any pre-empted transitions.
  2860. else if (+i < id) {
  2861. o.state = ENDED;
  2862. o.timer.stop();
  2863. o.on.call("cancel", node, node.__data__, o.index, o.group);
  2864. delete schedules[i];
  2865. }
  2866. }
  2867. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2868. // Note the transition may be canceled after start and before the first tick!
  2869. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2870. // Assuming this is successful, subsequent callbacks go straight to tick.
  2871. timeout$1(function() {
  2872. if (self.state === STARTED) {
  2873. self.state = RUNNING;
  2874. self.timer.restart(tick, self.delay, self.time);
  2875. tick(elapsed);
  2876. }
  2877. });
  2878. // Dispatch the start event.
  2879. // Note this must be done before the tween are initialized.
  2880. self.state = STARTING;
  2881. self.on.call("start", node, node.__data__, self.index, self.group);
  2882. if (self.state !== STARTING) return; // interrupted
  2883. self.state = STARTED;
  2884. // Initialize the tween, deleting null tween.
  2885. tween = new Array(n = self.tween.length);
  2886. for (i = 0, j = -1; i < n; ++i) {
  2887. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2888. tween[++j] = o;
  2889. }
  2890. }
  2891. tween.length = j + 1;
  2892. }
  2893. function tick(elapsed) {
  2894. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2895. i = -1,
  2896. n = tween.length;
  2897. while (++i < n) {
  2898. tween[i].call(node, t);
  2899. }
  2900. // Dispatch the end event.
  2901. if (self.state === ENDING) {
  2902. self.on.call("end", node, node.__data__, self.index, self.group);
  2903. stop();
  2904. }
  2905. }
  2906. function stop() {
  2907. self.state = ENDED;
  2908. self.timer.stop();
  2909. delete schedules[id];
  2910. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2911. delete node.__transition;
  2912. }
  2913. }
  2914. function interrupt(node, name) {
  2915. var schedules = node.__transition,
  2916. schedule,
  2917. active,
  2918. empty = true,
  2919. i;
  2920. if (!schedules) return;
  2921. name = name == null ? null : name + "";
  2922. for (i in schedules) {
  2923. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  2924. active = schedule.state > STARTING && schedule.state < ENDING;
  2925. schedule.state = ENDED;
  2926. schedule.timer.stop();
  2927. schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
  2928. delete schedules[i];
  2929. }
  2930. if (empty) delete node.__transition;
  2931. }
  2932. function selection_interrupt(name) {
  2933. return this.each(function() {
  2934. interrupt(this, name);
  2935. });
  2936. }
  2937. function tweenRemove(id, name) {
  2938. var tween0, tween1;
  2939. return function() {
  2940. var schedule = set$1(this, id),
  2941. tween = schedule.tween;
  2942. // If this node shared tween with the previous node,
  2943. // just assign the updated shared tween and we’re done!
  2944. // Otherwise, copy-on-write.
  2945. if (tween !== tween0) {
  2946. tween1 = tween0 = tween;
  2947. for (var i = 0, n = tween1.length; i < n; ++i) {
  2948. if (tween1[i].name === name) {
  2949. tween1 = tween1.slice();
  2950. tween1.splice(i, 1);
  2951. break;
  2952. }
  2953. }
  2954. }
  2955. schedule.tween = tween1;
  2956. };
  2957. }
  2958. function tweenFunction(id, name, value) {
  2959. var tween0, tween1;
  2960. if (typeof value !== "function") throw new Error;
  2961. return function() {
  2962. var schedule = set$1(this, id),
  2963. tween = schedule.tween;
  2964. // If this node shared tween with the previous node,
  2965. // just assign the updated shared tween and we’re done!
  2966. // Otherwise, copy-on-write.
  2967. if (tween !== tween0) {
  2968. tween1 = (tween0 = tween).slice();
  2969. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2970. if (tween1[i].name === name) {
  2971. tween1[i] = t;
  2972. break;
  2973. }
  2974. }
  2975. if (i === n) tween1.push(t);
  2976. }
  2977. schedule.tween = tween1;
  2978. };
  2979. }
  2980. function transition_tween(name, value) {
  2981. var id = this._id;
  2982. name += "";
  2983. if (arguments.length < 2) {
  2984. var tween = get$1(this.node(), id).tween;
  2985. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2986. if ((t = tween[i]).name === name) {
  2987. return t.value;
  2988. }
  2989. }
  2990. return null;
  2991. }
  2992. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2993. }
  2994. function tweenValue(transition, name, value) {
  2995. var id = transition._id;
  2996. transition.each(function() {
  2997. var schedule = set$1(this, id);
  2998. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  2999. });
  3000. return function(node) {
  3001. return get$1(node, id).value[name];
  3002. };
  3003. }
  3004. function interpolate(a, b) {
  3005. var c;
  3006. return (typeof b === "number" ? interpolateNumber
  3007. : b instanceof color ? interpolateRgb
  3008. : (c = color(b)) ? (b = c, interpolateRgb)
  3009. : interpolateString)(a, b);
  3010. }
  3011. function attrRemove$1(name) {
  3012. return function() {
  3013. this.removeAttribute(name);
  3014. };
  3015. }
  3016. function attrRemoveNS$1(fullname) {
  3017. return function() {
  3018. this.removeAttributeNS(fullname.space, fullname.local);
  3019. };
  3020. }
  3021. function attrConstant$1(name, interpolate, value1) {
  3022. var string00,
  3023. string1 = value1 + "",
  3024. interpolate0;
  3025. return function() {
  3026. var string0 = this.getAttribute(name);
  3027. return string0 === string1 ? null
  3028. : string0 === string00 ? interpolate0
  3029. : interpolate0 = interpolate(string00 = string0, value1);
  3030. };
  3031. }
  3032. function attrConstantNS$1(fullname, interpolate, value1) {
  3033. var string00,
  3034. string1 = value1 + "",
  3035. interpolate0;
  3036. return function() {
  3037. var string0 = this.getAttributeNS(fullname.space, fullname.local);
  3038. return string0 === string1 ? null
  3039. : string0 === string00 ? interpolate0
  3040. : interpolate0 = interpolate(string00 = string0, value1);
  3041. };
  3042. }
  3043. function attrFunction$1(name, interpolate, value) {
  3044. var string00,
  3045. string10,
  3046. interpolate0;
  3047. return function() {
  3048. var string0, value1 = value(this), string1;
  3049. if (value1 == null) return void this.removeAttribute(name);
  3050. string0 = this.getAttribute(name);
  3051. string1 = value1 + "";
  3052. return string0 === string1 ? null
  3053. : string0 === string00 && string1 === string10 ? interpolate0
  3054. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3055. };
  3056. }
  3057. function attrFunctionNS$1(fullname, interpolate, value) {
  3058. var string00,
  3059. string10,
  3060. interpolate0;
  3061. return function() {
  3062. var string0, value1 = value(this), string1;
  3063. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3064. string0 = this.getAttributeNS(fullname.space, fullname.local);
  3065. string1 = value1 + "";
  3066. return string0 === string1 ? null
  3067. : string0 === string00 && string1 === string10 ? interpolate0
  3068. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3069. };
  3070. }
  3071. function transition_attr(name, value) {
  3072. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  3073. return this.attrTween(name, typeof value === "function"
  3074. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  3075. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  3076. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
  3077. }
  3078. function attrInterpolate(name, i) {
  3079. return function(t) {
  3080. this.setAttribute(name, i.call(this, t));
  3081. };
  3082. }
  3083. function attrInterpolateNS(fullname, i) {
  3084. return function(t) {
  3085. this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
  3086. };
  3087. }
  3088. function attrTweenNS(fullname, value) {
  3089. var t0, i0;
  3090. function tween() {
  3091. var i = value.apply(this, arguments);
  3092. if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
  3093. return t0;
  3094. }
  3095. tween._value = value;
  3096. return tween;
  3097. }
  3098. function attrTween(name, value) {
  3099. var t0, i0;
  3100. function tween() {
  3101. var i = value.apply(this, arguments);
  3102. if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
  3103. return t0;
  3104. }
  3105. tween._value = value;
  3106. return tween;
  3107. }
  3108. function transition_attrTween(name, value) {
  3109. var key = "attr." + name;
  3110. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3111. if (value == null) return this.tween(key, null);
  3112. if (typeof value !== "function") throw new Error;
  3113. var fullname = namespace(name);
  3114. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3115. }
  3116. function delayFunction(id, value) {
  3117. return function() {
  3118. init(this, id).delay = +value.apply(this, arguments);
  3119. };
  3120. }
  3121. function delayConstant(id, value) {
  3122. return value = +value, function() {
  3123. init(this, id).delay = value;
  3124. };
  3125. }
  3126. function transition_delay(value) {
  3127. var id = this._id;
  3128. return arguments.length
  3129. ? this.each((typeof value === "function"
  3130. ? delayFunction
  3131. : delayConstant)(id, value))
  3132. : get$1(this.node(), id).delay;
  3133. }
  3134. function durationFunction(id, value) {
  3135. return function() {
  3136. set$1(this, id).duration = +value.apply(this, arguments);
  3137. };
  3138. }
  3139. function durationConstant(id, value) {
  3140. return value = +value, function() {
  3141. set$1(this, id).duration = value;
  3142. };
  3143. }
  3144. function transition_duration(value) {
  3145. var id = this._id;
  3146. return arguments.length
  3147. ? this.each((typeof value === "function"
  3148. ? durationFunction
  3149. : durationConstant)(id, value))
  3150. : get$1(this.node(), id).duration;
  3151. }
  3152. function easeConstant(id, value) {
  3153. if (typeof value !== "function") throw new Error;
  3154. return function() {
  3155. set$1(this, id).ease = value;
  3156. };
  3157. }
  3158. function transition_ease(value) {
  3159. var id = this._id;
  3160. return arguments.length
  3161. ? this.each(easeConstant(id, value))
  3162. : get$1(this.node(), id).ease;
  3163. }
  3164. function transition_filter(match) {
  3165. if (typeof match !== "function") match = matcher(match);
  3166. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3167. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3168. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3169. subgroup.push(node);
  3170. }
  3171. }
  3172. }
  3173. return new Transition(subgroups, this._parents, this._name, this._id);
  3174. }
  3175. function transition_merge(transition) {
  3176. if (transition._id !== this._id) throw new Error;
  3177. for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  3178. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3179. if (node = group0[i] || group1[i]) {
  3180. merge[i] = node;
  3181. }
  3182. }
  3183. }
  3184. for (; j < m0; ++j) {
  3185. merges[j] = groups0[j];
  3186. }
  3187. return new Transition(merges, this._parents, this._name, this._id);
  3188. }
  3189. function start(name) {
  3190. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3191. var i = t.indexOf(".");
  3192. if (i >= 0) t = t.slice(0, i);
  3193. return !t || t === "start";
  3194. });
  3195. }
  3196. function onFunction(id, name, listener) {
  3197. var on0, on1, sit = start(name) ? init : set$1;
  3198. return function() {
  3199. var schedule = sit(this, id),
  3200. on = schedule.on;
  3201. // If this node shared a dispatch with the previous node,
  3202. // just assign the updated shared dispatch and we’re done!
  3203. // Otherwise, copy-on-write.
  3204. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3205. schedule.on = on1;
  3206. };
  3207. }
  3208. function transition_on(name, listener) {
  3209. var id = this._id;
  3210. return arguments.length < 2
  3211. ? get$1(this.node(), id).on.on(name)
  3212. : this.each(onFunction(id, name, listener));
  3213. }
  3214. function removeFunction(id) {
  3215. return function() {
  3216. var parent = this.parentNode;
  3217. for (var i in this.__transition) if (+i !== id) return;
  3218. if (parent) parent.removeChild(this);
  3219. };
  3220. }
  3221. function transition_remove() {
  3222. return this.on("end.remove", removeFunction(this._id));
  3223. }
  3224. function transition_select(select) {
  3225. var name = this._name,
  3226. id = this._id;
  3227. if (typeof select !== "function") select = selector(select);
  3228. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3229. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3230. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  3231. if ("__data__" in node) subnode.__data__ = node.__data__;
  3232. subgroup[i] = subnode;
  3233. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3234. }
  3235. }
  3236. }
  3237. return new Transition(subgroups, this._parents, name, id);
  3238. }
  3239. function transition_selectAll(select) {
  3240. var name = this._name,
  3241. id = this._id;
  3242. if (typeof select !== "function") select = selectorAll(select);
  3243. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3244. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3245. if (node = group[i]) {
  3246. for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3247. if (child = children[k]) {
  3248. schedule(child, name, id, k, children, inherit);
  3249. }
  3250. }
  3251. subgroups.push(children);
  3252. parents.push(node);
  3253. }
  3254. }
  3255. }
  3256. return new Transition(subgroups, parents, name, id);
  3257. }
  3258. var Selection$1 = selection.prototype.constructor;
  3259. function transition_selection() {
  3260. return new Selection$1(this._groups, this._parents);
  3261. }
  3262. function styleNull(name, interpolate) {
  3263. var string00,
  3264. string10,
  3265. interpolate0;
  3266. return function() {
  3267. var string0 = styleValue(this, name),
  3268. string1 = (this.style.removeProperty(name), styleValue(this, name));
  3269. return string0 === string1 ? null
  3270. : string0 === string00 && string1 === string10 ? interpolate0
  3271. : interpolate0 = interpolate(string00 = string0, string10 = string1);
  3272. };
  3273. }
  3274. function styleRemove$1(name) {
  3275. return function() {
  3276. this.style.removeProperty(name);
  3277. };
  3278. }
  3279. function styleConstant$1(name, interpolate, value1) {
  3280. var string00,
  3281. string1 = value1 + "",
  3282. interpolate0;
  3283. return function() {
  3284. var string0 = styleValue(this, name);
  3285. return string0 === string1 ? null
  3286. : string0 === string00 ? interpolate0
  3287. : interpolate0 = interpolate(string00 = string0, value1);
  3288. };
  3289. }
  3290. function styleFunction$1(name, interpolate, value) {
  3291. var string00,
  3292. string10,
  3293. interpolate0;
  3294. return function() {
  3295. var string0 = styleValue(this, name),
  3296. value1 = value(this),
  3297. string1 = value1 + "";
  3298. if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
  3299. return string0 === string1 ? null
  3300. : string0 === string00 && string1 === string10 ? interpolate0
  3301. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3302. };
  3303. }
  3304. function styleMaybeRemove(id, name) {
  3305. var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
  3306. return function() {
  3307. var schedule = set$1(this, id),
  3308. on = schedule.on,
  3309. listener = schedule.value[key] == null ? remove || (remove = styleRemove$1(name)) : undefined;
  3310. // If this node shared a dispatch with the previous node,
  3311. // just assign the updated shared dispatch and we’re done!
  3312. // Otherwise, copy-on-write.
  3313. if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
  3314. schedule.on = on1;
  3315. };
  3316. }
  3317. function transition_style(name, value, priority) {
  3318. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3319. return value == null ? this
  3320. .styleTween(name, styleNull(name, i))
  3321. .on("end.style." + name, styleRemove$1(name))
  3322. : typeof value === "function" ? this
  3323. .styleTween(name, styleFunction$1(name, i, tweenValue(this, "style." + name, value)))
  3324. .each(styleMaybeRemove(this._id, name))
  3325. : this
  3326. .styleTween(name, styleConstant$1(name, i, value), priority)
  3327. .on("end.style." + name, null);
  3328. }
  3329. function styleInterpolate(name, i, priority) {
  3330. return function(t) {
  3331. this.style.setProperty(name, i.call(this, t), priority);
  3332. };
  3333. }
  3334. function styleTween(name, value, priority) {
  3335. var t, i0;
  3336. function tween() {
  3337. var i = value.apply(this, arguments);
  3338. if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
  3339. return t;
  3340. }
  3341. tween._value = value;
  3342. return tween;
  3343. }
  3344. function transition_styleTween(name, value, priority) {
  3345. var key = "style." + (name += "");
  3346. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3347. if (value == null) return this.tween(key, null);
  3348. if (typeof value !== "function") throw new Error;
  3349. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3350. }
  3351. function textConstant$1(value) {
  3352. return function() {
  3353. this.textContent = value;
  3354. };
  3355. }
  3356. function textFunction$1(value) {
  3357. return function() {
  3358. var value1 = value(this);
  3359. this.textContent = value1 == null ? "" : value1;
  3360. };
  3361. }
  3362. function transition_text(value) {
  3363. return this.tween("text", typeof value === "function"
  3364. ? textFunction$1(tweenValue(this, "text", value))
  3365. : textConstant$1(value == null ? "" : value + ""));
  3366. }
  3367. function textInterpolate(i) {
  3368. return function(t) {
  3369. this.textContent = i.call(this, t);
  3370. };
  3371. }
  3372. function textTween(value) {
  3373. var t0, i0;
  3374. function tween() {
  3375. var i = value.apply(this, arguments);
  3376. if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
  3377. return t0;
  3378. }
  3379. tween._value = value;
  3380. return tween;
  3381. }
  3382. function transition_textTween(value) {
  3383. var key = "text";
  3384. if (arguments.length < 1) return (key = this.tween(key)) && key._value;
  3385. if (value == null) return this.tween(key, null);
  3386. if (typeof value !== "function") throw new Error;
  3387. return this.tween(key, textTween(value));
  3388. }
  3389. function transition_transition() {
  3390. var name = this._name,
  3391. id0 = this._id,
  3392. id1 = newId();
  3393. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3394. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3395. if (node = group[i]) {
  3396. var inherit = get$1(node, id0);
  3397. schedule(node, name, id1, i, group, {
  3398. time: inherit.time + inherit.delay + inherit.duration,
  3399. delay: 0,
  3400. duration: inherit.duration,
  3401. ease: inherit.ease
  3402. });
  3403. }
  3404. }
  3405. }
  3406. return new Transition(groups, this._parents, name, id1);
  3407. }
  3408. function transition_end() {
  3409. var on0, on1, that = this, id = that._id, size = that.size();
  3410. return new Promise(function(resolve, reject) {
  3411. var cancel = {value: reject},
  3412. end = {value: function() { if (--size === 0) resolve(); }};
  3413. that.each(function() {
  3414. var schedule = set$1(this, id),
  3415. on = schedule.on;
  3416. // If this node shared a dispatch with the previous node,
  3417. // just assign the updated shared dispatch and we’re done!
  3418. // Otherwise, copy-on-write.
  3419. if (on !== on0) {
  3420. on1 = (on0 = on).copy();
  3421. on1._.cancel.push(cancel);
  3422. on1._.interrupt.push(cancel);
  3423. on1._.end.push(end);
  3424. }
  3425. schedule.on = on1;
  3426. });
  3427. });
  3428. }
  3429. var id = 0;
  3430. function Transition(groups, parents, name, id) {
  3431. this._groups = groups;
  3432. this._parents = parents;
  3433. this._name = name;
  3434. this._id = id;
  3435. }
  3436. function transition(name) {
  3437. return selection().transition(name);
  3438. }
  3439. function newId() {
  3440. return ++id;
  3441. }
  3442. var selection_prototype = selection.prototype;
  3443. Transition.prototype = transition.prototype = {
  3444. constructor: Transition,
  3445. select: transition_select,
  3446. selectAll: transition_selectAll,
  3447. filter: transition_filter,
  3448. merge: transition_merge,
  3449. selection: transition_selection,
  3450. transition: transition_transition,
  3451. call: selection_prototype.call,
  3452. nodes: selection_prototype.nodes,
  3453. node: selection_prototype.node,
  3454. size: selection_prototype.size,
  3455. empty: selection_prototype.empty,
  3456. each: selection_prototype.each,
  3457. on: transition_on,
  3458. attr: transition_attr,
  3459. attrTween: transition_attrTween,
  3460. style: transition_style,
  3461. styleTween: transition_styleTween,
  3462. text: transition_text,
  3463. textTween: transition_textTween,
  3464. remove: transition_remove,
  3465. tween: transition_tween,
  3466. delay: transition_delay,
  3467. duration: transition_duration,
  3468. ease: transition_ease,
  3469. end: transition_end
  3470. };
  3471. function linear$1(t) {
  3472. return +t;
  3473. }
  3474. function quadIn(t) {
  3475. return t * t;
  3476. }
  3477. function quadOut(t) {
  3478. return t * (2 - t);
  3479. }
  3480. function quadInOut(t) {
  3481. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3482. }
  3483. function cubicIn(t) {
  3484. return t * t * t;
  3485. }
  3486. function cubicOut(t) {
  3487. return --t * t * t + 1;
  3488. }
  3489. function cubicInOut(t) {
  3490. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3491. }
  3492. var exponent = 3;
  3493. var polyIn = (function custom(e) {
  3494. e = +e;
  3495. function polyIn(t) {
  3496. return Math.pow(t, e);
  3497. }
  3498. polyIn.exponent = custom;
  3499. return polyIn;
  3500. })(exponent);
  3501. var polyOut = (function custom(e) {
  3502. e = +e;
  3503. function polyOut(t) {
  3504. return 1 - Math.pow(1 - t, e);
  3505. }
  3506. polyOut.exponent = custom;
  3507. return polyOut;
  3508. })(exponent);
  3509. var polyInOut = (function custom(e) {
  3510. e = +e;
  3511. function polyInOut(t) {
  3512. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3513. }
  3514. polyInOut.exponent = custom;
  3515. return polyInOut;
  3516. })(exponent);
  3517. var pi = Math.PI,
  3518. halfPi = pi / 2;
  3519. function sinIn(t) {
  3520. return 1 - Math.cos(t * halfPi);
  3521. }
  3522. function sinOut(t) {
  3523. return Math.sin(t * halfPi);
  3524. }
  3525. function sinInOut(t) {
  3526. return (1 - Math.cos(pi * t)) / 2;
  3527. }
  3528. function expIn(t) {
  3529. return Math.pow(2, 10 * t - 10);
  3530. }
  3531. function expOut(t) {
  3532. return 1 - Math.pow(2, -10 * t);
  3533. }
  3534. function expInOut(t) {
  3535. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3536. }
  3537. function circleIn(t) {
  3538. return 1 - Math.sqrt(1 - t * t);
  3539. }
  3540. function circleOut(t) {
  3541. return Math.sqrt(1 - --t * t);
  3542. }
  3543. function circleInOut(t) {
  3544. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3545. }
  3546. var b1 = 4 / 11,
  3547. b2 = 6 / 11,
  3548. b3 = 8 / 11,
  3549. b4 = 3 / 4,
  3550. b5 = 9 / 11,
  3551. b6 = 10 / 11,
  3552. b7 = 15 / 16,
  3553. b8 = 21 / 22,
  3554. b9 = 63 / 64,
  3555. b0 = 1 / b1 / b1;
  3556. function bounceIn(t) {
  3557. return 1 - bounceOut(1 - t);
  3558. }
  3559. function bounceOut(t) {
  3560. return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
  3561. }
  3562. function bounceInOut(t) {
  3563. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3564. }
  3565. var overshoot = 1.70158;
  3566. var backIn = (function custom(s) {
  3567. s = +s;
  3568. function backIn(t) {
  3569. return t * t * ((s + 1) * t - s);
  3570. }
  3571. backIn.overshoot = custom;
  3572. return backIn;
  3573. })(overshoot);
  3574. var backOut = (function custom(s) {
  3575. s = +s;
  3576. function backOut(t) {
  3577. return --t * t * ((s + 1) * t + s) + 1;
  3578. }
  3579. backOut.overshoot = custom;
  3580. return backOut;
  3581. })(overshoot);
  3582. var backInOut = (function custom(s) {
  3583. s = +s;
  3584. function backInOut(t) {
  3585. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3586. }
  3587. backInOut.overshoot = custom;
  3588. return backInOut;
  3589. })(overshoot);
  3590. var tau = 2 * Math.PI,
  3591. amplitude = 1,
  3592. period = 0.3;
  3593. var elasticIn = (function custom(a, p) {
  3594. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3595. function elasticIn(t) {
  3596. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3597. }
  3598. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3599. elasticIn.period = function(p) { return custom(a, p); };
  3600. return elasticIn;
  3601. })(amplitude, period);
  3602. var elasticOut = (function custom(a, p) {
  3603. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3604. function elasticOut(t) {
  3605. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3606. }
  3607. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3608. elasticOut.period = function(p) { return custom(a, p); };
  3609. return elasticOut;
  3610. })(amplitude, period);
  3611. var elasticInOut = (function custom(a, p) {
  3612. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3613. function elasticInOut(t) {
  3614. return ((t = t * 2 - 1) < 0
  3615. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3616. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3617. }
  3618. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3619. elasticInOut.period = function(p) { return custom(a, p); };
  3620. return elasticInOut;
  3621. })(amplitude, period);
  3622. var defaultTiming = {
  3623. time: null, // Set on use.
  3624. delay: 0,
  3625. duration: 250,
  3626. ease: cubicInOut
  3627. };
  3628. function inherit(node, id) {
  3629. var timing;
  3630. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3631. if (!(node = node.parentNode)) {
  3632. return defaultTiming.time = now(), defaultTiming;
  3633. }
  3634. }
  3635. return timing;
  3636. }
  3637. function selection_transition(name) {
  3638. var id,
  3639. timing;
  3640. if (name instanceof Transition) {
  3641. id = name._id, name = name._name;
  3642. } else {
  3643. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3644. }
  3645. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3646. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3647. if (node = group[i]) {
  3648. schedule(node, name, id, i, group, timing || inherit(node, id));
  3649. }
  3650. }
  3651. }
  3652. return new Transition(groups, this._parents, name, id);
  3653. }
  3654. selection.prototype.interrupt = selection_interrupt;
  3655. selection.prototype.transition = selection_transition;
  3656. var root$1 = [null];
  3657. function active(node, name) {
  3658. var schedules = node.__transition,
  3659. schedule,
  3660. i;
  3661. if (schedules) {
  3662. name = name == null ? null : name + "";
  3663. for (i in schedules) {
  3664. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  3665. return new Transition([[node]], root$1, name, +i);
  3666. }
  3667. }
  3668. }
  3669. return null;
  3670. }
  3671. function constant$4(x) {
  3672. return function() {
  3673. return x;
  3674. };
  3675. }
  3676. function BrushEvent(target, type, selection) {
  3677. this.target = target;
  3678. this.type = type;
  3679. this.selection = selection;
  3680. }
  3681. function nopropagation$1() {
  3682. exports.event.stopImmediatePropagation();
  3683. }
  3684. function noevent$1() {
  3685. exports.event.preventDefault();
  3686. exports.event.stopImmediatePropagation();
  3687. }
  3688. var MODE_DRAG = {name: "drag"},
  3689. MODE_SPACE = {name: "space"},
  3690. MODE_HANDLE = {name: "handle"},
  3691. MODE_CENTER = {name: "center"};
  3692. function number1(e) {
  3693. return [+e[0], +e[1]];
  3694. }
  3695. function number2(e) {
  3696. return [number1(e[0]), number1(e[1])];
  3697. }
  3698. function toucher(identifier) {
  3699. return function(target) {
  3700. return touch(target, exports.event.touches, identifier);
  3701. };
  3702. }
  3703. var X = {
  3704. name: "x",
  3705. handles: ["w", "e"].map(type),
  3706. input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
  3707. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3708. };
  3709. var Y = {
  3710. name: "y",
  3711. handles: ["n", "s"].map(type),
  3712. input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
  3713. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3714. };
  3715. var XY = {
  3716. name: "xy",
  3717. handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
  3718. input: function(xy) { return xy == null ? null : number2(xy); },
  3719. output: function(xy) { return xy; }
  3720. };
  3721. var cursors = {
  3722. overlay: "crosshair",
  3723. selection: "move",
  3724. n: "ns-resize",
  3725. e: "ew-resize",
  3726. s: "ns-resize",
  3727. w: "ew-resize",
  3728. nw: "nwse-resize",
  3729. ne: "nesw-resize",
  3730. se: "nwse-resize",
  3731. sw: "nesw-resize"
  3732. };
  3733. var flipX = {
  3734. e: "w",
  3735. w: "e",
  3736. nw: "ne",
  3737. ne: "nw",
  3738. se: "sw",
  3739. sw: "se"
  3740. };
  3741. var flipY = {
  3742. n: "s",
  3743. s: "n",
  3744. nw: "sw",
  3745. ne: "se",
  3746. se: "ne",
  3747. sw: "nw"
  3748. };
  3749. var signsX = {
  3750. overlay: +1,
  3751. selection: +1,
  3752. n: null,
  3753. e: +1,
  3754. s: null,
  3755. w: -1,
  3756. nw: -1,
  3757. ne: +1,
  3758. se: +1,
  3759. sw: -1
  3760. };
  3761. var signsY = {
  3762. overlay: +1,
  3763. selection: +1,
  3764. n: -1,
  3765. e: null,
  3766. s: +1,
  3767. w: null,
  3768. nw: -1,
  3769. ne: -1,
  3770. se: +1,
  3771. sw: +1
  3772. };
  3773. function type(t) {
  3774. return {type: t};
  3775. }
  3776. // Ignore right-click, since that should open the context menu.
  3777. function defaultFilter$1() {
  3778. return !exports.event.ctrlKey && !exports.event.button;
  3779. }
  3780. function defaultExtent() {
  3781. var svg = this.ownerSVGElement || this;
  3782. if (svg.hasAttribute("viewBox")) {
  3783. svg = svg.viewBox.baseVal;
  3784. return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
  3785. }
  3786. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3787. }
  3788. function defaultTouchable$1() {
  3789. return navigator.maxTouchPoints || ("ontouchstart" in this);
  3790. }
  3791. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3792. function local$1(node) {
  3793. while (!node.__brush) if (!(node = node.parentNode)) return;
  3794. return node.__brush;
  3795. }
  3796. function empty$1(extent) {
  3797. return extent[0][0] === extent[1][0]
  3798. || extent[0][1] === extent[1][1];
  3799. }
  3800. function brushSelection(node) {
  3801. var state = node.__brush;
  3802. return state ? state.dim.output(state.selection) : null;
  3803. }
  3804. function brushX() {
  3805. return brush$1(X);
  3806. }
  3807. function brushY() {
  3808. return brush$1(Y);
  3809. }
  3810. function brush() {
  3811. return brush$1(XY);
  3812. }
  3813. function brush$1(dim) {
  3814. var extent = defaultExtent,
  3815. filter = defaultFilter$1,
  3816. touchable = defaultTouchable$1,
  3817. keys = true,
  3818. listeners = dispatch("start", "brush", "end"),
  3819. handleSize = 6,
  3820. touchending;
  3821. function brush(group) {
  3822. var overlay = group
  3823. .property("__brush", initialize)
  3824. .selectAll(".overlay")
  3825. .data([type("overlay")]);
  3826. overlay.enter().append("rect")
  3827. .attr("class", "overlay")
  3828. .attr("pointer-events", "all")
  3829. .attr("cursor", cursors.overlay)
  3830. .merge(overlay)
  3831. .each(function() {
  3832. var extent = local$1(this).extent;
  3833. select(this)
  3834. .attr("x", extent[0][0])
  3835. .attr("y", extent[0][1])
  3836. .attr("width", extent[1][0] - extent[0][0])
  3837. .attr("height", extent[1][1] - extent[0][1]);
  3838. });
  3839. group.selectAll(".selection")
  3840. .data([type("selection")])
  3841. .enter().append("rect")
  3842. .attr("class", "selection")
  3843. .attr("cursor", cursors.selection)
  3844. .attr("fill", "#777")
  3845. .attr("fill-opacity", 0.3)
  3846. .attr("stroke", "#fff")
  3847. .attr("shape-rendering", "crispEdges");
  3848. var handle = group.selectAll(".handle")
  3849. .data(dim.handles, function(d) { return d.type; });
  3850. handle.exit().remove();
  3851. handle.enter().append("rect")
  3852. .attr("class", function(d) { return "handle handle--" + d.type; })
  3853. .attr("cursor", function(d) { return cursors[d.type]; });
  3854. group
  3855. .each(redraw)
  3856. .attr("fill", "none")
  3857. .attr("pointer-events", "all")
  3858. .on("mousedown.brush", started)
  3859. .filter(touchable)
  3860. .on("touchstart.brush", started)
  3861. .on("touchmove.brush", touchmoved)
  3862. .on("touchend.brush touchcancel.brush", touchended)
  3863. .style("touch-action", "none")
  3864. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  3865. }
  3866. brush.move = function(group, selection) {
  3867. if (group.selection) {
  3868. group
  3869. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3870. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3871. .tween("brush", function() {
  3872. var that = this,
  3873. state = that.__brush,
  3874. emit = emitter(that, arguments),
  3875. selection0 = state.selection,
  3876. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  3877. i = interpolateValue(selection0, selection1);
  3878. function tween(t) {
  3879. state.selection = t === 1 && selection1 === null ? null : i(t);
  3880. redraw.call(that);
  3881. emit.brush();
  3882. }
  3883. return selection0 !== null && selection1 !== null ? tween : tween(1);
  3884. });
  3885. } else {
  3886. group
  3887. .each(function() {
  3888. var that = this,
  3889. args = arguments,
  3890. state = that.__brush,
  3891. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  3892. emit = emitter(that, args).beforestart();
  3893. interrupt(that);
  3894. state.selection = selection1 === null ? null : selection1;
  3895. redraw.call(that);
  3896. emit.start().brush().end();
  3897. });
  3898. }
  3899. };
  3900. brush.clear = function(group) {
  3901. brush.move(group, null);
  3902. };
  3903. function redraw() {
  3904. var group = select(this),
  3905. selection = local$1(this).selection;
  3906. if (selection) {
  3907. group.selectAll(".selection")
  3908. .style("display", null)
  3909. .attr("x", selection[0][0])
  3910. .attr("y", selection[0][1])
  3911. .attr("width", selection[1][0] - selection[0][0])
  3912. .attr("height", selection[1][1] - selection[0][1]);
  3913. group.selectAll(".handle")
  3914. .style("display", null)
  3915. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  3916. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  3917. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  3918. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  3919. }
  3920. else {
  3921. group.selectAll(".selection,.handle")
  3922. .style("display", "none")
  3923. .attr("x", null)
  3924. .attr("y", null)
  3925. .attr("width", null)
  3926. .attr("height", null);
  3927. }
  3928. }
  3929. function emitter(that, args, clean) {
  3930. return (!clean && that.__brush.emitter) || new Emitter(that, args);
  3931. }
  3932. function Emitter(that, args) {
  3933. this.that = that;
  3934. this.args = args;
  3935. this.state = that.__brush;
  3936. this.active = 0;
  3937. }
  3938. Emitter.prototype = {
  3939. beforestart: function() {
  3940. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3941. return this;
  3942. },
  3943. start: function() {
  3944. if (this.starting) this.starting = false, this.emit("start");
  3945. else this.emit("brush");
  3946. return this;
  3947. },
  3948. brush: function() {
  3949. this.emit("brush");
  3950. return this;
  3951. },
  3952. end: function() {
  3953. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3954. return this;
  3955. },
  3956. emit: function(type) {
  3957. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3958. }
  3959. };
  3960. function started() {
  3961. if (touchending && !exports.event.touches) return;
  3962. if (!filter.apply(this, arguments)) return;
  3963. var that = this,
  3964. type = exports.event.target.__data__.type,
  3965. mode = (keys && exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3966. signX = dim === Y ? null : signsX[type],
  3967. signY = dim === X ? null : signsY[type],
  3968. state = local$1(that),
  3969. extent = state.extent,
  3970. selection = state.selection,
  3971. W = extent[0][0], w0, w1,
  3972. N = extent[0][1], n0, n1,
  3973. E = extent[1][0], e0, e1,
  3974. S = extent[1][1], s0, s1,
  3975. dx = 0,
  3976. dy = 0,
  3977. moving,
  3978. shifting = signX && signY && keys && exports.event.shiftKey,
  3979. lockX,
  3980. lockY,
  3981. pointer = exports.event.touches ? toucher(exports.event.changedTouches[0].identifier) : mouse,
  3982. point0 = pointer(that),
  3983. point = point0,
  3984. emit = emitter(that, arguments, true).beforestart();
  3985. if (type === "overlay") {
  3986. if (selection) moving = true;
  3987. state.selection = selection = [
  3988. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3989. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3990. ];
  3991. } else {
  3992. w0 = selection[0][0];
  3993. n0 = selection[0][1];
  3994. e0 = selection[1][0];
  3995. s0 = selection[1][1];
  3996. }
  3997. w1 = w0;
  3998. n1 = n0;
  3999. e1 = e0;
  4000. s1 = s0;
  4001. var group = select(that)
  4002. .attr("pointer-events", "none");
  4003. var overlay = group.selectAll(".overlay")
  4004. .attr("cursor", cursors[type]);
  4005. if (exports.event.touches) {
  4006. emit.moved = moved;
  4007. emit.ended = ended;
  4008. } else {
  4009. var view = select(exports.event.view)
  4010. .on("mousemove.brush", moved, true)
  4011. .on("mouseup.brush", ended, true);
  4012. if (keys) view
  4013. .on("keydown.brush", keydowned, true)
  4014. .on("keyup.brush", keyupped, true);
  4015. dragDisable(exports.event.view);
  4016. }
  4017. nopropagation$1();
  4018. interrupt(that);
  4019. redraw.call(that);
  4020. emit.start();
  4021. function moved() {
  4022. var point1 = pointer(that);
  4023. if (shifting && !lockX && !lockY) {
  4024. if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
  4025. else lockX = true;
  4026. }
  4027. point = point1;
  4028. moving = true;
  4029. noevent$1();
  4030. move();
  4031. }
  4032. function move() {
  4033. var t;
  4034. dx = point[0] - point0[0];
  4035. dy = point[1] - point0[1];
  4036. switch (mode) {
  4037. case MODE_SPACE:
  4038. case MODE_DRAG: {
  4039. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  4040. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  4041. break;
  4042. }
  4043. case MODE_HANDLE: {
  4044. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  4045. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  4046. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  4047. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  4048. break;
  4049. }
  4050. case MODE_CENTER: {
  4051. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  4052. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  4053. break;
  4054. }
  4055. }
  4056. if (e1 < w1) {
  4057. signX *= -1;
  4058. t = w0, w0 = e0, e0 = t;
  4059. t = w1, w1 = e1, e1 = t;
  4060. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  4061. }
  4062. if (s1 < n1) {
  4063. signY *= -1;
  4064. t = n0, n0 = s0, s0 = t;
  4065. t = n1, n1 = s1, s1 = t;
  4066. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  4067. }
  4068. if (state.selection) selection = state.selection; // May be set by brush.move!
  4069. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  4070. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  4071. if (selection[0][0] !== w1
  4072. || selection[0][1] !== n1
  4073. || selection[1][0] !== e1
  4074. || selection[1][1] !== s1) {
  4075. state.selection = [[w1, n1], [e1, s1]];
  4076. redraw.call(that);
  4077. emit.brush();
  4078. }
  4079. }
  4080. function ended() {
  4081. nopropagation$1();
  4082. if (exports.event.touches) {
  4083. if (exports.event.touches.length) return;
  4084. if (touchending) clearTimeout(touchending);
  4085. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  4086. } else {
  4087. yesdrag(exports.event.view, moving);
  4088. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  4089. }
  4090. group.attr("pointer-events", "all");
  4091. overlay.attr("cursor", cursors.overlay);
  4092. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  4093. if (empty$1(selection)) state.selection = null, redraw.call(that);
  4094. emit.end();
  4095. }
  4096. function keydowned() {
  4097. switch (exports.event.keyCode) {
  4098. case 16: { // SHIFT
  4099. shifting = signX && signY;
  4100. break;
  4101. }
  4102. case 18: { // ALT
  4103. if (mode === MODE_HANDLE) {
  4104. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4105. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4106. mode = MODE_CENTER;
  4107. move();
  4108. }
  4109. break;
  4110. }
  4111. case 32: { // SPACE; takes priority over ALT
  4112. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  4113. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  4114. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  4115. mode = MODE_SPACE;
  4116. overlay.attr("cursor", cursors.selection);
  4117. move();
  4118. }
  4119. break;
  4120. }
  4121. default: return;
  4122. }
  4123. noevent$1();
  4124. }
  4125. function keyupped() {
  4126. switch (exports.event.keyCode) {
  4127. case 16: { // SHIFT
  4128. if (shifting) {
  4129. lockX = lockY = shifting = false;
  4130. move();
  4131. }
  4132. break;
  4133. }
  4134. case 18: { // ALT
  4135. if (mode === MODE_CENTER) {
  4136. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4137. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4138. mode = MODE_HANDLE;
  4139. move();
  4140. }
  4141. break;
  4142. }
  4143. case 32: { // SPACE
  4144. if (mode === MODE_SPACE) {
  4145. if (exports.event.altKey) {
  4146. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4147. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4148. mode = MODE_CENTER;
  4149. } else {
  4150. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4151. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4152. mode = MODE_HANDLE;
  4153. }
  4154. overlay.attr("cursor", cursors[type]);
  4155. move();
  4156. }
  4157. break;
  4158. }
  4159. default: return;
  4160. }
  4161. noevent$1();
  4162. }
  4163. }
  4164. function touchmoved() {
  4165. emitter(this, arguments).moved();
  4166. }
  4167. function touchended() {
  4168. emitter(this, arguments).ended();
  4169. }
  4170. function initialize() {
  4171. var state = this.__brush || {selection: null};
  4172. state.extent = number2(extent.apply(this, arguments));
  4173. state.dim = dim;
  4174. return state;
  4175. }
  4176. brush.extent = function(_) {
  4177. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4(number2(_)), brush) : extent;
  4178. };
  4179. brush.filter = function(_) {
  4180. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  4181. };
  4182. brush.touchable = function(_) {
  4183. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$4(!!_), brush) : touchable;
  4184. };
  4185. brush.handleSize = function(_) {
  4186. return arguments.length ? (handleSize = +_, brush) : handleSize;
  4187. };
  4188. brush.keyModifiers = function(_) {
  4189. return arguments.length ? (keys = !!_, brush) : keys;
  4190. };
  4191. brush.on = function() {
  4192. var value = listeners.on.apply(listeners, arguments);
  4193. return value === listeners ? brush : value;
  4194. };
  4195. return brush;
  4196. }
  4197. var cos = Math.cos;
  4198. var sin = Math.sin;
  4199. var pi$1 = Math.PI;
  4200. var halfPi$1 = pi$1 / 2;
  4201. var tau$1 = pi$1 * 2;
  4202. var max$1 = Math.max;
  4203. function compareValue(compare) {
  4204. return function(a, b) {
  4205. return compare(
  4206. a.source.value + a.target.value,
  4207. b.source.value + b.target.value
  4208. );
  4209. };
  4210. }
  4211. function chord() {
  4212. var padAngle = 0,
  4213. sortGroups = null,
  4214. sortSubgroups = null,
  4215. sortChords = null;
  4216. function chord(matrix) {
  4217. var n = matrix.length,
  4218. groupSums = [],
  4219. groupIndex = sequence(n),
  4220. subgroupIndex = [],
  4221. chords = [],
  4222. groups = chords.groups = new Array(n),
  4223. subgroups = new Array(n * n),
  4224. k,
  4225. x,
  4226. x0,
  4227. dx,
  4228. i,
  4229. j;
  4230. // Compute the sum.
  4231. k = 0, i = -1; while (++i < n) {
  4232. x = 0, j = -1; while (++j < n) {
  4233. x += matrix[i][j];
  4234. }
  4235. groupSums.push(x);
  4236. subgroupIndex.push(sequence(n));
  4237. k += x;
  4238. }
  4239. // Sort groups…
  4240. if (sortGroups) groupIndex.sort(function(a, b) {
  4241. return sortGroups(groupSums[a], groupSums[b]);
  4242. });
  4243. // Sort subgroups…
  4244. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4245. d.sort(function(a, b) {
  4246. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4247. });
  4248. });
  4249. // Convert the sum to scaling factor for [0, 2pi].
  4250. // TODO Allow start and end angle to be specified?
  4251. // TODO Allow padding to be specified as percentage?
  4252. k = max$1(0, tau$1 - padAngle * n) / k;
  4253. dx = k ? padAngle : tau$1 / n;
  4254. // Compute the start and end angle for each group and subgroup.
  4255. // Note: Opera has a bug reordering object literal properties!
  4256. x = 0, i = -1; while (++i < n) {
  4257. x0 = x, j = -1; while (++j < n) {
  4258. var di = groupIndex[i],
  4259. dj = subgroupIndex[di][j],
  4260. v = matrix[di][dj],
  4261. a0 = x,
  4262. a1 = x += v * k;
  4263. subgroups[dj * n + di] = {
  4264. index: di,
  4265. subindex: dj,
  4266. startAngle: a0,
  4267. endAngle: a1,
  4268. value: v
  4269. };
  4270. }
  4271. groups[di] = {
  4272. index: di,
  4273. startAngle: x0,
  4274. endAngle: x,
  4275. value: groupSums[di]
  4276. };
  4277. x += dx;
  4278. }
  4279. // Generate chords for each (non-empty) subgroup-subgroup link.
  4280. i = -1; while (++i < n) {
  4281. j = i - 1; while (++j < n) {
  4282. var source = subgroups[j * n + i],
  4283. target = subgroups[i * n + j];
  4284. if (source.value || target.value) {
  4285. chords.push(source.value < target.value
  4286. ? {source: target, target: source}
  4287. : {source: source, target: target});
  4288. }
  4289. }
  4290. }
  4291. return sortChords ? chords.sort(sortChords) : chords;
  4292. }
  4293. chord.padAngle = function(_) {
  4294. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4295. };
  4296. chord.sortGroups = function(_) {
  4297. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4298. };
  4299. chord.sortSubgroups = function(_) {
  4300. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4301. };
  4302. chord.sortChords = function(_) {
  4303. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4304. };
  4305. return chord;
  4306. }
  4307. var slice$2 = Array.prototype.slice;
  4308. function constant$5(x) {
  4309. return function() {
  4310. return x;
  4311. };
  4312. }
  4313. var pi$2 = Math.PI,
  4314. tau$2 = 2 * pi$2,
  4315. epsilon$1 = 1e-6,
  4316. tauEpsilon = tau$2 - epsilon$1;
  4317. function Path() {
  4318. this._x0 = this._y0 = // start of current subpath
  4319. this._x1 = this._y1 = null; // end of current subpath
  4320. this._ = "";
  4321. }
  4322. function path() {
  4323. return new Path;
  4324. }
  4325. Path.prototype = path.prototype = {
  4326. constructor: Path,
  4327. moveTo: function(x, y) {
  4328. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4329. },
  4330. closePath: function() {
  4331. if (this._x1 !== null) {
  4332. this._x1 = this._x0, this._y1 = this._y0;
  4333. this._ += "Z";
  4334. }
  4335. },
  4336. lineTo: function(x, y) {
  4337. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4338. },
  4339. quadraticCurveTo: function(x1, y1, x, y) {
  4340. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4341. },
  4342. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4343. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4344. },
  4345. arcTo: function(x1, y1, x2, y2, r) {
  4346. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4347. var x0 = this._x1,
  4348. y0 = this._y1,
  4349. x21 = x2 - x1,
  4350. y21 = y2 - y1,
  4351. x01 = x0 - x1,
  4352. y01 = y0 - y1,
  4353. l01_2 = x01 * x01 + y01 * y01;
  4354. // Is the radius negative? Error.
  4355. if (r < 0) throw new Error("negative radius: " + r);
  4356. // Is this path empty? Move to (x1,y1).
  4357. if (this._x1 === null) {
  4358. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4359. }
  4360. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4361. else if (!(l01_2 > epsilon$1));
  4362. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4363. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4364. // Or, is the radius zero? Line to (x1,y1).
  4365. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4366. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4367. }
  4368. // Otherwise, draw an arc!
  4369. else {
  4370. var x20 = x2 - x0,
  4371. y20 = y2 - y0,
  4372. l21_2 = x21 * x21 + y21 * y21,
  4373. l20_2 = x20 * x20 + y20 * y20,
  4374. l21 = Math.sqrt(l21_2),
  4375. l01 = Math.sqrt(l01_2),
  4376. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4377. t01 = l / l01,
  4378. t21 = l / l21;
  4379. // If the start tangent is not coincident with (x0,y0), line to.
  4380. if (Math.abs(t01 - 1) > epsilon$1) {
  4381. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4382. }
  4383. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4384. }
  4385. },
  4386. arc: function(x, y, r, a0, a1, ccw) {
  4387. x = +x, y = +y, r = +r, ccw = !!ccw;
  4388. var dx = r * Math.cos(a0),
  4389. dy = r * Math.sin(a0),
  4390. x0 = x + dx,
  4391. y0 = y + dy,
  4392. cw = 1 ^ ccw,
  4393. da = ccw ? a0 - a1 : a1 - a0;
  4394. // Is the radius negative? Error.
  4395. if (r < 0) throw new Error("negative radius: " + r);
  4396. // Is this path empty? Move to (x0,y0).
  4397. if (this._x1 === null) {
  4398. this._ += "M" + x0 + "," + y0;
  4399. }
  4400. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4401. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4402. this._ += "L" + x0 + "," + y0;
  4403. }
  4404. // Is this arc empty? We’re done.
  4405. if (!r) return;
  4406. // Does the angle go the wrong way? Flip the direction.
  4407. if (da < 0) da = da % tau$2 + tau$2;
  4408. // Is this a complete circle? Draw two arcs to complete the circle.
  4409. if (da > tauEpsilon) {
  4410. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4411. }
  4412. // Is this arc non-empty? Draw an arc!
  4413. else if (da > epsilon$1) {
  4414. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4415. }
  4416. },
  4417. rect: function(x, y, w, h) {
  4418. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4419. },
  4420. toString: function() {
  4421. return this._;
  4422. }
  4423. };
  4424. function defaultSource(d) {
  4425. return d.source;
  4426. }
  4427. function defaultTarget(d) {
  4428. return d.target;
  4429. }
  4430. function defaultRadius(d) {
  4431. return d.radius;
  4432. }
  4433. function defaultStartAngle(d) {
  4434. return d.startAngle;
  4435. }
  4436. function defaultEndAngle(d) {
  4437. return d.endAngle;
  4438. }
  4439. function ribbon() {
  4440. var source = defaultSource,
  4441. target = defaultTarget,
  4442. radius = defaultRadius,
  4443. startAngle = defaultStartAngle,
  4444. endAngle = defaultEndAngle,
  4445. context = null;
  4446. function ribbon() {
  4447. var buffer,
  4448. argv = slice$2.call(arguments),
  4449. s = source.apply(this, argv),
  4450. t = target.apply(this, argv),
  4451. sr = +radius.apply(this, (argv[0] = s, argv)),
  4452. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4453. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4454. sx0 = sr * cos(sa0),
  4455. sy0 = sr * sin(sa0),
  4456. tr = +radius.apply(this, (argv[0] = t, argv)),
  4457. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4458. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4459. if (!context) context = buffer = path();
  4460. context.moveTo(sx0, sy0);
  4461. context.arc(0, 0, sr, sa0, sa1);
  4462. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4463. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4464. context.arc(0, 0, tr, ta0, ta1);
  4465. }
  4466. context.quadraticCurveTo(0, 0, sx0, sy0);
  4467. context.closePath();
  4468. if (buffer) return context = null, buffer + "" || null;
  4469. }
  4470. ribbon.radius = function(_) {
  4471. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4472. };
  4473. ribbon.startAngle = function(_) {
  4474. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4475. };
  4476. ribbon.endAngle = function(_) {
  4477. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4478. };
  4479. ribbon.source = function(_) {
  4480. return arguments.length ? (source = _, ribbon) : source;
  4481. };
  4482. ribbon.target = function(_) {
  4483. return arguments.length ? (target = _, ribbon) : target;
  4484. };
  4485. ribbon.context = function(_) {
  4486. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  4487. };
  4488. return ribbon;
  4489. }
  4490. var prefix = "$";
  4491. function Map() {}
  4492. Map.prototype = map$1.prototype = {
  4493. constructor: Map,
  4494. has: function(key) {
  4495. return (prefix + key) in this;
  4496. },
  4497. get: function(key) {
  4498. return this[prefix + key];
  4499. },
  4500. set: function(key, value) {
  4501. this[prefix + key] = value;
  4502. return this;
  4503. },
  4504. remove: function(key) {
  4505. var property = prefix + key;
  4506. return property in this && delete this[property];
  4507. },
  4508. clear: function() {
  4509. for (var property in this) if (property[0] === prefix) delete this[property];
  4510. },
  4511. keys: function() {
  4512. var keys = [];
  4513. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4514. return keys;
  4515. },
  4516. values: function() {
  4517. var values = [];
  4518. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4519. return values;
  4520. },
  4521. entries: function() {
  4522. var entries = [];
  4523. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4524. return entries;
  4525. },
  4526. size: function() {
  4527. var size = 0;
  4528. for (var property in this) if (property[0] === prefix) ++size;
  4529. return size;
  4530. },
  4531. empty: function() {
  4532. for (var property in this) if (property[0] === prefix) return false;
  4533. return true;
  4534. },
  4535. each: function(f) {
  4536. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4537. }
  4538. };
  4539. function map$1(object, f) {
  4540. var map = new Map;
  4541. // Copy constructor.
  4542. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4543. // Index array by numeric index or specified key function.
  4544. else if (Array.isArray(object)) {
  4545. var i = -1,
  4546. n = object.length,
  4547. o;
  4548. if (f == null) while (++i < n) map.set(i, object[i]);
  4549. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4550. }
  4551. // Convert object to map.
  4552. else if (object) for (var key in object) map.set(key, object[key]);
  4553. return map;
  4554. }
  4555. function nest() {
  4556. var keys = [],
  4557. sortKeys = [],
  4558. sortValues,
  4559. rollup,
  4560. nest;
  4561. function apply(array, depth, createResult, setResult) {
  4562. if (depth >= keys.length) {
  4563. if (sortValues != null) array.sort(sortValues);
  4564. return rollup != null ? rollup(array) : array;
  4565. }
  4566. var i = -1,
  4567. n = array.length,
  4568. key = keys[depth++],
  4569. keyValue,
  4570. value,
  4571. valuesByKey = map$1(),
  4572. values,
  4573. result = createResult();
  4574. while (++i < n) {
  4575. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4576. values.push(value);
  4577. } else {
  4578. valuesByKey.set(keyValue, [value]);
  4579. }
  4580. }
  4581. valuesByKey.each(function(values, key) {
  4582. setResult(result, key, apply(values, depth, createResult, setResult));
  4583. });
  4584. return result;
  4585. }
  4586. function entries(map, depth) {
  4587. if (++depth > keys.length) return map;
  4588. var array, sortKey = sortKeys[depth - 1];
  4589. if (rollup != null && depth >= keys.length) array = map.entries();
  4590. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4591. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4592. }
  4593. return nest = {
  4594. object: function(array) { return apply(array, 0, createObject, setObject); },
  4595. map: function(array) { return apply(array, 0, createMap, setMap); },
  4596. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4597. key: function(d) { keys.push(d); return nest; },
  4598. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4599. sortValues: function(order) { sortValues = order; return nest; },
  4600. rollup: function(f) { rollup = f; return nest; }
  4601. };
  4602. }
  4603. function createObject() {
  4604. return {};
  4605. }
  4606. function setObject(object, key, value) {
  4607. object[key] = value;
  4608. }
  4609. function createMap() {
  4610. return map$1();
  4611. }
  4612. function setMap(map, key, value) {
  4613. map.set(key, value);
  4614. }
  4615. function Set() {}
  4616. var proto = map$1.prototype;
  4617. Set.prototype = set$2.prototype = {
  4618. constructor: Set,
  4619. has: proto.has,
  4620. add: function(value) {
  4621. value += "";
  4622. this[prefix + value] = value;
  4623. return this;
  4624. },
  4625. remove: proto.remove,
  4626. clear: proto.clear,
  4627. values: proto.keys,
  4628. size: proto.size,
  4629. empty: proto.empty,
  4630. each: proto.each
  4631. };
  4632. function set$2(object, f) {
  4633. var set = new Set;
  4634. // Copy constructor.
  4635. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4636. // Otherwise, assume it’s an array.
  4637. else if (object) {
  4638. var i = -1, n = object.length;
  4639. if (f == null) while (++i < n) set.add(object[i]);
  4640. else while (++i < n) set.add(f(object[i], i, object));
  4641. }
  4642. return set;
  4643. }
  4644. function keys(map) {
  4645. var keys = [];
  4646. for (var key in map) keys.push(key);
  4647. return keys;
  4648. }
  4649. function values(map) {
  4650. var values = [];
  4651. for (var key in map) values.push(map[key]);
  4652. return values;
  4653. }
  4654. function entries(map) {
  4655. var entries = [];
  4656. for (var key in map) entries.push({key: key, value: map[key]});
  4657. return entries;
  4658. }
  4659. var array$2 = Array.prototype;
  4660. var slice$3 = array$2.slice;
  4661. function ascending$2(a, b) {
  4662. return a - b;
  4663. }
  4664. function area(ring) {
  4665. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  4666. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  4667. return area;
  4668. }
  4669. function constant$6(x) {
  4670. return function() {
  4671. return x;
  4672. };
  4673. }
  4674. function contains(ring, hole) {
  4675. var i = -1, n = hole.length, c;
  4676. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  4677. return 0;
  4678. }
  4679. function ringContains(ring, point) {
  4680. var x = point[0], y = point[1], contains = -1;
  4681. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  4682. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  4683. if (segmentContains(pi, pj, point)) return 0;
  4684. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  4685. }
  4686. return contains;
  4687. }
  4688. function segmentContains(a, b, c) {
  4689. var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  4690. }
  4691. function collinear(a, b, c) {
  4692. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  4693. }
  4694. function within(p, q, r) {
  4695. return p <= q && q <= r || r <= q && q <= p;
  4696. }
  4697. function noop$1() {}
  4698. var cases = [
  4699. [],
  4700. [[[1.0, 1.5], [0.5, 1.0]]],
  4701. [[[1.5, 1.0], [1.0, 1.5]]],
  4702. [[[1.5, 1.0], [0.5, 1.0]]],
  4703. [[[1.0, 0.5], [1.5, 1.0]]],
  4704. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  4705. [[[1.0, 0.5], [1.0, 1.5]]],
  4706. [[[1.0, 0.5], [0.5, 1.0]]],
  4707. [[[0.5, 1.0], [1.0, 0.5]]],
  4708. [[[1.0, 1.5], [1.0, 0.5]]],
  4709. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  4710. [[[1.5, 1.0], [1.0, 0.5]]],
  4711. [[[0.5, 1.0], [1.5, 1.0]]],
  4712. [[[1.0, 1.5], [1.5, 1.0]]],
  4713. [[[0.5, 1.0], [1.0, 1.5]]],
  4714. []
  4715. ];
  4716. function contours() {
  4717. var dx = 1,
  4718. dy = 1,
  4719. threshold = thresholdSturges,
  4720. smooth = smoothLinear;
  4721. function contours(values) {
  4722. var tz = threshold(values);
  4723. // Convert number of thresholds into uniform thresholds.
  4724. if (!Array.isArray(tz)) {
  4725. var domain = extent(values), start = domain[0], stop = domain[1];
  4726. tz = tickStep(start, stop, tz);
  4727. tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
  4728. } else {
  4729. tz = tz.slice().sort(ascending$2);
  4730. }
  4731. return tz.map(function(value) {
  4732. return contour(values, value);
  4733. });
  4734. }
  4735. // Accumulate, smooth contour rings, assign holes to exterior rings.
  4736. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  4737. function contour(values, value) {
  4738. var polygons = [],
  4739. holes = [];
  4740. isorings(values, value, function(ring) {
  4741. smooth(ring, values, value);
  4742. if (area(ring) > 0) polygons.push([ring]);
  4743. else holes.push(ring);
  4744. });
  4745. holes.forEach(function(hole) {
  4746. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  4747. if (contains((polygon = polygons[i])[0], hole) !== -1) {
  4748. polygon.push(hole);
  4749. return;
  4750. }
  4751. }
  4752. });
  4753. return {
  4754. type: "MultiPolygon",
  4755. value: value,
  4756. coordinates: polygons
  4757. };
  4758. }
  4759. // Marching squares with isolines stitched into rings.
  4760. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  4761. function isorings(values, value, callback) {
  4762. var fragmentByStart = new Array,
  4763. fragmentByEnd = new Array,
  4764. x, y, t0, t1, t2, t3;
  4765. // Special case for the first row (y = -1, t2 = t3 = 0).
  4766. x = y = -1;
  4767. t1 = values[0] >= value;
  4768. cases[t1 << 1].forEach(stitch);
  4769. while (++x < dx - 1) {
  4770. t0 = t1, t1 = values[x + 1] >= value;
  4771. cases[t0 | t1 << 1].forEach(stitch);
  4772. }
  4773. cases[t1 << 0].forEach(stitch);
  4774. // General case for the intermediate rows.
  4775. while (++y < dy - 1) {
  4776. x = -1;
  4777. t1 = values[y * dx + dx] >= value;
  4778. t2 = values[y * dx] >= value;
  4779. cases[t1 << 1 | t2 << 2].forEach(stitch);
  4780. while (++x < dx - 1) {
  4781. t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
  4782. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4783. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  4784. }
  4785. cases[t1 | t2 << 3].forEach(stitch);
  4786. }
  4787. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  4788. x = -1;
  4789. t2 = values[y * dx] >= value;
  4790. cases[t2 << 2].forEach(stitch);
  4791. while (++x < dx - 1) {
  4792. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4793. cases[t2 << 2 | t3 << 3].forEach(stitch);
  4794. }
  4795. cases[t2 << 3].forEach(stitch);
  4796. function stitch(line) {
  4797. var start = [line[0][0] + x, line[0][1] + y],
  4798. end = [line[1][0] + x, line[1][1] + y],
  4799. startIndex = index(start),
  4800. endIndex = index(end),
  4801. f, g;
  4802. if (f = fragmentByEnd[startIndex]) {
  4803. if (g = fragmentByStart[endIndex]) {
  4804. delete fragmentByEnd[f.end];
  4805. delete fragmentByStart[g.start];
  4806. if (f === g) {
  4807. f.ring.push(end);
  4808. callback(f.ring);
  4809. } else {
  4810. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  4811. }
  4812. } else {
  4813. delete fragmentByEnd[f.end];
  4814. f.ring.push(end);
  4815. fragmentByEnd[f.end = endIndex] = f;
  4816. }
  4817. } else if (f = fragmentByStart[endIndex]) {
  4818. if (g = fragmentByEnd[startIndex]) {
  4819. delete fragmentByStart[f.start];
  4820. delete fragmentByEnd[g.end];
  4821. if (f === g) {
  4822. f.ring.push(end);
  4823. callback(f.ring);
  4824. } else {
  4825. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  4826. }
  4827. } else {
  4828. delete fragmentByStart[f.start];
  4829. f.ring.unshift(start);
  4830. fragmentByStart[f.start = startIndex] = f;
  4831. }
  4832. } else {
  4833. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  4834. }
  4835. }
  4836. }
  4837. function index(point) {
  4838. return point[0] * 2 + point[1] * (dx + 1) * 4;
  4839. }
  4840. function smoothLinear(ring, values, value) {
  4841. ring.forEach(function(point) {
  4842. var x = point[0],
  4843. y = point[1],
  4844. xt = x | 0,
  4845. yt = y | 0,
  4846. v0,
  4847. v1 = values[yt * dx + xt];
  4848. if (x > 0 && x < dx && xt === x) {
  4849. v0 = values[yt * dx + xt - 1];
  4850. point[0] = x + (value - v0) / (v1 - v0) - 0.5;
  4851. }
  4852. if (y > 0 && y < dy && yt === y) {
  4853. v0 = values[(yt - 1) * dx + xt];
  4854. point[1] = y + (value - v0) / (v1 - v0) - 0.5;
  4855. }
  4856. });
  4857. }
  4858. contours.contour = contour;
  4859. contours.size = function(_) {
  4860. if (!arguments.length) return [dx, dy];
  4861. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4862. if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
  4863. return dx = _0, dy = _1, contours;
  4864. };
  4865. contours.thresholds = function(_) {
  4866. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold;
  4867. };
  4868. contours.smooth = function(_) {
  4869. return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
  4870. };
  4871. return contours;
  4872. }
  4873. // TODO Optimize edge cases.
  4874. // TODO Optimize index calculation.
  4875. // TODO Optimize arguments.
  4876. function blurX(source, target, r) {
  4877. var n = source.width,
  4878. m = source.height,
  4879. w = (r << 1) + 1;
  4880. for (var j = 0; j < m; ++j) {
  4881. for (var i = 0, sr = 0; i < n + r; ++i) {
  4882. if (i < n) {
  4883. sr += source.data[i + j * n];
  4884. }
  4885. if (i >= r) {
  4886. if (i >= w) {
  4887. sr -= source.data[i - w + j * n];
  4888. }
  4889. target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
  4890. }
  4891. }
  4892. }
  4893. }
  4894. // TODO Optimize edge cases.
  4895. // TODO Optimize index calculation.
  4896. // TODO Optimize arguments.
  4897. function blurY(source, target, r) {
  4898. var n = source.width,
  4899. m = source.height,
  4900. w = (r << 1) + 1;
  4901. for (var i = 0; i < n; ++i) {
  4902. for (var j = 0, sr = 0; j < m + r; ++j) {
  4903. if (j < m) {
  4904. sr += source.data[i + j * n];
  4905. }
  4906. if (j >= r) {
  4907. if (j >= w) {
  4908. sr -= source.data[i + (j - w) * n];
  4909. }
  4910. target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
  4911. }
  4912. }
  4913. }
  4914. }
  4915. function defaultX(d) {
  4916. return d[0];
  4917. }
  4918. function defaultY(d) {
  4919. return d[1];
  4920. }
  4921. function defaultWeight() {
  4922. return 1;
  4923. }
  4924. function density() {
  4925. var x = defaultX,
  4926. y = defaultY,
  4927. weight = defaultWeight,
  4928. dx = 960,
  4929. dy = 500,
  4930. r = 20, // blur radius
  4931. k = 2, // log2(grid cell size)
  4932. o = r * 3, // grid offset, to pad for blur
  4933. n = (dx + o * 2) >> k, // grid width
  4934. m = (dy + o * 2) >> k, // grid height
  4935. threshold = constant$6(20);
  4936. function density(data) {
  4937. var values0 = new Float32Array(n * m),
  4938. values1 = new Float32Array(n * m);
  4939. data.forEach(function(d, i, data) {
  4940. var xi = (+x(d, i, data) + o) >> k,
  4941. yi = (+y(d, i, data) + o) >> k,
  4942. wi = +weight(d, i, data);
  4943. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  4944. values0[xi + yi * n] += wi;
  4945. }
  4946. });
  4947. // TODO Optimize.
  4948. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4949. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4950. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4951. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4952. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4953. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4954. var tz = threshold(values0);
  4955. // Convert number of thresholds into uniform thresholds.
  4956. if (!Array.isArray(tz)) {
  4957. var stop = max(values0);
  4958. tz = tickStep(0, stop, tz);
  4959. tz = sequence(0, Math.floor(stop / tz) * tz, tz);
  4960. tz.shift();
  4961. }
  4962. return contours()
  4963. .thresholds(tz)
  4964. .size([n, m])
  4965. (values0)
  4966. .map(transform);
  4967. }
  4968. function transform(geometry) {
  4969. geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
  4970. geometry.coordinates.forEach(transformPolygon);
  4971. return geometry;
  4972. }
  4973. function transformPolygon(coordinates) {
  4974. coordinates.forEach(transformRing);
  4975. }
  4976. function transformRing(coordinates) {
  4977. coordinates.forEach(transformPoint);
  4978. }
  4979. // TODO Optimize.
  4980. function transformPoint(coordinates) {
  4981. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  4982. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  4983. }
  4984. function resize() {
  4985. o = r * 3;
  4986. n = (dx + o * 2) >> k;
  4987. m = (dy + o * 2) >> k;
  4988. return density;
  4989. }
  4990. density.x = function(_) {
  4991. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
  4992. };
  4993. density.y = function(_) {
  4994. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
  4995. };
  4996. density.weight = function(_) {
  4997. return arguments.length ? (weight = typeof _ === "function" ? _ : constant$6(+_), density) : weight;
  4998. };
  4999. density.size = function(_) {
  5000. if (!arguments.length) return [dx, dy];
  5001. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  5002. if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
  5003. return dx = _0, dy = _1, resize();
  5004. };
  5005. density.cellSize = function(_) {
  5006. if (!arguments.length) return 1 << k;
  5007. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  5008. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  5009. };
  5010. density.thresholds = function(_) {
  5011. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold;
  5012. };
  5013. density.bandwidth = function(_) {
  5014. if (!arguments.length) return Math.sqrt(r * (r + 1));
  5015. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  5016. return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
  5017. };
  5018. return density;
  5019. }
  5020. var EOL = {},
  5021. EOF = {},
  5022. QUOTE = 34,
  5023. NEWLINE = 10,
  5024. RETURN = 13;
  5025. function objectConverter(columns) {
  5026. return new Function("d", "return {" + columns.map(function(name, i) {
  5027. return JSON.stringify(name) + ": d[" + i + "] || \"\"";
  5028. }).join(",") + "}");
  5029. }
  5030. function customConverter(columns, f) {
  5031. var object = objectConverter(columns);
  5032. return function(row, i) {
  5033. return f(object(row), i, columns);
  5034. };
  5035. }
  5036. // Compute unique columns in order of discovery.
  5037. function inferColumns(rows) {
  5038. var columnSet = Object.create(null),
  5039. columns = [];
  5040. rows.forEach(function(row) {
  5041. for (var column in row) {
  5042. if (!(column in columnSet)) {
  5043. columns.push(columnSet[column] = column);
  5044. }
  5045. }
  5046. });
  5047. return columns;
  5048. }
  5049. function pad(value, width) {
  5050. var s = value + "", length = s.length;
  5051. return length < width ? new Array(width - length + 1).join(0) + s : s;
  5052. }
  5053. function formatYear(year) {
  5054. return year < 0 ? "-" + pad(-year, 6)
  5055. : year > 9999 ? "+" + pad(year, 6)
  5056. : pad(year, 4);
  5057. }
  5058. function formatDate(date) {
  5059. var hours = date.getUTCHours(),
  5060. minutes = date.getUTCMinutes(),
  5061. seconds = date.getUTCSeconds(),
  5062. milliseconds = date.getUTCMilliseconds();
  5063. return isNaN(date) ? "Invalid Date"
  5064. : formatYear(date.getUTCFullYear()) + "-" + pad(date.getUTCMonth() + 1, 2) + "-" + pad(date.getUTCDate(), 2)
  5065. + (milliseconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "." + pad(milliseconds, 3) + "Z"
  5066. : seconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "Z"
  5067. : minutes || hours ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + "Z"
  5068. : "");
  5069. }
  5070. function dsvFormat(delimiter) {
  5071. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  5072. DELIMITER = delimiter.charCodeAt(0);
  5073. function parse(text, f) {
  5074. var convert, columns, rows = parseRows(text, function(row, i) {
  5075. if (convert) return convert(row, i - 1);
  5076. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  5077. });
  5078. rows.columns = columns || [];
  5079. return rows;
  5080. }
  5081. function parseRows(text, f) {
  5082. var rows = [], // output rows
  5083. N = text.length,
  5084. I = 0, // current character index
  5085. n = 0, // current line number
  5086. t, // current token
  5087. eof = N <= 0, // current token followed by EOF?
  5088. eol = false; // current token followed by EOL?
  5089. // Strip the trailing newline.
  5090. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  5091. if (text.charCodeAt(N - 1) === RETURN) --N;
  5092. function token() {
  5093. if (eof) return EOF;
  5094. if (eol) return eol = false, EOL;
  5095. // Unescape quotes.
  5096. var i, j = I, c;
  5097. if (text.charCodeAt(j) === QUOTE) {
  5098. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  5099. if ((i = I) >= N) eof = true;
  5100. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  5101. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  5102. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  5103. }
  5104. // Find next delimiter or newline.
  5105. while (I < N) {
  5106. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  5107. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  5108. else if (c !== DELIMITER) continue;
  5109. return text.slice(j, i);
  5110. }
  5111. // Return last token before EOF.
  5112. return eof = true, text.slice(j, N);
  5113. }
  5114. while ((t = token()) !== EOF) {
  5115. var row = [];
  5116. while (t !== EOL && t !== EOF) row.push(t), t = token();
  5117. if (f && (row = f(row, n++)) == null) continue;
  5118. rows.push(row);
  5119. }
  5120. return rows;
  5121. }
  5122. function preformatBody(rows, columns) {
  5123. return rows.map(function(row) {
  5124. return columns.map(function(column) {
  5125. return formatValue(row[column]);
  5126. }).join(delimiter);
  5127. });
  5128. }
  5129. function format(rows, columns) {
  5130. if (columns == null) columns = inferColumns(rows);
  5131. return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
  5132. }
  5133. function formatBody(rows, columns) {
  5134. if (columns == null) columns = inferColumns(rows);
  5135. return preformatBody(rows, columns).join("\n");
  5136. }
  5137. function formatRows(rows) {
  5138. return rows.map(formatRow).join("\n");
  5139. }
  5140. function formatRow(row) {
  5141. return row.map(formatValue).join(delimiter);
  5142. }
  5143. function formatValue(value) {
  5144. return value == null ? ""
  5145. : value instanceof Date ? formatDate(value)
  5146. : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
  5147. : value;
  5148. }
  5149. return {
  5150. parse: parse,
  5151. parseRows: parseRows,
  5152. format: format,
  5153. formatBody: formatBody,
  5154. formatRows: formatRows,
  5155. formatRow: formatRow,
  5156. formatValue: formatValue
  5157. };
  5158. }
  5159. var csv = dsvFormat(",");
  5160. var csvParse = csv.parse;
  5161. var csvParseRows = csv.parseRows;
  5162. var csvFormat = csv.format;
  5163. var csvFormatBody = csv.formatBody;
  5164. var csvFormatRows = csv.formatRows;
  5165. var csvFormatRow = csv.formatRow;
  5166. var csvFormatValue = csv.formatValue;
  5167. var tsv = dsvFormat("\t");
  5168. var tsvParse = tsv.parse;
  5169. var tsvParseRows = tsv.parseRows;
  5170. var tsvFormat = tsv.format;
  5171. var tsvFormatBody = tsv.formatBody;
  5172. var tsvFormatRows = tsv.formatRows;
  5173. var tsvFormatRow = tsv.formatRow;
  5174. var tsvFormatValue = tsv.formatValue;
  5175. function autoType(object) {
  5176. for (var key in object) {
  5177. var value = object[key].trim(), number, m;
  5178. if (!value) value = null;
  5179. else if (value === "true") value = true;
  5180. else if (value === "false") value = false;
  5181. else if (value === "NaN") value = NaN;
  5182. else if (!isNaN(number = +value)) value = number;
  5183. else if (m = value.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)) {
  5184. if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
  5185. value = new Date(value);
  5186. }
  5187. else continue;
  5188. object[key] = value;
  5189. }
  5190. return object;
  5191. }
  5192. // https://github.com/d3/d3-dsv/issues/45
  5193. var fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
  5194. function responseBlob(response) {
  5195. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5196. return response.blob();
  5197. }
  5198. function blob(input, init) {
  5199. return fetch(input, init).then(responseBlob);
  5200. }
  5201. function responseArrayBuffer(response) {
  5202. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5203. return response.arrayBuffer();
  5204. }
  5205. function buffer(input, init) {
  5206. return fetch(input, init).then(responseArrayBuffer);
  5207. }
  5208. function responseText(response) {
  5209. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5210. return response.text();
  5211. }
  5212. function text(input, init) {
  5213. return fetch(input, init).then(responseText);
  5214. }
  5215. function dsvParse(parse) {
  5216. return function(input, init, row) {
  5217. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  5218. return text(input, init).then(function(response) {
  5219. return parse(response, row);
  5220. });
  5221. };
  5222. }
  5223. function dsv(delimiter, input, init, row) {
  5224. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  5225. var format = dsvFormat(delimiter);
  5226. return text(input, init).then(function(response) {
  5227. return format.parse(response, row);
  5228. });
  5229. }
  5230. var csv$1 = dsvParse(csvParse);
  5231. var tsv$1 = dsvParse(tsvParse);
  5232. function image(input, init) {
  5233. return new Promise(function(resolve, reject) {
  5234. var image = new Image;
  5235. for (var key in init) image[key] = init[key];
  5236. image.onerror = reject;
  5237. image.onload = function() { resolve(image); };
  5238. image.src = input;
  5239. });
  5240. }
  5241. function responseJson(response) {
  5242. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5243. return response.json();
  5244. }
  5245. function json(input, init) {
  5246. return fetch(input, init).then(responseJson);
  5247. }
  5248. function parser(type) {
  5249. return function(input, init) {
  5250. return text(input, init).then(function(text) {
  5251. return (new DOMParser).parseFromString(text, type);
  5252. });
  5253. };
  5254. }
  5255. var xml = parser("application/xml");
  5256. var html = parser("text/html");
  5257. var svg = parser("image/svg+xml");
  5258. function center$1(x, y) {
  5259. var nodes;
  5260. if (x == null) x = 0;
  5261. if (y == null) y = 0;
  5262. function force() {
  5263. var i,
  5264. n = nodes.length,
  5265. node,
  5266. sx = 0,
  5267. sy = 0;
  5268. for (i = 0; i < n; ++i) {
  5269. node = nodes[i], sx += node.x, sy += node.y;
  5270. }
  5271. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  5272. node = nodes[i], node.x -= sx, node.y -= sy;
  5273. }
  5274. }
  5275. force.initialize = function(_) {
  5276. nodes = _;
  5277. };
  5278. force.x = function(_) {
  5279. return arguments.length ? (x = +_, force) : x;
  5280. };
  5281. force.y = function(_) {
  5282. return arguments.length ? (y = +_, force) : y;
  5283. };
  5284. return force;
  5285. }
  5286. function constant$7(x) {
  5287. return function() {
  5288. return x;
  5289. };
  5290. }
  5291. function jiggle() {
  5292. return (Math.random() - 0.5) * 1e-6;
  5293. }
  5294. function tree_add(d) {
  5295. var x = +this._x.call(null, d),
  5296. y = +this._y.call(null, d);
  5297. return add(this.cover(x, y), x, y, d);
  5298. }
  5299. function add(tree, x, y, d) {
  5300. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  5301. var parent,
  5302. node = tree._root,
  5303. leaf = {data: d},
  5304. x0 = tree._x0,
  5305. y0 = tree._y0,
  5306. x1 = tree._x1,
  5307. y1 = tree._y1,
  5308. xm,
  5309. ym,
  5310. xp,
  5311. yp,
  5312. right,
  5313. bottom,
  5314. i,
  5315. j;
  5316. // If the tree is empty, initialize the root as a leaf.
  5317. if (!node) return tree._root = leaf, tree;
  5318. // Find the existing leaf for the new point, or add it.
  5319. while (node.length) {
  5320. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5321. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5322. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  5323. }
  5324. // Is the new point is exactly coincident with the existing point?
  5325. xp = +tree._x.call(null, node.data);
  5326. yp = +tree._y.call(null, node.data);
  5327. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  5328. // Otherwise, split the leaf node until the old and new point are separated.
  5329. do {
  5330. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  5331. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5332. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5333. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  5334. return parent[j] = node, parent[i] = leaf, tree;
  5335. }
  5336. function addAll(data) {
  5337. var d, i, n = data.length,
  5338. x,
  5339. y,
  5340. xz = new Array(n),
  5341. yz = new Array(n),
  5342. x0 = Infinity,
  5343. y0 = Infinity,
  5344. x1 = -Infinity,
  5345. y1 = -Infinity;
  5346. // Compute the points and their extent.
  5347. for (i = 0; i < n; ++i) {
  5348. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  5349. xz[i] = x;
  5350. yz[i] = y;
  5351. if (x < x0) x0 = x;
  5352. if (x > x1) x1 = x;
  5353. if (y < y0) y0 = y;
  5354. if (y > y1) y1 = y;
  5355. }
  5356. // If there were no (valid) points, abort.
  5357. if (x0 > x1 || y0 > y1) return this;
  5358. // Expand the tree to cover the new points.
  5359. this.cover(x0, y0).cover(x1, y1);
  5360. // Add the new points.
  5361. for (i = 0; i < n; ++i) {
  5362. add(this, xz[i], yz[i], data[i]);
  5363. }
  5364. return this;
  5365. }
  5366. function tree_cover(x, y) {
  5367. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  5368. var x0 = this._x0,
  5369. y0 = this._y0,
  5370. x1 = this._x1,
  5371. y1 = this._y1;
  5372. // If the quadtree has no extent, initialize them.
  5373. // Integer extent are necessary so that if we later double the extent,
  5374. // the existing quadrant boundaries don’t change due to floating point error!
  5375. if (isNaN(x0)) {
  5376. x1 = (x0 = Math.floor(x)) + 1;
  5377. y1 = (y0 = Math.floor(y)) + 1;
  5378. }
  5379. // Otherwise, double repeatedly to cover.
  5380. else {
  5381. var z = x1 - x0,
  5382. node = this._root,
  5383. parent,
  5384. i;
  5385. while (x0 > x || x >= x1 || y0 > y || y >= y1) {
  5386. i = (y < y0) << 1 | (x < x0);
  5387. parent = new Array(4), parent[i] = node, node = parent, z *= 2;
  5388. switch (i) {
  5389. case 0: x1 = x0 + z, y1 = y0 + z; break;
  5390. case 1: x0 = x1 - z, y1 = y0 + z; break;
  5391. case 2: x1 = x0 + z, y0 = y1 - z; break;
  5392. case 3: x0 = x1 - z, y0 = y1 - z; break;
  5393. }
  5394. }
  5395. if (this._root && this._root.length) this._root = node;
  5396. }
  5397. this._x0 = x0;
  5398. this._y0 = y0;
  5399. this._x1 = x1;
  5400. this._y1 = y1;
  5401. return this;
  5402. }
  5403. function tree_data() {
  5404. var data = [];
  5405. this.visit(function(node) {
  5406. if (!node.length) do data.push(node.data); while (node = node.next)
  5407. });
  5408. return data;
  5409. }
  5410. function tree_extent(_) {
  5411. return arguments.length
  5412. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  5413. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  5414. }
  5415. function Quad(node, x0, y0, x1, y1) {
  5416. this.node = node;
  5417. this.x0 = x0;
  5418. this.y0 = y0;
  5419. this.x1 = x1;
  5420. this.y1 = y1;
  5421. }
  5422. function tree_find(x, y, radius) {
  5423. var data,
  5424. x0 = this._x0,
  5425. y0 = this._y0,
  5426. x1,
  5427. y1,
  5428. x2,
  5429. y2,
  5430. x3 = this._x1,
  5431. y3 = this._y1,
  5432. quads = [],
  5433. node = this._root,
  5434. q,
  5435. i;
  5436. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  5437. if (radius == null) radius = Infinity;
  5438. else {
  5439. x0 = x - radius, y0 = y - radius;
  5440. x3 = x + radius, y3 = y + radius;
  5441. radius *= radius;
  5442. }
  5443. while (q = quads.pop()) {
  5444. // Stop searching if this quadrant can’t contain a closer node.
  5445. if (!(node = q.node)
  5446. || (x1 = q.x0) > x3
  5447. || (y1 = q.y0) > y3
  5448. || (x2 = q.x1) < x0
  5449. || (y2 = q.y1) < y0) continue;
  5450. // Bisect the current quadrant.
  5451. if (node.length) {
  5452. var xm = (x1 + x2) / 2,
  5453. ym = (y1 + y2) / 2;
  5454. quads.push(
  5455. new Quad(node[3], xm, ym, x2, y2),
  5456. new Quad(node[2], x1, ym, xm, y2),
  5457. new Quad(node[1], xm, y1, x2, ym),
  5458. new Quad(node[0], x1, y1, xm, ym)
  5459. );
  5460. // Visit the closest quadrant first.
  5461. if (i = (y >= ym) << 1 | (x >= xm)) {
  5462. q = quads[quads.length - 1];
  5463. quads[quads.length - 1] = quads[quads.length - 1 - i];
  5464. quads[quads.length - 1 - i] = q;
  5465. }
  5466. }
  5467. // Visit this point. (Visiting coincident points isn’t necessary!)
  5468. else {
  5469. var dx = x - +this._x.call(null, node.data),
  5470. dy = y - +this._y.call(null, node.data),
  5471. d2 = dx * dx + dy * dy;
  5472. if (d2 < radius) {
  5473. var d = Math.sqrt(radius = d2);
  5474. x0 = x - d, y0 = y - d;
  5475. x3 = x + d, y3 = y + d;
  5476. data = node.data;
  5477. }
  5478. }
  5479. }
  5480. return data;
  5481. }
  5482. function tree_remove(d) {
  5483. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  5484. var parent,
  5485. node = this._root,
  5486. retainer,
  5487. previous,
  5488. next,
  5489. x0 = this._x0,
  5490. y0 = this._y0,
  5491. x1 = this._x1,
  5492. y1 = this._y1,
  5493. x,
  5494. y,
  5495. xm,
  5496. ym,
  5497. right,
  5498. bottom,
  5499. i,
  5500. j;
  5501. // If the tree is empty, initialize the root as a leaf.
  5502. if (!node) return this;
  5503. // Find the leaf node for the point.
  5504. // While descending, also retain the deepest parent with a non-removed sibling.
  5505. if (node.length) while (true) {
  5506. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5507. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5508. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  5509. if (!node.length) break;
  5510. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  5511. }
  5512. // Find the point to remove.
  5513. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  5514. if (next = node.next) delete node.next;
  5515. // If there are multiple coincident points, remove just the point.
  5516. if (previous) return (next ? previous.next = next : delete previous.next), this;
  5517. // If this is the root point, remove it.
  5518. if (!parent) return this._root = next, this;
  5519. // Remove this leaf.
  5520. next ? parent[i] = next : delete parent[i];
  5521. // If the parent now contains exactly one leaf, collapse superfluous parents.
  5522. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  5523. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  5524. && !node.length) {
  5525. if (retainer) retainer[j] = node;
  5526. else this._root = node;
  5527. }
  5528. return this;
  5529. }
  5530. function removeAll(data) {
  5531. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  5532. return this;
  5533. }
  5534. function tree_root() {
  5535. return this._root;
  5536. }
  5537. function tree_size() {
  5538. var size = 0;
  5539. this.visit(function(node) {
  5540. if (!node.length) do ++size; while (node = node.next)
  5541. });
  5542. return size;
  5543. }
  5544. function tree_visit(callback) {
  5545. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  5546. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  5547. while (q = quads.pop()) {
  5548. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  5549. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5550. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5551. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5552. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5553. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5554. }
  5555. }
  5556. return this;
  5557. }
  5558. function tree_visitAfter(callback) {
  5559. var quads = [], next = [], q;
  5560. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  5561. while (q = quads.pop()) {
  5562. var node = q.node;
  5563. if (node.length) {
  5564. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5565. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5566. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5567. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5568. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5569. }
  5570. next.push(q);
  5571. }
  5572. while (q = next.pop()) {
  5573. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  5574. }
  5575. return this;
  5576. }
  5577. function defaultX$1(d) {
  5578. return d[0];
  5579. }
  5580. function tree_x(_) {
  5581. return arguments.length ? (this._x = _, this) : this._x;
  5582. }
  5583. function defaultY$1(d) {
  5584. return d[1];
  5585. }
  5586. function tree_y(_) {
  5587. return arguments.length ? (this._y = _, this) : this._y;
  5588. }
  5589. function quadtree(nodes, x, y) {
  5590. var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
  5591. return nodes == null ? tree : tree.addAll(nodes);
  5592. }
  5593. function Quadtree(x, y, x0, y0, x1, y1) {
  5594. this._x = x;
  5595. this._y = y;
  5596. this._x0 = x0;
  5597. this._y0 = y0;
  5598. this._x1 = x1;
  5599. this._y1 = y1;
  5600. this._root = undefined;
  5601. }
  5602. function leaf_copy(leaf) {
  5603. var copy = {data: leaf.data}, next = copy;
  5604. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  5605. return copy;
  5606. }
  5607. var treeProto = quadtree.prototype = Quadtree.prototype;
  5608. treeProto.copy = function() {
  5609. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  5610. node = this._root,
  5611. nodes,
  5612. child;
  5613. if (!node) return copy;
  5614. if (!node.length) return copy._root = leaf_copy(node), copy;
  5615. nodes = [{source: node, target: copy._root = new Array(4)}];
  5616. while (node = nodes.pop()) {
  5617. for (var i = 0; i < 4; ++i) {
  5618. if (child = node.source[i]) {
  5619. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  5620. else node.target[i] = leaf_copy(child);
  5621. }
  5622. }
  5623. }
  5624. return copy;
  5625. };
  5626. treeProto.add = tree_add;
  5627. treeProto.addAll = addAll;
  5628. treeProto.cover = tree_cover;
  5629. treeProto.data = tree_data;
  5630. treeProto.extent = tree_extent;
  5631. treeProto.find = tree_find;
  5632. treeProto.remove = tree_remove;
  5633. treeProto.removeAll = removeAll;
  5634. treeProto.root = tree_root;
  5635. treeProto.size = tree_size;
  5636. treeProto.visit = tree_visit;
  5637. treeProto.visitAfter = tree_visitAfter;
  5638. treeProto.x = tree_x;
  5639. treeProto.y = tree_y;
  5640. function x(d) {
  5641. return d.x + d.vx;
  5642. }
  5643. function y(d) {
  5644. return d.y + d.vy;
  5645. }
  5646. function collide(radius) {
  5647. var nodes,
  5648. radii,
  5649. strength = 1,
  5650. iterations = 1;
  5651. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  5652. function force() {
  5653. var i, n = nodes.length,
  5654. tree,
  5655. node,
  5656. xi,
  5657. yi,
  5658. ri,
  5659. ri2;
  5660. for (var k = 0; k < iterations; ++k) {
  5661. tree = quadtree(nodes, x, y).visitAfter(prepare);
  5662. for (i = 0; i < n; ++i) {
  5663. node = nodes[i];
  5664. ri = radii[node.index], ri2 = ri * ri;
  5665. xi = node.x + node.vx;
  5666. yi = node.y + node.vy;
  5667. tree.visit(apply);
  5668. }
  5669. }
  5670. function apply(quad, x0, y0, x1, y1) {
  5671. var data = quad.data, rj = quad.r, r = ri + rj;
  5672. if (data) {
  5673. if (data.index > node.index) {
  5674. var x = xi - data.x - data.vx,
  5675. y = yi - data.y - data.vy,
  5676. l = x * x + y * y;
  5677. if (l < r * r) {
  5678. if (x === 0) x = jiggle(), l += x * x;
  5679. if (y === 0) y = jiggle(), l += y * y;
  5680. l = (r - (l = Math.sqrt(l))) / l * strength;
  5681. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5682. node.vy += (y *= l) * r;
  5683. data.vx -= x * (r = 1 - r);
  5684. data.vy -= y * r;
  5685. }
  5686. }
  5687. return;
  5688. }
  5689. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5690. }
  5691. }
  5692. function prepare(quad) {
  5693. if (quad.data) return quad.r = radii[quad.data.index];
  5694. for (var i = quad.r = 0; i < 4; ++i) {
  5695. if (quad[i] && quad[i].r > quad.r) {
  5696. quad.r = quad[i].r;
  5697. }
  5698. }
  5699. }
  5700. function initialize() {
  5701. if (!nodes) return;
  5702. var i, n = nodes.length, node;
  5703. radii = new Array(n);
  5704. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5705. }
  5706. force.initialize = function(_) {
  5707. nodes = _;
  5708. initialize();
  5709. };
  5710. force.iterations = function(_) {
  5711. return arguments.length ? (iterations = +_, force) : iterations;
  5712. };
  5713. force.strength = function(_) {
  5714. return arguments.length ? (strength = +_, force) : strength;
  5715. };
  5716. force.radius = function(_) {
  5717. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5718. };
  5719. return force;
  5720. }
  5721. function index(d) {
  5722. return d.index;
  5723. }
  5724. function find(nodeById, nodeId) {
  5725. var node = nodeById.get(nodeId);
  5726. if (!node) throw new Error("missing: " + nodeId);
  5727. return node;
  5728. }
  5729. function link(links) {
  5730. var id = index,
  5731. strength = defaultStrength,
  5732. strengths,
  5733. distance = constant$7(30),
  5734. distances,
  5735. nodes,
  5736. count,
  5737. bias,
  5738. iterations = 1;
  5739. if (links == null) links = [];
  5740. function defaultStrength(link) {
  5741. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5742. }
  5743. function force(alpha) {
  5744. for (var k = 0, n = links.length; k < iterations; ++k) {
  5745. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5746. link = links[i], source = link.source, target = link.target;
  5747. x = target.x + target.vx - source.x - source.vx || jiggle();
  5748. y = target.y + target.vy - source.y - source.vy || jiggle();
  5749. l = Math.sqrt(x * x + y * y);
  5750. l = (l - distances[i]) / l * alpha * strengths[i];
  5751. x *= l, y *= l;
  5752. target.vx -= x * (b = bias[i]);
  5753. target.vy -= y * b;
  5754. source.vx += x * (b = 1 - b);
  5755. source.vy += y * b;
  5756. }
  5757. }
  5758. }
  5759. function initialize() {
  5760. if (!nodes) return;
  5761. var i,
  5762. n = nodes.length,
  5763. m = links.length,
  5764. nodeById = map$1(nodes, id),
  5765. link;
  5766. for (i = 0, count = new Array(n); i < m; ++i) {
  5767. link = links[i], link.index = i;
  5768. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5769. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5770. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5771. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5772. }
  5773. for (i = 0, bias = new Array(m); i < m; ++i) {
  5774. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5775. }
  5776. strengths = new Array(m), initializeStrength();
  5777. distances = new Array(m), initializeDistance();
  5778. }
  5779. function initializeStrength() {
  5780. if (!nodes) return;
  5781. for (var i = 0, n = links.length; i < n; ++i) {
  5782. strengths[i] = +strength(links[i], i, links);
  5783. }
  5784. }
  5785. function initializeDistance() {
  5786. if (!nodes) return;
  5787. for (var i = 0, n = links.length; i < n; ++i) {
  5788. distances[i] = +distance(links[i], i, links);
  5789. }
  5790. }
  5791. force.initialize = function(_) {
  5792. nodes = _;
  5793. initialize();
  5794. };
  5795. force.links = function(_) {
  5796. return arguments.length ? (links = _, initialize(), force) : links;
  5797. };
  5798. force.id = function(_) {
  5799. return arguments.length ? (id = _, force) : id;
  5800. };
  5801. force.iterations = function(_) {
  5802. return arguments.length ? (iterations = +_, force) : iterations;
  5803. };
  5804. force.strength = function(_) {
  5805. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  5806. };
  5807. force.distance = function(_) {
  5808. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  5809. };
  5810. return force;
  5811. }
  5812. function x$1(d) {
  5813. return d.x;
  5814. }
  5815. function y$1(d) {
  5816. return d.y;
  5817. }
  5818. var initialRadius = 10,
  5819. initialAngle = Math.PI * (3 - Math.sqrt(5));
  5820. function simulation(nodes) {
  5821. var simulation,
  5822. alpha = 1,
  5823. alphaMin = 0.001,
  5824. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5825. alphaTarget = 0,
  5826. velocityDecay = 0.6,
  5827. forces = map$1(),
  5828. stepper = timer(step),
  5829. event = dispatch("tick", "end");
  5830. if (nodes == null) nodes = [];
  5831. function step() {
  5832. tick();
  5833. event.call("tick", simulation);
  5834. if (alpha < alphaMin) {
  5835. stepper.stop();
  5836. event.call("end", simulation);
  5837. }
  5838. }
  5839. function tick(iterations) {
  5840. var i, n = nodes.length, node;
  5841. if (iterations === undefined) iterations = 1;
  5842. for (var k = 0; k < iterations; ++k) {
  5843. alpha += (alphaTarget - alpha) * alphaDecay;
  5844. forces.each(function (force) {
  5845. force(alpha);
  5846. });
  5847. for (i = 0; i < n; ++i) {
  5848. node = nodes[i];
  5849. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5850. else node.x = node.fx, node.vx = 0;
  5851. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5852. else node.y = node.fy, node.vy = 0;
  5853. }
  5854. }
  5855. return simulation;
  5856. }
  5857. function initializeNodes() {
  5858. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5859. node = nodes[i], node.index = i;
  5860. if (node.fx != null) node.x = node.fx;
  5861. if (node.fy != null) node.y = node.fy;
  5862. if (isNaN(node.x) || isNaN(node.y)) {
  5863. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5864. node.x = radius * Math.cos(angle);
  5865. node.y = radius * Math.sin(angle);
  5866. }
  5867. if (isNaN(node.vx) || isNaN(node.vy)) {
  5868. node.vx = node.vy = 0;
  5869. }
  5870. }
  5871. }
  5872. function initializeForce(force) {
  5873. if (force.initialize) force.initialize(nodes);
  5874. return force;
  5875. }
  5876. initializeNodes();
  5877. return simulation = {
  5878. tick: tick,
  5879. restart: function() {
  5880. return stepper.restart(step), simulation;
  5881. },
  5882. stop: function() {
  5883. return stepper.stop(), simulation;
  5884. },
  5885. nodes: function(_) {
  5886. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5887. },
  5888. alpha: function(_) {
  5889. return arguments.length ? (alpha = +_, simulation) : alpha;
  5890. },
  5891. alphaMin: function(_) {
  5892. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5893. },
  5894. alphaDecay: function(_) {
  5895. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5896. },
  5897. alphaTarget: function(_) {
  5898. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5899. },
  5900. velocityDecay: function(_) {
  5901. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5902. },
  5903. force: function(name, _) {
  5904. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  5905. },
  5906. find: function(x, y, radius) {
  5907. var i = 0,
  5908. n = nodes.length,
  5909. dx,
  5910. dy,
  5911. d2,
  5912. node,
  5913. closest;
  5914. if (radius == null) radius = Infinity;
  5915. else radius *= radius;
  5916. for (i = 0; i < n; ++i) {
  5917. node = nodes[i];
  5918. dx = x - node.x;
  5919. dy = y - node.y;
  5920. d2 = dx * dx + dy * dy;
  5921. if (d2 < radius) closest = node, radius = d2;
  5922. }
  5923. return closest;
  5924. },
  5925. on: function(name, _) {
  5926. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5927. }
  5928. };
  5929. }
  5930. function manyBody() {
  5931. var nodes,
  5932. node,
  5933. alpha,
  5934. strength = constant$7(-30),
  5935. strengths,
  5936. distanceMin2 = 1,
  5937. distanceMax2 = Infinity,
  5938. theta2 = 0.81;
  5939. function force(_) {
  5940. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5941. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5942. }
  5943. function initialize() {
  5944. if (!nodes) return;
  5945. var i, n = nodes.length, node;
  5946. strengths = new Array(n);
  5947. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5948. }
  5949. function accumulate(quad) {
  5950. var strength = 0, q, c, weight = 0, x, y, i;
  5951. // For internal nodes, accumulate forces from child quadrants.
  5952. if (quad.length) {
  5953. for (x = y = i = 0; i < 4; ++i) {
  5954. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5955. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5956. }
  5957. }
  5958. quad.x = x / weight;
  5959. quad.y = y / weight;
  5960. }
  5961. // For leaf nodes, accumulate forces from coincident quadrants.
  5962. else {
  5963. q = quad;
  5964. q.x = q.data.x;
  5965. q.y = q.data.y;
  5966. do strength += strengths[q.data.index];
  5967. while (q = q.next);
  5968. }
  5969. quad.value = strength;
  5970. }
  5971. function apply(quad, x1, _, x2) {
  5972. if (!quad.value) return true;
  5973. var x = quad.x - node.x,
  5974. y = quad.y - node.y,
  5975. w = x2 - x1,
  5976. l = x * x + y * y;
  5977. // Apply the Barnes-Hut approximation if possible.
  5978. // Limit forces for very close nodes; randomize direction if coincident.
  5979. if (w * w / theta2 < l) {
  5980. if (l < distanceMax2) {
  5981. if (x === 0) x = jiggle(), l += x * x;
  5982. if (y === 0) y = jiggle(), l += y * y;
  5983. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5984. node.vx += x * quad.value * alpha / l;
  5985. node.vy += y * quad.value * alpha / l;
  5986. }
  5987. return true;
  5988. }
  5989. // Otherwise, process points directly.
  5990. else if (quad.length || l >= distanceMax2) return;
  5991. // Limit forces for very close nodes; randomize direction if coincident.
  5992. if (quad.data !== node || quad.next) {
  5993. if (x === 0) x = jiggle(), l += x * x;
  5994. if (y === 0) y = jiggle(), l += y * y;
  5995. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5996. }
  5997. do if (quad.data !== node) {
  5998. w = strengths[quad.data.index] * alpha / l;
  5999. node.vx += x * w;
  6000. node.vy += y * w;
  6001. } while (quad = quad.next);
  6002. }
  6003. force.initialize = function(_) {
  6004. nodes = _;
  6005. initialize();
  6006. };
  6007. force.strength = function(_) {
  6008. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6009. };
  6010. force.distanceMin = function(_) {
  6011. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  6012. };
  6013. force.distanceMax = function(_) {
  6014. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  6015. };
  6016. force.theta = function(_) {
  6017. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  6018. };
  6019. return force;
  6020. }
  6021. function radial(radius, x, y) {
  6022. var nodes,
  6023. strength = constant$7(0.1),
  6024. strengths,
  6025. radiuses;
  6026. if (typeof radius !== "function") radius = constant$7(+radius);
  6027. if (x == null) x = 0;
  6028. if (y == null) y = 0;
  6029. function force(alpha) {
  6030. for (var i = 0, n = nodes.length; i < n; ++i) {
  6031. var node = nodes[i],
  6032. dx = node.x - x || 1e-6,
  6033. dy = node.y - y || 1e-6,
  6034. r = Math.sqrt(dx * dx + dy * dy),
  6035. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  6036. node.vx += dx * k;
  6037. node.vy += dy * k;
  6038. }
  6039. }
  6040. function initialize() {
  6041. if (!nodes) return;
  6042. var i, n = nodes.length;
  6043. strengths = new Array(n);
  6044. radiuses = new Array(n);
  6045. for (i = 0; i < n; ++i) {
  6046. radiuses[i] = +radius(nodes[i], i, nodes);
  6047. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  6048. }
  6049. }
  6050. force.initialize = function(_) {
  6051. nodes = _, initialize();
  6052. };
  6053. force.strength = function(_) {
  6054. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6055. };
  6056. force.radius = function(_) {
  6057. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  6058. };
  6059. force.x = function(_) {
  6060. return arguments.length ? (x = +_, force) : x;
  6061. };
  6062. force.y = function(_) {
  6063. return arguments.length ? (y = +_, force) : y;
  6064. };
  6065. return force;
  6066. }
  6067. function x$2(x) {
  6068. var strength = constant$7(0.1),
  6069. nodes,
  6070. strengths,
  6071. xz;
  6072. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  6073. function force(alpha) {
  6074. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  6075. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  6076. }
  6077. }
  6078. function initialize() {
  6079. if (!nodes) return;
  6080. var i, n = nodes.length;
  6081. strengths = new Array(n);
  6082. xz = new Array(n);
  6083. for (i = 0; i < n; ++i) {
  6084. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  6085. }
  6086. }
  6087. force.initialize = function(_) {
  6088. nodes = _;
  6089. initialize();
  6090. };
  6091. force.strength = function(_) {
  6092. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6093. };
  6094. force.x = function(_) {
  6095. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  6096. };
  6097. return force;
  6098. }
  6099. function y$2(y) {
  6100. var strength = constant$7(0.1),
  6101. nodes,
  6102. strengths,
  6103. yz;
  6104. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  6105. function force(alpha) {
  6106. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  6107. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  6108. }
  6109. }
  6110. function initialize() {
  6111. if (!nodes) return;
  6112. var i, n = nodes.length;
  6113. strengths = new Array(n);
  6114. yz = new Array(n);
  6115. for (i = 0; i < n; ++i) {
  6116. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  6117. }
  6118. }
  6119. force.initialize = function(_) {
  6120. nodes = _;
  6121. initialize();
  6122. };
  6123. force.strength = function(_) {
  6124. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6125. };
  6126. force.y = function(_) {
  6127. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  6128. };
  6129. return force;
  6130. }
  6131. // Computes the decimal coefficient and exponent of the specified number x with
  6132. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  6133. // For example, formatDecimal(1.23) returns ["123", 0].
  6134. function formatDecimal(x, p) {
  6135. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  6136. var i, coefficient = x.slice(0, i);
  6137. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  6138. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  6139. return [
  6140. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  6141. +x.slice(i + 1)
  6142. ];
  6143. }
  6144. function exponent$1(x) {
  6145. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  6146. }
  6147. function formatGroup(grouping, thousands) {
  6148. return function(value, width) {
  6149. var i = value.length,
  6150. t = [],
  6151. j = 0,
  6152. g = grouping[0],
  6153. length = 0;
  6154. while (i > 0 && g > 0) {
  6155. if (length + g + 1 > width) g = Math.max(1, width - length);
  6156. t.push(value.substring(i -= g, i + g));
  6157. if ((length += g + 1) > width) break;
  6158. g = grouping[j = (j + 1) % grouping.length];
  6159. }
  6160. return t.reverse().join(thousands);
  6161. };
  6162. }
  6163. function formatNumerals(numerals) {
  6164. return function(value) {
  6165. return value.replace(/[0-9]/g, function(i) {
  6166. return numerals[+i];
  6167. });
  6168. };
  6169. }
  6170. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  6171. var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  6172. function formatSpecifier(specifier) {
  6173. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  6174. var match;
  6175. return new FormatSpecifier({
  6176. fill: match[1],
  6177. align: match[2],
  6178. sign: match[3],
  6179. symbol: match[4],
  6180. zero: match[5],
  6181. width: match[6],
  6182. comma: match[7],
  6183. precision: match[8] && match[8].slice(1),
  6184. trim: match[9],
  6185. type: match[10]
  6186. });
  6187. }
  6188. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  6189. function FormatSpecifier(specifier) {
  6190. this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
  6191. this.align = specifier.align === undefined ? ">" : specifier.align + "";
  6192. this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
  6193. this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
  6194. this.zero = !!specifier.zero;
  6195. this.width = specifier.width === undefined ? undefined : +specifier.width;
  6196. this.comma = !!specifier.comma;
  6197. this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
  6198. this.trim = !!specifier.trim;
  6199. this.type = specifier.type === undefined ? "" : specifier.type + "";
  6200. }
  6201. FormatSpecifier.prototype.toString = function() {
  6202. return this.fill
  6203. + this.align
  6204. + this.sign
  6205. + this.symbol
  6206. + (this.zero ? "0" : "")
  6207. + (this.width === undefined ? "" : Math.max(1, this.width | 0))
  6208. + (this.comma ? "," : "")
  6209. + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
  6210. + (this.trim ? "~" : "")
  6211. + this.type;
  6212. };
  6213. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  6214. function formatTrim(s) {
  6215. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  6216. switch (s[i]) {
  6217. case ".": i0 = i1 = i; break;
  6218. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  6219. default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
  6220. }
  6221. }
  6222. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  6223. }
  6224. var prefixExponent;
  6225. function formatPrefixAuto(x, p) {
  6226. var d = formatDecimal(x, p);
  6227. if (!d) return x + "";
  6228. var coefficient = d[0],
  6229. exponent = d[1],
  6230. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  6231. n = coefficient.length;
  6232. return i === n ? coefficient
  6233. : i > n ? coefficient + new Array(i - n + 1).join("0")
  6234. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  6235. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  6236. }
  6237. function formatRounded(x, p) {
  6238. var d = formatDecimal(x, p);
  6239. if (!d) return x + "";
  6240. var coefficient = d[0],
  6241. exponent = d[1];
  6242. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  6243. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  6244. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  6245. }
  6246. var formatTypes = {
  6247. "%": function(x, p) { return (x * 100).toFixed(p); },
  6248. "b": function(x) { return Math.round(x).toString(2); },
  6249. "c": function(x) { return x + ""; },
  6250. "d": function(x) { return Math.round(x).toString(10); },
  6251. "e": function(x, p) { return x.toExponential(p); },
  6252. "f": function(x, p) { return x.toFixed(p); },
  6253. "g": function(x, p) { return x.toPrecision(p); },
  6254. "o": function(x) { return Math.round(x).toString(8); },
  6255. "p": function(x, p) { return formatRounded(x * 100, p); },
  6256. "r": formatRounded,
  6257. "s": formatPrefixAuto,
  6258. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  6259. "x": function(x) { return Math.round(x).toString(16); }
  6260. };
  6261. function identity$3(x) {
  6262. return x;
  6263. }
  6264. var map$2 = Array.prototype.map,
  6265. prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  6266. function formatLocale(locale) {
  6267. var group = locale.grouping === undefined || locale.thousands === undefined ? identity$3 : formatGroup(map$2.call(locale.grouping, Number), locale.thousands + ""),
  6268. currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
  6269. currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
  6270. decimal = locale.decimal === undefined ? "." : locale.decimal + "",
  6271. numerals = locale.numerals === undefined ? identity$3 : formatNumerals(map$2.call(locale.numerals, String)),
  6272. percent = locale.percent === undefined ? "%" : locale.percent + "",
  6273. minus = locale.minus === undefined ? "-" : locale.minus + "",
  6274. nan = locale.nan === undefined ? "NaN" : locale.nan + "";
  6275. function newFormat(specifier) {
  6276. specifier = formatSpecifier(specifier);
  6277. var fill = specifier.fill,
  6278. align = specifier.align,
  6279. sign = specifier.sign,
  6280. symbol = specifier.symbol,
  6281. zero = specifier.zero,
  6282. width = specifier.width,
  6283. comma = specifier.comma,
  6284. precision = specifier.precision,
  6285. trim = specifier.trim,
  6286. type = specifier.type;
  6287. // The "n" type is an alias for ",g".
  6288. if (type === "n") comma = true, type = "g";
  6289. // The "" type, and any invalid type, is an alias for ".12~g".
  6290. else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
  6291. // If zero fill is specified, padding goes after sign and before digits.
  6292. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  6293. // Compute the prefix and suffix.
  6294. // For SI-prefix, the suffix is lazily computed.
  6295. var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  6296. suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
  6297. // What format function should we use?
  6298. // Is this an integer type?
  6299. // Can this type generate exponential notation?
  6300. var formatType = formatTypes[type],
  6301. maybeSuffix = /[defgprs%]/.test(type);
  6302. // Set the default precision if not specified,
  6303. // or clamp the specified precision to the supported range.
  6304. // For significant precision, it must be in [1, 21].
  6305. // For fixed precision, it must be in [0, 20].
  6306. precision = precision === undefined ? 6
  6307. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  6308. : Math.max(0, Math.min(20, precision));
  6309. function format(value) {
  6310. var valuePrefix = prefix,
  6311. valueSuffix = suffix,
  6312. i, n, c;
  6313. if (type === "c") {
  6314. valueSuffix = formatType(value) + valueSuffix;
  6315. value = "";
  6316. } else {
  6317. value = +value;
  6318. // Perform the initial formatting.
  6319. var valueNegative = value < 0;
  6320. value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
  6321. // Trim insignificant zeros.
  6322. if (trim) value = formatTrim(value);
  6323. // If a negative value rounds to zero during formatting, treat as positive.
  6324. if (valueNegative && +value === 0) valueNegative = false;
  6325. // Compute the prefix and suffix.
  6326. valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  6327. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  6328. // Break the formatted value into the integer “value” part that can be
  6329. // grouped, and fractional or exponential “suffix” part that is not.
  6330. if (maybeSuffix) {
  6331. i = -1, n = value.length;
  6332. while (++i < n) {
  6333. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  6334. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  6335. value = value.slice(0, i);
  6336. break;
  6337. }
  6338. }
  6339. }
  6340. }
  6341. // If the fill character is not "0", grouping is applied before padding.
  6342. if (comma && !zero) value = group(value, Infinity);
  6343. // Compute the padding.
  6344. var length = valuePrefix.length + value.length + valueSuffix.length,
  6345. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  6346. // If the fill character is "0", grouping is applied after padding.
  6347. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  6348. // Reconstruct the final output based on the desired alignment.
  6349. switch (align) {
  6350. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  6351. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  6352. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  6353. default: value = padding + valuePrefix + value + valueSuffix; break;
  6354. }
  6355. return numerals(value);
  6356. }
  6357. format.toString = function() {
  6358. return specifier + "";
  6359. };
  6360. return format;
  6361. }
  6362. function formatPrefix(specifier, value) {
  6363. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  6364. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  6365. k = Math.pow(10, -e),
  6366. prefix = prefixes[8 + e / 3];
  6367. return function(value) {
  6368. return f(k * value) + prefix;
  6369. };
  6370. }
  6371. return {
  6372. format: newFormat,
  6373. formatPrefix: formatPrefix
  6374. };
  6375. }
  6376. var locale;
  6377. defaultLocale({
  6378. decimal: ".",
  6379. thousands: ",",
  6380. grouping: [3],
  6381. currency: ["$", ""],
  6382. minus: "-"
  6383. });
  6384. function defaultLocale(definition) {
  6385. locale = formatLocale(definition);
  6386. exports.format = locale.format;
  6387. exports.formatPrefix = locale.formatPrefix;
  6388. return locale;
  6389. }
  6390. function precisionFixed(step) {
  6391. return Math.max(0, -exponent$1(Math.abs(step)));
  6392. }
  6393. function precisionPrefix(step, value) {
  6394. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  6395. }
  6396. function precisionRound(step, max) {
  6397. step = Math.abs(step), max = Math.abs(max) - step;
  6398. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  6399. }
  6400. // Adds floating point numbers with twice the normal precision.
  6401. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  6402. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  6403. // 305–363 (1997).
  6404. // Code adapted from GeographicLib by Charles F. F. Karney,
  6405. // http://geographiclib.sourceforge.net/
  6406. function adder() {
  6407. return new Adder;
  6408. }
  6409. function Adder() {
  6410. this.reset();
  6411. }
  6412. Adder.prototype = {
  6413. constructor: Adder,
  6414. reset: function() {
  6415. this.s = // rounded value
  6416. this.t = 0; // exact error
  6417. },
  6418. add: function(y) {
  6419. add$1(temp, y, this.t);
  6420. add$1(this, temp.s, this.s);
  6421. if (this.s) this.t += temp.t;
  6422. else this.s = temp.t;
  6423. },
  6424. valueOf: function() {
  6425. return this.s;
  6426. }
  6427. };
  6428. var temp = new Adder;
  6429. function add$1(adder, a, b) {
  6430. var x = adder.s = a + b,
  6431. bv = x - a,
  6432. av = x - bv;
  6433. adder.t = (a - av) + (b - bv);
  6434. }
  6435. var epsilon$2 = 1e-6;
  6436. var epsilon2$1 = 1e-12;
  6437. var pi$3 = Math.PI;
  6438. var halfPi$2 = pi$3 / 2;
  6439. var quarterPi = pi$3 / 4;
  6440. var tau$3 = pi$3 * 2;
  6441. var degrees$1 = 180 / pi$3;
  6442. var radians = pi$3 / 180;
  6443. var abs = Math.abs;
  6444. var atan = Math.atan;
  6445. var atan2 = Math.atan2;
  6446. var cos$1 = Math.cos;
  6447. var ceil = Math.ceil;
  6448. var exp = Math.exp;
  6449. var log = Math.log;
  6450. var pow = Math.pow;
  6451. var sin$1 = Math.sin;
  6452. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  6453. var sqrt = Math.sqrt;
  6454. var tan = Math.tan;
  6455. function acos(x) {
  6456. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  6457. }
  6458. function asin(x) {
  6459. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  6460. }
  6461. function haversin(x) {
  6462. return (x = sin$1(x / 2)) * x;
  6463. }
  6464. function noop$2() {}
  6465. function streamGeometry(geometry, stream) {
  6466. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  6467. streamGeometryType[geometry.type](geometry, stream);
  6468. }
  6469. }
  6470. var streamObjectType = {
  6471. Feature: function(object, stream) {
  6472. streamGeometry(object.geometry, stream);
  6473. },
  6474. FeatureCollection: function(object, stream) {
  6475. var features = object.features, i = -1, n = features.length;
  6476. while (++i < n) streamGeometry(features[i].geometry, stream);
  6477. }
  6478. };
  6479. var streamGeometryType = {
  6480. Sphere: function(object, stream) {
  6481. stream.sphere();
  6482. },
  6483. Point: function(object, stream) {
  6484. object = object.coordinates;
  6485. stream.point(object[0], object[1], object[2]);
  6486. },
  6487. MultiPoint: function(object, stream) {
  6488. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6489. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  6490. },
  6491. LineString: function(object, stream) {
  6492. streamLine(object.coordinates, stream, 0);
  6493. },
  6494. MultiLineString: function(object, stream) {
  6495. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6496. while (++i < n) streamLine(coordinates[i], stream, 0);
  6497. },
  6498. Polygon: function(object, stream) {
  6499. streamPolygon(object.coordinates, stream);
  6500. },
  6501. MultiPolygon: function(object, stream) {
  6502. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6503. while (++i < n) streamPolygon(coordinates[i], stream);
  6504. },
  6505. GeometryCollection: function(object, stream) {
  6506. var geometries = object.geometries, i = -1, n = geometries.length;
  6507. while (++i < n) streamGeometry(geometries[i], stream);
  6508. }
  6509. };
  6510. function streamLine(coordinates, stream, closed) {
  6511. var i = -1, n = coordinates.length - closed, coordinate;
  6512. stream.lineStart();
  6513. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  6514. stream.lineEnd();
  6515. }
  6516. function streamPolygon(coordinates, stream) {
  6517. var i = -1, n = coordinates.length;
  6518. stream.polygonStart();
  6519. while (++i < n) streamLine(coordinates[i], stream, 1);
  6520. stream.polygonEnd();
  6521. }
  6522. function geoStream(object, stream) {
  6523. if (object && streamObjectType.hasOwnProperty(object.type)) {
  6524. streamObjectType[object.type](object, stream);
  6525. } else {
  6526. streamGeometry(object, stream);
  6527. }
  6528. }
  6529. var areaRingSum = adder();
  6530. var areaSum = adder(),
  6531. lambda00,
  6532. phi00,
  6533. lambda0,
  6534. cosPhi0,
  6535. sinPhi0;
  6536. var areaStream = {
  6537. point: noop$2,
  6538. lineStart: noop$2,
  6539. lineEnd: noop$2,
  6540. polygonStart: function() {
  6541. areaRingSum.reset();
  6542. areaStream.lineStart = areaRingStart;
  6543. areaStream.lineEnd = areaRingEnd;
  6544. },
  6545. polygonEnd: function() {
  6546. var areaRing = +areaRingSum;
  6547. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  6548. this.lineStart = this.lineEnd = this.point = noop$2;
  6549. },
  6550. sphere: function() {
  6551. areaSum.add(tau$3);
  6552. }
  6553. };
  6554. function areaRingStart() {
  6555. areaStream.point = areaPointFirst;
  6556. }
  6557. function areaRingEnd() {
  6558. areaPoint(lambda00, phi00);
  6559. }
  6560. function areaPointFirst(lambda, phi) {
  6561. areaStream.point = areaPoint;
  6562. lambda00 = lambda, phi00 = phi;
  6563. lambda *= radians, phi *= radians;
  6564. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  6565. }
  6566. function areaPoint(lambda, phi) {
  6567. lambda *= radians, phi *= radians;
  6568. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  6569. // Spherical excess E for a spherical triangle with vertices: south pole,
  6570. // previous point, current point. Uses a formula derived from Cagnoli’s
  6571. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  6572. var dLambda = lambda - lambda0,
  6573. sdLambda = dLambda >= 0 ? 1 : -1,
  6574. adLambda = sdLambda * dLambda,
  6575. cosPhi = cos$1(phi),
  6576. sinPhi = sin$1(phi),
  6577. k = sinPhi0 * sinPhi,
  6578. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  6579. v = k * sdLambda * sin$1(adLambda);
  6580. areaRingSum.add(atan2(v, u));
  6581. // Advance the previous points.
  6582. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  6583. }
  6584. function area$1(object) {
  6585. areaSum.reset();
  6586. geoStream(object, areaStream);
  6587. return areaSum * 2;
  6588. }
  6589. function spherical(cartesian) {
  6590. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  6591. }
  6592. function cartesian(spherical) {
  6593. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  6594. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  6595. }
  6596. function cartesianDot(a, b) {
  6597. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6598. }
  6599. function cartesianCross(a, b) {
  6600. 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]];
  6601. }
  6602. // TODO return a
  6603. function cartesianAddInPlace(a, b) {
  6604. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  6605. }
  6606. function cartesianScale(vector, k) {
  6607. return [vector[0] * k, vector[1] * k, vector[2] * k];
  6608. }
  6609. // TODO return d
  6610. function cartesianNormalizeInPlace(d) {
  6611. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  6612. d[0] /= l, d[1] /= l, d[2] /= l;
  6613. }
  6614. var lambda0$1, phi0, lambda1, phi1, // bounds
  6615. lambda2, // previous lambda-coordinate
  6616. lambda00$1, phi00$1, // first point
  6617. p0, // previous 3D point
  6618. deltaSum = adder(),
  6619. ranges,
  6620. range;
  6621. var boundsStream = {
  6622. point: boundsPoint,
  6623. lineStart: boundsLineStart,
  6624. lineEnd: boundsLineEnd,
  6625. polygonStart: function() {
  6626. boundsStream.point = boundsRingPoint;
  6627. boundsStream.lineStart = boundsRingStart;
  6628. boundsStream.lineEnd = boundsRingEnd;
  6629. deltaSum.reset();
  6630. areaStream.polygonStart();
  6631. },
  6632. polygonEnd: function() {
  6633. areaStream.polygonEnd();
  6634. boundsStream.point = boundsPoint;
  6635. boundsStream.lineStart = boundsLineStart;
  6636. boundsStream.lineEnd = boundsLineEnd;
  6637. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6638. else if (deltaSum > epsilon$2) phi1 = 90;
  6639. else if (deltaSum < -epsilon$2) phi0 = -90;
  6640. range[0] = lambda0$1, range[1] = lambda1;
  6641. },
  6642. sphere: function() {
  6643. lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6644. }
  6645. };
  6646. function boundsPoint(lambda, phi) {
  6647. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6648. if (phi < phi0) phi0 = phi;
  6649. if (phi > phi1) phi1 = phi;
  6650. }
  6651. function linePoint(lambda, phi) {
  6652. var p = cartesian([lambda * radians, phi * radians]);
  6653. if (p0) {
  6654. var normal = cartesianCross(p0, p),
  6655. equatorial = [normal[1], -normal[0], 0],
  6656. inflection = cartesianCross(equatorial, normal);
  6657. cartesianNormalizeInPlace(inflection);
  6658. inflection = spherical(inflection);
  6659. var delta = lambda - lambda2,
  6660. sign = delta > 0 ? 1 : -1,
  6661. lambdai = inflection[0] * degrees$1 * sign,
  6662. phii,
  6663. antimeridian = abs(delta) > 180;
  6664. if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  6665. phii = inflection[1] * degrees$1;
  6666. if (phii > phi1) phi1 = phii;
  6667. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  6668. phii = -inflection[1] * degrees$1;
  6669. if (phii < phi0) phi0 = phii;
  6670. } else {
  6671. if (phi < phi0) phi0 = phi;
  6672. if (phi > phi1) phi1 = phi;
  6673. }
  6674. if (antimeridian) {
  6675. if (lambda < lambda2) {
  6676. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6677. } else {
  6678. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6679. }
  6680. } else {
  6681. if (lambda1 >= lambda0$1) {
  6682. if (lambda < lambda0$1) lambda0$1 = lambda;
  6683. if (lambda > lambda1) lambda1 = lambda;
  6684. } else {
  6685. if (lambda > lambda2) {
  6686. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6687. } else {
  6688. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6689. }
  6690. }
  6691. }
  6692. } else {
  6693. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6694. }
  6695. if (phi < phi0) phi0 = phi;
  6696. if (phi > phi1) phi1 = phi;
  6697. p0 = p, lambda2 = lambda;
  6698. }
  6699. function boundsLineStart() {
  6700. boundsStream.point = linePoint;
  6701. }
  6702. function boundsLineEnd() {
  6703. range[0] = lambda0$1, range[1] = lambda1;
  6704. boundsStream.point = boundsPoint;
  6705. p0 = null;
  6706. }
  6707. function boundsRingPoint(lambda, phi) {
  6708. if (p0) {
  6709. var delta = lambda - lambda2;
  6710. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6711. } else {
  6712. lambda00$1 = lambda, phi00$1 = phi;
  6713. }
  6714. areaStream.point(lambda, phi);
  6715. linePoint(lambda, phi);
  6716. }
  6717. function boundsRingStart() {
  6718. areaStream.lineStart();
  6719. }
  6720. function boundsRingEnd() {
  6721. boundsRingPoint(lambda00$1, phi00$1);
  6722. areaStream.lineEnd();
  6723. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6724. range[0] = lambda0$1, range[1] = lambda1;
  6725. p0 = null;
  6726. }
  6727. // Finds the left-right distance between two longitudes.
  6728. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6729. // the distance between ±180° to be 360°.
  6730. function angle(lambda0, lambda1) {
  6731. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6732. }
  6733. function rangeCompare(a, b) {
  6734. return a[0] - b[0];
  6735. }
  6736. function rangeContains(range, x) {
  6737. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6738. }
  6739. function bounds(feature) {
  6740. var i, n, a, b, merged, deltaMax, delta;
  6741. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6742. ranges = [];
  6743. geoStream(feature, boundsStream);
  6744. // First, sort ranges by their minimum longitudes.
  6745. if (n = ranges.length) {
  6746. ranges.sort(rangeCompare);
  6747. // Then, merge any ranges that overlap.
  6748. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6749. b = ranges[i];
  6750. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6751. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6752. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6753. } else {
  6754. merged.push(a = b);
  6755. }
  6756. }
  6757. // Finally, find the largest gap between the merged ranges.
  6758. // The final bounding box will be the inverse of this gap.
  6759. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6760. b = merged[i];
  6761. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6762. }
  6763. }
  6764. ranges = range = null;
  6765. return lambda0$1 === Infinity || phi0 === Infinity
  6766. ? [[NaN, NaN], [NaN, NaN]]
  6767. : [[lambda0$1, phi0], [lambda1, phi1]];
  6768. }
  6769. var W0, W1,
  6770. X0, Y0, Z0,
  6771. X1, Y1, Z1,
  6772. X2, Y2, Z2,
  6773. lambda00$2, phi00$2, // first point
  6774. x0, y0, z0; // previous point
  6775. var centroidStream = {
  6776. sphere: noop$2,
  6777. point: centroidPoint,
  6778. lineStart: centroidLineStart,
  6779. lineEnd: centroidLineEnd,
  6780. polygonStart: function() {
  6781. centroidStream.lineStart = centroidRingStart;
  6782. centroidStream.lineEnd = centroidRingEnd;
  6783. },
  6784. polygonEnd: function() {
  6785. centroidStream.lineStart = centroidLineStart;
  6786. centroidStream.lineEnd = centroidLineEnd;
  6787. }
  6788. };
  6789. // Arithmetic mean of Cartesian vectors.
  6790. function centroidPoint(lambda, phi) {
  6791. lambda *= radians, phi *= radians;
  6792. var cosPhi = cos$1(phi);
  6793. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6794. }
  6795. function centroidPointCartesian(x, y, z) {
  6796. ++W0;
  6797. X0 += (x - X0) / W0;
  6798. Y0 += (y - Y0) / W0;
  6799. Z0 += (z - Z0) / W0;
  6800. }
  6801. function centroidLineStart() {
  6802. centroidStream.point = centroidLinePointFirst;
  6803. }
  6804. function centroidLinePointFirst(lambda, phi) {
  6805. lambda *= radians, phi *= radians;
  6806. var cosPhi = cos$1(phi);
  6807. x0 = cosPhi * cos$1(lambda);
  6808. y0 = cosPhi * sin$1(lambda);
  6809. z0 = sin$1(phi);
  6810. centroidStream.point = centroidLinePoint;
  6811. centroidPointCartesian(x0, y0, z0);
  6812. }
  6813. function centroidLinePoint(lambda, phi) {
  6814. lambda *= radians, phi *= radians;
  6815. var cosPhi = cos$1(phi),
  6816. x = cosPhi * cos$1(lambda),
  6817. y = cosPhi * sin$1(lambda),
  6818. z = sin$1(phi),
  6819. 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);
  6820. W1 += w;
  6821. X1 += w * (x0 + (x0 = x));
  6822. Y1 += w * (y0 + (y0 = y));
  6823. Z1 += w * (z0 + (z0 = z));
  6824. centroidPointCartesian(x0, y0, z0);
  6825. }
  6826. function centroidLineEnd() {
  6827. centroidStream.point = centroidPoint;
  6828. }
  6829. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6830. // J. Applied Mechanics 42, 239 (1975).
  6831. function centroidRingStart() {
  6832. centroidStream.point = centroidRingPointFirst;
  6833. }
  6834. function centroidRingEnd() {
  6835. centroidRingPoint(lambda00$2, phi00$2);
  6836. centroidStream.point = centroidPoint;
  6837. }
  6838. function centroidRingPointFirst(lambda, phi) {
  6839. lambda00$2 = lambda, phi00$2 = phi;
  6840. lambda *= radians, phi *= radians;
  6841. centroidStream.point = centroidRingPoint;
  6842. var cosPhi = cos$1(phi);
  6843. x0 = cosPhi * cos$1(lambda);
  6844. y0 = cosPhi * sin$1(lambda);
  6845. z0 = sin$1(phi);
  6846. centroidPointCartesian(x0, y0, z0);
  6847. }
  6848. function centroidRingPoint(lambda, phi) {
  6849. lambda *= radians, phi *= radians;
  6850. var cosPhi = cos$1(phi),
  6851. x = cosPhi * cos$1(lambda),
  6852. y = cosPhi * sin$1(lambda),
  6853. z = sin$1(phi),
  6854. cx = y0 * z - z0 * y,
  6855. cy = z0 * x - x0 * z,
  6856. cz = x0 * y - y0 * x,
  6857. m = sqrt(cx * cx + cy * cy + cz * cz),
  6858. w = asin(m), // line weight = angle
  6859. v = m && -w / m; // area weight multiplier
  6860. X2 += v * cx;
  6861. Y2 += v * cy;
  6862. Z2 += v * cz;
  6863. W1 += w;
  6864. X1 += w * (x0 + (x0 = x));
  6865. Y1 += w * (y0 + (y0 = y));
  6866. Z1 += w * (z0 + (z0 = z));
  6867. centroidPointCartesian(x0, y0, z0);
  6868. }
  6869. function centroid(object) {
  6870. W0 = W1 =
  6871. X0 = Y0 = Z0 =
  6872. X1 = Y1 = Z1 =
  6873. X2 = Y2 = Z2 = 0;
  6874. geoStream(object, centroidStream);
  6875. var x = X2,
  6876. y = Y2,
  6877. z = Z2,
  6878. m = x * x + y * y + z * z;
  6879. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6880. if (m < epsilon2$1) {
  6881. x = X1, y = Y1, z = Z1;
  6882. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6883. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6884. m = x * x + y * y + z * z;
  6885. // If the feature still has an undefined ccentroid, then return.
  6886. if (m < epsilon2$1) return [NaN, NaN];
  6887. }
  6888. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6889. }
  6890. function constant$8(x) {
  6891. return function() {
  6892. return x;
  6893. };
  6894. }
  6895. function compose(a, b) {
  6896. function compose(x, y) {
  6897. return x = a(x, y), b(x[0], x[1]);
  6898. }
  6899. if (a.invert && b.invert) compose.invert = function(x, y) {
  6900. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6901. };
  6902. return compose;
  6903. }
  6904. function rotationIdentity(lambda, phi) {
  6905. return [abs(lambda) > pi$3 ? lambda + Math.round(-lambda / tau$3) * tau$3 : lambda, phi];
  6906. }
  6907. rotationIdentity.invert = rotationIdentity;
  6908. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6909. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6910. : rotationLambda(deltaLambda))
  6911. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6912. : rotationIdentity);
  6913. }
  6914. function forwardRotationLambda(deltaLambda) {
  6915. return function(lambda, phi) {
  6916. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6917. };
  6918. }
  6919. function rotationLambda(deltaLambda) {
  6920. var rotation = forwardRotationLambda(deltaLambda);
  6921. rotation.invert = forwardRotationLambda(-deltaLambda);
  6922. return rotation;
  6923. }
  6924. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6925. var cosDeltaPhi = cos$1(deltaPhi),
  6926. sinDeltaPhi = sin$1(deltaPhi),
  6927. cosDeltaGamma = cos$1(deltaGamma),
  6928. sinDeltaGamma = sin$1(deltaGamma);
  6929. function rotation(lambda, phi) {
  6930. var cosPhi = cos$1(phi),
  6931. x = cos$1(lambda) * cosPhi,
  6932. y = sin$1(lambda) * cosPhi,
  6933. z = sin$1(phi),
  6934. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6935. return [
  6936. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6937. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6938. ];
  6939. }
  6940. rotation.invert = function(lambda, phi) {
  6941. var cosPhi = cos$1(phi),
  6942. x = cos$1(lambda) * cosPhi,
  6943. y = sin$1(lambda) * cosPhi,
  6944. z = sin$1(phi),
  6945. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6946. return [
  6947. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6948. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6949. ];
  6950. };
  6951. return rotation;
  6952. }
  6953. function rotation(rotate) {
  6954. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6955. function forward(coordinates) {
  6956. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6957. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6958. }
  6959. forward.invert = function(coordinates) {
  6960. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6961. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6962. };
  6963. return forward;
  6964. }
  6965. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6966. function circleStream(stream, radius, delta, direction, t0, t1) {
  6967. if (!delta) return;
  6968. var cosRadius = cos$1(radius),
  6969. sinRadius = sin$1(radius),
  6970. step = direction * delta;
  6971. if (t0 == null) {
  6972. t0 = radius + direction * tau$3;
  6973. t1 = radius - step / 2;
  6974. } else {
  6975. t0 = circleRadius(cosRadius, t0);
  6976. t1 = circleRadius(cosRadius, t1);
  6977. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6978. }
  6979. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6980. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6981. stream.point(point[0], point[1]);
  6982. }
  6983. }
  6984. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6985. function circleRadius(cosRadius, point) {
  6986. point = cartesian(point), point[0] -= cosRadius;
  6987. cartesianNormalizeInPlace(point);
  6988. var radius = acos(-point[1]);
  6989. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6990. }
  6991. function circle() {
  6992. var center = constant$8([0, 0]),
  6993. radius = constant$8(90),
  6994. precision = constant$8(6),
  6995. ring,
  6996. rotate,
  6997. stream = {point: point};
  6998. function point(x, y) {
  6999. ring.push(x = rotate(x, y));
  7000. x[0] *= degrees$1, x[1] *= degrees$1;
  7001. }
  7002. function circle() {
  7003. var c = center.apply(this, arguments),
  7004. r = radius.apply(this, arguments) * radians,
  7005. p = precision.apply(this, arguments) * radians;
  7006. ring = [];
  7007. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  7008. circleStream(stream, r, p, 1);
  7009. c = {type: "Polygon", coordinates: [ring]};
  7010. ring = rotate = null;
  7011. return c;
  7012. }
  7013. circle.center = function(_) {
  7014. return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
  7015. };
  7016. circle.radius = function(_) {
  7017. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
  7018. };
  7019. circle.precision = function(_) {
  7020. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
  7021. };
  7022. return circle;
  7023. }
  7024. function clipBuffer() {
  7025. var lines = [],
  7026. line;
  7027. return {
  7028. point: function(x, y) {
  7029. line.push([x, y]);
  7030. },
  7031. lineStart: function() {
  7032. lines.push(line = []);
  7033. },
  7034. lineEnd: noop$2,
  7035. rejoin: function() {
  7036. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  7037. },
  7038. result: function() {
  7039. var result = lines;
  7040. lines = [];
  7041. line = null;
  7042. return result;
  7043. }
  7044. };
  7045. }
  7046. function pointEqual(a, b) {
  7047. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  7048. }
  7049. function Intersection(point, points, other, entry) {
  7050. this.x = point;
  7051. this.z = points;
  7052. this.o = other; // another intersection
  7053. this.e = entry; // is an entry?
  7054. this.v = false; // visited
  7055. this.n = this.p = null; // next & previous
  7056. }
  7057. // A generalized polygon clipping algorithm: given a polygon that has been cut
  7058. // into its visible line segments, and rejoins the segments by interpolating
  7059. // along the clip edge.
  7060. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  7061. var subject = [],
  7062. clip = [],
  7063. i,
  7064. n;
  7065. segments.forEach(function(segment) {
  7066. if ((n = segment.length - 1) <= 0) return;
  7067. var n, p0 = segment[0], p1 = segment[n], x;
  7068. // If the first and last points of a segment are coincident, then treat as a
  7069. // closed ring. TODO if all rings are closed, then the winding order of the
  7070. // exterior ring should be checked.
  7071. if (pointEqual(p0, p1)) {
  7072. stream.lineStart();
  7073. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  7074. stream.lineEnd();
  7075. return;
  7076. }
  7077. subject.push(x = new Intersection(p0, segment, null, true));
  7078. clip.push(x.o = new Intersection(p0, null, x, false));
  7079. subject.push(x = new Intersection(p1, segment, null, false));
  7080. clip.push(x.o = new Intersection(p1, null, x, true));
  7081. });
  7082. if (!subject.length) return;
  7083. clip.sort(compareIntersection);
  7084. link$1(subject);
  7085. link$1(clip);
  7086. for (i = 0, n = clip.length; i < n; ++i) {
  7087. clip[i].e = startInside = !startInside;
  7088. }
  7089. var start = subject[0],
  7090. points,
  7091. point;
  7092. while (1) {
  7093. // Find first unvisited intersection.
  7094. var current = start,
  7095. isSubject = true;
  7096. while (current.v) if ((current = current.n) === start) return;
  7097. points = current.z;
  7098. stream.lineStart();
  7099. do {
  7100. current.v = current.o.v = true;
  7101. if (current.e) {
  7102. if (isSubject) {
  7103. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  7104. } else {
  7105. interpolate(current.x, current.n.x, 1, stream);
  7106. }
  7107. current = current.n;
  7108. } else {
  7109. if (isSubject) {
  7110. points = current.p.z;
  7111. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  7112. } else {
  7113. interpolate(current.x, current.p.x, -1, stream);
  7114. }
  7115. current = current.p;
  7116. }
  7117. current = current.o;
  7118. points = current.z;
  7119. isSubject = !isSubject;
  7120. } while (!current.v);
  7121. stream.lineEnd();
  7122. }
  7123. }
  7124. function link$1(array) {
  7125. if (!(n = array.length)) return;
  7126. var n,
  7127. i = 0,
  7128. a = array[0],
  7129. b;
  7130. while (++i < n) {
  7131. a.n = b = array[i];
  7132. b.p = a;
  7133. a = b;
  7134. }
  7135. a.n = b = array[0];
  7136. b.p = a;
  7137. }
  7138. var sum$1 = adder();
  7139. function longitude(point) {
  7140. if (abs(point[0]) <= pi$3)
  7141. return point[0];
  7142. else
  7143. return sign(point[0]) * ((abs(point[0]) + pi$3) % tau$3 - pi$3);
  7144. }
  7145. function polygonContains(polygon, point) {
  7146. var lambda = longitude(point),
  7147. phi = point[1],
  7148. sinPhi = sin$1(phi),
  7149. normal = [sin$1(lambda), -cos$1(lambda), 0],
  7150. angle = 0,
  7151. winding = 0;
  7152. sum$1.reset();
  7153. if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
  7154. else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
  7155. for (var i = 0, n = polygon.length; i < n; ++i) {
  7156. if (!(m = (ring = polygon[i]).length)) continue;
  7157. var ring,
  7158. m,
  7159. point0 = ring[m - 1],
  7160. lambda0 = longitude(point0),
  7161. phi0 = point0[1] / 2 + quarterPi,
  7162. sinPhi0 = sin$1(phi0),
  7163. cosPhi0 = cos$1(phi0);
  7164. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  7165. var point1 = ring[j],
  7166. lambda1 = longitude(point1),
  7167. phi1 = point1[1] / 2 + quarterPi,
  7168. sinPhi1 = sin$1(phi1),
  7169. cosPhi1 = cos$1(phi1),
  7170. delta = lambda1 - lambda0,
  7171. sign = delta >= 0 ? 1 : -1,
  7172. absDelta = sign * delta,
  7173. antimeridian = absDelta > pi$3,
  7174. k = sinPhi0 * sinPhi1;
  7175. sum$1.add(atan2(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  7176. angle += antimeridian ? delta + sign * tau$3 : delta;
  7177. // Are the longitudes either side of the point’s meridian (lambda),
  7178. // and are the latitudes smaller than the parallel (phi)?
  7179. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  7180. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  7181. cartesianNormalizeInPlace(arc);
  7182. var intersection = cartesianCross(normal, arc);
  7183. cartesianNormalizeInPlace(intersection);
  7184. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  7185. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  7186. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  7187. }
  7188. }
  7189. }
  7190. }
  7191. // First, determine whether the South pole is inside or outside:
  7192. //
  7193. // It is inside if:
  7194. // * the polygon winds around it in a clockwise direction.
  7195. // * the polygon does not (cumulatively) wind around it, but has a negative
  7196. // (counter-clockwise) area.
  7197. //
  7198. // Second, count the (signed) number of times a segment crosses a lambda
  7199. // from the point to the South pole. If it is zero, then the point is the
  7200. // same side as the South pole.
  7201. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  7202. }
  7203. function clip(pointVisible, clipLine, interpolate, start) {
  7204. return function(sink) {
  7205. var line = clipLine(sink),
  7206. ringBuffer = clipBuffer(),
  7207. ringSink = clipLine(ringBuffer),
  7208. polygonStarted = false,
  7209. polygon,
  7210. segments,
  7211. ring;
  7212. var clip = {
  7213. point: point,
  7214. lineStart: lineStart,
  7215. lineEnd: lineEnd,
  7216. polygonStart: function() {
  7217. clip.point = pointRing;
  7218. clip.lineStart = ringStart;
  7219. clip.lineEnd = ringEnd;
  7220. segments = [];
  7221. polygon = [];
  7222. },
  7223. polygonEnd: function() {
  7224. clip.point = point;
  7225. clip.lineStart = lineStart;
  7226. clip.lineEnd = lineEnd;
  7227. segments = merge(segments);
  7228. var startInside = polygonContains(polygon, start);
  7229. if (segments.length) {
  7230. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7231. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  7232. } else if (startInside) {
  7233. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7234. sink.lineStart();
  7235. interpolate(null, null, 1, sink);
  7236. sink.lineEnd();
  7237. }
  7238. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  7239. segments = polygon = null;
  7240. },
  7241. sphere: function() {
  7242. sink.polygonStart();
  7243. sink.lineStart();
  7244. interpolate(null, null, 1, sink);
  7245. sink.lineEnd();
  7246. sink.polygonEnd();
  7247. }
  7248. };
  7249. function point(lambda, phi) {
  7250. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  7251. }
  7252. function pointLine(lambda, phi) {
  7253. line.point(lambda, phi);
  7254. }
  7255. function lineStart() {
  7256. clip.point = pointLine;
  7257. line.lineStart();
  7258. }
  7259. function lineEnd() {
  7260. clip.point = point;
  7261. line.lineEnd();
  7262. }
  7263. function pointRing(lambda, phi) {
  7264. ring.push([lambda, phi]);
  7265. ringSink.point(lambda, phi);
  7266. }
  7267. function ringStart() {
  7268. ringSink.lineStart();
  7269. ring = [];
  7270. }
  7271. function ringEnd() {
  7272. pointRing(ring[0][0], ring[0][1]);
  7273. ringSink.lineEnd();
  7274. var clean = ringSink.clean(),
  7275. ringSegments = ringBuffer.result(),
  7276. i, n = ringSegments.length, m,
  7277. segment,
  7278. point;
  7279. ring.pop();
  7280. polygon.push(ring);
  7281. ring = null;
  7282. if (!n) return;
  7283. // No intersections.
  7284. if (clean & 1) {
  7285. segment = ringSegments[0];
  7286. if ((m = segment.length - 1) > 0) {
  7287. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7288. sink.lineStart();
  7289. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7290. sink.lineEnd();
  7291. }
  7292. return;
  7293. }
  7294. // Rejoin connected segments.
  7295. // TODO reuse ringBuffer.rejoin()?
  7296. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7297. segments.push(ringSegments.filter(validSegment));
  7298. }
  7299. return clip;
  7300. };
  7301. }
  7302. function validSegment(segment) {
  7303. return segment.length > 1;
  7304. }
  7305. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7306. // and circle clipping, the same comparison is used.
  7307. function compareIntersection(a, b) {
  7308. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7309. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7310. }
  7311. var clipAntimeridian = clip(
  7312. function() { return true; },
  7313. clipAntimeridianLine,
  7314. clipAntimeridianInterpolate,
  7315. [-pi$3, -halfPi$2]
  7316. );
  7317. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7318. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7319. // intersections, and the first and last segments should be rejoined.
  7320. function clipAntimeridianLine(stream) {
  7321. var lambda0 = NaN,
  7322. phi0 = NaN,
  7323. sign0 = NaN,
  7324. clean; // no intersections
  7325. return {
  7326. lineStart: function() {
  7327. stream.lineStart();
  7328. clean = 1;
  7329. },
  7330. point: function(lambda1, phi1) {
  7331. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7332. delta = abs(lambda1 - lambda0);
  7333. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7334. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7335. stream.point(sign0, phi0);
  7336. stream.lineEnd();
  7337. stream.lineStart();
  7338. stream.point(sign1, phi0);
  7339. stream.point(lambda1, phi0);
  7340. clean = 0;
  7341. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7342. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7343. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7344. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7345. stream.point(sign0, phi0);
  7346. stream.lineEnd();
  7347. stream.lineStart();
  7348. stream.point(sign1, phi0);
  7349. clean = 0;
  7350. }
  7351. stream.point(lambda0 = lambda1, phi0 = phi1);
  7352. sign0 = sign1;
  7353. },
  7354. lineEnd: function() {
  7355. stream.lineEnd();
  7356. lambda0 = phi0 = NaN;
  7357. },
  7358. clean: function() {
  7359. return 2 - clean; // if intersections, rejoin first and last segments
  7360. }
  7361. };
  7362. }
  7363. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7364. var cosPhi0,
  7365. cosPhi1,
  7366. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7367. return abs(sinLambda0Lambda1) > epsilon$2
  7368. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7369. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7370. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7371. : (phi0 + phi1) / 2;
  7372. }
  7373. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7374. var phi;
  7375. if (from == null) {
  7376. phi = direction * halfPi$2;
  7377. stream.point(-pi$3, phi);
  7378. stream.point(0, phi);
  7379. stream.point(pi$3, phi);
  7380. stream.point(pi$3, 0);
  7381. stream.point(pi$3, -phi);
  7382. stream.point(0, -phi);
  7383. stream.point(-pi$3, -phi);
  7384. stream.point(-pi$3, 0);
  7385. stream.point(-pi$3, phi);
  7386. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7387. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7388. phi = direction * lambda / 2;
  7389. stream.point(-lambda, phi);
  7390. stream.point(0, phi);
  7391. stream.point(lambda, phi);
  7392. } else {
  7393. stream.point(to[0], to[1]);
  7394. }
  7395. }
  7396. function clipCircle(radius) {
  7397. var cr = cos$1(radius),
  7398. delta = 6 * radians,
  7399. smallRadius = cr > 0,
  7400. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7401. function interpolate(from, to, direction, stream) {
  7402. circleStream(stream, radius, delta, direction, from, to);
  7403. }
  7404. function visible(lambda, phi) {
  7405. return cos$1(lambda) * cos$1(phi) > cr;
  7406. }
  7407. // Takes a line and cuts into visible segments. Return values used for polygon
  7408. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7409. // intersections 2 - there were intersections, and the first and last segments
  7410. // should be rejoined.
  7411. function clipLine(stream) {
  7412. var point0, // previous point
  7413. c0, // code for previous point
  7414. v0, // visibility of previous point
  7415. v00, // visibility of first point
  7416. clean; // no intersections
  7417. return {
  7418. lineStart: function() {
  7419. v00 = v0 = false;
  7420. clean = 1;
  7421. },
  7422. point: function(lambda, phi) {
  7423. var point1 = [lambda, phi],
  7424. point2,
  7425. v = visible(lambda, phi),
  7426. c = smallRadius
  7427. ? v ? 0 : code(lambda, phi)
  7428. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7429. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7430. // Handle degeneracies.
  7431. // TODO ignore if not clipping polygons.
  7432. if (v !== v0) {
  7433. point2 = intersect(point0, point1);
  7434. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7435. point1[0] += epsilon$2;
  7436. point1[1] += epsilon$2;
  7437. v = visible(point1[0], point1[1]);
  7438. }
  7439. }
  7440. if (v !== v0) {
  7441. clean = 0;
  7442. if (v) {
  7443. // outside going in
  7444. stream.lineStart();
  7445. point2 = intersect(point1, point0);
  7446. stream.point(point2[0], point2[1]);
  7447. } else {
  7448. // inside going out
  7449. point2 = intersect(point0, point1);
  7450. stream.point(point2[0], point2[1]);
  7451. stream.lineEnd();
  7452. }
  7453. point0 = point2;
  7454. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7455. var t;
  7456. // If the codes for two points are different, or are both zero,
  7457. // and there this segment intersects with the small circle.
  7458. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7459. clean = 0;
  7460. if (smallRadius) {
  7461. stream.lineStart();
  7462. stream.point(t[0][0], t[0][1]);
  7463. stream.point(t[1][0], t[1][1]);
  7464. stream.lineEnd();
  7465. } else {
  7466. stream.point(t[1][0], t[1][1]);
  7467. stream.lineEnd();
  7468. stream.lineStart();
  7469. stream.point(t[0][0], t[0][1]);
  7470. }
  7471. }
  7472. }
  7473. if (v && (!point0 || !pointEqual(point0, point1))) {
  7474. stream.point(point1[0], point1[1]);
  7475. }
  7476. point0 = point1, v0 = v, c0 = c;
  7477. },
  7478. lineEnd: function() {
  7479. if (v0) stream.lineEnd();
  7480. point0 = null;
  7481. },
  7482. // Rejoin first and last segments if there were intersections and the first
  7483. // and last points were visible.
  7484. clean: function() {
  7485. return clean | ((v00 && v0) << 1);
  7486. }
  7487. };
  7488. }
  7489. // Intersects the great circle between a and b with the clip circle.
  7490. function intersect(a, b, two) {
  7491. var pa = cartesian(a),
  7492. pb = cartesian(b);
  7493. // We have two planes, n1.p = d1 and n2.p = d2.
  7494. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7495. var n1 = [1, 0, 0], // normal
  7496. n2 = cartesianCross(pa, pb),
  7497. n2n2 = cartesianDot(n2, n2),
  7498. n1n2 = n2[0], // cartesianDot(n1, n2),
  7499. determinant = n2n2 - n1n2 * n1n2;
  7500. // Two polar points.
  7501. if (!determinant) return !two && a;
  7502. var c1 = cr * n2n2 / determinant,
  7503. c2 = -cr * n1n2 / determinant,
  7504. n1xn2 = cartesianCross(n1, n2),
  7505. A = cartesianScale(n1, c1),
  7506. B = cartesianScale(n2, c2);
  7507. cartesianAddInPlace(A, B);
  7508. // Solve |p(t)|^2 = 1.
  7509. var u = n1xn2,
  7510. w = cartesianDot(A, u),
  7511. uu = cartesianDot(u, u),
  7512. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7513. if (t2 < 0) return;
  7514. var t = sqrt(t2),
  7515. q = cartesianScale(u, (-w - t) / uu);
  7516. cartesianAddInPlace(q, A);
  7517. q = spherical(q);
  7518. if (!two) return q;
  7519. // Two intersection points.
  7520. var lambda0 = a[0],
  7521. lambda1 = b[0],
  7522. phi0 = a[1],
  7523. phi1 = b[1],
  7524. z;
  7525. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7526. var delta = lambda1 - lambda0,
  7527. polar = abs(delta - pi$3) < epsilon$2,
  7528. meridian = polar || delta < epsilon$2;
  7529. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7530. // Check that the first point is between a and b.
  7531. if (meridian
  7532. ? polar
  7533. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7534. : phi0 <= q[1] && q[1] <= phi1
  7535. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7536. var q1 = cartesianScale(u, (-w + t) / uu);
  7537. cartesianAddInPlace(q1, A);
  7538. return [q, spherical(q1)];
  7539. }
  7540. }
  7541. // Generates a 4-bit vector representing the location of a point relative to
  7542. // the small circle's bounding box.
  7543. function code(lambda, phi) {
  7544. var r = smallRadius ? radius : pi$3 - radius,
  7545. code = 0;
  7546. if (lambda < -r) code |= 1; // left
  7547. else if (lambda > r) code |= 2; // right
  7548. if (phi < -r) code |= 4; // below
  7549. else if (phi > r) code |= 8; // above
  7550. return code;
  7551. }
  7552. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7553. }
  7554. function clipLine(a, b, x0, y0, x1, y1) {
  7555. var ax = a[0],
  7556. ay = a[1],
  7557. bx = b[0],
  7558. by = b[1],
  7559. t0 = 0,
  7560. t1 = 1,
  7561. dx = bx - ax,
  7562. dy = by - ay,
  7563. r;
  7564. r = x0 - ax;
  7565. if (!dx && r > 0) return;
  7566. r /= dx;
  7567. if (dx < 0) {
  7568. if (r < t0) return;
  7569. if (r < t1) t1 = r;
  7570. } else if (dx > 0) {
  7571. if (r > t1) return;
  7572. if (r > t0) t0 = r;
  7573. }
  7574. r = x1 - ax;
  7575. if (!dx && r < 0) return;
  7576. r /= dx;
  7577. if (dx < 0) {
  7578. if (r > t1) return;
  7579. if (r > t0) t0 = r;
  7580. } else if (dx > 0) {
  7581. if (r < t0) return;
  7582. if (r < t1) t1 = r;
  7583. }
  7584. r = y0 - ay;
  7585. if (!dy && r > 0) return;
  7586. r /= dy;
  7587. if (dy < 0) {
  7588. if (r < t0) return;
  7589. if (r < t1) t1 = r;
  7590. } else if (dy > 0) {
  7591. if (r > t1) return;
  7592. if (r > t0) t0 = r;
  7593. }
  7594. r = y1 - ay;
  7595. if (!dy && r < 0) return;
  7596. r /= dy;
  7597. if (dy < 0) {
  7598. if (r > t1) return;
  7599. if (r > t0) t0 = r;
  7600. } else if (dy > 0) {
  7601. if (r < t0) return;
  7602. if (r < t1) t1 = r;
  7603. }
  7604. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  7605. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  7606. return true;
  7607. }
  7608. var clipMax = 1e9, clipMin = -clipMax;
  7609. // TODO Use d3-polygon’s polygonContains here for the ring check?
  7610. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  7611. function clipRectangle(x0, y0, x1, y1) {
  7612. function visible(x, y) {
  7613. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  7614. }
  7615. function interpolate(from, to, direction, stream) {
  7616. var a = 0, a1 = 0;
  7617. if (from == null
  7618. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  7619. || comparePoint(from, to) < 0 ^ direction > 0) {
  7620. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  7621. while ((a = (a + direction + 4) % 4) !== a1);
  7622. } else {
  7623. stream.point(to[0], to[1]);
  7624. }
  7625. }
  7626. function corner(p, direction) {
  7627. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  7628. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  7629. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  7630. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  7631. }
  7632. function compareIntersection(a, b) {
  7633. return comparePoint(a.x, b.x);
  7634. }
  7635. function comparePoint(a, b) {
  7636. var ca = corner(a, 1),
  7637. cb = corner(b, 1);
  7638. return ca !== cb ? ca - cb
  7639. : ca === 0 ? b[1] - a[1]
  7640. : ca === 1 ? a[0] - b[0]
  7641. : ca === 2 ? a[1] - b[1]
  7642. : b[0] - a[0];
  7643. }
  7644. return function(stream) {
  7645. var activeStream = stream,
  7646. bufferStream = clipBuffer(),
  7647. segments,
  7648. polygon,
  7649. ring,
  7650. x__, y__, v__, // first point
  7651. x_, y_, v_, // previous point
  7652. first,
  7653. clean;
  7654. var clipStream = {
  7655. point: point,
  7656. lineStart: lineStart,
  7657. lineEnd: lineEnd,
  7658. polygonStart: polygonStart,
  7659. polygonEnd: polygonEnd
  7660. };
  7661. function point(x, y) {
  7662. if (visible(x, y)) activeStream.point(x, y);
  7663. }
  7664. function polygonInside() {
  7665. var winding = 0;
  7666. for (var i = 0, n = polygon.length; i < n; ++i) {
  7667. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  7668. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  7669. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  7670. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  7671. }
  7672. }
  7673. return winding;
  7674. }
  7675. // Buffer geometry within a polygon and then clip it en masse.
  7676. function polygonStart() {
  7677. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  7678. }
  7679. function polygonEnd() {
  7680. var startInside = polygonInside(),
  7681. cleanInside = clean && startInside,
  7682. visible = (segments = merge(segments)).length;
  7683. if (cleanInside || visible) {
  7684. stream.polygonStart();
  7685. if (cleanInside) {
  7686. stream.lineStart();
  7687. interpolate(null, null, 1, stream);
  7688. stream.lineEnd();
  7689. }
  7690. if (visible) {
  7691. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  7692. }
  7693. stream.polygonEnd();
  7694. }
  7695. activeStream = stream, segments = polygon = ring = null;
  7696. }
  7697. function lineStart() {
  7698. clipStream.point = linePoint;
  7699. if (polygon) polygon.push(ring = []);
  7700. first = true;
  7701. v_ = false;
  7702. x_ = y_ = NaN;
  7703. }
  7704. // TODO rather than special-case polygons, simply handle them separately.
  7705. // Ideally, coincident intersection points should be jittered to avoid
  7706. // clipping issues.
  7707. function lineEnd() {
  7708. if (segments) {
  7709. linePoint(x__, y__);
  7710. if (v__ && v_) bufferStream.rejoin();
  7711. segments.push(bufferStream.result());
  7712. }
  7713. clipStream.point = point;
  7714. if (v_) activeStream.lineEnd();
  7715. }
  7716. function linePoint(x, y) {
  7717. var v = visible(x, y);
  7718. if (polygon) ring.push([x, y]);
  7719. if (first) {
  7720. x__ = x, y__ = y, v__ = v;
  7721. first = false;
  7722. if (v) {
  7723. activeStream.lineStart();
  7724. activeStream.point(x, y);
  7725. }
  7726. } else {
  7727. if (v && v_) activeStream.point(x, y);
  7728. else {
  7729. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7730. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7731. if (clipLine(a, b, x0, y0, x1, y1)) {
  7732. if (!v_) {
  7733. activeStream.lineStart();
  7734. activeStream.point(a[0], a[1]);
  7735. }
  7736. activeStream.point(b[0], b[1]);
  7737. if (!v) activeStream.lineEnd();
  7738. clean = false;
  7739. } else if (v) {
  7740. activeStream.lineStart();
  7741. activeStream.point(x, y);
  7742. clean = false;
  7743. }
  7744. }
  7745. }
  7746. x_ = x, y_ = y, v_ = v;
  7747. }
  7748. return clipStream;
  7749. };
  7750. }
  7751. function extent$1() {
  7752. var x0 = 0,
  7753. y0 = 0,
  7754. x1 = 960,
  7755. y1 = 500,
  7756. cache,
  7757. cacheStream,
  7758. clip;
  7759. return clip = {
  7760. stream: function(stream) {
  7761. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7762. },
  7763. extent: function(_) {
  7764. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7765. }
  7766. };
  7767. }
  7768. var lengthSum = adder(),
  7769. lambda0$2,
  7770. sinPhi0$1,
  7771. cosPhi0$1;
  7772. var lengthStream = {
  7773. sphere: noop$2,
  7774. point: noop$2,
  7775. lineStart: lengthLineStart,
  7776. lineEnd: noop$2,
  7777. polygonStart: noop$2,
  7778. polygonEnd: noop$2
  7779. };
  7780. function lengthLineStart() {
  7781. lengthStream.point = lengthPointFirst;
  7782. lengthStream.lineEnd = lengthLineEnd;
  7783. }
  7784. function lengthLineEnd() {
  7785. lengthStream.point = lengthStream.lineEnd = noop$2;
  7786. }
  7787. function lengthPointFirst(lambda, phi) {
  7788. lambda *= radians, phi *= radians;
  7789. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7790. lengthStream.point = lengthPoint;
  7791. }
  7792. function lengthPoint(lambda, phi) {
  7793. lambda *= radians, phi *= radians;
  7794. var sinPhi = sin$1(phi),
  7795. cosPhi = cos$1(phi),
  7796. delta = abs(lambda - lambda0$2),
  7797. cosDelta = cos$1(delta),
  7798. sinDelta = sin$1(delta),
  7799. x = cosPhi * sinDelta,
  7800. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7801. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7802. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7803. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7804. }
  7805. function length$1(object) {
  7806. lengthSum.reset();
  7807. geoStream(object, lengthStream);
  7808. return +lengthSum;
  7809. }
  7810. var coordinates = [null, null],
  7811. object$1 = {type: "LineString", coordinates: coordinates};
  7812. function distance(a, b) {
  7813. coordinates[0] = a;
  7814. coordinates[1] = b;
  7815. return length$1(object$1);
  7816. }
  7817. var containsObjectType = {
  7818. Feature: function(object, point) {
  7819. return containsGeometry(object.geometry, point);
  7820. },
  7821. FeatureCollection: function(object, point) {
  7822. var features = object.features, i = -1, n = features.length;
  7823. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7824. return false;
  7825. }
  7826. };
  7827. var containsGeometryType = {
  7828. Sphere: function() {
  7829. return true;
  7830. },
  7831. Point: function(object, point) {
  7832. return containsPoint(object.coordinates, point);
  7833. },
  7834. MultiPoint: function(object, point) {
  7835. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7836. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7837. return false;
  7838. },
  7839. LineString: function(object, point) {
  7840. return containsLine(object.coordinates, point);
  7841. },
  7842. MultiLineString: function(object, point) {
  7843. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7844. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7845. return false;
  7846. },
  7847. Polygon: function(object, point) {
  7848. return containsPolygon(object.coordinates, point);
  7849. },
  7850. MultiPolygon: function(object, point) {
  7851. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7852. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7853. return false;
  7854. },
  7855. GeometryCollection: function(object, point) {
  7856. var geometries = object.geometries, i = -1, n = geometries.length;
  7857. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7858. return false;
  7859. }
  7860. };
  7861. function containsGeometry(geometry, point) {
  7862. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7863. ? containsGeometryType[geometry.type](geometry, point)
  7864. : false;
  7865. }
  7866. function containsPoint(coordinates, point) {
  7867. return distance(coordinates, point) === 0;
  7868. }
  7869. function containsLine(coordinates, point) {
  7870. var ao, bo, ab;
  7871. for (var i = 0, n = coordinates.length; i < n; i++) {
  7872. bo = distance(coordinates[i], point);
  7873. if (bo === 0) return true;
  7874. if (i > 0) {
  7875. ab = distance(coordinates[i], coordinates[i - 1]);
  7876. if (
  7877. ab > 0 &&
  7878. ao <= ab &&
  7879. bo <= ab &&
  7880. (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2$1 * ab
  7881. )
  7882. return true;
  7883. }
  7884. ao = bo;
  7885. }
  7886. return false;
  7887. }
  7888. function containsPolygon(coordinates, point) {
  7889. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7890. }
  7891. function ringRadians(ring) {
  7892. return ring = ring.map(pointRadians), ring.pop(), ring;
  7893. }
  7894. function pointRadians(point) {
  7895. return [point[0] * radians, point[1] * radians];
  7896. }
  7897. function contains$1(object, point) {
  7898. return (object && containsObjectType.hasOwnProperty(object.type)
  7899. ? containsObjectType[object.type]
  7900. : containsGeometry)(object, point);
  7901. }
  7902. function graticuleX(y0, y1, dy) {
  7903. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7904. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7905. }
  7906. function graticuleY(x0, x1, dx) {
  7907. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7908. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7909. }
  7910. function graticule() {
  7911. var x1, x0, X1, X0,
  7912. y1, y0, Y1, Y0,
  7913. dx = 10, dy = dx, DX = 90, DY = 360,
  7914. x, y, X, Y,
  7915. precision = 2.5;
  7916. function graticule() {
  7917. return {type: "MultiLineString", coordinates: lines()};
  7918. }
  7919. function lines() {
  7920. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7921. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7922. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7923. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7924. }
  7925. graticule.lines = function() {
  7926. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7927. };
  7928. graticule.outline = function() {
  7929. return {
  7930. type: "Polygon",
  7931. coordinates: [
  7932. X(X0).concat(
  7933. Y(Y1).slice(1),
  7934. X(X1).reverse().slice(1),
  7935. Y(Y0).reverse().slice(1))
  7936. ]
  7937. };
  7938. };
  7939. graticule.extent = function(_) {
  7940. if (!arguments.length) return graticule.extentMinor();
  7941. return graticule.extentMajor(_).extentMinor(_);
  7942. };
  7943. graticule.extentMajor = function(_) {
  7944. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7945. X0 = +_[0][0], X1 = +_[1][0];
  7946. Y0 = +_[0][1], Y1 = +_[1][1];
  7947. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7948. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7949. return graticule.precision(precision);
  7950. };
  7951. graticule.extentMinor = function(_) {
  7952. if (!arguments.length) return [[x0, y0], [x1, y1]];
  7953. x0 = +_[0][0], x1 = +_[1][0];
  7954. y0 = +_[0][1], y1 = +_[1][1];
  7955. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  7956. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  7957. return graticule.precision(precision);
  7958. };
  7959. graticule.step = function(_) {
  7960. if (!arguments.length) return graticule.stepMinor();
  7961. return graticule.stepMajor(_).stepMinor(_);
  7962. };
  7963. graticule.stepMajor = function(_) {
  7964. if (!arguments.length) return [DX, DY];
  7965. DX = +_[0], DY = +_[1];
  7966. return graticule;
  7967. };
  7968. graticule.stepMinor = function(_) {
  7969. if (!arguments.length) return [dx, dy];
  7970. dx = +_[0], dy = +_[1];
  7971. return graticule;
  7972. };
  7973. graticule.precision = function(_) {
  7974. if (!arguments.length) return precision;
  7975. precision = +_;
  7976. x = graticuleX(y0, y1, 90);
  7977. y = graticuleY(x0, x1, precision);
  7978. X = graticuleX(Y0, Y1, 90);
  7979. Y = graticuleY(X0, X1, precision);
  7980. return graticule;
  7981. };
  7982. return graticule
  7983. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7984. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7985. }
  7986. function graticule10() {
  7987. return graticule()();
  7988. }
  7989. function interpolate$1(a, b) {
  7990. var x0 = a[0] * radians,
  7991. y0 = a[1] * radians,
  7992. x1 = b[0] * radians,
  7993. y1 = b[1] * radians,
  7994. cy0 = cos$1(y0),
  7995. sy0 = sin$1(y0),
  7996. cy1 = cos$1(y1),
  7997. sy1 = sin$1(y1),
  7998. kx0 = cy0 * cos$1(x0),
  7999. ky0 = cy0 * sin$1(x0),
  8000. kx1 = cy1 * cos$1(x1),
  8001. ky1 = cy1 * sin$1(x1),
  8002. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  8003. k = sin$1(d);
  8004. var interpolate = d ? function(t) {
  8005. var B = sin$1(t *= d) / k,
  8006. A = sin$1(d - t) / k,
  8007. x = A * kx0 + B * kx1,
  8008. y = A * ky0 + B * ky1,
  8009. z = A * sy0 + B * sy1;
  8010. return [
  8011. atan2(y, x) * degrees$1,
  8012. atan2(z, sqrt(x * x + y * y)) * degrees$1
  8013. ];
  8014. } : function() {
  8015. return [x0 * degrees$1, y0 * degrees$1];
  8016. };
  8017. interpolate.distance = d;
  8018. return interpolate;
  8019. }
  8020. function identity$4(x) {
  8021. return x;
  8022. }
  8023. var areaSum$1 = adder(),
  8024. areaRingSum$1 = adder(),
  8025. x00,
  8026. y00,
  8027. x0$1,
  8028. y0$1;
  8029. var areaStream$1 = {
  8030. point: noop$2,
  8031. lineStart: noop$2,
  8032. lineEnd: noop$2,
  8033. polygonStart: function() {
  8034. areaStream$1.lineStart = areaRingStart$1;
  8035. areaStream$1.lineEnd = areaRingEnd$1;
  8036. },
  8037. polygonEnd: function() {
  8038. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  8039. areaSum$1.add(abs(areaRingSum$1));
  8040. areaRingSum$1.reset();
  8041. },
  8042. result: function() {
  8043. var area = areaSum$1 / 2;
  8044. areaSum$1.reset();
  8045. return area;
  8046. }
  8047. };
  8048. function areaRingStart$1() {
  8049. areaStream$1.point = areaPointFirst$1;
  8050. }
  8051. function areaPointFirst$1(x, y) {
  8052. areaStream$1.point = areaPoint$1;
  8053. x00 = x0$1 = x, y00 = y0$1 = y;
  8054. }
  8055. function areaPoint$1(x, y) {
  8056. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  8057. x0$1 = x, y0$1 = y;
  8058. }
  8059. function areaRingEnd$1() {
  8060. areaPoint$1(x00, y00);
  8061. }
  8062. var x0$2 = Infinity,
  8063. y0$2 = x0$2,
  8064. x1 = -x0$2,
  8065. y1 = x1;
  8066. var boundsStream$1 = {
  8067. point: boundsPoint$1,
  8068. lineStart: noop$2,
  8069. lineEnd: noop$2,
  8070. polygonStart: noop$2,
  8071. polygonEnd: noop$2,
  8072. result: function() {
  8073. var bounds = [[x0$2, y0$2], [x1, y1]];
  8074. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  8075. return bounds;
  8076. }
  8077. };
  8078. function boundsPoint$1(x, y) {
  8079. if (x < x0$2) x0$2 = x;
  8080. if (x > x1) x1 = x;
  8081. if (y < y0$2) y0$2 = y;
  8082. if (y > y1) y1 = y;
  8083. }
  8084. // TODO Enforce positive area for exterior, negative area for interior?
  8085. var X0$1 = 0,
  8086. Y0$1 = 0,
  8087. Z0$1 = 0,
  8088. X1$1 = 0,
  8089. Y1$1 = 0,
  8090. Z1$1 = 0,
  8091. X2$1 = 0,
  8092. Y2$1 = 0,
  8093. Z2$1 = 0,
  8094. x00$1,
  8095. y00$1,
  8096. x0$3,
  8097. y0$3;
  8098. var centroidStream$1 = {
  8099. point: centroidPoint$1,
  8100. lineStart: centroidLineStart$1,
  8101. lineEnd: centroidLineEnd$1,
  8102. polygonStart: function() {
  8103. centroidStream$1.lineStart = centroidRingStart$1;
  8104. centroidStream$1.lineEnd = centroidRingEnd$1;
  8105. },
  8106. polygonEnd: function() {
  8107. centroidStream$1.point = centroidPoint$1;
  8108. centroidStream$1.lineStart = centroidLineStart$1;
  8109. centroidStream$1.lineEnd = centroidLineEnd$1;
  8110. },
  8111. result: function() {
  8112. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  8113. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  8114. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  8115. : [NaN, NaN];
  8116. X0$1 = Y0$1 = Z0$1 =
  8117. X1$1 = Y1$1 = Z1$1 =
  8118. X2$1 = Y2$1 = Z2$1 = 0;
  8119. return centroid;
  8120. }
  8121. };
  8122. function centroidPoint$1(x, y) {
  8123. X0$1 += x;
  8124. Y0$1 += y;
  8125. ++Z0$1;
  8126. }
  8127. function centroidLineStart$1() {
  8128. centroidStream$1.point = centroidPointFirstLine;
  8129. }
  8130. function centroidPointFirstLine(x, y) {
  8131. centroidStream$1.point = centroidPointLine;
  8132. centroidPoint$1(x0$3 = x, y0$3 = y);
  8133. }
  8134. function centroidPointLine(x, y) {
  8135. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  8136. X1$1 += z * (x0$3 + x) / 2;
  8137. Y1$1 += z * (y0$3 + y) / 2;
  8138. Z1$1 += z;
  8139. centroidPoint$1(x0$3 = x, y0$3 = y);
  8140. }
  8141. function centroidLineEnd$1() {
  8142. centroidStream$1.point = centroidPoint$1;
  8143. }
  8144. function centroidRingStart$1() {
  8145. centroidStream$1.point = centroidPointFirstRing;
  8146. }
  8147. function centroidRingEnd$1() {
  8148. centroidPointRing(x00$1, y00$1);
  8149. }
  8150. function centroidPointFirstRing(x, y) {
  8151. centroidStream$1.point = centroidPointRing;
  8152. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  8153. }
  8154. function centroidPointRing(x, y) {
  8155. var dx = x - x0$3,
  8156. dy = y - y0$3,
  8157. z = sqrt(dx * dx + dy * dy);
  8158. X1$1 += z * (x0$3 + x) / 2;
  8159. Y1$1 += z * (y0$3 + y) / 2;
  8160. Z1$1 += z;
  8161. z = y0$3 * x - x0$3 * y;
  8162. X2$1 += z * (x0$3 + x);
  8163. Y2$1 += z * (y0$3 + y);
  8164. Z2$1 += z * 3;
  8165. centroidPoint$1(x0$3 = x, y0$3 = y);
  8166. }
  8167. function PathContext(context) {
  8168. this._context = context;
  8169. }
  8170. PathContext.prototype = {
  8171. _radius: 4.5,
  8172. pointRadius: function(_) {
  8173. return this._radius = _, this;
  8174. },
  8175. polygonStart: function() {
  8176. this._line = 0;
  8177. },
  8178. polygonEnd: function() {
  8179. this._line = NaN;
  8180. },
  8181. lineStart: function() {
  8182. this._point = 0;
  8183. },
  8184. lineEnd: function() {
  8185. if (this._line === 0) this._context.closePath();
  8186. this._point = NaN;
  8187. },
  8188. point: function(x, y) {
  8189. switch (this._point) {
  8190. case 0: {
  8191. this._context.moveTo(x, y);
  8192. this._point = 1;
  8193. break;
  8194. }
  8195. case 1: {
  8196. this._context.lineTo(x, y);
  8197. break;
  8198. }
  8199. default: {
  8200. this._context.moveTo(x + this._radius, y);
  8201. this._context.arc(x, y, this._radius, 0, tau$3);
  8202. break;
  8203. }
  8204. }
  8205. },
  8206. result: noop$2
  8207. };
  8208. var lengthSum$1 = adder(),
  8209. lengthRing,
  8210. x00$2,
  8211. y00$2,
  8212. x0$4,
  8213. y0$4;
  8214. var lengthStream$1 = {
  8215. point: noop$2,
  8216. lineStart: function() {
  8217. lengthStream$1.point = lengthPointFirst$1;
  8218. },
  8219. lineEnd: function() {
  8220. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  8221. lengthStream$1.point = noop$2;
  8222. },
  8223. polygonStart: function() {
  8224. lengthRing = true;
  8225. },
  8226. polygonEnd: function() {
  8227. lengthRing = null;
  8228. },
  8229. result: function() {
  8230. var length = +lengthSum$1;
  8231. lengthSum$1.reset();
  8232. return length;
  8233. }
  8234. };
  8235. function lengthPointFirst$1(x, y) {
  8236. lengthStream$1.point = lengthPoint$1;
  8237. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  8238. }
  8239. function lengthPoint$1(x, y) {
  8240. x0$4 -= x, y0$4 -= y;
  8241. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  8242. x0$4 = x, y0$4 = y;
  8243. }
  8244. function PathString() {
  8245. this._string = [];
  8246. }
  8247. PathString.prototype = {
  8248. _radius: 4.5,
  8249. _circle: circle$1(4.5),
  8250. pointRadius: function(_) {
  8251. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  8252. return this;
  8253. },
  8254. polygonStart: function() {
  8255. this._line = 0;
  8256. },
  8257. polygonEnd: function() {
  8258. this._line = NaN;
  8259. },
  8260. lineStart: function() {
  8261. this._point = 0;
  8262. },
  8263. lineEnd: function() {
  8264. if (this._line === 0) this._string.push("Z");
  8265. this._point = NaN;
  8266. },
  8267. point: function(x, y) {
  8268. switch (this._point) {
  8269. case 0: {
  8270. this._string.push("M", x, ",", y);
  8271. this._point = 1;
  8272. break;
  8273. }
  8274. case 1: {
  8275. this._string.push("L", x, ",", y);
  8276. break;
  8277. }
  8278. default: {
  8279. if (this._circle == null) this._circle = circle$1(this._radius);
  8280. this._string.push("M", x, ",", y, this._circle);
  8281. break;
  8282. }
  8283. }
  8284. },
  8285. result: function() {
  8286. if (this._string.length) {
  8287. var result = this._string.join("");
  8288. this._string = [];
  8289. return result;
  8290. } else {
  8291. return null;
  8292. }
  8293. }
  8294. };
  8295. function circle$1(radius) {
  8296. return "m0," + radius
  8297. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  8298. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  8299. + "z";
  8300. }
  8301. function index$1(projection, context) {
  8302. var pointRadius = 4.5,
  8303. projectionStream,
  8304. contextStream;
  8305. function path(object) {
  8306. if (object) {
  8307. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  8308. geoStream(object, projectionStream(contextStream));
  8309. }
  8310. return contextStream.result();
  8311. }
  8312. path.area = function(object) {
  8313. geoStream(object, projectionStream(areaStream$1));
  8314. return areaStream$1.result();
  8315. };
  8316. path.measure = function(object) {
  8317. geoStream(object, projectionStream(lengthStream$1));
  8318. return lengthStream$1.result();
  8319. };
  8320. path.bounds = function(object) {
  8321. geoStream(object, projectionStream(boundsStream$1));
  8322. return boundsStream$1.result();
  8323. };
  8324. path.centroid = function(object) {
  8325. geoStream(object, projectionStream(centroidStream$1));
  8326. return centroidStream$1.result();
  8327. };
  8328. path.projection = function(_) {
  8329. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  8330. };
  8331. path.context = function(_) {
  8332. if (!arguments.length) return context;
  8333. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  8334. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  8335. return path;
  8336. };
  8337. path.pointRadius = function(_) {
  8338. if (!arguments.length) return pointRadius;
  8339. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  8340. return path;
  8341. };
  8342. return path.projection(projection).context(context);
  8343. }
  8344. function transform(methods) {
  8345. return {
  8346. stream: transformer(methods)
  8347. };
  8348. }
  8349. function transformer(methods) {
  8350. return function(stream) {
  8351. var s = new TransformStream;
  8352. for (var key in methods) s[key] = methods[key];
  8353. s.stream = stream;
  8354. return s;
  8355. };
  8356. }
  8357. function TransformStream() {}
  8358. TransformStream.prototype = {
  8359. constructor: TransformStream,
  8360. point: function(x, y) { this.stream.point(x, y); },
  8361. sphere: function() { this.stream.sphere(); },
  8362. lineStart: function() { this.stream.lineStart(); },
  8363. lineEnd: function() { this.stream.lineEnd(); },
  8364. polygonStart: function() { this.stream.polygonStart(); },
  8365. polygonEnd: function() { this.stream.polygonEnd(); }
  8366. };
  8367. function fit(projection, fitBounds, object) {
  8368. var clip = projection.clipExtent && projection.clipExtent();
  8369. projection.scale(150).translate([0, 0]);
  8370. if (clip != null) projection.clipExtent(null);
  8371. geoStream(object, projection.stream(boundsStream$1));
  8372. fitBounds(boundsStream$1.result());
  8373. if (clip != null) projection.clipExtent(clip);
  8374. return projection;
  8375. }
  8376. function fitExtent(projection, extent, object) {
  8377. return fit(projection, function(b) {
  8378. var w = extent[1][0] - extent[0][0],
  8379. h = extent[1][1] - extent[0][1],
  8380. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  8381. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  8382. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  8383. projection.scale(150 * k).translate([x, y]);
  8384. }, object);
  8385. }
  8386. function fitSize(projection, size, object) {
  8387. return fitExtent(projection, [[0, 0], size], object);
  8388. }
  8389. function fitWidth(projection, width, object) {
  8390. return fit(projection, function(b) {
  8391. var w = +width,
  8392. k = w / (b[1][0] - b[0][0]),
  8393. x = (w - k * (b[1][0] + b[0][0])) / 2,
  8394. y = -k * b[0][1];
  8395. projection.scale(150 * k).translate([x, y]);
  8396. }, object);
  8397. }
  8398. function fitHeight(projection, height, object) {
  8399. return fit(projection, function(b) {
  8400. var h = +height,
  8401. k = h / (b[1][1] - b[0][1]),
  8402. x = -k * b[0][0],
  8403. y = (h - k * (b[1][1] + b[0][1])) / 2;
  8404. projection.scale(150 * k).translate([x, y]);
  8405. }, object);
  8406. }
  8407. var maxDepth = 16, // maximum depth of subdivision
  8408. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  8409. function resample(project, delta2) {
  8410. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  8411. }
  8412. function resampleNone(project) {
  8413. return transformer({
  8414. point: function(x, y) {
  8415. x = project(x, y);
  8416. this.stream.point(x[0], x[1]);
  8417. }
  8418. });
  8419. }
  8420. function resample$1(project, delta2) {
  8421. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  8422. var dx = x1 - x0,
  8423. dy = y1 - y0,
  8424. d2 = dx * dx + dy * dy;
  8425. if (d2 > 4 * delta2 && depth--) {
  8426. var a = a0 + a1,
  8427. b = b0 + b1,
  8428. c = c0 + c1,
  8429. m = sqrt(a * a + b * b + c * c),
  8430. phi2 = asin(c /= m),
  8431. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  8432. p = project(lambda2, phi2),
  8433. x2 = p[0],
  8434. y2 = p[1],
  8435. dx2 = x2 - x0,
  8436. dy2 = y2 - y0,
  8437. dz = dy * dx2 - dx * dy2;
  8438. if (dz * dz / d2 > delta2 // perpendicular projected distance
  8439. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  8440. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  8441. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  8442. stream.point(x2, y2);
  8443. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  8444. }
  8445. }
  8446. }
  8447. return function(stream) {
  8448. var lambda00, x00, y00, a00, b00, c00, // first point
  8449. lambda0, x0, y0, a0, b0, c0; // previous point
  8450. var resampleStream = {
  8451. point: point,
  8452. lineStart: lineStart,
  8453. lineEnd: lineEnd,
  8454. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  8455. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  8456. };
  8457. function point(x, y) {
  8458. x = project(x, y);
  8459. stream.point(x[0], x[1]);
  8460. }
  8461. function lineStart() {
  8462. x0 = NaN;
  8463. resampleStream.point = linePoint;
  8464. stream.lineStart();
  8465. }
  8466. function linePoint(lambda, phi) {
  8467. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  8468. 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);
  8469. stream.point(x0, y0);
  8470. }
  8471. function lineEnd() {
  8472. resampleStream.point = point;
  8473. stream.lineEnd();
  8474. }
  8475. function ringStart() {
  8476. lineStart();
  8477. resampleStream.point = ringPoint;
  8478. resampleStream.lineEnd = ringEnd;
  8479. }
  8480. function ringPoint(lambda, phi) {
  8481. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  8482. resampleStream.point = linePoint;
  8483. }
  8484. function ringEnd() {
  8485. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  8486. resampleStream.lineEnd = lineEnd;
  8487. lineEnd();
  8488. }
  8489. return resampleStream;
  8490. };
  8491. }
  8492. var transformRadians = transformer({
  8493. point: function(x, y) {
  8494. this.stream.point(x * radians, y * radians);
  8495. }
  8496. });
  8497. function transformRotate(rotate) {
  8498. return transformer({
  8499. point: function(x, y) {
  8500. var r = rotate(x, y);
  8501. return this.stream.point(r[0], r[1]);
  8502. }
  8503. });
  8504. }
  8505. function scaleTranslate(k, dx, dy) {
  8506. function transform(x, y) {
  8507. return [dx + k * x, dy - k * y];
  8508. }
  8509. transform.invert = function(x, y) {
  8510. return [(x - dx) / k, (dy - y) / k];
  8511. };
  8512. return transform;
  8513. }
  8514. function scaleTranslateRotate(k, dx, dy, alpha) {
  8515. var cosAlpha = cos$1(alpha),
  8516. sinAlpha = sin$1(alpha),
  8517. a = cosAlpha * k,
  8518. b = sinAlpha * k,
  8519. ai = cosAlpha / k,
  8520. bi = sinAlpha / k,
  8521. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  8522. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  8523. function transform(x, y) {
  8524. return [a * x - b * y + dx, dy - b * x - a * y];
  8525. }
  8526. transform.invert = function(x, y) {
  8527. return [ai * x - bi * y + ci, fi - bi * x - ai * y];
  8528. };
  8529. return transform;
  8530. }
  8531. function projection(project) {
  8532. return projectionMutator(function() { return project; })();
  8533. }
  8534. function projectionMutator(projectAt) {
  8535. var project,
  8536. k = 150, // scale
  8537. x = 480, y = 250, // translate
  8538. lambda = 0, phi = 0, // center
  8539. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  8540. alpha = 0, // post-rotate
  8541. theta = null, preclip = clipAntimeridian, // pre-clip angle
  8542. x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
  8543. delta2 = 0.5, // precision
  8544. projectResample,
  8545. projectTransform,
  8546. projectRotateTransform,
  8547. cache,
  8548. cacheStream;
  8549. function projection(point) {
  8550. return projectRotateTransform(point[0] * radians, point[1] * radians);
  8551. }
  8552. function invert(point) {
  8553. point = projectRotateTransform.invert(point[0], point[1]);
  8554. return point && [point[0] * degrees$1, point[1] * degrees$1];
  8555. }
  8556. projection.stream = function(stream) {
  8557. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  8558. };
  8559. projection.preclip = function(_) {
  8560. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  8561. };
  8562. projection.postclip = function(_) {
  8563. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8564. };
  8565. projection.clipAngle = function(_) {
  8566. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  8567. };
  8568. projection.clipExtent = function(_) {
  8569. 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]];
  8570. };
  8571. projection.scale = function(_) {
  8572. return arguments.length ? (k = +_, recenter()) : k;
  8573. };
  8574. projection.translate = function(_) {
  8575. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  8576. };
  8577. projection.center = function(_) {
  8578. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  8579. };
  8580. projection.rotate = function(_) {
  8581. 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];
  8582. };
  8583. projection.angle = function(_) {
  8584. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
  8585. };
  8586. projection.precision = function(_) {
  8587. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  8588. };
  8589. projection.fitExtent = function(extent, object) {
  8590. return fitExtent(projection, extent, object);
  8591. };
  8592. projection.fitSize = function(size, object) {
  8593. return fitSize(projection, size, object);
  8594. };
  8595. projection.fitWidth = function(width, object) {
  8596. return fitWidth(projection, width, object);
  8597. };
  8598. projection.fitHeight = function(height, object) {
  8599. return fitHeight(projection, height, object);
  8600. };
  8601. function recenter() {
  8602. var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
  8603. transform = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
  8604. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  8605. projectTransform = compose(project, transform);
  8606. projectRotateTransform = compose(rotate, projectTransform);
  8607. projectResample = resample(projectTransform, delta2);
  8608. return reset();
  8609. }
  8610. function reset() {
  8611. cache = cacheStream = null;
  8612. return projection;
  8613. }
  8614. return function() {
  8615. project = projectAt.apply(this, arguments);
  8616. projection.invert = project.invert && invert;
  8617. return recenter();
  8618. };
  8619. }
  8620. function conicProjection(projectAt) {
  8621. var phi0 = 0,
  8622. phi1 = pi$3 / 3,
  8623. m = projectionMutator(projectAt),
  8624. p = m(phi0, phi1);
  8625. p.parallels = function(_) {
  8626. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  8627. };
  8628. return p;
  8629. }
  8630. function cylindricalEqualAreaRaw(phi0) {
  8631. var cosPhi0 = cos$1(phi0);
  8632. function forward(lambda, phi) {
  8633. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  8634. }
  8635. forward.invert = function(x, y) {
  8636. return [x / cosPhi0, asin(y * cosPhi0)];
  8637. };
  8638. return forward;
  8639. }
  8640. function conicEqualAreaRaw(y0, y1) {
  8641. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  8642. // Are the parallels symmetrical around the Equator?
  8643. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  8644. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  8645. function project(x, y) {
  8646. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  8647. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  8648. }
  8649. project.invert = function(x, y) {
  8650. var r0y = r0 - y;
  8651. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  8652. };
  8653. return project;
  8654. }
  8655. function conicEqualArea() {
  8656. return conicProjection(conicEqualAreaRaw)
  8657. .scale(155.424)
  8658. .center([0, 33.6442]);
  8659. }
  8660. function albers() {
  8661. return conicEqualArea()
  8662. .parallels([29.5, 45.5])
  8663. .scale(1070)
  8664. .translate([480, 250])
  8665. .rotate([96, 0])
  8666. .center([-0.6, 38.7]);
  8667. }
  8668. // The projections must have mutually exclusive clip regions on the sphere,
  8669. // as this will avoid emitting interleaving lines and polygons.
  8670. function multiplex(streams) {
  8671. var n = streams.length;
  8672. return {
  8673. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  8674. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  8675. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  8676. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  8677. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  8678. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  8679. };
  8680. }
  8681. // A composite projection for the United States, configured by default for
  8682. // 960×500. The projection also works quite well at 960×600 if you change the
  8683. // scale to 1285 and adjust the translate accordingly. The set of standard
  8684. // parallels for each region comes from USGS, which is published here:
  8685. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  8686. function albersUsa() {
  8687. var cache,
  8688. cacheStream,
  8689. lower48 = albers(), lower48Point,
  8690. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  8691. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  8692. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  8693. function albersUsa(coordinates) {
  8694. var x = coordinates[0], y = coordinates[1];
  8695. return point = null,
  8696. (lower48Point.point(x, y), point)
  8697. || (alaskaPoint.point(x, y), point)
  8698. || (hawaiiPoint.point(x, y), point);
  8699. }
  8700. albersUsa.invert = function(coordinates) {
  8701. var k = lower48.scale(),
  8702. t = lower48.translate(),
  8703. x = (coordinates[0] - t[0]) / k,
  8704. y = (coordinates[1] - t[1]) / k;
  8705. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  8706. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  8707. : lower48).invert(coordinates);
  8708. };
  8709. albersUsa.stream = function(stream) {
  8710. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  8711. };
  8712. albersUsa.precision = function(_) {
  8713. if (!arguments.length) return lower48.precision();
  8714. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  8715. return reset();
  8716. };
  8717. albersUsa.scale = function(_) {
  8718. if (!arguments.length) return lower48.scale();
  8719. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  8720. return albersUsa.translate(lower48.translate());
  8721. };
  8722. albersUsa.translate = function(_) {
  8723. if (!arguments.length) return lower48.translate();
  8724. var k = lower48.scale(), x = +_[0], y = +_[1];
  8725. lower48Point = lower48
  8726. .translate(_)
  8727. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  8728. .stream(pointStream);
  8729. alaskaPoint = alaska
  8730. .translate([x - 0.307 * k, y + 0.201 * k])
  8731. .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]])
  8732. .stream(pointStream);
  8733. hawaiiPoint = hawaii
  8734. .translate([x - 0.205 * k, y + 0.212 * k])
  8735. .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]])
  8736. .stream(pointStream);
  8737. return reset();
  8738. };
  8739. albersUsa.fitExtent = function(extent, object) {
  8740. return fitExtent(albersUsa, extent, object);
  8741. };
  8742. albersUsa.fitSize = function(size, object) {
  8743. return fitSize(albersUsa, size, object);
  8744. };
  8745. albersUsa.fitWidth = function(width, object) {
  8746. return fitWidth(albersUsa, width, object);
  8747. };
  8748. albersUsa.fitHeight = function(height, object) {
  8749. return fitHeight(albersUsa, height, object);
  8750. };
  8751. function reset() {
  8752. cache = cacheStream = null;
  8753. return albersUsa;
  8754. }
  8755. return albersUsa.scale(1070);
  8756. }
  8757. function azimuthalRaw(scale) {
  8758. return function(x, y) {
  8759. var cx = cos$1(x),
  8760. cy = cos$1(y),
  8761. k = scale(cx * cy);
  8762. return [
  8763. k * cy * sin$1(x),
  8764. k * sin$1(y)
  8765. ];
  8766. }
  8767. }
  8768. function azimuthalInvert(angle) {
  8769. return function(x, y) {
  8770. var z = sqrt(x * x + y * y),
  8771. c = angle(z),
  8772. sc = sin$1(c),
  8773. cc = cos$1(c);
  8774. return [
  8775. atan2(x * sc, z * cc),
  8776. asin(z && y * sc / z)
  8777. ];
  8778. }
  8779. }
  8780. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8781. return sqrt(2 / (1 + cxcy));
  8782. });
  8783. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8784. return 2 * asin(z / 2);
  8785. });
  8786. function azimuthalEqualArea() {
  8787. return projection(azimuthalEqualAreaRaw)
  8788. .scale(124.75)
  8789. .clipAngle(180 - 1e-3);
  8790. }
  8791. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8792. return (c = acos(c)) && c / sin$1(c);
  8793. });
  8794. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8795. return z;
  8796. });
  8797. function azimuthalEquidistant() {
  8798. return projection(azimuthalEquidistantRaw)
  8799. .scale(79.4188)
  8800. .clipAngle(180 - 1e-3);
  8801. }
  8802. function mercatorRaw(lambda, phi) {
  8803. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8804. }
  8805. mercatorRaw.invert = function(x, y) {
  8806. return [x, 2 * atan(exp(y)) - halfPi$2];
  8807. };
  8808. function mercator() {
  8809. return mercatorProjection(mercatorRaw)
  8810. .scale(961 / tau$3);
  8811. }
  8812. function mercatorProjection(project) {
  8813. var m = projection(project),
  8814. center = m.center,
  8815. scale = m.scale,
  8816. translate = m.translate,
  8817. clipExtent = m.clipExtent,
  8818. x0 = null, y0, x1, y1; // clip extent
  8819. m.scale = function(_) {
  8820. return arguments.length ? (scale(_), reclip()) : scale();
  8821. };
  8822. m.translate = function(_) {
  8823. return arguments.length ? (translate(_), reclip()) : translate();
  8824. };
  8825. m.center = function(_) {
  8826. return arguments.length ? (center(_), reclip()) : center();
  8827. };
  8828. m.clipExtent = function(_) {
  8829. 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]];
  8830. };
  8831. function reclip() {
  8832. var k = pi$3 * scale(),
  8833. t = m(rotation(m.rotate()).invert([0, 0]));
  8834. return clipExtent(x0 == null
  8835. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8836. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8837. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8838. }
  8839. return reclip();
  8840. }
  8841. function tany(y) {
  8842. return tan((halfPi$2 + y) / 2);
  8843. }
  8844. function conicConformalRaw(y0, y1) {
  8845. var cy0 = cos$1(y0),
  8846. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8847. f = cy0 * pow(tany(y0), n) / n;
  8848. if (!n) return mercatorRaw;
  8849. function project(x, y) {
  8850. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8851. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8852. var r = f / pow(tany(y), n);
  8853. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8854. }
  8855. project.invert = function(x, y) {
  8856. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8857. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8858. };
  8859. return project;
  8860. }
  8861. function conicConformal() {
  8862. return conicProjection(conicConformalRaw)
  8863. .scale(109.5)
  8864. .parallels([30, 30]);
  8865. }
  8866. function equirectangularRaw(lambda, phi) {
  8867. return [lambda, phi];
  8868. }
  8869. equirectangularRaw.invert = equirectangularRaw;
  8870. function equirectangular() {
  8871. return projection(equirectangularRaw)
  8872. .scale(152.63);
  8873. }
  8874. function conicEquidistantRaw(y0, y1) {
  8875. var cy0 = cos$1(y0),
  8876. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8877. g = cy0 / n + y0;
  8878. if (abs(n) < epsilon$2) return equirectangularRaw;
  8879. function project(x, y) {
  8880. var gy = g - y, nx = n * x;
  8881. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8882. }
  8883. project.invert = function(x, y) {
  8884. var gy = g - y;
  8885. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8886. };
  8887. return project;
  8888. }
  8889. function conicEquidistant() {
  8890. return conicProjection(conicEquidistantRaw)
  8891. .scale(131.154)
  8892. .center([0, 13.9389]);
  8893. }
  8894. var A1 = 1.340264,
  8895. A2 = -0.081106,
  8896. A3 = 0.000893,
  8897. A4 = 0.003796,
  8898. M = sqrt(3) / 2,
  8899. iterations = 12;
  8900. function equalEarthRaw(lambda, phi) {
  8901. var l = asin(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
  8902. return [
  8903. lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
  8904. l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
  8905. ];
  8906. }
  8907. equalEarthRaw.invert = function(x, y) {
  8908. var l = y, l2 = l * l, l6 = l2 * l2 * l2;
  8909. for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
  8910. fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
  8911. fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
  8912. l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
  8913. if (abs(delta) < epsilon2$1) break;
  8914. }
  8915. return [
  8916. M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
  8917. asin(sin$1(l) / M)
  8918. ];
  8919. };
  8920. function equalEarth() {
  8921. return projection(equalEarthRaw)
  8922. .scale(177.158);
  8923. }
  8924. function gnomonicRaw(x, y) {
  8925. var cy = cos$1(y), k = cos$1(x) * cy;
  8926. return [cy * sin$1(x) / k, sin$1(y) / k];
  8927. }
  8928. gnomonicRaw.invert = azimuthalInvert(atan);
  8929. function gnomonic() {
  8930. return projection(gnomonicRaw)
  8931. .scale(144.049)
  8932. .clipAngle(60);
  8933. }
  8934. function scaleTranslate$1(kx, ky, tx, ty) {
  8935. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8936. point: function(x, y) {
  8937. this.stream.point(x * kx + tx, y * ky + ty);
  8938. }
  8939. });
  8940. }
  8941. function identity$5() {
  8942. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform = identity$4, // scale, translate and reflect
  8943. x0 = null, y0, x1, y1, // clip extent
  8944. postclip = identity$4,
  8945. cache,
  8946. cacheStream,
  8947. projection;
  8948. function reset() {
  8949. cache = cacheStream = null;
  8950. return projection;
  8951. }
  8952. return projection = {
  8953. stream: function(stream) {
  8954. return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
  8955. },
  8956. postclip: function(_) {
  8957. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8958. },
  8959. clipExtent: function(_) {
  8960. 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]];
  8961. },
  8962. scale: function(_) {
  8963. return arguments.length ? (transform = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8964. },
  8965. translate: function(_) {
  8966. return arguments.length ? (transform = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8967. },
  8968. reflectX: function(_) {
  8969. return arguments.length ? (transform = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8970. },
  8971. reflectY: function(_) {
  8972. return arguments.length ? (transform = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8973. },
  8974. fitExtent: function(extent, object) {
  8975. return fitExtent(projection, extent, object);
  8976. },
  8977. fitSize: function(size, object) {
  8978. return fitSize(projection, size, object);
  8979. },
  8980. fitWidth: function(width, object) {
  8981. return fitWidth(projection, width, object);
  8982. },
  8983. fitHeight: function(height, object) {
  8984. return fitHeight(projection, height, object);
  8985. }
  8986. };
  8987. }
  8988. function naturalEarth1Raw(lambda, phi) {
  8989. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8990. return [
  8991. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  8992. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  8993. ];
  8994. }
  8995. naturalEarth1Raw.invert = function(x, y) {
  8996. var phi = y, i = 25, delta;
  8997. do {
  8998. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8999. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  9000. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  9001. } while (abs(delta) > epsilon$2 && --i > 0);
  9002. return [
  9003. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  9004. phi
  9005. ];
  9006. };
  9007. function naturalEarth1() {
  9008. return projection(naturalEarth1Raw)
  9009. .scale(175.295);
  9010. }
  9011. function orthographicRaw(x, y) {
  9012. return [cos$1(y) * sin$1(x), sin$1(y)];
  9013. }
  9014. orthographicRaw.invert = azimuthalInvert(asin);
  9015. function orthographic() {
  9016. return projection(orthographicRaw)
  9017. .scale(249.5)
  9018. .clipAngle(90 + epsilon$2);
  9019. }
  9020. function stereographicRaw(x, y) {
  9021. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  9022. return [cy * sin$1(x) / k, sin$1(y) / k];
  9023. }
  9024. stereographicRaw.invert = azimuthalInvert(function(z) {
  9025. return 2 * atan(z);
  9026. });
  9027. function stereographic() {
  9028. return projection(stereographicRaw)
  9029. .scale(250)
  9030. .clipAngle(142);
  9031. }
  9032. function transverseMercatorRaw(lambda, phi) {
  9033. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  9034. }
  9035. transverseMercatorRaw.invert = function(x, y) {
  9036. return [-y, 2 * atan(exp(x)) - halfPi$2];
  9037. };
  9038. function transverseMercator() {
  9039. var m = mercatorProjection(transverseMercatorRaw),
  9040. center = m.center,
  9041. rotate = m.rotate;
  9042. m.center = function(_) {
  9043. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  9044. };
  9045. m.rotate = function(_) {
  9046. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  9047. };
  9048. return rotate([0, 0, 90])
  9049. .scale(159.155);
  9050. }
  9051. function defaultSeparation(a, b) {
  9052. return a.parent === b.parent ? 1 : 2;
  9053. }
  9054. function meanX(children) {
  9055. return children.reduce(meanXReduce, 0) / children.length;
  9056. }
  9057. function meanXReduce(x, c) {
  9058. return x + c.x;
  9059. }
  9060. function maxY(children) {
  9061. return 1 + children.reduce(maxYReduce, 0);
  9062. }
  9063. function maxYReduce(y, c) {
  9064. return Math.max(y, c.y);
  9065. }
  9066. function leafLeft(node) {
  9067. var children;
  9068. while (children = node.children) node = children[0];
  9069. return node;
  9070. }
  9071. function leafRight(node) {
  9072. var children;
  9073. while (children = node.children) node = children[children.length - 1];
  9074. return node;
  9075. }
  9076. function cluster() {
  9077. var separation = defaultSeparation,
  9078. dx = 1,
  9079. dy = 1,
  9080. nodeSize = false;
  9081. function cluster(root) {
  9082. var previousNode,
  9083. x = 0;
  9084. // First walk, computing the initial x & y values.
  9085. root.eachAfter(function(node) {
  9086. var children = node.children;
  9087. if (children) {
  9088. node.x = meanX(children);
  9089. node.y = maxY(children);
  9090. } else {
  9091. node.x = previousNode ? x += separation(node, previousNode) : 0;
  9092. node.y = 0;
  9093. previousNode = node;
  9094. }
  9095. });
  9096. var left = leafLeft(root),
  9097. right = leafRight(root),
  9098. x0 = left.x - separation(left, right) / 2,
  9099. x1 = right.x + separation(right, left) / 2;
  9100. // Second walk, normalizing x & y to the desired size.
  9101. return root.eachAfter(nodeSize ? function(node) {
  9102. node.x = (node.x - root.x) * dx;
  9103. node.y = (root.y - node.y) * dy;
  9104. } : function(node) {
  9105. node.x = (node.x - x0) / (x1 - x0) * dx;
  9106. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  9107. });
  9108. }
  9109. cluster.separation = function(x) {
  9110. return arguments.length ? (separation = x, cluster) : separation;
  9111. };
  9112. cluster.size = function(x) {
  9113. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  9114. };
  9115. cluster.nodeSize = function(x) {
  9116. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  9117. };
  9118. return cluster;
  9119. }
  9120. function count(node) {
  9121. var sum = 0,
  9122. children = node.children,
  9123. i = children && children.length;
  9124. if (!i) sum = 1;
  9125. else while (--i >= 0) sum += children[i].value;
  9126. node.value = sum;
  9127. }
  9128. function node_count() {
  9129. return this.eachAfter(count);
  9130. }
  9131. function node_each(callback) {
  9132. var node = this, current, next = [node], children, i, n;
  9133. do {
  9134. current = next.reverse(), next = [];
  9135. while (node = current.pop()) {
  9136. callback(node), children = node.children;
  9137. if (children) for (i = 0, n = children.length; i < n; ++i) {
  9138. next.push(children[i]);
  9139. }
  9140. }
  9141. } while (next.length);
  9142. return this;
  9143. }
  9144. function node_eachBefore(callback) {
  9145. var node = this, nodes = [node], children, i;
  9146. while (node = nodes.pop()) {
  9147. callback(node), children = node.children;
  9148. if (children) for (i = children.length - 1; i >= 0; --i) {
  9149. nodes.push(children[i]);
  9150. }
  9151. }
  9152. return this;
  9153. }
  9154. function node_eachAfter(callback) {
  9155. var node = this, nodes = [node], next = [], children, i, n;
  9156. while (node = nodes.pop()) {
  9157. next.push(node), children = node.children;
  9158. if (children) for (i = 0, n = children.length; i < n; ++i) {
  9159. nodes.push(children[i]);
  9160. }
  9161. }
  9162. while (node = next.pop()) {
  9163. callback(node);
  9164. }
  9165. return this;
  9166. }
  9167. function node_sum(value) {
  9168. return this.eachAfter(function(node) {
  9169. var sum = +value(node.data) || 0,
  9170. children = node.children,
  9171. i = children && children.length;
  9172. while (--i >= 0) sum += children[i].value;
  9173. node.value = sum;
  9174. });
  9175. }
  9176. function node_sort(compare) {
  9177. return this.eachBefore(function(node) {
  9178. if (node.children) {
  9179. node.children.sort(compare);
  9180. }
  9181. });
  9182. }
  9183. function node_path(end) {
  9184. var start = this,
  9185. ancestor = leastCommonAncestor(start, end),
  9186. nodes = [start];
  9187. while (start !== ancestor) {
  9188. start = start.parent;
  9189. nodes.push(start);
  9190. }
  9191. var k = nodes.length;
  9192. while (end !== ancestor) {
  9193. nodes.splice(k, 0, end);
  9194. end = end.parent;
  9195. }
  9196. return nodes;
  9197. }
  9198. function leastCommonAncestor(a, b) {
  9199. if (a === b) return a;
  9200. var aNodes = a.ancestors(),
  9201. bNodes = b.ancestors(),
  9202. c = null;
  9203. a = aNodes.pop();
  9204. b = bNodes.pop();
  9205. while (a === b) {
  9206. c = a;
  9207. a = aNodes.pop();
  9208. b = bNodes.pop();
  9209. }
  9210. return c;
  9211. }
  9212. function node_ancestors() {
  9213. var node = this, nodes = [node];
  9214. while (node = node.parent) {
  9215. nodes.push(node);
  9216. }
  9217. return nodes;
  9218. }
  9219. function node_descendants() {
  9220. var nodes = [];
  9221. this.each(function(node) {
  9222. nodes.push(node);
  9223. });
  9224. return nodes;
  9225. }
  9226. function node_leaves() {
  9227. var leaves = [];
  9228. this.eachBefore(function(node) {
  9229. if (!node.children) {
  9230. leaves.push(node);
  9231. }
  9232. });
  9233. return leaves;
  9234. }
  9235. function node_links() {
  9236. var root = this, links = [];
  9237. root.each(function(node) {
  9238. if (node !== root) { // Don’t include the root’s parent, if any.
  9239. links.push({source: node.parent, target: node});
  9240. }
  9241. });
  9242. return links;
  9243. }
  9244. function hierarchy(data, children) {
  9245. var root = new Node(data),
  9246. valued = +data.value && (root.value = data.value),
  9247. node,
  9248. nodes = [root],
  9249. child,
  9250. childs,
  9251. i,
  9252. n;
  9253. if (children == null) children = defaultChildren;
  9254. while (node = nodes.pop()) {
  9255. if (valued) node.value = +node.data.value;
  9256. if ((childs = children(node.data)) && (n = childs.length)) {
  9257. node.children = new Array(n);
  9258. for (i = n - 1; i >= 0; --i) {
  9259. nodes.push(child = node.children[i] = new Node(childs[i]));
  9260. child.parent = node;
  9261. child.depth = node.depth + 1;
  9262. }
  9263. }
  9264. }
  9265. return root.eachBefore(computeHeight);
  9266. }
  9267. function node_copy() {
  9268. return hierarchy(this).eachBefore(copyData);
  9269. }
  9270. function defaultChildren(d) {
  9271. return d.children;
  9272. }
  9273. function copyData(node) {
  9274. node.data = node.data.data;
  9275. }
  9276. function computeHeight(node) {
  9277. var height = 0;
  9278. do node.height = height;
  9279. while ((node = node.parent) && (node.height < ++height));
  9280. }
  9281. function Node(data) {
  9282. this.data = data;
  9283. this.depth =
  9284. this.height = 0;
  9285. this.parent = null;
  9286. }
  9287. Node.prototype = hierarchy.prototype = {
  9288. constructor: Node,
  9289. count: node_count,
  9290. each: node_each,
  9291. eachAfter: node_eachAfter,
  9292. eachBefore: node_eachBefore,
  9293. sum: node_sum,
  9294. sort: node_sort,
  9295. path: node_path,
  9296. ancestors: node_ancestors,
  9297. descendants: node_descendants,
  9298. leaves: node_leaves,
  9299. links: node_links,
  9300. copy: node_copy
  9301. };
  9302. var slice$4 = Array.prototype.slice;
  9303. function shuffle$1(array) {
  9304. var m = array.length,
  9305. t,
  9306. i;
  9307. while (m) {
  9308. i = Math.random() * m-- | 0;
  9309. t = array[m];
  9310. array[m] = array[i];
  9311. array[i] = t;
  9312. }
  9313. return array;
  9314. }
  9315. function enclose(circles) {
  9316. var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
  9317. while (i < n) {
  9318. p = circles[i];
  9319. if (e && enclosesWeak(e, p)) ++i;
  9320. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  9321. }
  9322. return e;
  9323. }
  9324. function extendBasis(B, p) {
  9325. var i, j;
  9326. if (enclosesWeakAll(p, B)) return [p];
  9327. // If we get here then B must have at least one element.
  9328. for (i = 0; i < B.length; ++i) {
  9329. if (enclosesNot(p, B[i])
  9330. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  9331. return [B[i], p];
  9332. }
  9333. }
  9334. // If we get here then B must have at least two elements.
  9335. for (i = 0; i < B.length - 1; ++i) {
  9336. for (j = i + 1; j < B.length; ++j) {
  9337. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  9338. && enclosesNot(encloseBasis2(B[i], p), B[j])
  9339. && enclosesNot(encloseBasis2(B[j], p), B[i])
  9340. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  9341. return [B[i], B[j], p];
  9342. }
  9343. }
  9344. }
  9345. // If we get here then something is very wrong.
  9346. throw new Error;
  9347. }
  9348. function enclosesNot(a, b) {
  9349. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  9350. return dr < 0 || dr * dr < dx * dx + dy * dy;
  9351. }
  9352. function enclosesWeak(a, b) {
  9353. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9354. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9355. }
  9356. function enclosesWeakAll(a, B) {
  9357. for (var i = 0; i < B.length; ++i) {
  9358. if (!enclosesWeak(a, B[i])) {
  9359. return false;
  9360. }
  9361. }
  9362. return true;
  9363. }
  9364. function encloseBasis(B) {
  9365. switch (B.length) {
  9366. case 1: return encloseBasis1(B[0]);
  9367. case 2: return encloseBasis2(B[0], B[1]);
  9368. case 3: return encloseBasis3(B[0], B[1], B[2]);
  9369. }
  9370. }
  9371. function encloseBasis1(a) {
  9372. return {
  9373. x: a.x,
  9374. y: a.y,
  9375. r: a.r
  9376. };
  9377. }
  9378. function encloseBasis2(a, b) {
  9379. var x1 = a.x, y1 = a.y, r1 = a.r,
  9380. x2 = b.x, y2 = b.y, r2 = b.r,
  9381. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  9382. l = Math.sqrt(x21 * x21 + y21 * y21);
  9383. return {
  9384. x: (x1 + x2 + x21 / l * r21) / 2,
  9385. y: (y1 + y2 + y21 / l * r21) / 2,
  9386. r: (l + r1 + r2) / 2
  9387. };
  9388. }
  9389. function encloseBasis3(a, b, c) {
  9390. var x1 = a.x, y1 = a.y, r1 = a.r,
  9391. x2 = b.x, y2 = b.y, r2 = b.r,
  9392. x3 = c.x, y3 = c.y, r3 = c.r,
  9393. a2 = x1 - x2,
  9394. a3 = x1 - x3,
  9395. b2 = y1 - y2,
  9396. b3 = y1 - y3,
  9397. c2 = r2 - r1,
  9398. c3 = r3 - r1,
  9399. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  9400. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  9401. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  9402. ab = a3 * b2 - a2 * b3,
  9403. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  9404. xb = (b3 * c2 - b2 * c3) / ab,
  9405. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  9406. yb = (a2 * c3 - a3 * c2) / ab,
  9407. A = xb * xb + yb * yb - 1,
  9408. B = 2 * (r1 + xa * xb + ya * yb),
  9409. C = xa * xa + ya * ya - r1 * r1,
  9410. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  9411. return {
  9412. x: x1 + xa + xb * r,
  9413. y: y1 + ya + yb * r,
  9414. r: r
  9415. };
  9416. }
  9417. function place(b, a, c) {
  9418. var dx = b.x - a.x, x, a2,
  9419. dy = b.y - a.y, y, b2,
  9420. d2 = dx * dx + dy * dy;
  9421. if (d2) {
  9422. a2 = a.r + c.r, a2 *= a2;
  9423. b2 = b.r + c.r, b2 *= b2;
  9424. if (a2 > b2) {
  9425. x = (d2 + b2 - a2) / (2 * d2);
  9426. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  9427. c.x = b.x - x * dx - y * dy;
  9428. c.y = b.y - x * dy + y * dx;
  9429. } else {
  9430. x = (d2 + a2 - b2) / (2 * d2);
  9431. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  9432. c.x = a.x + x * dx - y * dy;
  9433. c.y = a.y + x * dy + y * dx;
  9434. }
  9435. } else {
  9436. c.x = a.x + c.r;
  9437. c.y = a.y;
  9438. }
  9439. }
  9440. function intersects(a, b) {
  9441. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9442. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9443. }
  9444. function score(node) {
  9445. var a = node._,
  9446. b = node.next._,
  9447. ab = a.r + b.r,
  9448. dx = (a.x * b.r + b.x * a.r) / ab,
  9449. dy = (a.y * b.r + b.y * a.r) / ab;
  9450. return dx * dx + dy * dy;
  9451. }
  9452. function Node$1(circle) {
  9453. this._ = circle;
  9454. this.next = null;
  9455. this.previous = null;
  9456. }
  9457. function packEnclose(circles) {
  9458. if (!(n = circles.length)) return 0;
  9459. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  9460. // Place the first circle.
  9461. a = circles[0], a.x = 0, a.y = 0;
  9462. if (!(n > 1)) return a.r;
  9463. // Place the second circle.
  9464. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  9465. if (!(n > 2)) return a.r + b.r;
  9466. // Place the third circle.
  9467. place(b, a, c = circles[2]);
  9468. // Initialize the front-chain using the first three circles a, b and c.
  9469. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  9470. a.next = c.previous = b;
  9471. b.next = a.previous = c;
  9472. c.next = b.previous = a;
  9473. // Attempt to place each remaining circle…
  9474. pack: for (i = 3; i < n; ++i) {
  9475. place(a._, b._, c = circles[i]), c = new Node$1(c);
  9476. // Find the closest intersecting circle on the front-chain, if any.
  9477. // “Closeness” is determined by linear distance along the front-chain.
  9478. // “Ahead” or “behind” is likewise determined by linear distance.
  9479. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  9480. do {
  9481. if (sj <= sk) {
  9482. if (intersects(j._, c._)) {
  9483. b = j, a.next = b, b.previous = a, --i;
  9484. continue pack;
  9485. }
  9486. sj += j._.r, j = j.next;
  9487. } else {
  9488. if (intersects(k._, c._)) {
  9489. a = k, a.next = b, b.previous = a, --i;
  9490. continue pack;
  9491. }
  9492. sk += k._.r, k = k.previous;
  9493. }
  9494. } while (j !== k.next);
  9495. // Success! Insert the new circle c between a and b.
  9496. c.previous = a, c.next = b, a.next = b.previous = b = c;
  9497. // Compute the new closest circle pair to the centroid.
  9498. aa = score(a);
  9499. while ((c = c.next) !== b) {
  9500. if ((ca = score(c)) < aa) {
  9501. a = c, aa = ca;
  9502. }
  9503. }
  9504. b = a.next;
  9505. }
  9506. // Compute the enclosing circle of the front chain.
  9507. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  9508. // Translate the circles to put the enclosing circle around the origin.
  9509. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  9510. return c.r;
  9511. }
  9512. function siblings(circles) {
  9513. packEnclose(circles);
  9514. return circles;
  9515. }
  9516. function optional(f) {
  9517. return f == null ? null : required(f);
  9518. }
  9519. function required(f) {
  9520. if (typeof f !== "function") throw new Error;
  9521. return f;
  9522. }
  9523. function constantZero() {
  9524. return 0;
  9525. }
  9526. function constant$9(x) {
  9527. return function() {
  9528. return x;
  9529. };
  9530. }
  9531. function defaultRadius$1(d) {
  9532. return Math.sqrt(d.value);
  9533. }
  9534. function index$2() {
  9535. var radius = null,
  9536. dx = 1,
  9537. dy = 1,
  9538. padding = constantZero;
  9539. function pack(root) {
  9540. root.x = dx / 2, root.y = dy / 2;
  9541. if (radius) {
  9542. root.eachBefore(radiusLeaf(radius))
  9543. .eachAfter(packChildren(padding, 0.5))
  9544. .eachBefore(translateChild(1));
  9545. } else {
  9546. root.eachBefore(radiusLeaf(defaultRadius$1))
  9547. .eachAfter(packChildren(constantZero, 1))
  9548. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  9549. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  9550. }
  9551. return root;
  9552. }
  9553. pack.radius = function(x) {
  9554. return arguments.length ? (radius = optional(x), pack) : radius;
  9555. };
  9556. pack.size = function(x) {
  9557. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  9558. };
  9559. pack.padding = function(x) {
  9560. return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
  9561. };
  9562. return pack;
  9563. }
  9564. function radiusLeaf(radius) {
  9565. return function(node) {
  9566. if (!node.children) {
  9567. node.r = Math.max(0, +radius(node) || 0);
  9568. }
  9569. };
  9570. }
  9571. function packChildren(padding, k) {
  9572. return function(node) {
  9573. if (children = node.children) {
  9574. var children,
  9575. i,
  9576. n = children.length,
  9577. r = padding(node) * k || 0,
  9578. e;
  9579. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  9580. e = packEnclose(children);
  9581. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  9582. node.r = e + r;
  9583. }
  9584. };
  9585. }
  9586. function translateChild(k) {
  9587. return function(node) {
  9588. var parent = node.parent;
  9589. node.r *= k;
  9590. if (parent) {
  9591. node.x = parent.x + k * node.x;
  9592. node.y = parent.y + k * node.y;
  9593. }
  9594. };
  9595. }
  9596. function roundNode(node) {
  9597. node.x0 = Math.round(node.x0);
  9598. node.y0 = Math.round(node.y0);
  9599. node.x1 = Math.round(node.x1);
  9600. node.y1 = Math.round(node.y1);
  9601. }
  9602. function treemapDice(parent, x0, y0, x1, y1) {
  9603. var nodes = parent.children,
  9604. node,
  9605. i = -1,
  9606. n = nodes.length,
  9607. k = parent.value && (x1 - x0) / parent.value;
  9608. while (++i < n) {
  9609. node = nodes[i], node.y0 = y0, node.y1 = y1;
  9610. node.x0 = x0, node.x1 = x0 += node.value * k;
  9611. }
  9612. }
  9613. function partition() {
  9614. var dx = 1,
  9615. dy = 1,
  9616. padding = 0,
  9617. round = false;
  9618. function partition(root) {
  9619. var n = root.height + 1;
  9620. root.x0 =
  9621. root.y0 = padding;
  9622. root.x1 = dx;
  9623. root.y1 = dy / n;
  9624. root.eachBefore(positionNode(dy, n));
  9625. if (round) root.eachBefore(roundNode);
  9626. return root;
  9627. }
  9628. function positionNode(dy, n) {
  9629. return function(node) {
  9630. if (node.children) {
  9631. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  9632. }
  9633. var x0 = node.x0,
  9634. y0 = node.y0,
  9635. x1 = node.x1 - padding,
  9636. y1 = node.y1 - padding;
  9637. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9638. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9639. node.x0 = x0;
  9640. node.y0 = y0;
  9641. node.x1 = x1;
  9642. node.y1 = y1;
  9643. };
  9644. }
  9645. partition.round = function(x) {
  9646. return arguments.length ? (round = !!x, partition) : round;
  9647. };
  9648. partition.size = function(x) {
  9649. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  9650. };
  9651. partition.padding = function(x) {
  9652. return arguments.length ? (padding = +x, partition) : padding;
  9653. };
  9654. return partition;
  9655. }
  9656. var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
  9657. preroot = {depth: -1},
  9658. ambiguous = {};
  9659. function defaultId(d) {
  9660. return d.id;
  9661. }
  9662. function defaultParentId(d) {
  9663. return d.parentId;
  9664. }
  9665. function stratify() {
  9666. var id = defaultId,
  9667. parentId = defaultParentId;
  9668. function stratify(data) {
  9669. var d,
  9670. i,
  9671. n = data.length,
  9672. root,
  9673. parent,
  9674. node,
  9675. nodes = new Array(n),
  9676. nodeId,
  9677. nodeKey,
  9678. nodeByKey = {};
  9679. for (i = 0; i < n; ++i) {
  9680. d = data[i], node = nodes[i] = new Node(d);
  9681. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  9682. nodeKey = keyPrefix$1 + (node.id = nodeId);
  9683. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  9684. }
  9685. }
  9686. for (i = 0; i < n; ++i) {
  9687. node = nodes[i], nodeId = parentId(data[i], i, data);
  9688. if (nodeId == null || !(nodeId += "")) {
  9689. if (root) throw new Error("multiple roots");
  9690. root = node;
  9691. } else {
  9692. parent = nodeByKey[keyPrefix$1 + nodeId];
  9693. if (!parent) throw new Error("missing: " + nodeId);
  9694. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  9695. if (parent.children) parent.children.push(node);
  9696. else parent.children = [node];
  9697. node.parent = parent;
  9698. }
  9699. }
  9700. if (!root) throw new Error("no root");
  9701. root.parent = preroot;
  9702. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  9703. root.parent = null;
  9704. if (n > 0) throw new Error("cycle");
  9705. return root;
  9706. }
  9707. stratify.id = function(x) {
  9708. return arguments.length ? (id = required(x), stratify) : id;
  9709. };
  9710. stratify.parentId = function(x) {
  9711. return arguments.length ? (parentId = required(x), stratify) : parentId;
  9712. };
  9713. return stratify;
  9714. }
  9715. function defaultSeparation$1(a, b) {
  9716. return a.parent === b.parent ? 1 : 2;
  9717. }
  9718. // function radialSeparation(a, b) {
  9719. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  9720. // }
  9721. // This function is used to traverse the left contour of a subtree (or
  9722. // subforest). It returns the successor of v on this contour. This successor is
  9723. // either given by the leftmost child of v or by the thread of v. The function
  9724. // returns null if and only if v is on the highest level of its subtree.
  9725. function nextLeft(v) {
  9726. var children = v.children;
  9727. return children ? children[0] : v.t;
  9728. }
  9729. // This function works analogously to nextLeft.
  9730. function nextRight(v) {
  9731. var children = v.children;
  9732. return children ? children[children.length - 1] : v.t;
  9733. }
  9734. // Shifts the current subtree rooted at w+. This is done by increasing
  9735. // prelim(w+) and mod(w+) by shift.
  9736. function moveSubtree(wm, wp, shift) {
  9737. var change = shift / (wp.i - wm.i);
  9738. wp.c -= change;
  9739. wp.s += shift;
  9740. wm.c += change;
  9741. wp.z += shift;
  9742. wp.m += shift;
  9743. }
  9744. // All other shifts, applied to the smaller subtrees between w- and w+, are
  9745. // performed by this function. To prepare the shifts, we have to adjust
  9746. // change(w+), shift(w+), and change(w-).
  9747. function executeShifts(v) {
  9748. var shift = 0,
  9749. change = 0,
  9750. children = v.children,
  9751. i = children.length,
  9752. w;
  9753. while (--i >= 0) {
  9754. w = children[i];
  9755. w.z += shift;
  9756. w.m += shift;
  9757. shift += w.s + (change += w.c);
  9758. }
  9759. }
  9760. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  9761. // returns the specified (default) ancestor.
  9762. function nextAncestor(vim, v, ancestor) {
  9763. return vim.a.parent === v.parent ? vim.a : ancestor;
  9764. }
  9765. function TreeNode(node, i) {
  9766. this._ = node;
  9767. this.parent = null;
  9768. this.children = null;
  9769. this.A = null; // default ancestor
  9770. this.a = this; // ancestor
  9771. this.z = 0; // prelim
  9772. this.m = 0; // mod
  9773. this.c = 0; // change
  9774. this.s = 0; // shift
  9775. this.t = null; // thread
  9776. this.i = i; // number
  9777. }
  9778. TreeNode.prototype = Object.create(Node.prototype);
  9779. function treeRoot(root) {
  9780. var tree = new TreeNode(root, 0),
  9781. node,
  9782. nodes = [tree],
  9783. child,
  9784. children,
  9785. i,
  9786. n;
  9787. while (node = nodes.pop()) {
  9788. if (children = node._.children) {
  9789. node.children = new Array(n = children.length);
  9790. for (i = n - 1; i >= 0; --i) {
  9791. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  9792. child.parent = node;
  9793. }
  9794. }
  9795. }
  9796. (tree.parent = new TreeNode(null, 0)).children = [tree];
  9797. return tree;
  9798. }
  9799. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  9800. function tree() {
  9801. var separation = defaultSeparation$1,
  9802. dx = 1,
  9803. dy = 1,
  9804. nodeSize = null;
  9805. function tree(root) {
  9806. var t = treeRoot(root);
  9807. // Compute the layout using Buchheim et al.’s algorithm.
  9808. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9809. t.eachBefore(secondWalk);
  9810. // If a fixed node size is specified, scale x and y.
  9811. if (nodeSize) root.eachBefore(sizeNode);
  9812. // If a fixed tree size is specified, scale x and y based on the extent.
  9813. // Compute the left-most, right-most, and depth-most nodes for extents.
  9814. else {
  9815. var left = root,
  9816. right = root,
  9817. bottom = root;
  9818. root.eachBefore(function(node) {
  9819. if (node.x < left.x) left = node;
  9820. if (node.x > right.x) right = node;
  9821. if (node.depth > bottom.depth) bottom = node;
  9822. });
  9823. var s = left === right ? 1 : separation(left, right) / 2,
  9824. tx = s - left.x,
  9825. kx = dx / (right.x + s + tx),
  9826. ky = dy / (bottom.depth || 1);
  9827. root.eachBefore(function(node) {
  9828. node.x = (node.x + tx) * kx;
  9829. node.y = node.depth * ky;
  9830. });
  9831. }
  9832. return root;
  9833. }
  9834. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9835. // applied recursively to the children of v, as well as the function
  9836. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9837. // node v is placed to the midpoint of its outermost children.
  9838. function firstWalk(v) {
  9839. var children = v.children,
  9840. siblings = v.parent.children,
  9841. w = v.i ? siblings[v.i - 1] : null;
  9842. if (children) {
  9843. executeShifts(v);
  9844. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9845. if (w) {
  9846. v.z = w.z + separation(v._, w._);
  9847. v.m = v.z - midpoint;
  9848. } else {
  9849. v.z = midpoint;
  9850. }
  9851. } else if (w) {
  9852. v.z = w.z + separation(v._, w._);
  9853. }
  9854. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9855. }
  9856. // Computes all real x-coordinates by summing up the modifiers recursively.
  9857. function secondWalk(v) {
  9858. v._.x = v.z + v.parent.m;
  9859. v.m += v.parent.m;
  9860. }
  9861. // The core of the algorithm. Here, a new subtree is combined with the
  9862. // previous subtrees. Threads are used to traverse the inside and outside
  9863. // contours of the left and right subtree up to the highest common level. The
  9864. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9865. // superscript o means outside and i means inside, the subscript - means left
  9866. // subtree and + means right subtree. For summing up the modifiers along the
  9867. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9868. // nodes of the inside contours conflict, we compute the left one of the
  9869. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9870. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9871. // Finally, we add a new thread (if necessary).
  9872. function apportion(v, w, ancestor) {
  9873. if (w) {
  9874. var vip = v,
  9875. vop = v,
  9876. vim = w,
  9877. vom = vip.parent.children[0],
  9878. sip = vip.m,
  9879. sop = vop.m,
  9880. sim = vim.m,
  9881. som = vom.m,
  9882. shift;
  9883. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9884. vom = nextLeft(vom);
  9885. vop = nextRight(vop);
  9886. vop.a = v;
  9887. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9888. if (shift > 0) {
  9889. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9890. sip += shift;
  9891. sop += shift;
  9892. }
  9893. sim += vim.m;
  9894. sip += vip.m;
  9895. som += vom.m;
  9896. sop += vop.m;
  9897. }
  9898. if (vim && !nextRight(vop)) {
  9899. vop.t = vim;
  9900. vop.m += sim - sop;
  9901. }
  9902. if (vip && !nextLeft(vom)) {
  9903. vom.t = vip;
  9904. vom.m += sip - som;
  9905. ancestor = v;
  9906. }
  9907. }
  9908. return ancestor;
  9909. }
  9910. function sizeNode(node) {
  9911. node.x *= dx;
  9912. node.y = node.depth * dy;
  9913. }
  9914. tree.separation = function(x) {
  9915. return arguments.length ? (separation = x, tree) : separation;
  9916. };
  9917. tree.size = function(x) {
  9918. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9919. };
  9920. tree.nodeSize = function(x) {
  9921. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9922. };
  9923. return tree;
  9924. }
  9925. function treemapSlice(parent, x0, y0, x1, y1) {
  9926. var nodes = parent.children,
  9927. node,
  9928. i = -1,
  9929. n = nodes.length,
  9930. k = parent.value && (y1 - y0) / parent.value;
  9931. while (++i < n) {
  9932. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9933. node.y0 = y0, node.y1 = y0 += node.value * k;
  9934. }
  9935. }
  9936. var phi = (1 + Math.sqrt(5)) / 2;
  9937. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9938. var rows = [],
  9939. nodes = parent.children,
  9940. row,
  9941. nodeValue,
  9942. i0 = 0,
  9943. i1 = 0,
  9944. n = nodes.length,
  9945. dx, dy,
  9946. value = parent.value,
  9947. sumValue,
  9948. minValue,
  9949. maxValue,
  9950. newRatio,
  9951. minRatio,
  9952. alpha,
  9953. beta;
  9954. while (i0 < n) {
  9955. dx = x1 - x0, dy = y1 - y0;
  9956. // Find the next non-empty node.
  9957. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9958. minValue = maxValue = sumValue;
  9959. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9960. beta = sumValue * sumValue * alpha;
  9961. minRatio = Math.max(maxValue / beta, beta / minValue);
  9962. // Keep adding nodes while the aspect ratio maintains or improves.
  9963. for (; i1 < n; ++i1) {
  9964. sumValue += nodeValue = nodes[i1].value;
  9965. if (nodeValue < minValue) minValue = nodeValue;
  9966. if (nodeValue > maxValue) maxValue = nodeValue;
  9967. beta = sumValue * sumValue * alpha;
  9968. newRatio = Math.max(maxValue / beta, beta / minValue);
  9969. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9970. minRatio = newRatio;
  9971. }
  9972. // Position and record the row orientation.
  9973. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9974. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9975. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9976. value -= sumValue, i0 = i1;
  9977. }
  9978. return rows;
  9979. }
  9980. var squarify = (function custom(ratio) {
  9981. function squarify(parent, x0, y0, x1, y1) {
  9982. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9983. }
  9984. squarify.ratio = function(x) {
  9985. return custom((x = +x) > 1 ? x : 1);
  9986. };
  9987. return squarify;
  9988. })(phi);
  9989. function index$3() {
  9990. var tile = squarify,
  9991. round = false,
  9992. dx = 1,
  9993. dy = 1,
  9994. paddingStack = [0],
  9995. paddingInner = constantZero,
  9996. paddingTop = constantZero,
  9997. paddingRight = constantZero,
  9998. paddingBottom = constantZero,
  9999. paddingLeft = constantZero;
  10000. function treemap(root) {
  10001. root.x0 =
  10002. root.y0 = 0;
  10003. root.x1 = dx;
  10004. root.y1 = dy;
  10005. root.eachBefore(positionNode);
  10006. paddingStack = [0];
  10007. if (round) root.eachBefore(roundNode);
  10008. return root;
  10009. }
  10010. function positionNode(node) {
  10011. var p = paddingStack[node.depth],
  10012. x0 = node.x0 + p,
  10013. y0 = node.y0 + p,
  10014. x1 = node.x1 - p,
  10015. y1 = node.y1 - p;
  10016. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  10017. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  10018. node.x0 = x0;
  10019. node.y0 = y0;
  10020. node.x1 = x1;
  10021. node.y1 = y1;
  10022. if (node.children) {
  10023. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  10024. x0 += paddingLeft(node) - p;
  10025. y0 += paddingTop(node) - p;
  10026. x1 -= paddingRight(node) - p;
  10027. y1 -= paddingBottom(node) - p;
  10028. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  10029. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  10030. tile(node, x0, y0, x1, y1);
  10031. }
  10032. }
  10033. treemap.round = function(x) {
  10034. return arguments.length ? (round = !!x, treemap) : round;
  10035. };
  10036. treemap.size = function(x) {
  10037. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  10038. };
  10039. treemap.tile = function(x) {
  10040. return arguments.length ? (tile = required(x), treemap) : tile;
  10041. };
  10042. treemap.padding = function(x) {
  10043. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  10044. };
  10045. treemap.paddingInner = function(x) {
  10046. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
  10047. };
  10048. treemap.paddingOuter = function(x) {
  10049. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  10050. };
  10051. treemap.paddingTop = function(x) {
  10052. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
  10053. };
  10054. treemap.paddingRight = function(x) {
  10055. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
  10056. };
  10057. treemap.paddingBottom = function(x) {
  10058. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
  10059. };
  10060. treemap.paddingLeft = function(x) {
  10061. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
  10062. };
  10063. return treemap;
  10064. }
  10065. function binary(parent, x0, y0, x1, y1) {
  10066. var nodes = parent.children,
  10067. i, n = nodes.length,
  10068. sum, sums = new Array(n + 1);
  10069. for (sums[0] = sum = i = 0; i < n; ++i) {
  10070. sums[i + 1] = sum += nodes[i].value;
  10071. }
  10072. partition(0, n, parent.value, x0, y0, x1, y1);
  10073. function partition(i, j, value, x0, y0, x1, y1) {
  10074. if (i >= j - 1) {
  10075. var node = nodes[i];
  10076. node.x0 = x0, node.y0 = y0;
  10077. node.x1 = x1, node.y1 = y1;
  10078. return;
  10079. }
  10080. var valueOffset = sums[i],
  10081. valueTarget = (value / 2) + valueOffset,
  10082. k = i + 1,
  10083. hi = j - 1;
  10084. while (k < hi) {
  10085. var mid = k + hi >>> 1;
  10086. if (sums[mid] < valueTarget) k = mid + 1;
  10087. else hi = mid;
  10088. }
  10089. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  10090. var valueLeft = sums[k] - valueOffset,
  10091. valueRight = value - valueLeft;
  10092. if ((x1 - x0) > (y1 - y0)) {
  10093. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  10094. partition(i, k, valueLeft, x0, y0, xk, y1);
  10095. partition(k, j, valueRight, xk, y0, x1, y1);
  10096. } else {
  10097. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  10098. partition(i, k, valueLeft, x0, y0, x1, yk);
  10099. partition(k, j, valueRight, x0, yk, x1, y1);
  10100. }
  10101. }
  10102. }
  10103. function sliceDice(parent, x0, y0, x1, y1) {
  10104. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  10105. }
  10106. var resquarify = (function custom(ratio) {
  10107. function resquarify(parent, x0, y0, x1, y1) {
  10108. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  10109. var rows,
  10110. row,
  10111. nodes,
  10112. i,
  10113. j = -1,
  10114. n,
  10115. m = rows.length,
  10116. value = parent.value;
  10117. while (++j < m) {
  10118. row = rows[j], nodes = row.children;
  10119. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  10120. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  10121. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  10122. value -= row.value;
  10123. }
  10124. } else {
  10125. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  10126. rows.ratio = ratio;
  10127. }
  10128. }
  10129. resquarify.ratio = function(x) {
  10130. return custom((x = +x) > 1 ? x : 1);
  10131. };
  10132. return resquarify;
  10133. })(phi);
  10134. function area$2(polygon) {
  10135. var i = -1,
  10136. n = polygon.length,
  10137. a,
  10138. b = polygon[n - 1],
  10139. area = 0;
  10140. while (++i < n) {
  10141. a = b;
  10142. b = polygon[i];
  10143. area += a[1] * b[0] - a[0] * b[1];
  10144. }
  10145. return area / 2;
  10146. }
  10147. function centroid$1(polygon) {
  10148. var i = -1,
  10149. n = polygon.length,
  10150. x = 0,
  10151. y = 0,
  10152. a,
  10153. b = polygon[n - 1],
  10154. c,
  10155. k = 0;
  10156. while (++i < n) {
  10157. a = b;
  10158. b = polygon[i];
  10159. k += c = a[0] * b[1] - b[0] * a[1];
  10160. x += (a[0] + b[0]) * c;
  10161. y += (a[1] + b[1]) * c;
  10162. }
  10163. return k *= 3, [x / k, y / k];
  10164. }
  10165. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  10166. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  10167. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  10168. // negative if clockwise, and zero if the points are collinear.
  10169. function cross$1(a, b, c) {
  10170. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  10171. }
  10172. function lexicographicOrder(a, b) {
  10173. return a[0] - b[0] || a[1] - b[1];
  10174. }
  10175. // Computes the upper convex hull per the monotone chain algorithm.
  10176. // Assumes points.length >= 3, is sorted by x, unique in y.
  10177. // Returns an array of indices into points in left-to-right order.
  10178. function computeUpperHullIndexes(points) {
  10179. var n = points.length,
  10180. indexes = [0, 1],
  10181. size = 2;
  10182. for (var i = 2; i < n; ++i) {
  10183. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  10184. indexes[size++] = i;
  10185. }
  10186. return indexes.slice(0, size); // remove popped points
  10187. }
  10188. function hull(points) {
  10189. if ((n = points.length) < 3) return null;
  10190. var i,
  10191. n,
  10192. sortedPoints = new Array(n),
  10193. flippedPoints = new Array(n);
  10194. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  10195. sortedPoints.sort(lexicographicOrder);
  10196. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  10197. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  10198. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  10199. // Construct the hull polygon, removing possible duplicate endpoints.
  10200. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  10201. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  10202. hull = [];
  10203. // Add upper hull in right-to-l order.
  10204. // Then add lower hull in left-to-right order.
  10205. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  10206. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  10207. return hull;
  10208. }
  10209. function contains$2(polygon, point) {
  10210. var n = polygon.length,
  10211. p = polygon[n - 1],
  10212. x = point[0], y = point[1],
  10213. x0 = p[0], y0 = p[1],
  10214. x1, y1,
  10215. inside = false;
  10216. for (var i = 0; i < n; ++i) {
  10217. p = polygon[i], x1 = p[0], y1 = p[1];
  10218. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  10219. x0 = x1, y0 = y1;
  10220. }
  10221. return inside;
  10222. }
  10223. function length$2(polygon) {
  10224. var i = -1,
  10225. n = polygon.length,
  10226. b = polygon[n - 1],
  10227. xa,
  10228. ya,
  10229. xb = b[0],
  10230. yb = b[1],
  10231. perimeter = 0;
  10232. while (++i < n) {
  10233. xa = xb;
  10234. ya = yb;
  10235. b = polygon[i];
  10236. xb = b[0];
  10237. yb = b[1];
  10238. xa -= xb;
  10239. ya -= yb;
  10240. perimeter += Math.sqrt(xa * xa + ya * ya);
  10241. }
  10242. return perimeter;
  10243. }
  10244. function defaultSource$1() {
  10245. return Math.random();
  10246. }
  10247. var uniform = (function sourceRandomUniform(source) {
  10248. function randomUniform(min, max) {
  10249. min = min == null ? 0 : +min;
  10250. max = max == null ? 1 : +max;
  10251. if (arguments.length === 1) max = min, min = 0;
  10252. else max -= min;
  10253. return function() {
  10254. return source() * max + min;
  10255. };
  10256. }
  10257. randomUniform.source = sourceRandomUniform;
  10258. return randomUniform;
  10259. })(defaultSource$1);
  10260. var normal = (function sourceRandomNormal(source) {
  10261. function randomNormal(mu, sigma) {
  10262. var x, r;
  10263. mu = mu == null ? 0 : +mu;
  10264. sigma = sigma == null ? 1 : +sigma;
  10265. return function() {
  10266. var y;
  10267. // If available, use the second previously-generated uniform random.
  10268. if (x != null) y = x, x = null;
  10269. // Otherwise, generate a new x and y.
  10270. else do {
  10271. x = source() * 2 - 1;
  10272. y = source() * 2 - 1;
  10273. r = x * x + y * y;
  10274. } while (!r || r > 1);
  10275. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  10276. };
  10277. }
  10278. randomNormal.source = sourceRandomNormal;
  10279. return randomNormal;
  10280. })(defaultSource$1);
  10281. var logNormal = (function sourceRandomLogNormal(source) {
  10282. function randomLogNormal() {
  10283. var randomNormal = normal.source(source).apply(this, arguments);
  10284. return function() {
  10285. return Math.exp(randomNormal());
  10286. };
  10287. }
  10288. randomLogNormal.source = sourceRandomLogNormal;
  10289. return randomLogNormal;
  10290. })(defaultSource$1);
  10291. var irwinHall = (function sourceRandomIrwinHall(source) {
  10292. function randomIrwinHall(n) {
  10293. return function() {
  10294. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  10295. return sum;
  10296. };
  10297. }
  10298. randomIrwinHall.source = sourceRandomIrwinHall;
  10299. return randomIrwinHall;
  10300. })(defaultSource$1);
  10301. var bates = (function sourceRandomBates(source) {
  10302. function randomBates(n) {
  10303. var randomIrwinHall = irwinHall.source(source)(n);
  10304. return function() {
  10305. return randomIrwinHall() / n;
  10306. };
  10307. }
  10308. randomBates.source = sourceRandomBates;
  10309. return randomBates;
  10310. })(defaultSource$1);
  10311. var exponential$1 = (function sourceRandomExponential(source) {
  10312. function randomExponential(lambda) {
  10313. return function() {
  10314. return -Math.log(1 - source()) / lambda;
  10315. };
  10316. }
  10317. randomExponential.source = sourceRandomExponential;
  10318. return randomExponential;
  10319. })(defaultSource$1);
  10320. function initRange(domain, range) {
  10321. switch (arguments.length) {
  10322. case 0: break;
  10323. case 1: this.range(domain); break;
  10324. default: this.range(range).domain(domain); break;
  10325. }
  10326. return this;
  10327. }
  10328. function initInterpolator(domain, interpolator) {
  10329. switch (arguments.length) {
  10330. case 0: break;
  10331. case 1: this.interpolator(domain); break;
  10332. default: this.interpolator(interpolator).domain(domain); break;
  10333. }
  10334. return this;
  10335. }
  10336. var array$3 = Array.prototype;
  10337. var map$3 = array$3.map;
  10338. var slice$5 = array$3.slice;
  10339. var implicit = {name: "implicit"};
  10340. function ordinal() {
  10341. var index = map$1(),
  10342. domain = [],
  10343. range = [],
  10344. unknown = implicit;
  10345. function scale(d) {
  10346. var key = d + "", i = index.get(key);
  10347. if (!i) {
  10348. if (unknown !== implicit) return unknown;
  10349. index.set(key, i = domain.push(d));
  10350. }
  10351. return range[(i - 1) % range.length];
  10352. }
  10353. scale.domain = function(_) {
  10354. if (!arguments.length) return domain.slice();
  10355. domain = [], index = map$1();
  10356. var i = -1, n = _.length, d, key;
  10357. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  10358. return scale;
  10359. };
  10360. scale.range = function(_) {
  10361. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  10362. };
  10363. scale.unknown = function(_) {
  10364. return arguments.length ? (unknown = _, scale) : unknown;
  10365. };
  10366. scale.copy = function() {
  10367. return ordinal(domain, range).unknown(unknown);
  10368. };
  10369. initRange.apply(scale, arguments);
  10370. return scale;
  10371. }
  10372. function band() {
  10373. var scale = ordinal().unknown(undefined),
  10374. domain = scale.domain,
  10375. ordinalRange = scale.range,
  10376. range = [0, 1],
  10377. step,
  10378. bandwidth,
  10379. round = false,
  10380. paddingInner = 0,
  10381. paddingOuter = 0,
  10382. align = 0.5;
  10383. delete scale.unknown;
  10384. function rescale() {
  10385. var n = domain().length,
  10386. reverse = range[1] < range[0],
  10387. start = range[reverse - 0],
  10388. stop = range[1 - reverse];
  10389. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  10390. if (round) step = Math.floor(step);
  10391. start += (stop - start - step * (n - paddingInner)) * align;
  10392. bandwidth = step * (1 - paddingInner);
  10393. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  10394. var values = sequence(n).map(function(i) { return start + step * i; });
  10395. return ordinalRange(reverse ? values.reverse() : values);
  10396. }
  10397. scale.domain = function(_) {
  10398. return arguments.length ? (domain(_), rescale()) : domain();
  10399. };
  10400. scale.range = function(_) {
  10401. return arguments.length ? (range = [+_[0], +_[1]], rescale()) : range.slice();
  10402. };
  10403. scale.rangeRound = function(_) {
  10404. return range = [+_[0], +_[1]], round = true, rescale();
  10405. };
  10406. scale.bandwidth = function() {
  10407. return bandwidth;
  10408. };
  10409. scale.step = function() {
  10410. return step;
  10411. };
  10412. scale.round = function(_) {
  10413. return arguments.length ? (round = !!_, rescale()) : round;
  10414. };
  10415. scale.padding = function(_) {
  10416. return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
  10417. };
  10418. scale.paddingInner = function(_) {
  10419. return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
  10420. };
  10421. scale.paddingOuter = function(_) {
  10422. return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
  10423. };
  10424. scale.align = function(_) {
  10425. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  10426. };
  10427. scale.copy = function() {
  10428. return band(domain(), range)
  10429. .round(round)
  10430. .paddingInner(paddingInner)
  10431. .paddingOuter(paddingOuter)
  10432. .align(align);
  10433. };
  10434. return initRange.apply(rescale(), arguments);
  10435. }
  10436. function pointish(scale) {
  10437. var copy = scale.copy;
  10438. scale.padding = scale.paddingOuter;
  10439. delete scale.paddingInner;
  10440. delete scale.paddingOuter;
  10441. scale.copy = function() {
  10442. return pointish(copy());
  10443. };
  10444. return scale;
  10445. }
  10446. function point$1() {
  10447. return pointish(band.apply(null, arguments).paddingInner(1));
  10448. }
  10449. function constant$a(x) {
  10450. return function() {
  10451. return x;
  10452. };
  10453. }
  10454. function number$2(x) {
  10455. return +x;
  10456. }
  10457. var unit = [0, 1];
  10458. function identity$6(x) {
  10459. return x;
  10460. }
  10461. function normalize(a, b) {
  10462. return (b -= (a = +a))
  10463. ? function(x) { return (x - a) / b; }
  10464. : constant$a(isNaN(b) ? NaN : 0.5);
  10465. }
  10466. function clamper(domain) {
  10467. var a = domain[0], b = domain[domain.length - 1], t;
  10468. if (a > b) t = a, a = b, b = t;
  10469. return function(x) { return Math.max(a, Math.min(b, x)); };
  10470. }
  10471. // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  10472. // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
  10473. function bimap(domain, range, interpolate) {
  10474. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  10475. if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
  10476. else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
  10477. return function(x) { return r0(d0(x)); };
  10478. }
  10479. function polymap(domain, range, interpolate) {
  10480. var j = Math.min(domain.length, range.length) - 1,
  10481. d = new Array(j),
  10482. r = new Array(j),
  10483. i = -1;
  10484. // Reverse descending domains.
  10485. if (domain[j] < domain[0]) {
  10486. domain = domain.slice().reverse();
  10487. range = range.slice().reverse();
  10488. }
  10489. while (++i < j) {
  10490. d[i] = normalize(domain[i], domain[i + 1]);
  10491. r[i] = interpolate(range[i], range[i + 1]);
  10492. }
  10493. return function(x) {
  10494. var i = bisectRight(domain, x, 1, j) - 1;
  10495. return r[i](d[i](x));
  10496. };
  10497. }
  10498. function copy(source, target) {
  10499. return target
  10500. .domain(source.domain())
  10501. .range(source.range())
  10502. .interpolate(source.interpolate())
  10503. .clamp(source.clamp())
  10504. .unknown(source.unknown());
  10505. }
  10506. function transformer$1() {
  10507. var domain = unit,
  10508. range = unit,
  10509. interpolate = interpolateValue,
  10510. transform,
  10511. untransform,
  10512. unknown,
  10513. clamp = identity$6,
  10514. piecewise,
  10515. output,
  10516. input;
  10517. function rescale() {
  10518. piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  10519. output = input = null;
  10520. return scale;
  10521. }
  10522. function scale(x) {
  10523. return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
  10524. }
  10525. scale.invert = function(y) {
  10526. return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
  10527. };
  10528. scale.domain = function(_) {
  10529. return arguments.length ? (domain = map$3.call(_, number$2), clamp === identity$6 || (clamp = clamper(domain)), rescale()) : domain.slice();
  10530. };
  10531. scale.range = function(_) {
  10532. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10533. };
  10534. scale.rangeRound = function(_) {
  10535. return range = slice$5.call(_), interpolate = interpolateRound, rescale();
  10536. };
  10537. scale.clamp = function(_) {
  10538. return arguments.length ? (clamp = _ ? clamper(domain) : identity$6, scale) : clamp !== identity$6;
  10539. };
  10540. scale.interpolate = function(_) {
  10541. return arguments.length ? (interpolate = _, rescale()) : interpolate;
  10542. };
  10543. scale.unknown = function(_) {
  10544. return arguments.length ? (unknown = _, scale) : unknown;
  10545. };
  10546. return function(t, u) {
  10547. transform = t, untransform = u;
  10548. return rescale();
  10549. };
  10550. }
  10551. function continuous(transform, untransform) {
  10552. return transformer$1()(transform, untransform);
  10553. }
  10554. function tickFormat(start, stop, count, specifier) {
  10555. var step = tickStep(start, stop, count),
  10556. precision;
  10557. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10558. switch (specifier.type) {
  10559. case "s": {
  10560. var value = Math.max(Math.abs(start), Math.abs(stop));
  10561. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10562. return exports.formatPrefix(specifier, value);
  10563. }
  10564. case "":
  10565. case "e":
  10566. case "g":
  10567. case "p":
  10568. case "r": {
  10569. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10570. break;
  10571. }
  10572. case "f":
  10573. case "%": {
  10574. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10575. break;
  10576. }
  10577. }
  10578. return exports.format(specifier);
  10579. }
  10580. function linearish(scale) {
  10581. var domain = scale.domain;
  10582. scale.ticks = function(count) {
  10583. var d = domain();
  10584. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10585. };
  10586. scale.tickFormat = function(count, specifier) {
  10587. var d = domain();
  10588. return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
  10589. };
  10590. scale.nice = function(count) {
  10591. if (count == null) count = 10;
  10592. var d = domain(),
  10593. i0 = 0,
  10594. i1 = d.length - 1,
  10595. start = d[i0],
  10596. stop = d[i1],
  10597. step;
  10598. if (stop < start) {
  10599. step = start, start = stop, stop = step;
  10600. step = i0, i0 = i1, i1 = step;
  10601. }
  10602. step = tickIncrement(start, stop, count);
  10603. if (step > 0) {
  10604. start = Math.floor(start / step) * step;
  10605. stop = Math.ceil(stop / step) * step;
  10606. step = tickIncrement(start, stop, count);
  10607. } else if (step < 0) {
  10608. start = Math.ceil(start * step) / step;
  10609. stop = Math.floor(stop * step) / step;
  10610. step = tickIncrement(start, stop, count);
  10611. }
  10612. if (step > 0) {
  10613. d[i0] = Math.floor(start / step) * step;
  10614. d[i1] = Math.ceil(stop / step) * step;
  10615. domain(d);
  10616. } else if (step < 0) {
  10617. d[i0] = Math.ceil(start * step) / step;
  10618. d[i1] = Math.floor(stop * step) / step;
  10619. domain(d);
  10620. }
  10621. return scale;
  10622. };
  10623. return scale;
  10624. }
  10625. function linear$2() {
  10626. var scale = continuous(identity$6, identity$6);
  10627. scale.copy = function() {
  10628. return copy(scale, linear$2());
  10629. };
  10630. initRange.apply(scale, arguments);
  10631. return linearish(scale);
  10632. }
  10633. function identity$7(domain) {
  10634. var unknown;
  10635. function scale(x) {
  10636. return isNaN(x = +x) ? unknown : x;
  10637. }
  10638. scale.invert = scale;
  10639. scale.domain = scale.range = function(_) {
  10640. return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
  10641. };
  10642. scale.unknown = function(_) {
  10643. return arguments.length ? (unknown = _, scale) : unknown;
  10644. };
  10645. scale.copy = function() {
  10646. return identity$7(domain).unknown(unknown);
  10647. };
  10648. domain = arguments.length ? map$3.call(domain, number$2) : [0, 1];
  10649. return linearish(scale);
  10650. }
  10651. function nice(domain, interval) {
  10652. domain = domain.slice();
  10653. var i0 = 0,
  10654. i1 = domain.length - 1,
  10655. x0 = domain[i0],
  10656. x1 = domain[i1],
  10657. t;
  10658. if (x1 < x0) {
  10659. t = i0, i0 = i1, i1 = t;
  10660. t = x0, x0 = x1, x1 = t;
  10661. }
  10662. domain[i0] = interval.floor(x0);
  10663. domain[i1] = interval.ceil(x1);
  10664. return domain;
  10665. }
  10666. function transformLog(x) {
  10667. return Math.log(x);
  10668. }
  10669. function transformExp(x) {
  10670. return Math.exp(x);
  10671. }
  10672. function transformLogn(x) {
  10673. return -Math.log(-x);
  10674. }
  10675. function transformExpn(x) {
  10676. return -Math.exp(-x);
  10677. }
  10678. function pow10(x) {
  10679. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10680. }
  10681. function powp(base) {
  10682. return base === 10 ? pow10
  10683. : base === Math.E ? Math.exp
  10684. : function(x) { return Math.pow(base, x); };
  10685. }
  10686. function logp(base) {
  10687. return base === Math.E ? Math.log
  10688. : base === 10 && Math.log10
  10689. || base === 2 && Math.log2
  10690. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10691. }
  10692. function reflect(f) {
  10693. return function(x) {
  10694. return -f(-x);
  10695. };
  10696. }
  10697. function loggish(transform) {
  10698. var scale = transform(transformLog, transformExp),
  10699. domain = scale.domain,
  10700. base = 10,
  10701. logs,
  10702. pows;
  10703. function rescale() {
  10704. logs = logp(base), pows = powp(base);
  10705. if (domain()[0] < 0) {
  10706. logs = reflect(logs), pows = reflect(pows);
  10707. transform(transformLogn, transformExpn);
  10708. } else {
  10709. transform(transformLog, transformExp);
  10710. }
  10711. return scale;
  10712. }
  10713. scale.base = function(_) {
  10714. return arguments.length ? (base = +_, rescale()) : base;
  10715. };
  10716. scale.domain = function(_) {
  10717. return arguments.length ? (domain(_), rescale()) : domain();
  10718. };
  10719. scale.ticks = function(count) {
  10720. var d = domain(),
  10721. u = d[0],
  10722. v = d[d.length - 1],
  10723. r;
  10724. if (r = v < u) i = u, u = v, v = i;
  10725. var i = logs(u),
  10726. j = logs(v),
  10727. p,
  10728. k,
  10729. t,
  10730. n = count == null ? 10 : +count,
  10731. z = [];
  10732. if (!(base % 1) && j - i < n) {
  10733. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10734. if (u > 0) for (; i < j; ++i) {
  10735. for (k = 1, p = pows(i); k < base; ++k) {
  10736. t = p * k;
  10737. if (t < u) continue;
  10738. if (t > v) break;
  10739. z.push(t);
  10740. }
  10741. } else for (; i < j; ++i) {
  10742. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10743. t = p * k;
  10744. if (t < u) continue;
  10745. if (t > v) break;
  10746. z.push(t);
  10747. }
  10748. }
  10749. } else {
  10750. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10751. }
  10752. return r ? z.reverse() : z;
  10753. };
  10754. scale.tickFormat = function(count, specifier) {
  10755. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10756. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10757. if (count === Infinity) return specifier;
  10758. if (count == null) count = 10;
  10759. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10760. return function(d) {
  10761. var i = d / pows(Math.round(logs(d)));
  10762. if (i * base < base - 0.5) i *= base;
  10763. return i <= k ? specifier(d) : "";
  10764. };
  10765. };
  10766. scale.nice = function() {
  10767. return domain(nice(domain(), {
  10768. floor: function(x) { return pows(Math.floor(logs(x))); },
  10769. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10770. }));
  10771. };
  10772. return scale;
  10773. }
  10774. function log$1() {
  10775. var scale = loggish(transformer$1()).domain([1, 10]);
  10776. scale.copy = function() {
  10777. return copy(scale, log$1()).base(scale.base());
  10778. };
  10779. initRange.apply(scale, arguments);
  10780. return scale;
  10781. }
  10782. function transformSymlog(c) {
  10783. return function(x) {
  10784. return Math.sign(x) * Math.log1p(Math.abs(x / c));
  10785. };
  10786. }
  10787. function transformSymexp(c) {
  10788. return function(x) {
  10789. return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
  10790. };
  10791. }
  10792. function symlogish(transform) {
  10793. var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
  10794. scale.constant = function(_) {
  10795. return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
  10796. };
  10797. return linearish(scale);
  10798. }
  10799. function symlog() {
  10800. var scale = symlogish(transformer$1());
  10801. scale.copy = function() {
  10802. return copy(scale, symlog()).constant(scale.constant());
  10803. };
  10804. return initRange.apply(scale, arguments);
  10805. }
  10806. function transformPow(exponent) {
  10807. return function(x) {
  10808. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10809. };
  10810. }
  10811. function transformSqrt(x) {
  10812. return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
  10813. }
  10814. function transformSquare(x) {
  10815. return x < 0 ? -x * x : x * x;
  10816. }
  10817. function powish(transform) {
  10818. var scale = transform(identity$6, identity$6),
  10819. exponent = 1;
  10820. function rescale() {
  10821. return exponent === 1 ? transform(identity$6, identity$6)
  10822. : exponent === 0.5 ? transform(transformSqrt, transformSquare)
  10823. : transform(transformPow(exponent), transformPow(1 / exponent));
  10824. }
  10825. scale.exponent = function(_) {
  10826. return arguments.length ? (exponent = +_, rescale()) : exponent;
  10827. };
  10828. return linearish(scale);
  10829. }
  10830. function pow$1() {
  10831. var scale = powish(transformer$1());
  10832. scale.copy = function() {
  10833. return copy(scale, pow$1()).exponent(scale.exponent());
  10834. };
  10835. initRange.apply(scale, arguments);
  10836. return scale;
  10837. }
  10838. function sqrt$1() {
  10839. return pow$1.apply(null, arguments).exponent(0.5);
  10840. }
  10841. function quantile() {
  10842. var domain = [],
  10843. range = [],
  10844. thresholds = [],
  10845. unknown;
  10846. function rescale() {
  10847. var i = 0, n = Math.max(1, range.length);
  10848. thresholds = new Array(n - 1);
  10849. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10850. return scale;
  10851. }
  10852. function scale(x) {
  10853. return isNaN(x = +x) ? unknown : range[bisectRight(thresholds, x)];
  10854. }
  10855. scale.invertExtent = function(y) {
  10856. var i = range.indexOf(y);
  10857. return i < 0 ? [NaN, NaN] : [
  10858. i > 0 ? thresholds[i - 1] : domain[0],
  10859. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10860. ];
  10861. };
  10862. scale.domain = function(_) {
  10863. if (!arguments.length) return domain.slice();
  10864. domain = [];
  10865. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10866. domain.sort(ascending);
  10867. return rescale();
  10868. };
  10869. scale.range = function(_) {
  10870. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10871. };
  10872. scale.unknown = function(_) {
  10873. return arguments.length ? (unknown = _, scale) : unknown;
  10874. };
  10875. scale.quantiles = function() {
  10876. return thresholds.slice();
  10877. };
  10878. scale.copy = function() {
  10879. return quantile()
  10880. .domain(domain)
  10881. .range(range)
  10882. .unknown(unknown);
  10883. };
  10884. return initRange.apply(scale, arguments);
  10885. }
  10886. function quantize$1() {
  10887. var x0 = 0,
  10888. x1 = 1,
  10889. n = 1,
  10890. domain = [0.5],
  10891. range = [0, 1],
  10892. unknown;
  10893. function scale(x) {
  10894. return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
  10895. }
  10896. function rescale() {
  10897. var i = -1;
  10898. domain = new Array(n);
  10899. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10900. return scale;
  10901. }
  10902. scale.domain = function(_) {
  10903. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10904. };
  10905. scale.range = function(_) {
  10906. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10907. };
  10908. scale.invertExtent = function(y) {
  10909. var i = range.indexOf(y);
  10910. return i < 0 ? [NaN, NaN]
  10911. : i < 1 ? [x0, domain[0]]
  10912. : i >= n ? [domain[n - 1], x1]
  10913. : [domain[i - 1], domain[i]];
  10914. };
  10915. scale.unknown = function(_) {
  10916. return arguments.length ? (unknown = _, scale) : scale;
  10917. };
  10918. scale.thresholds = function() {
  10919. return domain.slice();
  10920. };
  10921. scale.copy = function() {
  10922. return quantize$1()
  10923. .domain([x0, x1])
  10924. .range(range)
  10925. .unknown(unknown);
  10926. };
  10927. return initRange.apply(linearish(scale), arguments);
  10928. }
  10929. function threshold$1() {
  10930. var domain = [0.5],
  10931. range = [0, 1],
  10932. unknown,
  10933. n = 1;
  10934. function scale(x) {
  10935. return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
  10936. }
  10937. scale.domain = function(_) {
  10938. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10939. };
  10940. scale.range = function(_) {
  10941. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10942. };
  10943. scale.invertExtent = function(y) {
  10944. var i = range.indexOf(y);
  10945. return [domain[i - 1], domain[i]];
  10946. };
  10947. scale.unknown = function(_) {
  10948. return arguments.length ? (unknown = _, scale) : unknown;
  10949. };
  10950. scale.copy = function() {
  10951. return threshold$1()
  10952. .domain(domain)
  10953. .range(range)
  10954. .unknown(unknown);
  10955. };
  10956. return initRange.apply(scale, arguments);
  10957. }
  10958. var t0$1 = new Date,
  10959. t1$1 = new Date;
  10960. function newInterval(floori, offseti, count, field) {
  10961. function interval(date) {
  10962. return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
  10963. }
  10964. interval.floor = function(date) {
  10965. return floori(date = new Date(+date)), date;
  10966. };
  10967. interval.ceil = function(date) {
  10968. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10969. };
  10970. interval.round = function(date) {
  10971. var d0 = interval(date),
  10972. d1 = interval.ceil(date);
  10973. return date - d0 < d1 - date ? d0 : d1;
  10974. };
  10975. interval.offset = function(date, step) {
  10976. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10977. };
  10978. interval.range = function(start, stop, step) {
  10979. var range = [], previous;
  10980. start = interval.ceil(start);
  10981. step = step == null ? 1 : Math.floor(step);
  10982. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10983. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  10984. while (previous < start && start < stop);
  10985. return range;
  10986. };
  10987. interval.filter = function(test) {
  10988. return newInterval(function(date) {
  10989. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10990. }, function(date, step) {
  10991. if (date >= date) {
  10992. if (step < 0) while (++step <= 0) {
  10993. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10994. } else while (--step >= 0) {
  10995. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10996. }
  10997. }
  10998. });
  10999. };
  11000. if (count) {
  11001. interval.count = function(start, end) {
  11002. t0$1.setTime(+start), t1$1.setTime(+end);
  11003. floori(t0$1), floori(t1$1);
  11004. return Math.floor(count(t0$1, t1$1));
  11005. };
  11006. interval.every = function(step) {
  11007. step = Math.floor(step);
  11008. return !isFinite(step) || !(step > 0) ? null
  11009. : !(step > 1) ? interval
  11010. : interval.filter(field
  11011. ? function(d) { return field(d) % step === 0; }
  11012. : function(d) { return interval.count(0, d) % step === 0; });
  11013. };
  11014. }
  11015. return interval;
  11016. }
  11017. var millisecond = newInterval(function() {
  11018. // noop
  11019. }, function(date, step) {
  11020. date.setTime(+date + step);
  11021. }, function(start, end) {
  11022. return end - start;
  11023. });
  11024. // An optimized implementation for this simple case.
  11025. millisecond.every = function(k) {
  11026. k = Math.floor(k);
  11027. if (!isFinite(k) || !(k > 0)) return null;
  11028. if (!(k > 1)) return millisecond;
  11029. return newInterval(function(date) {
  11030. date.setTime(Math.floor(date / k) * k);
  11031. }, function(date, step) {
  11032. date.setTime(+date + step * k);
  11033. }, function(start, end) {
  11034. return (end - start) / k;
  11035. });
  11036. };
  11037. var milliseconds = millisecond.range;
  11038. var durationSecond = 1e3;
  11039. var durationMinute = 6e4;
  11040. var durationHour = 36e5;
  11041. var durationDay = 864e5;
  11042. var durationWeek = 6048e5;
  11043. var second = newInterval(function(date) {
  11044. date.setTime(date - date.getMilliseconds());
  11045. }, function(date, step) {
  11046. date.setTime(+date + step * durationSecond);
  11047. }, function(start, end) {
  11048. return (end - start) / durationSecond;
  11049. }, function(date) {
  11050. return date.getUTCSeconds();
  11051. });
  11052. var seconds = second.range;
  11053. var minute = newInterval(function(date) {
  11054. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
  11055. }, function(date, step) {
  11056. date.setTime(+date + step * durationMinute);
  11057. }, function(start, end) {
  11058. return (end - start) / durationMinute;
  11059. }, function(date) {
  11060. return date.getMinutes();
  11061. });
  11062. var minutes = minute.range;
  11063. var hour = newInterval(function(date) {
  11064. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
  11065. }, function(date, step) {
  11066. date.setTime(+date + step * durationHour);
  11067. }, function(start, end) {
  11068. return (end - start) / durationHour;
  11069. }, function(date) {
  11070. return date.getHours();
  11071. });
  11072. var hours = hour.range;
  11073. var day = newInterval(function(date) {
  11074. date.setHours(0, 0, 0, 0);
  11075. }, function(date, step) {
  11076. date.setDate(date.getDate() + step);
  11077. }, function(start, end) {
  11078. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  11079. }, function(date) {
  11080. return date.getDate() - 1;
  11081. });
  11082. var days = day.range;
  11083. function weekday(i) {
  11084. return newInterval(function(date) {
  11085. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  11086. date.setHours(0, 0, 0, 0);
  11087. }, function(date, step) {
  11088. date.setDate(date.getDate() + step * 7);
  11089. }, function(start, end) {
  11090. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  11091. });
  11092. }
  11093. var sunday = weekday(0);
  11094. var monday = weekday(1);
  11095. var tuesday = weekday(2);
  11096. var wednesday = weekday(3);
  11097. var thursday = weekday(4);
  11098. var friday = weekday(5);
  11099. var saturday = weekday(6);
  11100. var sundays = sunday.range;
  11101. var mondays = monday.range;
  11102. var tuesdays = tuesday.range;
  11103. var wednesdays = wednesday.range;
  11104. var thursdays = thursday.range;
  11105. var fridays = friday.range;
  11106. var saturdays = saturday.range;
  11107. var month = newInterval(function(date) {
  11108. date.setDate(1);
  11109. date.setHours(0, 0, 0, 0);
  11110. }, function(date, step) {
  11111. date.setMonth(date.getMonth() + step);
  11112. }, function(start, end) {
  11113. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  11114. }, function(date) {
  11115. return date.getMonth();
  11116. });
  11117. var months = month.range;
  11118. var year = newInterval(function(date) {
  11119. date.setMonth(0, 1);
  11120. date.setHours(0, 0, 0, 0);
  11121. }, function(date, step) {
  11122. date.setFullYear(date.getFullYear() + step);
  11123. }, function(start, end) {
  11124. return end.getFullYear() - start.getFullYear();
  11125. }, function(date) {
  11126. return date.getFullYear();
  11127. });
  11128. // An optimized implementation for this simple case.
  11129. year.every = function(k) {
  11130. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  11131. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  11132. date.setMonth(0, 1);
  11133. date.setHours(0, 0, 0, 0);
  11134. }, function(date, step) {
  11135. date.setFullYear(date.getFullYear() + step * k);
  11136. });
  11137. };
  11138. var years = year.range;
  11139. var utcMinute = newInterval(function(date) {
  11140. date.setUTCSeconds(0, 0);
  11141. }, function(date, step) {
  11142. date.setTime(+date + step * durationMinute);
  11143. }, function(start, end) {
  11144. return (end - start) / durationMinute;
  11145. }, function(date) {
  11146. return date.getUTCMinutes();
  11147. });
  11148. var utcMinutes = utcMinute.range;
  11149. var utcHour = newInterval(function(date) {
  11150. date.setUTCMinutes(0, 0, 0);
  11151. }, function(date, step) {
  11152. date.setTime(+date + step * durationHour);
  11153. }, function(start, end) {
  11154. return (end - start) / durationHour;
  11155. }, function(date) {
  11156. return date.getUTCHours();
  11157. });
  11158. var utcHours = utcHour.range;
  11159. var utcDay = newInterval(function(date) {
  11160. date.setUTCHours(0, 0, 0, 0);
  11161. }, function(date, step) {
  11162. date.setUTCDate(date.getUTCDate() + step);
  11163. }, function(start, end) {
  11164. return (end - start) / durationDay;
  11165. }, function(date) {
  11166. return date.getUTCDate() - 1;
  11167. });
  11168. var utcDays = utcDay.range;
  11169. function utcWeekday(i) {
  11170. return newInterval(function(date) {
  11171. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  11172. date.setUTCHours(0, 0, 0, 0);
  11173. }, function(date, step) {
  11174. date.setUTCDate(date.getUTCDate() + step * 7);
  11175. }, function(start, end) {
  11176. return (end - start) / durationWeek;
  11177. });
  11178. }
  11179. var utcSunday = utcWeekday(0);
  11180. var utcMonday = utcWeekday(1);
  11181. var utcTuesday = utcWeekday(2);
  11182. var utcWednesday = utcWeekday(3);
  11183. var utcThursday = utcWeekday(4);
  11184. var utcFriday = utcWeekday(5);
  11185. var utcSaturday = utcWeekday(6);
  11186. var utcSundays = utcSunday.range;
  11187. var utcMondays = utcMonday.range;
  11188. var utcTuesdays = utcTuesday.range;
  11189. var utcWednesdays = utcWednesday.range;
  11190. var utcThursdays = utcThursday.range;
  11191. var utcFridays = utcFriday.range;
  11192. var utcSaturdays = utcSaturday.range;
  11193. var utcMonth = newInterval(function(date) {
  11194. date.setUTCDate(1);
  11195. date.setUTCHours(0, 0, 0, 0);
  11196. }, function(date, step) {
  11197. date.setUTCMonth(date.getUTCMonth() + step);
  11198. }, function(start, end) {
  11199. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  11200. }, function(date) {
  11201. return date.getUTCMonth();
  11202. });
  11203. var utcMonths = utcMonth.range;
  11204. var utcYear = newInterval(function(date) {
  11205. date.setUTCMonth(0, 1);
  11206. date.setUTCHours(0, 0, 0, 0);
  11207. }, function(date, step) {
  11208. date.setUTCFullYear(date.getUTCFullYear() + step);
  11209. }, function(start, end) {
  11210. return end.getUTCFullYear() - start.getUTCFullYear();
  11211. }, function(date) {
  11212. return date.getUTCFullYear();
  11213. });
  11214. // An optimized implementation for this simple case.
  11215. utcYear.every = function(k) {
  11216. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  11217. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  11218. date.setUTCMonth(0, 1);
  11219. date.setUTCHours(0, 0, 0, 0);
  11220. }, function(date, step) {
  11221. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  11222. });
  11223. };
  11224. var utcYears = utcYear.range;
  11225. function localDate(d) {
  11226. if (0 <= d.y && d.y < 100) {
  11227. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  11228. date.setFullYear(d.y);
  11229. return date;
  11230. }
  11231. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  11232. }
  11233. function utcDate(d) {
  11234. if (0 <= d.y && d.y < 100) {
  11235. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  11236. date.setUTCFullYear(d.y);
  11237. return date;
  11238. }
  11239. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  11240. }
  11241. function newDate(y, m, d) {
  11242. return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
  11243. }
  11244. function formatLocale$1(locale) {
  11245. var locale_dateTime = locale.dateTime,
  11246. locale_date = locale.date,
  11247. locale_time = locale.time,
  11248. locale_periods = locale.periods,
  11249. locale_weekdays = locale.days,
  11250. locale_shortWeekdays = locale.shortDays,
  11251. locale_months = locale.months,
  11252. locale_shortMonths = locale.shortMonths;
  11253. var periodRe = formatRe(locale_periods),
  11254. periodLookup = formatLookup(locale_periods),
  11255. weekdayRe = formatRe(locale_weekdays),
  11256. weekdayLookup = formatLookup(locale_weekdays),
  11257. shortWeekdayRe = formatRe(locale_shortWeekdays),
  11258. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  11259. monthRe = formatRe(locale_months),
  11260. monthLookup = formatLookup(locale_months),
  11261. shortMonthRe = formatRe(locale_shortMonths),
  11262. shortMonthLookup = formatLookup(locale_shortMonths);
  11263. var formats = {
  11264. "a": formatShortWeekday,
  11265. "A": formatWeekday,
  11266. "b": formatShortMonth,
  11267. "B": formatMonth,
  11268. "c": null,
  11269. "d": formatDayOfMonth,
  11270. "e": formatDayOfMonth,
  11271. "f": formatMicroseconds,
  11272. "H": formatHour24,
  11273. "I": formatHour12,
  11274. "j": formatDayOfYear,
  11275. "L": formatMilliseconds,
  11276. "m": formatMonthNumber,
  11277. "M": formatMinutes,
  11278. "p": formatPeriod,
  11279. "q": formatQuarter,
  11280. "Q": formatUnixTimestamp,
  11281. "s": formatUnixTimestampSeconds,
  11282. "S": formatSeconds,
  11283. "u": formatWeekdayNumberMonday,
  11284. "U": formatWeekNumberSunday,
  11285. "V": formatWeekNumberISO,
  11286. "w": formatWeekdayNumberSunday,
  11287. "W": formatWeekNumberMonday,
  11288. "x": null,
  11289. "X": null,
  11290. "y": formatYear$1,
  11291. "Y": formatFullYear,
  11292. "Z": formatZone,
  11293. "%": formatLiteralPercent
  11294. };
  11295. var utcFormats = {
  11296. "a": formatUTCShortWeekday,
  11297. "A": formatUTCWeekday,
  11298. "b": formatUTCShortMonth,
  11299. "B": formatUTCMonth,
  11300. "c": null,
  11301. "d": formatUTCDayOfMonth,
  11302. "e": formatUTCDayOfMonth,
  11303. "f": formatUTCMicroseconds,
  11304. "H": formatUTCHour24,
  11305. "I": formatUTCHour12,
  11306. "j": formatUTCDayOfYear,
  11307. "L": formatUTCMilliseconds,
  11308. "m": formatUTCMonthNumber,
  11309. "M": formatUTCMinutes,
  11310. "p": formatUTCPeriod,
  11311. "q": formatUTCQuarter,
  11312. "Q": formatUnixTimestamp,
  11313. "s": formatUnixTimestampSeconds,
  11314. "S": formatUTCSeconds,
  11315. "u": formatUTCWeekdayNumberMonday,
  11316. "U": formatUTCWeekNumberSunday,
  11317. "V": formatUTCWeekNumberISO,
  11318. "w": formatUTCWeekdayNumberSunday,
  11319. "W": formatUTCWeekNumberMonday,
  11320. "x": null,
  11321. "X": null,
  11322. "y": formatUTCYear,
  11323. "Y": formatUTCFullYear,
  11324. "Z": formatUTCZone,
  11325. "%": formatLiteralPercent
  11326. };
  11327. var parses = {
  11328. "a": parseShortWeekday,
  11329. "A": parseWeekday,
  11330. "b": parseShortMonth,
  11331. "B": parseMonth,
  11332. "c": parseLocaleDateTime,
  11333. "d": parseDayOfMonth,
  11334. "e": parseDayOfMonth,
  11335. "f": parseMicroseconds,
  11336. "H": parseHour24,
  11337. "I": parseHour24,
  11338. "j": parseDayOfYear,
  11339. "L": parseMilliseconds,
  11340. "m": parseMonthNumber,
  11341. "M": parseMinutes,
  11342. "p": parsePeriod,
  11343. "q": parseQuarter,
  11344. "Q": parseUnixTimestamp,
  11345. "s": parseUnixTimestampSeconds,
  11346. "S": parseSeconds,
  11347. "u": parseWeekdayNumberMonday,
  11348. "U": parseWeekNumberSunday,
  11349. "V": parseWeekNumberISO,
  11350. "w": parseWeekdayNumberSunday,
  11351. "W": parseWeekNumberMonday,
  11352. "x": parseLocaleDate,
  11353. "X": parseLocaleTime,
  11354. "y": parseYear,
  11355. "Y": parseFullYear,
  11356. "Z": parseZone,
  11357. "%": parseLiteralPercent
  11358. };
  11359. // These recursive directive definitions must be deferred.
  11360. formats.x = newFormat(locale_date, formats);
  11361. formats.X = newFormat(locale_time, formats);
  11362. formats.c = newFormat(locale_dateTime, formats);
  11363. utcFormats.x = newFormat(locale_date, utcFormats);
  11364. utcFormats.X = newFormat(locale_time, utcFormats);
  11365. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  11366. function newFormat(specifier, formats) {
  11367. return function(date) {
  11368. var string = [],
  11369. i = -1,
  11370. j = 0,
  11371. n = specifier.length,
  11372. c,
  11373. pad,
  11374. format;
  11375. if (!(date instanceof Date)) date = new Date(+date);
  11376. while (++i < n) {
  11377. if (specifier.charCodeAt(i) === 37) {
  11378. string.push(specifier.slice(j, i));
  11379. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  11380. else pad = c === "e" ? " " : "0";
  11381. if (format = formats[c]) c = format(date, pad);
  11382. string.push(c);
  11383. j = i + 1;
  11384. }
  11385. }
  11386. string.push(specifier.slice(j, i));
  11387. return string.join("");
  11388. };
  11389. }
  11390. function newParse(specifier, Z) {
  11391. return function(string) {
  11392. var d = newDate(1900, undefined, 1),
  11393. i = parseSpecifier(d, specifier, string += "", 0),
  11394. week, day$1;
  11395. if (i != string.length) return null;
  11396. // If a UNIX timestamp is specified, return it.
  11397. if ("Q" in d) return new Date(d.Q);
  11398. if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
  11399. // If this is utcParse, never use the local timezone.
  11400. if (Z && !("Z" in d)) d.Z = 0;
  11401. // The am-pm flag is 0 for AM, and 1 for PM.
  11402. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  11403. // If the month was not specified, inherit from the quarter.
  11404. if (d.m === undefined) d.m = "q" in d ? d.q : 0;
  11405. // Convert day-of-week and week-of-year to day-of-year.
  11406. if ("V" in d) {
  11407. if (d.V < 1 || d.V > 53) return null;
  11408. if (!("w" in d)) d.w = 1;
  11409. if ("Z" in d) {
  11410. week = utcDate(newDate(d.y, 0, 1)), day$1 = week.getUTCDay();
  11411. week = day$1 > 4 || day$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  11412. week = utcDay.offset(week, (d.V - 1) * 7);
  11413. d.y = week.getUTCFullYear();
  11414. d.m = week.getUTCMonth();
  11415. d.d = week.getUTCDate() + (d.w + 6) % 7;
  11416. } else {
  11417. week = localDate(newDate(d.y, 0, 1)), day$1 = week.getDay();
  11418. week = day$1 > 4 || day$1 === 0 ? monday.ceil(week) : monday(week);
  11419. week = day.offset(week, (d.V - 1) * 7);
  11420. d.y = week.getFullYear();
  11421. d.m = week.getMonth();
  11422. d.d = week.getDate() + (d.w + 6) % 7;
  11423. }
  11424. } else if ("W" in d || "U" in d) {
  11425. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  11426. day$1 = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
  11427. d.m = 0;
  11428. 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;
  11429. }
  11430. // If a time zone is specified, all fields are interpreted as UTC and then
  11431. // offset according to the specified time zone.
  11432. if ("Z" in d) {
  11433. d.H += d.Z / 100 | 0;
  11434. d.M += d.Z % 100;
  11435. return utcDate(d);
  11436. }
  11437. // Otherwise, all fields are in local time.
  11438. return localDate(d);
  11439. };
  11440. }
  11441. function parseSpecifier(d, specifier, string, j) {
  11442. var i = 0,
  11443. n = specifier.length,
  11444. m = string.length,
  11445. c,
  11446. parse;
  11447. while (i < n) {
  11448. if (j >= m) return -1;
  11449. c = specifier.charCodeAt(i++);
  11450. if (c === 37) {
  11451. c = specifier.charAt(i++);
  11452. parse = parses[c in pads ? specifier.charAt(i++) : c];
  11453. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  11454. } else if (c != string.charCodeAt(j++)) {
  11455. return -1;
  11456. }
  11457. }
  11458. return j;
  11459. }
  11460. function parsePeriod(d, string, i) {
  11461. var n = periodRe.exec(string.slice(i));
  11462. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11463. }
  11464. function parseShortWeekday(d, string, i) {
  11465. var n = shortWeekdayRe.exec(string.slice(i));
  11466. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11467. }
  11468. function parseWeekday(d, string, i) {
  11469. var n = weekdayRe.exec(string.slice(i));
  11470. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11471. }
  11472. function parseShortMonth(d, string, i) {
  11473. var n = shortMonthRe.exec(string.slice(i));
  11474. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11475. }
  11476. function parseMonth(d, string, i) {
  11477. var n = monthRe.exec(string.slice(i));
  11478. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11479. }
  11480. function parseLocaleDateTime(d, string, i) {
  11481. return parseSpecifier(d, locale_dateTime, string, i);
  11482. }
  11483. function parseLocaleDate(d, string, i) {
  11484. return parseSpecifier(d, locale_date, string, i);
  11485. }
  11486. function parseLocaleTime(d, string, i) {
  11487. return parseSpecifier(d, locale_time, string, i);
  11488. }
  11489. function formatShortWeekday(d) {
  11490. return locale_shortWeekdays[d.getDay()];
  11491. }
  11492. function formatWeekday(d) {
  11493. return locale_weekdays[d.getDay()];
  11494. }
  11495. function formatShortMonth(d) {
  11496. return locale_shortMonths[d.getMonth()];
  11497. }
  11498. function formatMonth(d) {
  11499. return locale_months[d.getMonth()];
  11500. }
  11501. function formatPeriod(d) {
  11502. return locale_periods[+(d.getHours() >= 12)];
  11503. }
  11504. function formatQuarter(d) {
  11505. return 1 + ~~(d.getMonth() / 3);
  11506. }
  11507. function formatUTCShortWeekday(d) {
  11508. return locale_shortWeekdays[d.getUTCDay()];
  11509. }
  11510. function formatUTCWeekday(d) {
  11511. return locale_weekdays[d.getUTCDay()];
  11512. }
  11513. function formatUTCShortMonth(d) {
  11514. return locale_shortMonths[d.getUTCMonth()];
  11515. }
  11516. function formatUTCMonth(d) {
  11517. return locale_months[d.getUTCMonth()];
  11518. }
  11519. function formatUTCPeriod(d) {
  11520. return locale_periods[+(d.getUTCHours() >= 12)];
  11521. }
  11522. function formatUTCQuarter(d) {
  11523. return 1 + ~~(d.getUTCMonth() / 3);
  11524. }
  11525. return {
  11526. format: function(specifier) {
  11527. var f = newFormat(specifier += "", formats);
  11528. f.toString = function() { return specifier; };
  11529. return f;
  11530. },
  11531. parse: function(specifier) {
  11532. var p = newParse(specifier += "", false);
  11533. p.toString = function() { return specifier; };
  11534. return p;
  11535. },
  11536. utcFormat: function(specifier) {
  11537. var f = newFormat(specifier += "", utcFormats);
  11538. f.toString = function() { return specifier; };
  11539. return f;
  11540. },
  11541. utcParse: function(specifier) {
  11542. var p = newParse(specifier += "", true);
  11543. p.toString = function() { return specifier; };
  11544. return p;
  11545. }
  11546. };
  11547. }
  11548. var pads = {"-": "", "_": " ", "0": "0"},
  11549. numberRe = /^\s*\d+/, // note: ignores next directive
  11550. percentRe = /^%/,
  11551. requoteRe = /[\\^$*+?|[\]().{}]/g;
  11552. function pad$1(value, fill, width) {
  11553. var sign = value < 0 ? "-" : "",
  11554. string = (sign ? -value : value) + "",
  11555. length = string.length;
  11556. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  11557. }
  11558. function requote(s) {
  11559. return s.replace(requoteRe, "\\$&");
  11560. }
  11561. function formatRe(names) {
  11562. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  11563. }
  11564. function formatLookup(names) {
  11565. var map = {}, i = -1, n = names.length;
  11566. while (++i < n) map[names[i].toLowerCase()] = i;
  11567. return map;
  11568. }
  11569. function parseWeekdayNumberSunday(d, string, i) {
  11570. var n = numberRe.exec(string.slice(i, i + 1));
  11571. return n ? (d.w = +n[0], i + n[0].length) : -1;
  11572. }
  11573. function parseWeekdayNumberMonday(d, string, i) {
  11574. var n = numberRe.exec(string.slice(i, i + 1));
  11575. return n ? (d.u = +n[0], i + n[0].length) : -1;
  11576. }
  11577. function parseWeekNumberSunday(d, string, i) {
  11578. var n = numberRe.exec(string.slice(i, i + 2));
  11579. return n ? (d.U = +n[0], i + n[0].length) : -1;
  11580. }
  11581. function parseWeekNumberISO(d, string, i) {
  11582. var n = numberRe.exec(string.slice(i, i + 2));
  11583. return n ? (d.V = +n[0], i + n[0].length) : -1;
  11584. }
  11585. function parseWeekNumberMonday(d, string, i) {
  11586. var n = numberRe.exec(string.slice(i, i + 2));
  11587. return n ? (d.W = +n[0], i + n[0].length) : -1;
  11588. }
  11589. function parseFullYear(d, string, i) {
  11590. var n = numberRe.exec(string.slice(i, i + 4));
  11591. return n ? (d.y = +n[0], i + n[0].length) : -1;
  11592. }
  11593. function parseYear(d, string, i) {
  11594. var n = numberRe.exec(string.slice(i, i + 2));
  11595. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  11596. }
  11597. function parseZone(d, string, i) {
  11598. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  11599. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  11600. }
  11601. function parseQuarter(d, string, i) {
  11602. var n = numberRe.exec(string.slice(i, i + 1));
  11603. return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
  11604. }
  11605. function parseMonthNumber(d, string, i) {
  11606. var n = numberRe.exec(string.slice(i, i + 2));
  11607. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  11608. }
  11609. function parseDayOfMonth(d, string, i) {
  11610. var n = numberRe.exec(string.slice(i, i + 2));
  11611. return n ? (d.d = +n[0], i + n[0].length) : -1;
  11612. }
  11613. function parseDayOfYear(d, string, i) {
  11614. var n = numberRe.exec(string.slice(i, i + 3));
  11615. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  11616. }
  11617. function parseHour24(d, string, i) {
  11618. var n = numberRe.exec(string.slice(i, i + 2));
  11619. return n ? (d.H = +n[0], i + n[0].length) : -1;
  11620. }
  11621. function parseMinutes(d, string, i) {
  11622. var n = numberRe.exec(string.slice(i, i + 2));
  11623. return n ? (d.M = +n[0], i + n[0].length) : -1;
  11624. }
  11625. function parseSeconds(d, string, i) {
  11626. var n = numberRe.exec(string.slice(i, i + 2));
  11627. return n ? (d.S = +n[0], i + n[0].length) : -1;
  11628. }
  11629. function parseMilliseconds(d, string, i) {
  11630. var n = numberRe.exec(string.slice(i, i + 3));
  11631. return n ? (d.L = +n[0], i + n[0].length) : -1;
  11632. }
  11633. function parseMicroseconds(d, string, i) {
  11634. var n = numberRe.exec(string.slice(i, i + 6));
  11635. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  11636. }
  11637. function parseLiteralPercent(d, string, i) {
  11638. var n = percentRe.exec(string.slice(i, i + 1));
  11639. return n ? i + n[0].length : -1;
  11640. }
  11641. function parseUnixTimestamp(d, string, i) {
  11642. var n = numberRe.exec(string.slice(i));
  11643. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  11644. }
  11645. function parseUnixTimestampSeconds(d, string, i) {
  11646. var n = numberRe.exec(string.slice(i));
  11647. return n ? (d.s = +n[0], i + n[0].length) : -1;
  11648. }
  11649. function formatDayOfMonth(d, p) {
  11650. return pad$1(d.getDate(), p, 2);
  11651. }
  11652. function formatHour24(d, p) {
  11653. return pad$1(d.getHours(), p, 2);
  11654. }
  11655. function formatHour12(d, p) {
  11656. return pad$1(d.getHours() % 12 || 12, p, 2);
  11657. }
  11658. function formatDayOfYear(d, p) {
  11659. return pad$1(1 + day.count(year(d), d), p, 3);
  11660. }
  11661. function formatMilliseconds(d, p) {
  11662. return pad$1(d.getMilliseconds(), p, 3);
  11663. }
  11664. function formatMicroseconds(d, p) {
  11665. return formatMilliseconds(d, p) + "000";
  11666. }
  11667. function formatMonthNumber(d, p) {
  11668. return pad$1(d.getMonth() + 1, p, 2);
  11669. }
  11670. function formatMinutes(d, p) {
  11671. return pad$1(d.getMinutes(), p, 2);
  11672. }
  11673. function formatSeconds(d, p) {
  11674. return pad$1(d.getSeconds(), p, 2);
  11675. }
  11676. function formatWeekdayNumberMonday(d) {
  11677. var day = d.getDay();
  11678. return day === 0 ? 7 : day;
  11679. }
  11680. function formatWeekNumberSunday(d, p) {
  11681. return pad$1(sunday.count(year(d) - 1, d), p, 2);
  11682. }
  11683. function formatWeekNumberISO(d, p) {
  11684. var day = d.getDay();
  11685. d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
  11686. return pad$1(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  11687. }
  11688. function formatWeekdayNumberSunday(d) {
  11689. return d.getDay();
  11690. }
  11691. function formatWeekNumberMonday(d, p) {
  11692. return pad$1(monday.count(year(d) - 1, d), p, 2);
  11693. }
  11694. function formatYear$1(d, p) {
  11695. return pad$1(d.getFullYear() % 100, p, 2);
  11696. }
  11697. function formatFullYear(d, p) {
  11698. return pad$1(d.getFullYear() % 10000, p, 4);
  11699. }
  11700. function formatZone(d) {
  11701. var z = d.getTimezoneOffset();
  11702. return (z > 0 ? "-" : (z *= -1, "+"))
  11703. + pad$1(z / 60 | 0, "0", 2)
  11704. + pad$1(z % 60, "0", 2);
  11705. }
  11706. function formatUTCDayOfMonth(d, p) {
  11707. return pad$1(d.getUTCDate(), p, 2);
  11708. }
  11709. function formatUTCHour24(d, p) {
  11710. return pad$1(d.getUTCHours(), p, 2);
  11711. }
  11712. function formatUTCHour12(d, p) {
  11713. return pad$1(d.getUTCHours() % 12 || 12, p, 2);
  11714. }
  11715. function formatUTCDayOfYear(d, p) {
  11716. return pad$1(1 + utcDay.count(utcYear(d), d), p, 3);
  11717. }
  11718. function formatUTCMilliseconds(d, p) {
  11719. return pad$1(d.getUTCMilliseconds(), p, 3);
  11720. }
  11721. function formatUTCMicroseconds(d, p) {
  11722. return formatUTCMilliseconds(d, p) + "000";
  11723. }
  11724. function formatUTCMonthNumber(d, p) {
  11725. return pad$1(d.getUTCMonth() + 1, p, 2);
  11726. }
  11727. function formatUTCMinutes(d, p) {
  11728. return pad$1(d.getUTCMinutes(), p, 2);
  11729. }
  11730. function formatUTCSeconds(d, p) {
  11731. return pad$1(d.getUTCSeconds(), p, 2);
  11732. }
  11733. function formatUTCWeekdayNumberMonday(d) {
  11734. var dow = d.getUTCDay();
  11735. return dow === 0 ? 7 : dow;
  11736. }
  11737. function formatUTCWeekNumberSunday(d, p) {
  11738. return pad$1(utcSunday.count(utcYear(d) - 1, d), p, 2);
  11739. }
  11740. function formatUTCWeekNumberISO(d, p) {
  11741. var day = d.getUTCDay();
  11742. d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  11743. return pad$1(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  11744. }
  11745. function formatUTCWeekdayNumberSunday(d) {
  11746. return d.getUTCDay();
  11747. }
  11748. function formatUTCWeekNumberMonday(d, p) {
  11749. return pad$1(utcMonday.count(utcYear(d) - 1, d), p, 2);
  11750. }
  11751. function formatUTCYear(d, p) {
  11752. return pad$1(d.getUTCFullYear() % 100, p, 2);
  11753. }
  11754. function formatUTCFullYear(d, p) {
  11755. return pad$1(d.getUTCFullYear() % 10000, p, 4);
  11756. }
  11757. function formatUTCZone() {
  11758. return "+0000";
  11759. }
  11760. function formatLiteralPercent() {
  11761. return "%";
  11762. }
  11763. function formatUnixTimestamp(d) {
  11764. return +d;
  11765. }
  11766. function formatUnixTimestampSeconds(d) {
  11767. return Math.floor(+d / 1000);
  11768. }
  11769. var locale$1;
  11770. defaultLocale$1({
  11771. dateTime: "%x, %X",
  11772. date: "%-m/%-d/%Y",
  11773. time: "%-I:%M:%S %p",
  11774. periods: ["AM", "PM"],
  11775. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11776. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11777. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11778. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11779. });
  11780. function defaultLocale$1(definition) {
  11781. locale$1 = formatLocale$1(definition);
  11782. exports.timeFormat = locale$1.format;
  11783. exports.timeParse = locale$1.parse;
  11784. exports.utcFormat = locale$1.utcFormat;
  11785. exports.utcParse = locale$1.utcParse;
  11786. return locale$1;
  11787. }
  11788. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11789. function formatIsoNative(date) {
  11790. return date.toISOString();
  11791. }
  11792. var formatIso = Date.prototype.toISOString
  11793. ? formatIsoNative
  11794. : exports.utcFormat(isoSpecifier);
  11795. function parseIsoNative(string) {
  11796. var date = new Date(string);
  11797. return isNaN(date) ? null : date;
  11798. }
  11799. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11800. ? parseIsoNative
  11801. : exports.utcParse(isoSpecifier);
  11802. var durationSecond$1 = 1000,
  11803. durationMinute$1 = durationSecond$1 * 60,
  11804. durationHour$1 = durationMinute$1 * 60,
  11805. durationDay$1 = durationHour$1 * 24,
  11806. durationWeek$1 = durationDay$1 * 7,
  11807. durationMonth = durationDay$1 * 30,
  11808. durationYear = durationDay$1 * 365;
  11809. function date$1(t) {
  11810. return new Date(t);
  11811. }
  11812. function number$3(t) {
  11813. return t instanceof Date ? +t : +new Date(+t);
  11814. }
  11815. function calendar(year, month, week, day, hour, minute, second, millisecond, format) {
  11816. var scale = continuous(identity$6, identity$6),
  11817. invert = scale.invert,
  11818. domain = scale.domain;
  11819. var formatMillisecond = format(".%L"),
  11820. formatSecond = format(":%S"),
  11821. formatMinute = format("%I:%M"),
  11822. formatHour = format("%I %p"),
  11823. formatDay = format("%a %d"),
  11824. formatWeek = format("%b %d"),
  11825. formatMonth = format("%B"),
  11826. formatYear = format("%Y");
  11827. var tickIntervals = [
  11828. [second, 1, durationSecond$1],
  11829. [second, 5, 5 * durationSecond$1],
  11830. [second, 15, 15 * durationSecond$1],
  11831. [second, 30, 30 * durationSecond$1],
  11832. [minute, 1, durationMinute$1],
  11833. [minute, 5, 5 * durationMinute$1],
  11834. [minute, 15, 15 * durationMinute$1],
  11835. [minute, 30, 30 * durationMinute$1],
  11836. [ hour, 1, durationHour$1 ],
  11837. [ hour, 3, 3 * durationHour$1 ],
  11838. [ hour, 6, 6 * durationHour$1 ],
  11839. [ hour, 12, 12 * durationHour$1 ],
  11840. [ day, 1, durationDay$1 ],
  11841. [ day, 2, 2 * durationDay$1 ],
  11842. [ week, 1, durationWeek$1 ],
  11843. [ month, 1, durationMonth ],
  11844. [ month, 3, 3 * durationMonth ],
  11845. [ year, 1, durationYear ]
  11846. ];
  11847. function tickFormat(date) {
  11848. return (second(date) < date ? formatMillisecond
  11849. : minute(date) < date ? formatSecond
  11850. : hour(date) < date ? formatMinute
  11851. : day(date) < date ? formatHour
  11852. : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
  11853. : year(date) < date ? formatMonth
  11854. : formatYear)(date);
  11855. }
  11856. function tickInterval(interval, start, stop, step) {
  11857. if (interval == null) interval = 10;
  11858. // If a desired tick count is specified, pick a reasonable tick interval
  11859. // based on the extent of the domain and a rough estimate of tick size.
  11860. // Otherwise, assume interval is already a time interval and use it.
  11861. if (typeof interval === "number") {
  11862. var target = Math.abs(stop - start) / interval,
  11863. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11864. if (i === tickIntervals.length) {
  11865. step = tickStep(start / durationYear, stop / durationYear, interval);
  11866. interval = year;
  11867. } else if (i) {
  11868. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11869. step = i[1];
  11870. interval = i[0];
  11871. } else {
  11872. step = Math.max(tickStep(start, stop, interval), 1);
  11873. interval = millisecond;
  11874. }
  11875. }
  11876. return step == null ? interval : interval.every(step);
  11877. }
  11878. scale.invert = function(y) {
  11879. return new Date(invert(y));
  11880. };
  11881. scale.domain = function(_) {
  11882. return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
  11883. };
  11884. scale.ticks = function(interval, step) {
  11885. var d = domain(),
  11886. t0 = d[0],
  11887. t1 = d[d.length - 1],
  11888. r = t1 < t0,
  11889. t;
  11890. if (r) t = t0, t0 = t1, t1 = t;
  11891. t = tickInterval(interval, t0, t1, step);
  11892. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11893. return r ? t.reverse() : t;
  11894. };
  11895. scale.tickFormat = function(count, specifier) {
  11896. return specifier == null ? tickFormat : format(specifier);
  11897. };
  11898. scale.nice = function(interval, step) {
  11899. var d = domain();
  11900. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11901. ? domain(nice(d, interval))
  11902. : scale;
  11903. };
  11904. scale.copy = function() {
  11905. return copy(scale, calendar(year, month, week, day, hour, minute, second, millisecond, format));
  11906. };
  11907. return scale;
  11908. }
  11909. function time() {
  11910. return initRange.apply(calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
  11911. }
  11912. function utcTime() {
  11913. return initRange.apply(calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
  11914. }
  11915. function transformer$2() {
  11916. var x0 = 0,
  11917. x1 = 1,
  11918. t0,
  11919. t1,
  11920. k10,
  11921. transform,
  11922. interpolator = identity$6,
  11923. clamp = false,
  11924. unknown;
  11925. function scale(x) {
  11926. return isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
  11927. }
  11928. scale.domain = function(_) {
  11929. return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
  11930. };
  11931. scale.clamp = function(_) {
  11932. return arguments.length ? (clamp = !!_, scale) : clamp;
  11933. };
  11934. scale.interpolator = function(_) {
  11935. return arguments.length ? (interpolator = _, scale) : interpolator;
  11936. };
  11937. scale.unknown = function(_) {
  11938. return arguments.length ? (unknown = _, scale) : unknown;
  11939. };
  11940. return function(t) {
  11941. transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
  11942. return scale;
  11943. };
  11944. }
  11945. function copy$1(source, target) {
  11946. return target
  11947. .domain(source.domain())
  11948. .interpolator(source.interpolator())
  11949. .clamp(source.clamp())
  11950. .unknown(source.unknown());
  11951. }
  11952. function sequential() {
  11953. var scale = linearish(transformer$2()(identity$6));
  11954. scale.copy = function() {
  11955. return copy$1(scale, sequential());
  11956. };
  11957. return initInterpolator.apply(scale, arguments);
  11958. }
  11959. function sequentialLog() {
  11960. var scale = loggish(transformer$2()).domain([1, 10]);
  11961. scale.copy = function() {
  11962. return copy$1(scale, sequentialLog()).base(scale.base());
  11963. };
  11964. return initInterpolator.apply(scale, arguments);
  11965. }
  11966. function sequentialSymlog() {
  11967. var scale = symlogish(transformer$2());
  11968. scale.copy = function() {
  11969. return copy$1(scale, sequentialSymlog()).constant(scale.constant());
  11970. };
  11971. return initInterpolator.apply(scale, arguments);
  11972. }
  11973. function sequentialPow() {
  11974. var scale = powish(transformer$2());
  11975. scale.copy = function() {
  11976. return copy$1(scale, sequentialPow()).exponent(scale.exponent());
  11977. };
  11978. return initInterpolator.apply(scale, arguments);
  11979. }
  11980. function sequentialSqrt() {
  11981. return sequentialPow.apply(null, arguments).exponent(0.5);
  11982. }
  11983. function sequentialQuantile() {
  11984. var domain = [],
  11985. interpolator = identity$6;
  11986. function scale(x) {
  11987. if (!isNaN(x = +x)) return interpolator((bisectRight(domain, x) - 1) / (domain.length - 1));
  11988. }
  11989. scale.domain = function(_) {
  11990. if (!arguments.length) return domain.slice();
  11991. domain = [];
  11992. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  11993. domain.sort(ascending);
  11994. return scale;
  11995. };
  11996. scale.interpolator = function(_) {
  11997. return arguments.length ? (interpolator = _, scale) : interpolator;
  11998. };
  11999. scale.copy = function() {
  12000. return sequentialQuantile(interpolator).domain(domain);
  12001. };
  12002. return initInterpolator.apply(scale, arguments);
  12003. }
  12004. function transformer$3() {
  12005. var x0 = 0,
  12006. x1 = 0.5,
  12007. x2 = 1,
  12008. t0,
  12009. t1,
  12010. t2,
  12011. k10,
  12012. k21,
  12013. interpolator = identity$6,
  12014. transform,
  12015. clamp = false,
  12016. unknown;
  12017. function scale(x) {
  12018. return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (x < t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
  12019. }
  12020. scale.domain = function(_) {
  12021. return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), t2 = transform(x2 = +_[2]), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), scale) : [x0, x1, x2];
  12022. };
  12023. scale.clamp = function(_) {
  12024. return arguments.length ? (clamp = !!_, scale) : clamp;
  12025. };
  12026. scale.interpolator = function(_) {
  12027. return arguments.length ? (interpolator = _, scale) : interpolator;
  12028. };
  12029. scale.unknown = function(_) {
  12030. return arguments.length ? (unknown = _, scale) : unknown;
  12031. };
  12032. return function(t) {
  12033. transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1);
  12034. return scale;
  12035. };
  12036. }
  12037. function diverging() {
  12038. var scale = linearish(transformer$3()(identity$6));
  12039. scale.copy = function() {
  12040. return copy$1(scale, diverging());
  12041. };
  12042. return initInterpolator.apply(scale, arguments);
  12043. }
  12044. function divergingLog() {
  12045. var scale = loggish(transformer$3()).domain([0.1, 1, 10]);
  12046. scale.copy = function() {
  12047. return copy$1(scale, divergingLog()).base(scale.base());
  12048. };
  12049. return initInterpolator.apply(scale, arguments);
  12050. }
  12051. function divergingSymlog() {
  12052. var scale = symlogish(transformer$3());
  12053. scale.copy = function() {
  12054. return copy$1(scale, divergingSymlog()).constant(scale.constant());
  12055. };
  12056. return initInterpolator.apply(scale, arguments);
  12057. }
  12058. function divergingPow() {
  12059. var scale = powish(transformer$3());
  12060. scale.copy = function() {
  12061. return copy$1(scale, divergingPow()).exponent(scale.exponent());
  12062. };
  12063. return initInterpolator.apply(scale, arguments);
  12064. }
  12065. function divergingSqrt() {
  12066. return divergingPow.apply(null, arguments).exponent(0.5);
  12067. }
  12068. function colors(specifier) {
  12069. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  12070. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  12071. return colors;
  12072. }
  12073. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  12074. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  12075. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  12076. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  12077. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  12078. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  12079. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  12080. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  12081. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  12082. var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
  12083. function ramp(scheme) {
  12084. return rgbBasis(scheme[scheme.length - 1]);
  12085. }
  12086. var scheme = new Array(3).concat(
  12087. "d8b365f5f5f55ab4ac",
  12088. "a6611adfc27d80cdc1018571",
  12089. "a6611adfc27df5f5f580cdc1018571",
  12090. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  12091. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  12092. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  12093. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  12094. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  12095. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  12096. ).map(colors);
  12097. var BrBG = ramp(scheme);
  12098. var scheme$1 = new Array(3).concat(
  12099. "af8dc3f7f7f77fbf7b",
  12100. "7b3294c2a5cfa6dba0008837",
  12101. "7b3294c2a5cff7f7f7a6dba0008837",
  12102. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  12103. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  12104. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  12105. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  12106. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  12107. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  12108. ).map(colors);
  12109. var PRGn = ramp(scheme$1);
  12110. var scheme$2 = new Array(3).concat(
  12111. "e9a3c9f7f7f7a1d76a",
  12112. "d01c8bf1b6dab8e1864dac26",
  12113. "d01c8bf1b6daf7f7f7b8e1864dac26",
  12114. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  12115. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  12116. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  12117. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  12118. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  12119. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  12120. ).map(colors);
  12121. var PiYG = ramp(scheme$2);
  12122. var scheme$3 = new Array(3).concat(
  12123. "998ec3f7f7f7f1a340",
  12124. "5e3c99b2abd2fdb863e66101",
  12125. "5e3c99b2abd2f7f7f7fdb863e66101",
  12126. "542788998ec3d8daebfee0b6f1a340b35806",
  12127. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  12128. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  12129. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  12130. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  12131. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  12132. ).map(colors);
  12133. var PuOr = ramp(scheme$3);
  12134. var scheme$4 = new Array(3).concat(
  12135. "ef8a62f7f7f767a9cf",
  12136. "ca0020f4a58292c5de0571b0",
  12137. "ca0020f4a582f7f7f792c5de0571b0",
  12138. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  12139. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  12140. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  12141. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  12142. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  12143. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  12144. ).map(colors);
  12145. var RdBu = ramp(scheme$4);
  12146. var scheme$5 = new Array(3).concat(
  12147. "ef8a62ffffff999999",
  12148. "ca0020f4a582bababa404040",
  12149. "ca0020f4a582ffffffbababa404040",
  12150. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  12151. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  12152. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  12153. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  12154. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  12155. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  12156. ).map(colors);
  12157. var RdGy = ramp(scheme$5);
  12158. var scheme$6 = new Array(3).concat(
  12159. "fc8d59ffffbf91bfdb",
  12160. "d7191cfdae61abd9e92c7bb6",
  12161. "d7191cfdae61ffffbfabd9e92c7bb6",
  12162. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  12163. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  12164. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  12165. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  12166. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  12167. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  12168. ).map(colors);
  12169. var RdYlBu = ramp(scheme$6);
  12170. var scheme$7 = new Array(3).concat(
  12171. "fc8d59ffffbf91cf60",
  12172. "d7191cfdae61a6d96a1a9641",
  12173. "d7191cfdae61ffffbfa6d96a1a9641",
  12174. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  12175. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  12176. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  12177. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  12178. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  12179. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  12180. ).map(colors);
  12181. var RdYlGn = ramp(scheme$7);
  12182. var scheme$8 = new Array(3).concat(
  12183. "fc8d59ffffbf99d594",
  12184. "d7191cfdae61abdda42b83ba",
  12185. "d7191cfdae61ffffbfabdda42b83ba",
  12186. "d53e4ffc8d59fee08be6f59899d5943288bd",
  12187. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  12188. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  12189. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  12190. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  12191. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  12192. ).map(colors);
  12193. var Spectral = ramp(scheme$8);
  12194. var scheme$9 = new Array(3).concat(
  12195. "e5f5f999d8c92ca25f",
  12196. "edf8fbb2e2e266c2a4238b45",
  12197. "edf8fbb2e2e266c2a42ca25f006d2c",
  12198. "edf8fbccece699d8c966c2a42ca25f006d2c",
  12199. "edf8fbccece699d8c966c2a441ae76238b45005824",
  12200. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  12201. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  12202. ).map(colors);
  12203. var BuGn = ramp(scheme$9);
  12204. var scheme$a = new Array(3).concat(
  12205. "e0ecf49ebcda8856a7",
  12206. "edf8fbb3cde38c96c688419d",
  12207. "edf8fbb3cde38c96c68856a7810f7c",
  12208. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  12209. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  12210. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  12211. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  12212. ).map(colors);
  12213. var BuPu = ramp(scheme$a);
  12214. var scheme$b = new Array(3).concat(
  12215. "e0f3dba8ddb543a2ca",
  12216. "f0f9e8bae4bc7bccc42b8cbe",
  12217. "f0f9e8bae4bc7bccc443a2ca0868ac",
  12218. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  12219. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  12220. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  12221. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  12222. ).map(colors);
  12223. var GnBu = ramp(scheme$b);
  12224. var scheme$c = new Array(3).concat(
  12225. "fee8c8fdbb84e34a33",
  12226. "fef0d9fdcc8afc8d59d7301f",
  12227. "fef0d9fdcc8afc8d59e34a33b30000",
  12228. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  12229. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  12230. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  12231. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  12232. ).map(colors);
  12233. var OrRd = ramp(scheme$c);
  12234. var scheme$d = new Array(3).concat(
  12235. "ece2f0a6bddb1c9099",
  12236. "f6eff7bdc9e167a9cf02818a",
  12237. "f6eff7bdc9e167a9cf1c9099016c59",
  12238. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  12239. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  12240. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  12241. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  12242. ).map(colors);
  12243. var PuBuGn = ramp(scheme$d);
  12244. var scheme$e = new Array(3).concat(
  12245. "ece7f2a6bddb2b8cbe",
  12246. "f1eef6bdc9e174a9cf0570b0",
  12247. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  12248. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  12249. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  12250. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  12251. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  12252. ).map(colors);
  12253. var PuBu = ramp(scheme$e);
  12254. var scheme$f = new Array(3).concat(
  12255. "e7e1efc994c7dd1c77",
  12256. "f1eef6d7b5d8df65b0ce1256",
  12257. "f1eef6d7b5d8df65b0dd1c77980043",
  12258. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  12259. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  12260. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  12261. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  12262. ).map(colors);
  12263. var PuRd = ramp(scheme$f);
  12264. var scheme$g = new Array(3).concat(
  12265. "fde0ddfa9fb5c51b8a",
  12266. "feebe2fbb4b9f768a1ae017e",
  12267. "feebe2fbb4b9f768a1c51b8a7a0177",
  12268. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  12269. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  12270. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  12271. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  12272. ).map(colors);
  12273. var RdPu = ramp(scheme$g);
  12274. var scheme$h = new Array(3).concat(
  12275. "edf8b17fcdbb2c7fb8",
  12276. "ffffcca1dab441b6c4225ea8",
  12277. "ffffcca1dab441b6c42c7fb8253494",
  12278. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  12279. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  12280. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  12281. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  12282. ).map(colors);
  12283. var YlGnBu = ramp(scheme$h);
  12284. var scheme$i = new Array(3).concat(
  12285. "f7fcb9addd8e31a354",
  12286. "ffffccc2e69978c679238443",
  12287. "ffffccc2e69978c67931a354006837",
  12288. "ffffccd9f0a3addd8e78c67931a354006837",
  12289. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  12290. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  12291. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  12292. ).map(colors);
  12293. var YlGn = ramp(scheme$i);
  12294. var scheme$j = new Array(3).concat(
  12295. "fff7bcfec44fd95f0e",
  12296. "ffffd4fed98efe9929cc4c02",
  12297. "ffffd4fed98efe9929d95f0e993404",
  12298. "ffffd4fee391fec44ffe9929d95f0e993404",
  12299. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  12300. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  12301. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  12302. ).map(colors);
  12303. var YlOrBr = ramp(scheme$j);
  12304. var scheme$k = new Array(3).concat(
  12305. "ffeda0feb24cf03b20",
  12306. "ffffb2fecc5cfd8d3ce31a1c",
  12307. "ffffb2fecc5cfd8d3cf03b20bd0026",
  12308. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  12309. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  12310. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  12311. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  12312. ).map(colors);
  12313. var YlOrRd = ramp(scheme$k);
  12314. var scheme$l = new Array(3).concat(
  12315. "deebf79ecae13182bd",
  12316. "eff3ffbdd7e76baed62171b5",
  12317. "eff3ffbdd7e76baed63182bd08519c",
  12318. "eff3ffc6dbef9ecae16baed63182bd08519c",
  12319. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  12320. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  12321. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  12322. ).map(colors);
  12323. var Blues = ramp(scheme$l);
  12324. var scheme$m = new Array(3).concat(
  12325. "e5f5e0a1d99b31a354",
  12326. "edf8e9bae4b374c476238b45",
  12327. "edf8e9bae4b374c47631a354006d2c",
  12328. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  12329. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  12330. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  12331. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  12332. ).map(colors);
  12333. var Greens = ramp(scheme$m);
  12334. var scheme$n = new Array(3).concat(
  12335. "f0f0f0bdbdbd636363",
  12336. "f7f7f7cccccc969696525252",
  12337. "f7f7f7cccccc969696636363252525",
  12338. "f7f7f7d9d9d9bdbdbd969696636363252525",
  12339. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  12340. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  12341. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  12342. ).map(colors);
  12343. var Greys = ramp(scheme$n);
  12344. var scheme$o = new Array(3).concat(
  12345. "efedf5bcbddc756bb1",
  12346. "f2f0f7cbc9e29e9ac86a51a3",
  12347. "f2f0f7cbc9e29e9ac8756bb154278f",
  12348. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  12349. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  12350. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  12351. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  12352. ).map(colors);
  12353. var Purples = ramp(scheme$o);
  12354. var scheme$p = new Array(3).concat(
  12355. "fee0d2fc9272de2d26",
  12356. "fee5d9fcae91fb6a4acb181d",
  12357. "fee5d9fcae91fb6a4ade2d26a50f15",
  12358. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  12359. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  12360. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  12361. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  12362. ).map(colors);
  12363. var Reds = ramp(scheme$p);
  12364. var scheme$q = new Array(3).concat(
  12365. "fee6cefdae6be6550d",
  12366. "feeddefdbe85fd8d3cd94701",
  12367. "feeddefdbe85fd8d3ce6550da63603",
  12368. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  12369. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  12370. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  12371. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  12372. ).map(colors);
  12373. var Oranges = ramp(scheme$q);
  12374. function cividis(t) {
  12375. t = Math.max(0, Math.min(1, t));
  12376. return "rgb("
  12377. + Math.max(0, Math.min(255, Math.round(-4.54 - t * (35.34 - t * (2381.73 - t * (6402.7 - t * (7024.72 - t * 2710.57))))))) + ", "
  12378. + Math.max(0, Math.min(255, Math.round(32.49 + t * (170.73 + t * (52.82 - t * (131.46 - t * (176.58 - t * 67.37))))))) + ", "
  12379. + Math.max(0, Math.min(255, Math.round(81.24 + t * (442.36 - t * (2482.43 - t * (6167.24 - t * (6614.94 - t * 2475.67)))))))
  12380. + ")";
  12381. }
  12382. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  12383. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  12384. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  12385. var c = cubehelix();
  12386. function rainbow(t) {
  12387. if (t < 0 || t > 1) t -= Math.floor(t);
  12388. var ts = Math.abs(t - 0.5);
  12389. c.h = 360 * t - 100;
  12390. c.s = 1.5 - 1.5 * ts;
  12391. c.l = 0.8 - 0.9 * ts;
  12392. return c + "";
  12393. }
  12394. var c$1 = rgb(),
  12395. pi_1_3 = Math.PI / 3,
  12396. pi_2_3 = Math.PI * 2 / 3;
  12397. function sinebow(t) {
  12398. var x;
  12399. t = (0.5 - t) * Math.PI;
  12400. c$1.r = 255 * (x = Math.sin(t)) * x;
  12401. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  12402. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  12403. return c$1 + "";
  12404. }
  12405. function turbo(t) {
  12406. t = Math.max(0, Math.min(1, t));
  12407. return "rgb("
  12408. + Math.max(0, Math.min(255, Math.round(34.61 + t * (1172.33 - t * (10793.56 - t * (33300.12 - t * (38394.49 - t * 14825.05))))))) + ", "
  12409. + Math.max(0, Math.min(255, Math.round(23.31 + t * (557.33 + t * (1225.33 - t * (3574.96 - t * (1073.77 + t * 707.56))))))) + ", "
  12410. + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
  12411. + ")";
  12412. }
  12413. function ramp$1(range) {
  12414. var n = range.length;
  12415. return function(t) {
  12416. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  12417. };
  12418. }
  12419. var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  12420. var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  12421. var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  12422. var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  12423. function constant$b(x) {
  12424. return function constant() {
  12425. return x;
  12426. };
  12427. }
  12428. var abs$1 = Math.abs;
  12429. var atan2$1 = Math.atan2;
  12430. var cos$2 = Math.cos;
  12431. var max$2 = Math.max;
  12432. var min$1 = Math.min;
  12433. var sin$2 = Math.sin;
  12434. var sqrt$2 = Math.sqrt;
  12435. var epsilon$3 = 1e-12;
  12436. var pi$4 = Math.PI;
  12437. var halfPi$3 = pi$4 / 2;
  12438. var tau$4 = 2 * pi$4;
  12439. function acos$1(x) {
  12440. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  12441. }
  12442. function asin$1(x) {
  12443. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  12444. }
  12445. function arcInnerRadius(d) {
  12446. return d.innerRadius;
  12447. }
  12448. function arcOuterRadius(d) {
  12449. return d.outerRadius;
  12450. }
  12451. function arcStartAngle(d) {
  12452. return d.startAngle;
  12453. }
  12454. function arcEndAngle(d) {
  12455. return d.endAngle;
  12456. }
  12457. function arcPadAngle(d) {
  12458. return d && d.padAngle; // Note: optional!
  12459. }
  12460. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  12461. var x10 = x1 - x0, y10 = y1 - y0,
  12462. x32 = x3 - x2, y32 = y3 - y2,
  12463. t = y32 * x10 - x32 * y10;
  12464. if (t * t < epsilon$3) return;
  12465. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
  12466. return [x0 + t * x10, y0 + t * y10];
  12467. }
  12468. // Compute perpendicular offset line of length rc.
  12469. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  12470. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  12471. var x01 = x0 - x1,
  12472. y01 = y0 - y1,
  12473. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  12474. ox = lo * y01,
  12475. oy = -lo * x01,
  12476. x11 = x0 + ox,
  12477. y11 = y0 + oy,
  12478. x10 = x1 + ox,
  12479. y10 = y1 + oy,
  12480. x00 = (x11 + x10) / 2,
  12481. y00 = (y11 + y10) / 2,
  12482. dx = x10 - x11,
  12483. dy = y10 - y11,
  12484. d2 = dx * dx + dy * dy,
  12485. r = r1 - rc,
  12486. D = x11 * y10 - x10 * y11,
  12487. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  12488. cx0 = (D * dy - dx * d) / d2,
  12489. cy0 = (-D * dx - dy * d) / d2,
  12490. cx1 = (D * dy + dx * d) / d2,
  12491. cy1 = (-D * dx + dy * d) / d2,
  12492. dx0 = cx0 - x00,
  12493. dy0 = cy0 - y00,
  12494. dx1 = cx1 - x00,
  12495. dy1 = cy1 - y00;
  12496. // Pick the closer of the two intersection points.
  12497. // TODO Is there a faster way to determine which intersection to use?
  12498. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  12499. return {
  12500. cx: cx0,
  12501. cy: cy0,
  12502. x01: -ox,
  12503. y01: -oy,
  12504. x11: cx0 * (r1 / r - 1),
  12505. y11: cy0 * (r1 / r - 1)
  12506. };
  12507. }
  12508. function arc() {
  12509. var innerRadius = arcInnerRadius,
  12510. outerRadius = arcOuterRadius,
  12511. cornerRadius = constant$b(0),
  12512. padRadius = null,
  12513. startAngle = arcStartAngle,
  12514. endAngle = arcEndAngle,
  12515. padAngle = arcPadAngle,
  12516. context = null;
  12517. function arc() {
  12518. var buffer,
  12519. r,
  12520. r0 = +innerRadius.apply(this, arguments),
  12521. r1 = +outerRadius.apply(this, arguments),
  12522. a0 = startAngle.apply(this, arguments) - halfPi$3,
  12523. a1 = endAngle.apply(this, arguments) - halfPi$3,
  12524. da = abs$1(a1 - a0),
  12525. cw = a1 > a0;
  12526. if (!context) context = buffer = path();
  12527. // Ensure that the outer radius is always larger than the inner radius.
  12528. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  12529. // Is it a point?
  12530. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  12531. // Or is it a circle or annulus?
  12532. else if (da > tau$4 - epsilon$3) {
  12533. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  12534. context.arc(0, 0, r1, a0, a1, !cw);
  12535. if (r0 > epsilon$3) {
  12536. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  12537. context.arc(0, 0, r0, a1, a0, cw);
  12538. }
  12539. }
  12540. // Or is it a circular or annular sector?
  12541. else {
  12542. var a01 = a0,
  12543. a11 = a1,
  12544. a00 = a0,
  12545. a10 = a1,
  12546. da0 = da,
  12547. da1 = da,
  12548. ap = padAngle.apply(this, arguments) / 2,
  12549. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  12550. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  12551. rc0 = rc,
  12552. rc1 = rc,
  12553. t0,
  12554. t1;
  12555. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  12556. if (rp > epsilon$3) {
  12557. var p0 = asin$1(rp / r0 * sin$2(ap)),
  12558. p1 = asin$1(rp / r1 * sin$2(ap));
  12559. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  12560. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  12561. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  12562. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  12563. }
  12564. var x01 = r1 * cos$2(a01),
  12565. y01 = r1 * sin$2(a01),
  12566. x10 = r0 * cos$2(a10),
  12567. y10 = r0 * sin$2(a10);
  12568. // Apply rounded corners?
  12569. if (rc > epsilon$3) {
  12570. var x11 = r1 * cos$2(a11),
  12571. y11 = r1 * sin$2(a11),
  12572. x00 = r0 * cos$2(a00),
  12573. y00 = r0 * sin$2(a00),
  12574. oc;
  12575. // Restrict the corner radius according to the sector angle.
  12576. if (da < pi$4 && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
  12577. var ax = x01 - oc[0],
  12578. ay = y01 - oc[1],
  12579. bx = x11 - oc[0],
  12580. by = y11 - oc[1],
  12581. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  12582. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  12583. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  12584. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  12585. }
  12586. }
  12587. // Is the sector collapsed to a line?
  12588. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  12589. // Does the sector’s outer ring have rounded corners?
  12590. else if (rc1 > epsilon$3) {
  12591. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  12592. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  12593. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12594. // Have the corners merged?
  12595. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12596. // Otherwise, draw the two corners and the ring.
  12597. else {
  12598. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12599. 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);
  12600. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12601. }
  12602. }
  12603. // Or is the outer ring just a circular arc?
  12604. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  12605. // Is there no inner ring, and it’s a circular sector?
  12606. // Or perhaps it’s an annular sector collapsed due to padding?
  12607. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  12608. // Does the sector’s inner ring (or point) have rounded corners?
  12609. else if (rc0 > epsilon$3) {
  12610. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  12611. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  12612. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12613. // Have the corners merged?
  12614. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12615. // Otherwise, draw the two corners and the ring.
  12616. else {
  12617. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12618. 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);
  12619. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12620. }
  12621. }
  12622. // Or is the inner ring just a circular arc?
  12623. else context.arc(0, 0, r0, a10, a00, cw);
  12624. }
  12625. context.closePath();
  12626. if (buffer) return context = null, buffer + "" || null;
  12627. }
  12628. arc.centroid = function() {
  12629. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  12630. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  12631. return [cos$2(a) * r, sin$2(a) * r];
  12632. };
  12633. arc.innerRadius = function(_) {
  12634. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : innerRadius;
  12635. };
  12636. arc.outerRadius = function(_) {
  12637. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : outerRadius;
  12638. };
  12639. arc.cornerRadius = function(_) {
  12640. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : cornerRadius;
  12641. };
  12642. arc.padRadius = function(_) {
  12643. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), arc) : padRadius;
  12644. };
  12645. arc.startAngle = function(_) {
  12646. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : startAngle;
  12647. };
  12648. arc.endAngle = function(_) {
  12649. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : endAngle;
  12650. };
  12651. arc.padAngle = function(_) {
  12652. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : padAngle;
  12653. };
  12654. arc.context = function(_) {
  12655. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  12656. };
  12657. return arc;
  12658. }
  12659. function Linear(context) {
  12660. this._context = context;
  12661. }
  12662. Linear.prototype = {
  12663. areaStart: function() {
  12664. this._line = 0;
  12665. },
  12666. areaEnd: function() {
  12667. this._line = NaN;
  12668. },
  12669. lineStart: function() {
  12670. this._point = 0;
  12671. },
  12672. lineEnd: function() {
  12673. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12674. this._line = 1 - this._line;
  12675. },
  12676. point: function(x, y) {
  12677. x = +x, y = +y;
  12678. switch (this._point) {
  12679. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12680. case 1: this._point = 2; // proceed
  12681. default: this._context.lineTo(x, y); break;
  12682. }
  12683. }
  12684. };
  12685. function curveLinear(context) {
  12686. return new Linear(context);
  12687. }
  12688. function x$3(p) {
  12689. return p[0];
  12690. }
  12691. function y$3(p) {
  12692. return p[1];
  12693. }
  12694. function line() {
  12695. var x = x$3,
  12696. y = y$3,
  12697. defined = constant$b(true),
  12698. context = null,
  12699. curve = curveLinear,
  12700. output = null;
  12701. function line(data) {
  12702. var i,
  12703. n = data.length,
  12704. d,
  12705. defined0 = false,
  12706. buffer;
  12707. if (context == null) output = curve(buffer = path());
  12708. for (i = 0; i <= n; ++i) {
  12709. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12710. if (defined0 = !defined0) output.lineStart();
  12711. else output.lineEnd();
  12712. }
  12713. if (defined0) output.point(+x(d, i, data), +y(d, i, data));
  12714. }
  12715. if (buffer) return output = null, buffer + "" || null;
  12716. }
  12717. line.x = function(_) {
  12718. return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), line) : x;
  12719. };
  12720. line.y = function(_) {
  12721. return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), line) : y;
  12722. };
  12723. line.defined = function(_) {
  12724. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), line) : defined;
  12725. };
  12726. line.curve = function(_) {
  12727. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  12728. };
  12729. line.context = function(_) {
  12730. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  12731. };
  12732. return line;
  12733. }
  12734. function area$3() {
  12735. var x0 = x$3,
  12736. x1 = null,
  12737. y0 = constant$b(0),
  12738. y1 = y$3,
  12739. defined = constant$b(true),
  12740. context = null,
  12741. curve = curveLinear,
  12742. output = null;
  12743. function area(data) {
  12744. var i,
  12745. j,
  12746. k,
  12747. n = data.length,
  12748. d,
  12749. defined0 = false,
  12750. buffer,
  12751. x0z = new Array(n),
  12752. y0z = new Array(n);
  12753. if (context == null) output = curve(buffer = path());
  12754. for (i = 0; i <= n; ++i) {
  12755. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12756. if (defined0 = !defined0) {
  12757. j = i;
  12758. output.areaStart();
  12759. output.lineStart();
  12760. } else {
  12761. output.lineEnd();
  12762. output.lineStart();
  12763. for (k = i - 1; k >= j; --k) {
  12764. output.point(x0z[k], y0z[k]);
  12765. }
  12766. output.lineEnd();
  12767. output.areaEnd();
  12768. }
  12769. }
  12770. if (defined0) {
  12771. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  12772. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  12773. }
  12774. }
  12775. if (buffer) return output = null, buffer + "" || null;
  12776. }
  12777. function arealine() {
  12778. return line().defined(defined).curve(curve).context(context);
  12779. }
  12780. area.x = function(_) {
  12781. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), x1 = null, area) : x0;
  12782. };
  12783. area.x0 = function(_) {
  12784. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), area) : x0;
  12785. };
  12786. area.x1 = function(_) {
  12787. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : x1;
  12788. };
  12789. area.y = function(_) {
  12790. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), y1 = null, area) : y0;
  12791. };
  12792. area.y0 = function(_) {
  12793. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), area) : y0;
  12794. };
  12795. area.y1 = function(_) {
  12796. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : y1;
  12797. };
  12798. area.lineX0 =
  12799. area.lineY0 = function() {
  12800. return arealine().x(x0).y(y0);
  12801. };
  12802. area.lineY1 = function() {
  12803. return arealine().x(x0).y(y1);
  12804. };
  12805. area.lineX1 = function() {
  12806. return arealine().x(x1).y(y0);
  12807. };
  12808. area.defined = function(_) {
  12809. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), area) : defined;
  12810. };
  12811. area.curve = function(_) {
  12812. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  12813. };
  12814. area.context = function(_) {
  12815. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  12816. };
  12817. return area;
  12818. }
  12819. function descending$1(a, b) {
  12820. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  12821. }
  12822. function identity$8(d) {
  12823. return d;
  12824. }
  12825. function pie() {
  12826. var value = identity$8,
  12827. sortValues = descending$1,
  12828. sort = null,
  12829. startAngle = constant$b(0),
  12830. endAngle = constant$b(tau$4),
  12831. padAngle = constant$b(0);
  12832. function pie(data) {
  12833. var i,
  12834. n = data.length,
  12835. j,
  12836. k,
  12837. sum = 0,
  12838. index = new Array(n),
  12839. arcs = new Array(n),
  12840. a0 = +startAngle.apply(this, arguments),
  12841. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  12842. a1,
  12843. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  12844. pa = p * (da < 0 ? -1 : 1),
  12845. v;
  12846. for (i = 0; i < n; ++i) {
  12847. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  12848. sum += v;
  12849. }
  12850. }
  12851. // Optionally sort the arcs by previously-computed values or by data.
  12852. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  12853. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  12854. // Compute the arcs! They are stored in the original data's order.
  12855. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  12856. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  12857. data: data[j],
  12858. index: i,
  12859. value: v,
  12860. startAngle: a0,
  12861. endAngle: a1,
  12862. padAngle: p
  12863. };
  12864. }
  12865. return arcs;
  12866. }
  12867. pie.value = function(_) {
  12868. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), pie) : value;
  12869. };
  12870. pie.sortValues = function(_) {
  12871. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  12872. };
  12873. pie.sort = function(_) {
  12874. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  12875. };
  12876. pie.startAngle = function(_) {
  12877. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : startAngle;
  12878. };
  12879. pie.endAngle = function(_) {
  12880. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : endAngle;
  12881. };
  12882. pie.padAngle = function(_) {
  12883. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : padAngle;
  12884. };
  12885. return pie;
  12886. }
  12887. var curveRadialLinear = curveRadial(curveLinear);
  12888. function Radial(curve) {
  12889. this._curve = curve;
  12890. }
  12891. Radial.prototype = {
  12892. areaStart: function() {
  12893. this._curve.areaStart();
  12894. },
  12895. areaEnd: function() {
  12896. this._curve.areaEnd();
  12897. },
  12898. lineStart: function() {
  12899. this._curve.lineStart();
  12900. },
  12901. lineEnd: function() {
  12902. this._curve.lineEnd();
  12903. },
  12904. point: function(a, r) {
  12905. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  12906. }
  12907. };
  12908. function curveRadial(curve) {
  12909. function radial(context) {
  12910. return new Radial(curve(context));
  12911. }
  12912. radial._curve = curve;
  12913. return radial;
  12914. }
  12915. function lineRadial(l) {
  12916. var c = l.curve;
  12917. l.angle = l.x, delete l.x;
  12918. l.radius = l.y, delete l.y;
  12919. l.curve = function(_) {
  12920. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12921. };
  12922. return l;
  12923. }
  12924. function lineRadial$1() {
  12925. return lineRadial(line().curve(curveRadialLinear));
  12926. }
  12927. function areaRadial() {
  12928. var a = area$3().curve(curveRadialLinear),
  12929. c = a.curve,
  12930. x0 = a.lineX0,
  12931. x1 = a.lineX1,
  12932. y0 = a.lineY0,
  12933. y1 = a.lineY1;
  12934. a.angle = a.x, delete a.x;
  12935. a.startAngle = a.x0, delete a.x0;
  12936. a.endAngle = a.x1, delete a.x1;
  12937. a.radius = a.y, delete a.y;
  12938. a.innerRadius = a.y0, delete a.y0;
  12939. a.outerRadius = a.y1, delete a.y1;
  12940. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  12941. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  12942. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  12943. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  12944. a.curve = function(_) {
  12945. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12946. };
  12947. return a;
  12948. }
  12949. function pointRadial(x, y) {
  12950. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  12951. }
  12952. var slice$6 = Array.prototype.slice;
  12953. function linkSource(d) {
  12954. return d.source;
  12955. }
  12956. function linkTarget(d) {
  12957. return d.target;
  12958. }
  12959. function link$2(curve) {
  12960. var source = linkSource,
  12961. target = linkTarget,
  12962. x = x$3,
  12963. y = y$3,
  12964. context = null;
  12965. function link() {
  12966. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  12967. if (!context) context = buffer = path();
  12968. curve(context, +x.apply(this, (argv[0] = s, argv)), +y.apply(this, argv), +x.apply(this, (argv[0] = t, argv)), +y.apply(this, argv));
  12969. if (buffer) return context = null, buffer + "" || null;
  12970. }
  12971. link.source = function(_) {
  12972. return arguments.length ? (source = _, link) : source;
  12973. };
  12974. link.target = function(_) {
  12975. return arguments.length ? (target = _, link) : target;
  12976. };
  12977. link.x = function(_) {
  12978. return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), link) : x;
  12979. };
  12980. link.y = function(_) {
  12981. return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), link) : y;
  12982. };
  12983. link.context = function(_) {
  12984. return arguments.length ? ((context = _ == null ? null : _), link) : context;
  12985. };
  12986. return link;
  12987. }
  12988. function curveHorizontal(context, x0, y0, x1, y1) {
  12989. context.moveTo(x0, y0);
  12990. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  12991. }
  12992. function curveVertical(context, x0, y0, x1, y1) {
  12993. context.moveTo(x0, y0);
  12994. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  12995. }
  12996. function curveRadial$1(context, x0, y0, x1, y1) {
  12997. var p0 = pointRadial(x0, y0),
  12998. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  12999. p2 = pointRadial(x1, y0),
  13000. p3 = pointRadial(x1, y1);
  13001. context.moveTo(p0[0], p0[1]);
  13002. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  13003. }
  13004. function linkHorizontal() {
  13005. return link$2(curveHorizontal);
  13006. }
  13007. function linkVertical() {
  13008. return link$2(curveVertical);
  13009. }
  13010. function linkRadial() {
  13011. var l = link$2(curveRadial$1);
  13012. l.angle = l.x, delete l.x;
  13013. l.radius = l.y, delete l.y;
  13014. return l;
  13015. }
  13016. var circle$2 = {
  13017. draw: function(context, size) {
  13018. var r = Math.sqrt(size / pi$4);
  13019. context.moveTo(r, 0);
  13020. context.arc(0, 0, r, 0, tau$4);
  13021. }
  13022. };
  13023. var cross$2 = {
  13024. draw: function(context, size) {
  13025. var r = Math.sqrt(size / 5) / 2;
  13026. context.moveTo(-3 * r, -r);
  13027. context.lineTo(-r, -r);
  13028. context.lineTo(-r, -3 * r);
  13029. context.lineTo(r, -3 * r);
  13030. context.lineTo(r, -r);
  13031. context.lineTo(3 * r, -r);
  13032. context.lineTo(3 * r, r);
  13033. context.lineTo(r, r);
  13034. context.lineTo(r, 3 * r);
  13035. context.lineTo(-r, 3 * r);
  13036. context.lineTo(-r, r);
  13037. context.lineTo(-3 * r, r);
  13038. context.closePath();
  13039. }
  13040. };
  13041. var tan30 = Math.sqrt(1 / 3),
  13042. tan30_2 = tan30 * 2;
  13043. var diamond = {
  13044. draw: function(context, size) {
  13045. var y = Math.sqrt(size / tan30_2),
  13046. x = y * tan30;
  13047. context.moveTo(0, -y);
  13048. context.lineTo(x, 0);
  13049. context.lineTo(0, y);
  13050. context.lineTo(-x, 0);
  13051. context.closePath();
  13052. }
  13053. };
  13054. var ka = 0.89081309152928522810,
  13055. kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
  13056. kx = Math.sin(tau$4 / 10) * kr,
  13057. ky = -Math.cos(tau$4 / 10) * kr;
  13058. var star = {
  13059. draw: function(context, size) {
  13060. var r = Math.sqrt(size * ka),
  13061. x = kx * r,
  13062. y = ky * r;
  13063. context.moveTo(0, -r);
  13064. context.lineTo(x, y);
  13065. for (var i = 1; i < 5; ++i) {
  13066. var a = tau$4 * i / 5,
  13067. c = Math.cos(a),
  13068. s = Math.sin(a);
  13069. context.lineTo(s * r, -c * r);
  13070. context.lineTo(c * x - s * y, s * x + c * y);
  13071. }
  13072. context.closePath();
  13073. }
  13074. };
  13075. var square = {
  13076. draw: function(context, size) {
  13077. var w = Math.sqrt(size),
  13078. x = -w / 2;
  13079. context.rect(x, x, w, w);
  13080. }
  13081. };
  13082. var sqrt3 = Math.sqrt(3);
  13083. var triangle = {
  13084. draw: function(context, size) {
  13085. var y = -Math.sqrt(size / (sqrt3 * 3));
  13086. context.moveTo(0, y * 2);
  13087. context.lineTo(-sqrt3 * y, -y);
  13088. context.lineTo(sqrt3 * y, -y);
  13089. context.closePath();
  13090. }
  13091. };
  13092. var c$2 = -0.5,
  13093. s = Math.sqrt(3) / 2,
  13094. k = 1 / Math.sqrt(12),
  13095. a = (k / 2 + 1) * 3;
  13096. var wye = {
  13097. draw: function(context, size) {
  13098. var r = Math.sqrt(size / a),
  13099. x0 = r / 2,
  13100. y0 = r * k,
  13101. x1 = x0,
  13102. y1 = r * k + r,
  13103. x2 = -x1,
  13104. y2 = y1;
  13105. context.moveTo(x0, y0);
  13106. context.lineTo(x1, y1);
  13107. context.lineTo(x2, y2);
  13108. context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
  13109. context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
  13110. context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
  13111. context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
  13112. context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
  13113. context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
  13114. context.closePath();
  13115. }
  13116. };
  13117. var symbols = [
  13118. circle$2,
  13119. cross$2,
  13120. diamond,
  13121. square,
  13122. star,
  13123. triangle,
  13124. wye
  13125. ];
  13126. function symbol() {
  13127. var type = constant$b(circle$2),
  13128. size = constant$b(64),
  13129. context = null;
  13130. function symbol() {
  13131. var buffer;
  13132. if (!context) context = buffer = path();
  13133. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  13134. if (buffer) return context = null, buffer + "" || null;
  13135. }
  13136. symbol.type = function(_) {
  13137. return arguments.length ? (type = typeof _ === "function" ? _ : constant$b(_), symbol) : type;
  13138. };
  13139. symbol.size = function(_) {
  13140. return arguments.length ? (size = typeof _ === "function" ? _ : constant$b(+_), symbol) : size;
  13141. };
  13142. symbol.context = function(_) {
  13143. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  13144. };
  13145. return symbol;
  13146. }
  13147. function noop$3() {}
  13148. function point$2(that, x, y) {
  13149. that._context.bezierCurveTo(
  13150. (2 * that._x0 + that._x1) / 3,
  13151. (2 * that._y0 + that._y1) / 3,
  13152. (that._x0 + 2 * that._x1) / 3,
  13153. (that._y0 + 2 * that._y1) / 3,
  13154. (that._x0 + 4 * that._x1 + x) / 6,
  13155. (that._y0 + 4 * that._y1 + y) / 6
  13156. );
  13157. }
  13158. function Basis(context) {
  13159. this._context = context;
  13160. }
  13161. Basis.prototype = {
  13162. areaStart: function() {
  13163. this._line = 0;
  13164. },
  13165. areaEnd: function() {
  13166. this._line = NaN;
  13167. },
  13168. lineStart: function() {
  13169. this._x0 = this._x1 =
  13170. this._y0 = this._y1 = NaN;
  13171. this._point = 0;
  13172. },
  13173. lineEnd: function() {
  13174. switch (this._point) {
  13175. case 3: point$2(this, this._x1, this._y1); // proceed
  13176. case 2: this._context.lineTo(this._x1, this._y1); break;
  13177. }
  13178. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13179. this._line = 1 - this._line;
  13180. },
  13181. point: function(x, y) {
  13182. x = +x, y = +y;
  13183. switch (this._point) {
  13184. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13185. case 1: this._point = 2; break;
  13186. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  13187. default: point$2(this, x, y); break;
  13188. }
  13189. this._x0 = this._x1, this._x1 = x;
  13190. this._y0 = this._y1, this._y1 = y;
  13191. }
  13192. };
  13193. function basis$2(context) {
  13194. return new Basis(context);
  13195. }
  13196. function BasisClosed(context) {
  13197. this._context = context;
  13198. }
  13199. BasisClosed.prototype = {
  13200. areaStart: noop$3,
  13201. areaEnd: noop$3,
  13202. lineStart: function() {
  13203. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  13204. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  13205. this._point = 0;
  13206. },
  13207. lineEnd: function() {
  13208. switch (this._point) {
  13209. case 1: {
  13210. this._context.moveTo(this._x2, this._y2);
  13211. this._context.closePath();
  13212. break;
  13213. }
  13214. case 2: {
  13215. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  13216. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  13217. this._context.closePath();
  13218. break;
  13219. }
  13220. case 3: {
  13221. this.point(this._x2, this._y2);
  13222. this.point(this._x3, this._y3);
  13223. this.point(this._x4, this._y4);
  13224. break;
  13225. }
  13226. }
  13227. },
  13228. point: function(x, y) {
  13229. x = +x, y = +y;
  13230. switch (this._point) {
  13231. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  13232. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  13233. 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;
  13234. default: point$2(this, x, y); break;
  13235. }
  13236. this._x0 = this._x1, this._x1 = x;
  13237. this._y0 = this._y1, this._y1 = y;
  13238. }
  13239. };
  13240. function basisClosed$1(context) {
  13241. return new BasisClosed(context);
  13242. }
  13243. function BasisOpen(context) {
  13244. this._context = context;
  13245. }
  13246. BasisOpen.prototype = {
  13247. areaStart: function() {
  13248. this._line = 0;
  13249. },
  13250. areaEnd: function() {
  13251. this._line = NaN;
  13252. },
  13253. lineStart: function() {
  13254. this._x0 = this._x1 =
  13255. this._y0 = this._y1 = NaN;
  13256. this._point = 0;
  13257. },
  13258. lineEnd: function() {
  13259. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13260. this._line = 1 - this._line;
  13261. },
  13262. point: function(x, y) {
  13263. x = +x, y = +y;
  13264. switch (this._point) {
  13265. case 0: this._point = 1; break;
  13266. case 1: this._point = 2; break;
  13267. 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;
  13268. case 3: this._point = 4; // proceed
  13269. default: point$2(this, x, y); break;
  13270. }
  13271. this._x0 = this._x1, this._x1 = x;
  13272. this._y0 = this._y1, this._y1 = y;
  13273. }
  13274. };
  13275. function basisOpen(context) {
  13276. return new BasisOpen(context);
  13277. }
  13278. function Bundle(context, beta) {
  13279. this._basis = new Basis(context);
  13280. this._beta = beta;
  13281. }
  13282. Bundle.prototype = {
  13283. lineStart: function() {
  13284. this._x = [];
  13285. this._y = [];
  13286. this._basis.lineStart();
  13287. },
  13288. lineEnd: function() {
  13289. var x = this._x,
  13290. y = this._y,
  13291. j = x.length - 1;
  13292. if (j > 0) {
  13293. var x0 = x[0],
  13294. y0 = y[0],
  13295. dx = x[j] - x0,
  13296. dy = y[j] - y0,
  13297. i = -1,
  13298. t;
  13299. while (++i <= j) {
  13300. t = i / j;
  13301. this._basis.point(
  13302. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  13303. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  13304. );
  13305. }
  13306. }
  13307. this._x = this._y = null;
  13308. this._basis.lineEnd();
  13309. },
  13310. point: function(x, y) {
  13311. this._x.push(+x);
  13312. this._y.push(+y);
  13313. }
  13314. };
  13315. var bundle = (function custom(beta) {
  13316. function bundle(context) {
  13317. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  13318. }
  13319. bundle.beta = function(beta) {
  13320. return custom(+beta);
  13321. };
  13322. return bundle;
  13323. })(0.85);
  13324. function point$3(that, x, y) {
  13325. that._context.bezierCurveTo(
  13326. that._x1 + that._k * (that._x2 - that._x0),
  13327. that._y1 + that._k * (that._y2 - that._y0),
  13328. that._x2 + that._k * (that._x1 - x),
  13329. that._y2 + that._k * (that._y1 - y),
  13330. that._x2,
  13331. that._y2
  13332. );
  13333. }
  13334. function Cardinal(context, tension) {
  13335. this._context = context;
  13336. this._k = (1 - tension) / 6;
  13337. }
  13338. Cardinal.prototype = {
  13339. areaStart: function() {
  13340. this._line = 0;
  13341. },
  13342. areaEnd: function() {
  13343. this._line = NaN;
  13344. },
  13345. lineStart: function() {
  13346. this._x0 = this._x1 = this._x2 =
  13347. this._y0 = this._y1 = this._y2 = NaN;
  13348. this._point = 0;
  13349. },
  13350. lineEnd: function() {
  13351. switch (this._point) {
  13352. case 2: this._context.lineTo(this._x2, this._y2); break;
  13353. case 3: point$3(this, this._x1, this._y1); break;
  13354. }
  13355. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13356. this._line = 1 - this._line;
  13357. },
  13358. point: function(x, y) {
  13359. x = +x, y = +y;
  13360. switch (this._point) {
  13361. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13362. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  13363. case 2: this._point = 3; // proceed
  13364. default: point$3(this, x, y); break;
  13365. }
  13366. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13367. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13368. }
  13369. };
  13370. var cardinal = (function custom(tension) {
  13371. function cardinal(context) {
  13372. return new Cardinal(context, tension);
  13373. }
  13374. cardinal.tension = function(tension) {
  13375. return custom(+tension);
  13376. };
  13377. return cardinal;
  13378. })(0);
  13379. function CardinalClosed(context, tension) {
  13380. this._context = context;
  13381. this._k = (1 - tension) / 6;
  13382. }
  13383. CardinalClosed.prototype = {
  13384. areaStart: noop$3,
  13385. areaEnd: noop$3,
  13386. lineStart: function() {
  13387. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13388. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13389. this._point = 0;
  13390. },
  13391. lineEnd: function() {
  13392. switch (this._point) {
  13393. case 1: {
  13394. this._context.moveTo(this._x3, this._y3);
  13395. this._context.closePath();
  13396. break;
  13397. }
  13398. case 2: {
  13399. this._context.lineTo(this._x3, this._y3);
  13400. this._context.closePath();
  13401. break;
  13402. }
  13403. case 3: {
  13404. this.point(this._x3, this._y3);
  13405. this.point(this._x4, this._y4);
  13406. this.point(this._x5, this._y5);
  13407. break;
  13408. }
  13409. }
  13410. },
  13411. point: function(x, y) {
  13412. x = +x, y = +y;
  13413. switch (this._point) {
  13414. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13415. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13416. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13417. default: point$3(this, x, y); break;
  13418. }
  13419. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13420. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13421. }
  13422. };
  13423. var cardinalClosed = (function custom(tension) {
  13424. function cardinal(context) {
  13425. return new CardinalClosed(context, tension);
  13426. }
  13427. cardinal.tension = function(tension) {
  13428. return custom(+tension);
  13429. };
  13430. return cardinal;
  13431. })(0);
  13432. function CardinalOpen(context, tension) {
  13433. this._context = context;
  13434. this._k = (1 - tension) / 6;
  13435. }
  13436. CardinalOpen.prototype = {
  13437. areaStart: function() {
  13438. this._line = 0;
  13439. },
  13440. areaEnd: function() {
  13441. this._line = NaN;
  13442. },
  13443. lineStart: function() {
  13444. this._x0 = this._x1 = this._x2 =
  13445. this._y0 = this._y1 = this._y2 = NaN;
  13446. this._point = 0;
  13447. },
  13448. lineEnd: function() {
  13449. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13450. this._line = 1 - this._line;
  13451. },
  13452. point: function(x, y) {
  13453. x = +x, y = +y;
  13454. switch (this._point) {
  13455. case 0: this._point = 1; break;
  13456. case 1: this._point = 2; break;
  13457. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13458. case 3: this._point = 4; // proceed
  13459. default: point$3(this, x, y); break;
  13460. }
  13461. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13462. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13463. }
  13464. };
  13465. var cardinalOpen = (function custom(tension) {
  13466. function cardinal(context) {
  13467. return new CardinalOpen(context, tension);
  13468. }
  13469. cardinal.tension = function(tension) {
  13470. return custom(+tension);
  13471. };
  13472. return cardinal;
  13473. })(0);
  13474. function point$4(that, x, y) {
  13475. var x1 = that._x1,
  13476. y1 = that._y1,
  13477. x2 = that._x2,
  13478. y2 = that._y2;
  13479. if (that._l01_a > epsilon$3) {
  13480. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  13481. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  13482. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  13483. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  13484. }
  13485. if (that._l23_a > epsilon$3) {
  13486. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  13487. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  13488. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  13489. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  13490. }
  13491. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  13492. }
  13493. function CatmullRom(context, alpha) {
  13494. this._context = context;
  13495. this._alpha = alpha;
  13496. }
  13497. CatmullRom.prototype = {
  13498. areaStart: function() {
  13499. this._line = 0;
  13500. },
  13501. areaEnd: function() {
  13502. this._line = NaN;
  13503. },
  13504. lineStart: function() {
  13505. this._x0 = this._x1 = this._x2 =
  13506. this._y0 = this._y1 = this._y2 = NaN;
  13507. this._l01_a = this._l12_a = this._l23_a =
  13508. this._l01_2a = this._l12_2a = this._l23_2a =
  13509. this._point = 0;
  13510. },
  13511. lineEnd: function() {
  13512. switch (this._point) {
  13513. case 2: this._context.lineTo(this._x2, this._y2); break;
  13514. case 3: this.point(this._x2, this._y2); break;
  13515. }
  13516. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13517. this._line = 1 - this._line;
  13518. },
  13519. point: function(x, y) {
  13520. x = +x, y = +y;
  13521. if (this._point) {
  13522. var x23 = this._x2 - x,
  13523. y23 = this._y2 - y;
  13524. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13525. }
  13526. switch (this._point) {
  13527. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13528. case 1: this._point = 2; break;
  13529. case 2: this._point = 3; // proceed
  13530. default: point$4(this, x, y); break;
  13531. }
  13532. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13533. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13534. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13535. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13536. }
  13537. };
  13538. var catmullRom = (function custom(alpha) {
  13539. function catmullRom(context) {
  13540. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  13541. }
  13542. catmullRom.alpha = function(alpha) {
  13543. return custom(+alpha);
  13544. };
  13545. return catmullRom;
  13546. })(0.5);
  13547. function CatmullRomClosed(context, alpha) {
  13548. this._context = context;
  13549. this._alpha = alpha;
  13550. }
  13551. CatmullRomClosed.prototype = {
  13552. areaStart: noop$3,
  13553. areaEnd: noop$3,
  13554. lineStart: function() {
  13555. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13556. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13557. this._l01_a = this._l12_a = this._l23_a =
  13558. this._l01_2a = this._l12_2a = this._l23_2a =
  13559. this._point = 0;
  13560. },
  13561. lineEnd: function() {
  13562. switch (this._point) {
  13563. case 1: {
  13564. this._context.moveTo(this._x3, this._y3);
  13565. this._context.closePath();
  13566. break;
  13567. }
  13568. case 2: {
  13569. this._context.lineTo(this._x3, this._y3);
  13570. this._context.closePath();
  13571. break;
  13572. }
  13573. case 3: {
  13574. this.point(this._x3, this._y3);
  13575. this.point(this._x4, this._y4);
  13576. this.point(this._x5, this._y5);
  13577. break;
  13578. }
  13579. }
  13580. },
  13581. point: function(x, y) {
  13582. x = +x, y = +y;
  13583. if (this._point) {
  13584. var x23 = this._x2 - x,
  13585. y23 = this._y2 - y;
  13586. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13587. }
  13588. switch (this._point) {
  13589. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13590. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13591. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13592. default: point$4(this, x, y); break;
  13593. }
  13594. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13595. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13596. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13597. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13598. }
  13599. };
  13600. var catmullRomClosed = (function custom(alpha) {
  13601. function catmullRom(context) {
  13602. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  13603. }
  13604. catmullRom.alpha = function(alpha) {
  13605. return custom(+alpha);
  13606. };
  13607. return catmullRom;
  13608. })(0.5);
  13609. function CatmullRomOpen(context, alpha) {
  13610. this._context = context;
  13611. this._alpha = alpha;
  13612. }
  13613. CatmullRomOpen.prototype = {
  13614. areaStart: function() {
  13615. this._line = 0;
  13616. },
  13617. areaEnd: function() {
  13618. this._line = NaN;
  13619. },
  13620. lineStart: function() {
  13621. this._x0 = this._x1 = this._x2 =
  13622. this._y0 = this._y1 = this._y2 = NaN;
  13623. this._l01_a = this._l12_a = this._l23_a =
  13624. this._l01_2a = this._l12_2a = this._l23_2a =
  13625. this._point = 0;
  13626. },
  13627. lineEnd: function() {
  13628. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13629. this._line = 1 - this._line;
  13630. },
  13631. point: function(x, y) {
  13632. x = +x, y = +y;
  13633. if (this._point) {
  13634. var x23 = this._x2 - x,
  13635. y23 = this._y2 - y;
  13636. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13637. }
  13638. switch (this._point) {
  13639. case 0: this._point = 1; break;
  13640. case 1: this._point = 2; break;
  13641. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13642. case 3: this._point = 4; // proceed
  13643. default: point$4(this, x, y); break;
  13644. }
  13645. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13646. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13647. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13648. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13649. }
  13650. };
  13651. var catmullRomOpen = (function custom(alpha) {
  13652. function catmullRom(context) {
  13653. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  13654. }
  13655. catmullRom.alpha = function(alpha) {
  13656. return custom(+alpha);
  13657. };
  13658. return catmullRom;
  13659. })(0.5);
  13660. function LinearClosed(context) {
  13661. this._context = context;
  13662. }
  13663. LinearClosed.prototype = {
  13664. areaStart: noop$3,
  13665. areaEnd: noop$3,
  13666. lineStart: function() {
  13667. this._point = 0;
  13668. },
  13669. lineEnd: function() {
  13670. if (this._point) this._context.closePath();
  13671. },
  13672. point: function(x, y) {
  13673. x = +x, y = +y;
  13674. if (this._point) this._context.lineTo(x, y);
  13675. else this._point = 1, this._context.moveTo(x, y);
  13676. }
  13677. };
  13678. function linearClosed(context) {
  13679. return new LinearClosed(context);
  13680. }
  13681. function sign$1(x) {
  13682. return x < 0 ? -1 : 1;
  13683. }
  13684. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  13685. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  13686. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  13687. // NOV(II), P. 443, 1990.
  13688. function slope3(that, x2, y2) {
  13689. var h0 = that._x1 - that._x0,
  13690. h1 = x2 - that._x1,
  13691. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  13692. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  13693. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  13694. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  13695. }
  13696. // Calculate a one-sided slope.
  13697. function slope2(that, t) {
  13698. var h = that._x1 - that._x0;
  13699. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  13700. }
  13701. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  13702. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  13703. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  13704. function point$5(that, t0, t1) {
  13705. var x0 = that._x0,
  13706. y0 = that._y0,
  13707. x1 = that._x1,
  13708. y1 = that._y1,
  13709. dx = (x1 - x0) / 3;
  13710. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  13711. }
  13712. function MonotoneX(context) {
  13713. this._context = context;
  13714. }
  13715. MonotoneX.prototype = {
  13716. areaStart: function() {
  13717. this._line = 0;
  13718. },
  13719. areaEnd: function() {
  13720. this._line = NaN;
  13721. },
  13722. lineStart: function() {
  13723. this._x0 = this._x1 =
  13724. this._y0 = this._y1 =
  13725. this._t0 = NaN;
  13726. this._point = 0;
  13727. },
  13728. lineEnd: function() {
  13729. switch (this._point) {
  13730. case 2: this._context.lineTo(this._x1, this._y1); break;
  13731. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  13732. }
  13733. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13734. this._line = 1 - this._line;
  13735. },
  13736. point: function(x, y) {
  13737. var t1 = NaN;
  13738. x = +x, y = +y;
  13739. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  13740. switch (this._point) {
  13741. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13742. case 1: this._point = 2; break;
  13743. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  13744. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  13745. }
  13746. this._x0 = this._x1, this._x1 = x;
  13747. this._y0 = this._y1, this._y1 = y;
  13748. this._t0 = t1;
  13749. }
  13750. };
  13751. function MonotoneY(context) {
  13752. this._context = new ReflectContext(context);
  13753. }
  13754. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  13755. MonotoneX.prototype.point.call(this, y, x);
  13756. };
  13757. function ReflectContext(context) {
  13758. this._context = context;
  13759. }
  13760. ReflectContext.prototype = {
  13761. moveTo: function(x, y) { this._context.moveTo(y, x); },
  13762. closePath: function() { this._context.closePath(); },
  13763. lineTo: function(x, y) { this._context.lineTo(y, x); },
  13764. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  13765. };
  13766. function monotoneX(context) {
  13767. return new MonotoneX(context);
  13768. }
  13769. function monotoneY(context) {
  13770. return new MonotoneY(context);
  13771. }
  13772. function Natural(context) {
  13773. this._context = context;
  13774. }
  13775. Natural.prototype = {
  13776. areaStart: function() {
  13777. this._line = 0;
  13778. },
  13779. areaEnd: function() {
  13780. this._line = NaN;
  13781. },
  13782. lineStart: function() {
  13783. this._x = [];
  13784. this._y = [];
  13785. },
  13786. lineEnd: function() {
  13787. var x = this._x,
  13788. y = this._y,
  13789. n = x.length;
  13790. if (n) {
  13791. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  13792. if (n === 2) {
  13793. this._context.lineTo(x[1], y[1]);
  13794. } else {
  13795. var px = controlPoints(x),
  13796. py = controlPoints(y);
  13797. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  13798. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  13799. }
  13800. }
  13801. }
  13802. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  13803. this._line = 1 - this._line;
  13804. this._x = this._y = null;
  13805. },
  13806. point: function(x, y) {
  13807. this._x.push(+x);
  13808. this._y.push(+y);
  13809. }
  13810. };
  13811. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  13812. function controlPoints(x) {
  13813. var i,
  13814. n = x.length - 1,
  13815. m,
  13816. a = new Array(n),
  13817. b = new Array(n),
  13818. r = new Array(n);
  13819. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  13820. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  13821. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  13822. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  13823. a[n - 1] = r[n - 1] / b[n - 1];
  13824. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  13825. b[n - 1] = (x[n] + a[n - 1]) / 2;
  13826. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  13827. return [a, b];
  13828. }
  13829. function natural(context) {
  13830. return new Natural(context);
  13831. }
  13832. function Step(context, t) {
  13833. this._context = context;
  13834. this._t = t;
  13835. }
  13836. Step.prototype = {
  13837. areaStart: function() {
  13838. this._line = 0;
  13839. },
  13840. areaEnd: function() {
  13841. this._line = NaN;
  13842. },
  13843. lineStart: function() {
  13844. this._x = this._y = NaN;
  13845. this._point = 0;
  13846. },
  13847. lineEnd: function() {
  13848. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  13849. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13850. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  13851. },
  13852. point: function(x, y) {
  13853. x = +x, y = +y;
  13854. switch (this._point) {
  13855. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13856. case 1: this._point = 2; // proceed
  13857. default: {
  13858. if (this._t <= 0) {
  13859. this._context.lineTo(this._x, y);
  13860. this._context.lineTo(x, y);
  13861. } else {
  13862. var x1 = this._x * (1 - this._t) + x * this._t;
  13863. this._context.lineTo(x1, this._y);
  13864. this._context.lineTo(x1, y);
  13865. }
  13866. break;
  13867. }
  13868. }
  13869. this._x = x, this._y = y;
  13870. }
  13871. };
  13872. function step(context) {
  13873. return new Step(context, 0.5);
  13874. }
  13875. function stepBefore(context) {
  13876. return new Step(context, 0);
  13877. }
  13878. function stepAfter(context) {
  13879. return new Step(context, 1);
  13880. }
  13881. function none$1(series, order) {
  13882. if (!((n = series.length) > 1)) return;
  13883. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  13884. s0 = s1, s1 = series[order[i]];
  13885. for (j = 0; j < m; ++j) {
  13886. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  13887. }
  13888. }
  13889. }
  13890. function none$2(series) {
  13891. var n = series.length, o = new Array(n);
  13892. while (--n >= 0) o[n] = n;
  13893. return o;
  13894. }
  13895. function stackValue(d, key) {
  13896. return d[key];
  13897. }
  13898. function stack() {
  13899. var keys = constant$b([]),
  13900. order = none$2,
  13901. offset = none$1,
  13902. value = stackValue;
  13903. function stack(data) {
  13904. var kz = keys.apply(this, arguments),
  13905. i,
  13906. m = data.length,
  13907. n = kz.length,
  13908. sz = new Array(n),
  13909. oz;
  13910. for (i = 0; i < n; ++i) {
  13911. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  13912. si[j] = sij = [0, +value(data[j], ki, j, data)];
  13913. sij.data = data[j];
  13914. }
  13915. si.key = ki;
  13916. }
  13917. for (i = 0, oz = order(sz); i < n; ++i) {
  13918. sz[oz[i]].index = i;
  13919. }
  13920. offset(sz, oz);
  13921. return sz;
  13922. }
  13923. stack.keys = function(_) {
  13924. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : keys;
  13925. };
  13926. stack.value = function(_) {
  13927. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), stack) : value;
  13928. };
  13929. stack.order = function(_) {
  13930. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : order;
  13931. };
  13932. stack.offset = function(_) {
  13933. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  13934. };
  13935. return stack;
  13936. }
  13937. function expand(series, order) {
  13938. if (!((n = series.length) > 0)) return;
  13939. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  13940. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  13941. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  13942. }
  13943. none$1(series, order);
  13944. }
  13945. function diverging$1(series, order) {
  13946. if (!((n = series.length) > 0)) return;
  13947. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  13948. for (yp = yn = 0, i = 0; i < n; ++i) {
  13949. if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
  13950. d[0] = yp, d[1] = yp += dy;
  13951. } else if (dy < 0) {
  13952. d[1] = yn, d[0] = yn += dy;
  13953. } else {
  13954. d[0] = 0, d[1] = dy;
  13955. }
  13956. }
  13957. }
  13958. }
  13959. function silhouette(series, order) {
  13960. if (!((n = series.length) > 0)) return;
  13961. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  13962. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  13963. s0[j][1] += s0[j][0] = -y / 2;
  13964. }
  13965. none$1(series, order);
  13966. }
  13967. function wiggle(series, order) {
  13968. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  13969. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  13970. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  13971. var si = series[order[i]],
  13972. sij0 = si[j][1] || 0,
  13973. sij1 = si[j - 1][1] || 0,
  13974. s3 = (sij0 - sij1) / 2;
  13975. for (var k = 0; k < i; ++k) {
  13976. var sk = series[order[k]],
  13977. skj0 = sk[j][1] || 0,
  13978. skj1 = sk[j - 1][1] || 0;
  13979. s3 += skj0 - skj1;
  13980. }
  13981. s1 += sij0, s2 += s3 * sij0;
  13982. }
  13983. s0[j - 1][1] += s0[j - 1][0] = y;
  13984. if (s1) y -= s2 / s1;
  13985. }
  13986. s0[j - 1][1] += s0[j - 1][0] = y;
  13987. none$1(series, order);
  13988. }
  13989. function appearance(series) {
  13990. var peaks = series.map(peak);
  13991. return none$2(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
  13992. }
  13993. function peak(series) {
  13994. var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
  13995. while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
  13996. return j;
  13997. }
  13998. function ascending$3(series) {
  13999. var sums = series.map(sum$2);
  14000. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  14001. }
  14002. function sum$2(series) {
  14003. var s = 0, i = -1, n = series.length, v;
  14004. while (++i < n) if (v = +series[i][1]) s += v;
  14005. return s;
  14006. }
  14007. function descending$2(series) {
  14008. return ascending$3(series).reverse();
  14009. }
  14010. function insideOut(series) {
  14011. var n = series.length,
  14012. i,
  14013. j,
  14014. sums = series.map(sum$2),
  14015. order = appearance(series),
  14016. top = 0,
  14017. bottom = 0,
  14018. tops = [],
  14019. bottoms = [];
  14020. for (i = 0; i < n; ++i) {
  14021. j = order[i];
  14022. if (top < bottom) {
  14023. top += sums[j];
  14024. tops.push(j);
  14025. } else {
  14026. bottom += sums[j];
  14027. bottoms.push(j);
  14028. }
  14029. }
  14030. return bottoms.reverse().concat(tops);
  14031. }
  14032. function reverse(series) {
  14033. return none$2(series).reverse();
  14034. }
  14035. function constant$c(x) {
  14036. return function() {
  14037. return x;
  14038. };
  14039. }
  14040. function x$4(d) {
  14041. return d[0];
  14042. }
  14043. function y$4(d) {
  14044. return d[1];
  14045. }
  14046. function RedBlackTree() {
  14047. this._ = null; // root node
  14048. }
  14049. function RedBlackNode(node) {
  14050. node.U = // parent node
  14051. node.C = // color - true for red, false for black
  14052. node.L = // left node
  14053. node.R = // right node
  14054. node.P = // previous node
  14055. node.N = null; // next node
  14056. }
  14057. RedBlackTree.prototype = {
  14058. constructor: RedBlackTree,
  14059. insert: function(after, node) {
  14060. var parent, grandpa, uncle;
  14061. if (after) {
  14062. node.P = after;
  14063. node.N = after.N;
  14064. if (after.N) after.N.P = node;
  14065. after.N = node;
  14066. if (after.R) {
  14067. after = after.R;
  14068. while (after.L) after = after.L;
  14069. after.L = node;
  14070. } else {
  14071. after.R = node;
  14072. }
  14073. parent = after;
  14074. } else if (this._) {
  14075. after = RedBlackFirst(this._);
  14076. node.P = null;
  14077. node.N = after;
  14078. after.P = after.L = node;
  14079. parent = after;
  14080. } else {
  14081. node.P = node.N = null;
  14082. this._ = node;
  14083. parent = null;
  14084. }
  14085. node.L = node.R = null;
  14086. node.U = parent;
  14087. node.C = true;
  14088. after = node;
  14089. while (parent && parent.C) {
  14090. grandpa = parent.U;
  14091. if (parent === grandpa.L) {
  14092. uncle = grandpa.R;
  14093. if (uncle && uncle.C) {
  14094. parent.C = uncle.C = false;
  14095. grandpa.C = true;
  14096. after = grandpa;
  14097. } else {
  14098. if (after === parent.R) {
  14099. RedBlackRotateLeft(this, parent);
  14100. after = parent;
  14101. parent = after.U;
  14102. }
  14103. parent.C = false;
  14104. grandpa.C = true;
  14105. RedBlackRotateRight(this, grandpa);
  14106. }
  14107. } else {
  14108. uncle = grandpa.L;
  14109. if (uncle && uncle.C) {
  14110. parent.C = uncle.C = false;
  14111. grandpa.C = true;
  14112. after = grandpa;
  14113. } else {
  14114. if (after === parent.L) {
  14115. RedBlackRotateRight(this, parent);
  14116. after = parent;
  14117. parent = after.U;
  14118. }
  14119. parent.C = false;
  14120. grandpa.C = true;
  14121. RedBlackRotateLeft(this, grandpa);
  14122. }
  14123. }
  14124. parent = after.U;
  14125. }
  14126. this._.C = false;
  14127. },
  14128. remove: function(node) {
  14129. if (node.N) node.N.P = node.P;
  14130. if (node.P) node.P.N = node.N;
  14131. node.N = node.P = null;
  14132. var parent = node.U,
  14133. sibling,
  14134. left = node.L,
  14135. right = node.R,
  14136. next,
  14137. red;
  14138. if (!left) next = right;
  14139. else if (!right) next = left;
  14140. else next = RedBlackFirst(right);
  14141. if (parent) {
  14142. if (parent.L === node) parent.L = next;
  14143. else parent.R = next;
  14144. } else {
  14145. this._ = next;
  14146. }
  14147. if (left && right) {
  14148. red = next.C;
  14149. next.C = node.C;
  14150. next.L = left;
  14151. left.U = next;
  14152. if (next !== right) {
  14153. parent = next.U;
  14154. next.U = node.U;
  14155. node = next.R;
  14156. parent.L = node;
  14157. next.R = right;
  14158. right.U = next;
  14159. } else {
  14160. next.U = parent;
  14161. parent = next;
  14162. node = next.R;
  14163. }
  14164. } else {
  14165. red = node.C;
  14166. node = next;
  14167. }
  14168. if (node) node.U = parent;
  14169. if (red) return;
  14170. if (node && node.C) { node.C = false; return; }
  14171. do {
  14172. if (node === this._) break;
  14173. if (node === parent.L) {
  14174. sibling = parent.R;
  14175. if (sibling.C) {
  14176. sibling.C = false;
  14177. parent.C = true;
  14178. RedBlackRotateLeft(this, parent);
  14179. sibling = parent.R;
  14180. }
  14181. if ((sibling.L && sibling.L.C)
  14182. || (sibling.R && sibling.R.C)) {
  14183. if (!sibling.R || !sibling.R.C) {
  14184. sibling.L.C = false;
  14185. sibling.C = true;
  14186. RedBlackRotateRight(this, sibling);
  14187. sibling = parent.R;
  14188. }
  14189. sibling.C = parent.C;
  14190. parent.C = sibling.R.C = false;
  14191. RedBlackRotateLeft(this, parent);
  14192. node = this._;
  14193. break;
  14194. }
  14195. } else {
  14196. sibling = parent.L;
  14197. if (sibling.C) {
  14198. sibling.C = false;
  14199. parent.C = true;
  14200. RedBlackRotateRight(this, parent);
  14201. sibling = parent.L;
  14202. }
  14203. if ((sibling.L && sibling.L.C)
  14204. || (sibling.R && sibling.R.C)) {
  14205. if (!sibling.L || !sibling.L.C) {
  14206. sibling.R.C = false;
  14207. sibling.C = true;
  14208. RedBlackRotateLeft(this, sibling);
  14209. sibling = parent.L;
  14210. }
  14211. sibling.C = parent.C;
  14212. parent.C = sibling.L.C = false;
  14213. RedBlackRotateRight(this, parent);
  14214. node = this._;
  14215. break;
  14216. }
  14217. }
  14218. sibling.C = true;
  14219. node = parent;
  14220. parent = parent.U;
  14221. } while (!node.C);
  14222. if (node) node.C = false;
  14223. }
  14224. };
  14225. function RedBlackRotateLeft(tree, node) {
  14226. var p = node,
  14227. q = node.R,
  14228. parent = p.U;
  14229. if (parent) {
  14230. if (parent.L === p) parent.L = q;
  14231. else parent.R = q;
  14232. } else {
  14233. tree._ = q;
  14234. }
  14235. q.U = parent;
  14236. p.U = q;
  14237. p.R = q.L;
  14238. if (p.R) p.R.U = p;
  14239. q.L = p;
  14240. }
  14241. function RedBlackRotateRight(tree, node) {
  14242. var p = node,
  14243. q = node.L,
  14244. parent = p.U;
  14245. if (parent) {
  14246. if (parent.L === p) parent.L = q;
  14247. else parent.R = q;
  14248. } else {
  14249. tree._ = q;
  14250. }
  14251. q.U = parent;
  14252. p.U = q;
  14253. p.L = q.R;
  14254. if (p.L) p.L.U = p;
  14255. q.R = p;
  14256. }
  14257. function RedBlackFirst(node) {
  14258. while (node.L) node = node.L;
  14259. return node;
  14260. }
  14261. function createEdge(left, right, v0, v1) {
  14262. var edge = [null, null],
  14263. index = edges.push(edge) - 1;
  14264. edge.left = left;
  14265. edge.right = right;
  14266. if (v0) setEdgeEnd(edge, left, right, v0);
  14267. if (v1) setEdgeEnd(edge, right, left, v1);
  14268. cells[left.index].halfedges.push(index);
  14269. cells[right.index].halfedges.push(index);
  14270. return edge;
  14271. }
  14272. function createBorderEdge(left, v0, v1) {
  14273. var edge = [v0, v1];
  14274. edge.left = left;
  14275. return edge;
  14276. }
  14277. function setEdgeEnd(edge, left, right, vertex) {
  14278. if (!edge[0] && !edge[1]) {
  14279. edge[0] = vertex;
  14280. edge.left = left;
  14281. edge.right = right;
  14282. } else if (edge.left === right) {
  14283. edge[1] = vertex;
  14284. } else {
  14285. edge[0] = vertex;
  14286. }
  14287. }
  14288. // Liang–Barsky line clipping.
  14289. function clipEdge(edge, x0, y0, x1, y1) {
  14290. var a = edge[0],
  14291. b = edge[1],
  14292. ax = a[0],
  14293. ay = a[1],
  14294. bx = b[0],
  14295. by = b[1],
  14296. t0 = 0,
  14297. t1 = 1,
  14298. dx = bx - ax,
  14299. dy = by - ay,
  14300. r;
  14301. r = x0 - ax;
  14302. if (!dx && r > 0) return;
  14303. r /= dx;
  14304. if (dx < 0) {
  14305. if (r < t0) return;
  14306. if (r < t1) t1 = r;
  14307. } else if (dx > 0) {
  14308. if (r > t1) return;
  14309. if (r > t0) t0 = r;
  14310. }
  14311. r = x1 - ax;
  14312. if (!dx && r < 0) return;
  14313. r /= dx;
  14314. if (dx < 0) {
  14315. if (r > t1) return;
  14316. if (r > t0) t0 = r;
  14317. } else if (dx > 0) {
  14318. if (r < t0) return;
  14319. if (r < t1) t1 = r;
  14320. }
  14321. r = y0 - ay;
  14322. if (!dy && r > 0) return;
  14323. r /= dy;
  14324. if (dy < 0) {
  14325. if (r < t0) return;
  14326. if (r < t1) t1 = r;
  14327. } else if (dy > 0) {
  14328. if (r > t1) return;
  14329. if (r > t0) t0 = r;
  14330. }
  14331. r = y1 - ay;
  14332. if (!dy && r < 0) return;
  14333. r /= dy;
  14334. if (dy < 0) {
  14335. if (r > t1) return;
  14336. if (r > t0) t0 = r;
  14337. } else if (dy > 0) {
  14338. if (r < t0) return;
  14339. if (r < t1) t1 = r;
  14340. }
  14341. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  14342. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  14343. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  14344. return true;
  14345. }
  14346. function connectEdge(edge, x0, y0, x1, y1) {
  14347. var v1 = edge[1];
  14348. if (v1) return true;
  14349. var v0 = edge[0],
  14350. left = edge.left,
  14351. right = edge.right,
  14352. lx = left[0],
  14353. ly = left[1],
  14354. rx = right[0],
  14355. ry = right[1],
  14356. fx = (lx + rx) / 2,
  14357. fy = (ly + ry) / 2,
  14358. fm,
  14359. fb;
  14360. if (ry === ly) {
  14361. if (fx < x0 || fx >= x1) return;
  14362. if (lx > rx) {
  14363. if (!v0) v0 = [fx, y0];
  14364. else if (v0[1] >= y1) return;
  14365. v1 = [fx, y1];
  14366. } else {
  14367. if (!v0) v0 = [fx, y1];
  14368. else if (v0[1] < y0) return;
  14369. v1 = [fx, y0];
  14370. }
  14371. } else {
  14372. fm = (lx - rx) / (ry - ly);
  14373. fb = fy - fm * fx;
  14374. if (fm < -1 || fm > 1) {
  14375. if (lx > rx) {
  14376. if (!v0) v0 = [(y0 - fb) / fm, y0];
  14377. else if (v0[1] >= y1) return;
  14378. v1 = [(y1 - fb) / fm, y1];
  14379. } else {
  14380. if (!v0) v0 = [(y1 - fb) / fm, y1];
  14381. else if (v0[1] < y0) return;
  14382. v1 = [(y0 - fb) / fm, y0];
  14383. }
  14384. } else {
  14385. if (ly < ry) {
  14386. if (!v0) v0 = [x0, fm * x0 + fb];
  14387. else if (v0[0] >= x1) return;
  14388. v1 = [x1, fm * x1 + fb];
  14389. } else {
  14390. if (!v0) v0 = [x1, fm * x1 + fb];
  14391. else if (v0[0] < x0) return;
  14392. v1 = [x0, fm * x0 + fb];
  14393. }
  14394. }
  14395. }
  14396. edge[0] = v0;
  14397. edge[1] = v1;
  14398. return true;
  14399. }
  14400. function clipEdges(x0, y0, x1, y1) {
  14401. var i = edges.length,
  14402. edge;
  14403. while (i--) {
  14404. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  14405. || !clipEdge(edge, x0, y0, x1, y1)
  14406. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  14407. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  14408. delete edges[i];
  14409. }
  14410. }
  14411. }
  14412. function createCell(site) {
  14413. return cells[site.index] = {
  14414. site: site,
  14415. halfedges: []
  14416. };
  14417. }
  14418. function cellHalfedgeAngle(cell, edge) {
  14419. var site = cell.site,
  14420. va = edge.left,
  14421. vb = edge.right;
  14422. if (site === vb) vb = va, va = site;
  14423. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  14424. if (site === va) va = edge[1], vb = edge[0];
  14425. else va = edge[0], vb = edge[1];
  14426. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  14427. }
  14428. function cellHalfedgeStart(cell, edge) {
  14429. return edge[+(edge.left !== cell.site)];
  14430. }
  14431. function cellHalfedgeEnd(cell, edge) {
  14432. return edge[+(edge.left === cell.site)];
  14433. }
  14434. function sortCellHalfedges() {
  14435. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  14436. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  14437. var index = new Array(m),
  14438. array = new Array(m);
  14439. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  14440. index.sort(function(i, j) { return array[j] - array[i]; });
  14441. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  14442. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  14443. }
  14444. }
  14445. }
  14446. function clipCells(x0, y0, x1, y1) {
  14447. var nCells = cells.length,
  14448. iCell,
  14449. cell,
  14450. site,
  14451. iHalfedge,
  14452. halfedges,
  14453. nHalfedges,
  14454. start,
  14455. startX,
  14456. startY,
  14457. end,
  14458. endX,
  14459. endY,
  14460. cover = true;
  14461. for (iCell = 0; iCell < nCells; ++iCell) {
  14462. if (cell = cells[iCell]) {
  14463. site = cell.site;
  14464. halfedges = cell.halfedges;
  14465. iHalfedge = halfedges.length;
  14466. // Remove any dangling clipped edges.
  14467. while (iHalfedge--) {
  14468. if (!edges[halfedges[iHalfedge]]) {
  14469. halfedges.splice(iHalfedge, 1);
  14470. }
  14471. }
  14472. // Insert any border edges as necessary.
  14473. iHalfedge = 0, nHalfedges = halfedges.length;
  14474. while (iHalfedge < nHalfedges) {
  14475. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  14476. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  14477. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  14478. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  14479. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  14480. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  14481. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  14482. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  14483. : null)) - 1);
  14484. ++nHalfedges;
  14485. }
  14486. }
  14487. if (nHalfedges) cover = false;
  14488. }
  14489. }
  14490. // If there weren’t any edges, have the closest site cover the extent.
  14491. // It doesn’t matter which corner of the extent we measure!
  14492. if (cover) {
  14493. var dx, dy, d2, dc = Infinity;
  14494. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  14495. if (cell = cells[iCell]) {
  14496. site = cell.site;
  14497. dx = site[0] - x0;
  14498. dy = site[1] - y0;
  14499. d2 = dx * dx + dy * dy;
  14500. if (d2 < dc) dc = d2, cover = cell;
  14501. }
  14502. }
  14503. if (cover) {
  14504. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  14505. cover.halfedges.push(
  14506. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  14507. edges.push(createBorderEdge(site, v01, v11)) - 1,
  14508. edges.push(createBorderEdge(site, v11, v10)) - 1,
  14509. edges.push(createBorderEdge(site, v10, v00)) - 1
  14510. );
  14511. }
  14512. }
  14513. // Lastly delete any cells with no edges; these were entirely clipped.
  14514. for (iCell = 0; iCell < nCells; ++iCell) {
  14515. if (cell = cells[iCell]) {
  14516. if (!cell.halfedges.length) {
  14517. delete cells[iCell];
  14518. }
  14519. }
  14520. }
  14521. }
  14522. var circlePool = [];
  14523. var firstCircle;
  14524. function Circle() {
  14525. RedBlackNode(this);
  14526. this.x =
  14527. this.y =
  14528. this.arc =
  14529. this.site =
  14530. this.cy = null;
  14531. }
  14532. function attachCircle(arc) {
  14533. var lArc = arc.P,
  14534. rArc = arc.N;
  14535. if (!lArc || !rArc) return;
  14536. var lSite = lArc.site,
  14537. cSite = arc.site,
  14538. rSite = rArc.site;
  14539. if (lSite === rSite) return;
  14540. var bx = cSite[0],
  14541. by = cSite[1],
  14542. ax = lSite[0] - bx,
  14543. ay = lSite[1] - by,
  14544. cx = rSite[0] - bx,
  14545. cy = rSite[1] - by;
  14546. var d = 2 * (ax * cy - ay * cx);
  14547. if (d >= -epsilon2$2) return;
  14548. var ha = ax * ax + ay * ay,
  14549. hc = cx * cx + cy * cy,
  14550. x = (cy * ha - ay * hc) / d,
  14551. y = (ax * hc - cx * ha) / d;
  14552. var circle = circlePool.pop() || new Circle;
  14553. circle.arc = arc;
  14554. circle.site = cSite;
  14555. circle.x = x + bx;
  14556. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  14557. arc.circle = circle;
  14558. var before = null,
  14559. node = circles._;
  14560. while (node) {
  14561. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  14562. if (node.L) node = node.L;
  14563. else { before = node.P; break; }
  14564. } else {
  14565. if (node.R) node = node.R;
  14566. else { before = node; break; }
  14567. }
  14568. }
  14569. circles.insert(before, circle);
  14570. if (!before) firstCircle = circle;
  14571. }
  14572. function detachCircle(arc) {
  14573. var circle = arc.circle;
  14574. if (circle) {
  14575. if (!circle.P) firstCircle = circle.N;
  14576. circles.remove(circle);
  14577. circlePool.push(circle);
  14578. RedBlackNode(circle);
  14579. arc.circle = null;
  14580. }
  14581. }
  14582. var beachPool = [];
  14583. function Beach() {
  14584. RedBlackNode(this);
  14585. this.edge =
  14586. this.site =
  14587. this.circle = null;
  14588. }
  14589. function createBeach(site) {
  14590. var beach = beachPool.pop() || new Beach;
  14591. beach.site = site;
  14592. return beach;
  14593. }
  14594. function detachBeach(beach) {
  14595. detachCircle(beach);
  14596. beaches.remove(beach);
  14597. beachPool.push(beach);
  14598. RedBlackNode(beach);
  14599. }
  14600. function removeBeach(beach) {
  14601. var circle = beach.circle,
  14602. x = circle.x,
  14603. y = circle.cy,
  14604. vertex = [x, y],
  14605. previous = beach.P,
  14606. next = beach.N,
  14607. disappearing = [beach];
  14608. detachBeach(beach);
  14609. var lArc = previous;
  14610. while (lArc.circle
  14611. && Math.abs(x - lArc.circle.x) < epsilon$4
  14612. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  14613. previous = lArc.P;
  14614. disappearing.unshift(lArc);
  14615. detachBeach(lArc);
  14616. lArc = previous;
  14617. }
  14618. disappearing.unshift(lArc);
  14619. detachCircle(lArc);
  14620. var rArc = next;
  14621. while (rArc.circle
  14622. && Math.abs(x - rArc.circle.x) < epsilon$4
  14623. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  14624. next = rArc.N;
  14625. disappearing.push(rArc);
  14626. detachBeach(rArc);
  14627. rArc = next;
  14628. }
  14629. disappearing.push(rArc);
  14630. detachCircle(rArc);
  14631. var nArcs = disappearing.length,
  14632. iArc;
  14633. for (iArc = 1; iArc < nArcs; ++iArc) {
  14634. rArc = disappearing[iArc];
  14635. lArc = disappearing[iArc - 1];
  14636. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  14637. }
  14638. lArc = disappearing[0];
  14639. rArc = disappearing[nArcs - 1];
  14640. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  14641. attachCircle(lArc);
  14642. attachCircle(rArc);
  14643. }
  14644. function addBeach(site) {
  14645. var x = site[0],
  14646. directrix = site[1],
  14647. lArc,
  14648. rArc,
  14649. dxl,
  14650. dxr,
  14651. node = beaches._;
  14652. while (node) {
  14653. dxl = leftBreakPoint(node, directrix) - x;
  14654. if (dxl > epsilon$4) node = node.L; else {
  14655. dxr = x - rightBreakPoint(node, directrix);
  14656. if (dxr > epsilon$4) {
  14657. if (!node.R) {
  14658. lArc = node;
  14659. break;
  14660. }
  14661. node = node.R;
  14662. } else {
  14663. if (dxl > -epsilon$4) {
  14664. lArc = node.P;
  14665. rArc = node;
  14666. } else if (dxr > -epsilon$4) {
  14667. lArc = node;
  14668. rArc = node.N;
  14669. } else {
  14670. lArc = rArc = node;
  14671. }
  14672. break;
  14673. }
  14674. }
  14675. }
  14676. createCell(site);
  14677. var newArc = createBeach(site);
  14678. beaches.insert(lArc, newArc);
  14679. if (!lArc && !rArc) return;
  14680. if (lArc === rArc) {
  14681. detachCircle(lArc);
  14682. rArc = createBeach(lArc.site);
  14683. beaches.insert(newArc, rArc);
  14684. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  14685. attachCircle(lArc);
  14686. attachCircle(rArc);
  14687. return;
  14688. }
  14689. if (!rArc) { // && lArc
  14690. newArc.edge = createEdge(lArc.site, newArc.site);
  14691. return;
  14692. }
  14693. // else lArc !== rArc
  14694. detachCircle(lArc);
  14695. detachCircle(rArc);
  14696. var lSite = lArc.site,
  14697. ax = lSite[0],
  14698. ay = lSite[1],
  14699. bx = site[0] - ax,
  14700. by = site[1] - ay,
  14701. rSite = rArc.site,
  14702. cx = rSite[0] - ax,
  14703. cy = rSite[1] - ay,
  14704. d = 2 * (bx * cy - by * cx),
  14705. hb = bx * bx + by * by,
  14706. hc = cx * cx + cy * cy,
  14707. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  14708. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  14709. newArc.edge = createEdge(lSite, site, null, vertex);
  14710. rArc.edge = createEdge(site, rSite, null, vertex);
  14711. attachCircle(lArc);
  14712. attachCircle(rArc);
  14713. }
  14714. function leftBreakPoint(arc, directrix) {
  14715. var site = arc.site,
  14716. rfocx = site[0],
  14717. rfocy = site[1],
  14718. pby2 = rfocy - directrix;
  14719. if (!pby2) return rfocx;
  14720. var lArc = arc.P;
  14721. if (!lArc) return -Infinity;
  14722. site = lArc.site;
  14723. var lfocx = site[0],
  14724. lfocy = site[1],
  14725. plby2 = lfocy - directrix;
  14726. if (!plby2) return lfocx;
  14727. var hl = lfocx - rfocx,
  14728. aby2 = 1 / pby2 - 1 / plby2,
  14729. b = hl / plby2;
  14730. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  14731. return (rfocx + lfocx) / 2;
  14732. }
  14733. function rightBreakPoint(arc, directrix) {
  14734. var rArc = arc.N;
  14735. if (rArc) return leftBreakPoint(rArc, directrix);
  14736. var site = arc.site;
  14737. return site[1] === directrix ? site[0] : Infinity;
  14738. }
  14739. var epsilon$4 = 1e-6;
  14740. var epsilon2$2 = 1e-12;
  14741. var beaches;
  14742. var cells;
  14743. var circles;
  14744. var edges;
  14745. function triangleArea(a, b, c) {
  14746. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  14747. }
  14748. function lexicographic(a, b) {
  14749. return b[1] - a[1]
  14750. || b[0] - a[0];
  14751. }
  14752. function Diagram(sites, extent) {
  14753. var site = sites.sort(lexicographic).pop(),
  14754. x,
  14755. y,
  14756. circle;
  14757. edges = [];
  14758. cells = new Array(sites.length);
  14759. beaches = new RedBlackTree;
  14760. circles = new RedBlackTree;
  14761. while (true) {
  14762. circle = firstCircle;
  14763. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  14764. if (site[0] !== x || site[1] !== y) {
  14765. addBeach(site);
  14766. x = site[0], y = site[1];
  14767. }
  14768. site = sites.pop();
  14769. } else if (circle) {
  14770. removeBeach(circle.arc);
  14771. } else {
  14772. break;
  14773. }
  14774. }
  14775. sortCellHalfedges();
  14776. if (extent) {
  14777. var x0 = +extent[0][0],
  14778. y0 = +extent[0][1],
  14779. x1 = +extent[1][0],
  14780. y1 = +extent[1][1];
  14781. clipEdges(x0, y0, x1, y1);
  14782. clipCells(x0, y0, x1, y1);
  14783. }
  14784. this.edges = edges;
  14785. this.cells = cells;
  14786. beaches =
  14787. circles =
  14788. edges =
  14789. cells = null;
  14790. }
  14791. Diagram.prototype = {
  14792. constructor: Diagram,
  14793. polygons: function() {
  14794. var edges = this.edges;
  14795. return this.cells.map(function(cell) {
  14796. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  14797. polygon.data = cell.site.data;
  14798. return polygon;
  14799. });
  14800. },
  14801. triangles: function() {
  14802. var triangles = [],
  14803. edges = this.edges;
  14804. this.cells.forEach(function(cell, i) {
  14805. if (!(m = (halfedges = cell.halfedges).length)) return;
  14806. var site = cell.site,
  14807. halfedges,
  14808. j = -1,
  14809. m,
  14810. s0,
  14811. e1 = edges[halfedges[m - 1]],
  14812. s1 = e1.left === site ? e1.right : e1.left;
  14813. while (++j < m) {
  14814. s0 = s1;
  14815. e1 = edges[halfedges[j]];
  14816. s1 = e1.left === site ? e1.right : e1.left;
  14817. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  14818. triangles.push([site.data, s0.data, s1.data]);
  14819. }
  14820. }
  14821. });
  14822. return triangles;
  14823. },
  14824. links: function() {
  14825. return this.edges.filter(function(edge) {
  14826. return edge.right;
  14827. }).map(function(edge) {
  14828. return {
  14829. source: edge.left.data,
  14830. target: edge.right.data
  14831. };
  14832. });
  14833. },
  14834. find: function(x, y, radius) {
  14835. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  14836. // Use the previously-found cell, or start with an arbitrary one.
  14837. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  14838. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  14839. // Traverse the half-edges to find a closer cell, if any.
  14840. do {
  14841. cell = that.cells[i0 = i1], i1 = null;
  14842. cell.halfedges.forEach(function(e) {
  14843. var edge = that.edges[e], v = edge.left;
  14844. if ((v === cell.site || !v) && !(v = edge.right)) return;
  14845. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  14846. if (v2 < d2) d2 = v2, i1 = v.index;
  14847. });
  14848. } while (i1 !== null);
  14849. that._found = i0;
  14850. return radius == null || d2 <= radius * radius ? cell.site : null;
  14851. }
  14852. };
  14853. function voronoi() {
  14854. var x = x$4,
  14855. y = y$4,
  14856. extent = null;
  14857. function voronoi(data) {
  14858. return new Diagram(data.map(function(d, i) {
  14859. var s = [Math.round(x(d, i, data) / epsilon$4) * epsilon$4, Math.round(y(d, i, data) / epsilon$4) * epsilon$4];
  14860. s.index = i;
  14861. s.data = d;
  14862. return s;
  14863. }), extent);
  14864. }
  14865. voronoi.polygons = function(data) {
  14866. return voronoi(data).polygons();
  14867. };
  14868. voronoi.links = function(data) {
  14869. return voronoi(data).links();
  14870. };
  14871. voronoi.triangles = function(data) {
  14872. return voronoi(data).triangles();
  14873. };
  14874. voronoi.x = function(_) {
  14875. return arguments.length ? (x = typeof _ === "function" ? _ : constant$c(+_), voronoi) : x;
  14876. };
  14877. voronoi.y = function(_) {
  14878. return arguments.length ? (y = typeof _ === "function" ? _ : constant$c(+_), voronoi) : y;
  14879. };
  14880. voronoi.extent = function(_) {
  14881. 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]]];
  14882. };
  14883. voronoi.size = function(_) {
  14884. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  14885. };
  14886. return voronoi;
  14887. }
  14888. function constant$d(x) {
  14889. return function() {
  14890. return x;
  14891. };
  14892. }
  14893. function ZoomEvent(target, type, transform) {
  14894. this.target = target;
  14895. this.type = type;
  14896. this.transform = transform;
  14897. }
  14898. function Transform(k, x, y) {
  14899. this.k = k;
  14900. this.x = x;
  14901. this.y = y;
  14902. }
  14903. Transform.prototype = {
  14904. constructor: Transform,
  14905. scale: function(k) {
  14906. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  14907. },
  14908. translate: function(x, y) {
  14909. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  14910. },
  14911. apply: function(point) {
  14912. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  14913. },
  14914. applyX: function(x) {
  14915. return x * this.k + this.x;
  14916. },
  14917. applyY: function(y) {
  14918. return y * this.k + this.y;
  14919. },
  14920. invert: function(location) {
  14921. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  14922. },
  14923. invertX: function(x) {
  14924. return (x - this.x) / this.k;
  14925. },
  14926. invertY: function(y) {
  14927. return (y - this.y) / this.k;
  14928. },
  14929. rescaleX: function(x) {
  14930. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  14931. },
  14932. rescaleY: function(y) {
  14933. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  14934. },
  14935. toString: function() {
  14936. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  14937. }
  14938. };
  14939. var identity$9 = new Transform(1, 0, 0);
  14940. transform$1.prototype = Transform.prototype;
  14941. function transform$1(node) {
  14942. while (!node.__zoom) if (!(node = node.parentNode)) return identity$9;
  14943. return node.__zoom;
  14944. }
  14945. function nopropagation$2() {
  14946. exports.event.stopImmediatePropagation();
  14947. }
  14948. function noevent$2() {
  14949. exports.event.preventDefault();
  14950. exports.event.stopImmediatePropagation();
  14951. }
  14952. // Ignore right-click, since that should open the context menu.
  14953. function defaultFilter$2() {
  14954. return !exports.event.ctrlKey && !exports.event.button;
  14955. }
  14956. function defaultExtent$1() {
  14957. var e = this;
  14958. if (e instanceof SVGElement) {
  14959. e = e.ownerSVGElement || e;
  14960. if (e.hasAttribute("viewBox")) {
  14961. e = e.viewBox.baseVal;
  14962. return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
  14963. }
  14964. return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
  14965. }
  14966. return [[0, 0], [e.clientWidth, e.clientHeight]];
  14967. }
  14968. function defaultTransform() {
  14969. return this.__zoom || identity$9;
  14970. }
  14971. function defaultWheelDelta() {
  14972. return -exports.event.deltaY * (exports.event.deltaMode === 1 ? 0.05 : exports.event.deltaMode ? 1 : 0.002);
  14973. }
  14974. function defaultTouchable$2() {
  14975. return navigator.maxTouchPoints || ("ontouchstart" in this);
  14976. }
  14977. function defaultConstrain(transform, extent, translateExtent) {
  14978. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  14979. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  14980. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  14981. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  14982. return transform.translate(
  14983. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  14984. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  14985. );
  14986. }
  14987. function zoom() {
  14988. var filter = defaultFilter$2,
  14989. extent = defaultExtent$1,
  14990. constrain = defaultConstrain,
  14991. wheelDelta = defaultWheelDelta,
  14992. touchable = defaultTouchable$2,
  14993. scaleExtent = [0, Infinity],
  14994. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  14995. duration = 250,
  14996. interpolate = interpolateZoom,
  14997. listeners = dispatch("start", "zoom", "end"),
  14998. touchstarting,
  14999. touchending,
  15000. touchDelay = 500,
  15001. wheelDelay = 150,
  15002. clickDistance2 = 0;
  15003. function zoom(selection) {
  15004. selection
  15005. .property("__zoom", defaultTransform)
  15006. .on("wheel.zoom", wheeled)
  15007. .on("mousedown.zoom", mousedowned)
  15008. .on("dblclick.zoom", dblclicked)
  15009. .filter(touchable)
  15010. .on("touchstart.zoom", touchstarted)
  15011. .on("touchmove.zoom", touchmoved)
  15012. .on("touchend.zoom touchcancel.zoom", touchended)
  15013. .style("touch-action", "none")
  15014. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  15015. }
  15016. zoom.transform = function(collection, transform, point) {
  15017. var selection = collection.selection ? collection.selection() : collection;
  15018. selection.property("__zoom", defaultTransform);
  15019. if (collection !== selection) {
  15020. schedule(collection, transform, point);
  15021. } else {
  15022. selection.interrupt().each(function() {
  15023. gesture(this, arguments)
  15024. .start()
  15025. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  15026. .end();
  15027. });
  15028. }
  15029. };
  15030. zoom.scaleBy = function(selection, k, p) {
  15031. zoom.scaleTo(selection, function() {
  15032. var k0 = this.__zoom.k,
  15033. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  15034. return k0 * k1;
  15035. }, p);
  15036. };
  15037. zoom.scaleTo = function(selection, k, p) {
  15038. zoom.transform(selection, function() {
  15039. var e = extent.apply(this, arguments),
  15040. t0 = this.__zoom,
  15041. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
  15042. p1 = t0.invert(p0),
  15043. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  15044. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  15045. }, p);
  15046. };
  15047. zoom.translateBy = function(selection, x, y) {
  15048. zoom.transform(selection, function() {
  15049. return constrain(this.__zoom.translate(
  15050. typeof x === "function" ? x.apply(this, arguments) : x,
  15051. typeof y === "function" ? y.apply(this, arguments) : y
  15052. ), extent.apply(this, arguments), translateExtent);
  15053. });
  15054. };
  15055. zoom.translateTo = function(selection, x, y, p) {
  15056. zoom.transform(selection, function() {
  15057. var e = extent.apply(this, arguments),
  15058. t = this.__zoom,
  15059. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
  15060. return constrain(identity$9.translate(p0[0], p0[1]).scale(t.k).translate(
  15061. typeof x === "function" ? -x.apply(this, arguments) : -x,
  15062. typeof y === "function" ? -y.apply(this, arguments) : -y
  15063. ), e, translateExtent);
  15064. }, p);
  15065. };
  15066. function scale(transform, k) {
  15067. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  15068. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  15069. }
  15070. function translate(transform, p0, p1) {
  15071. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  15072. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  15073. }
  15074. function centroid(extent) {
  15075. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  15076. }
  15077. function schedule(transition, transform, point) {
  15078. transition
  15079. .on("start.zoom", function() { gesture(this, arguments).start(); })
  15080. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  15081. .tween("zoom", function() {
  15082. var that = this,
  15083. args = arguments,
  15084. g = gesture(that, args),
  15085. e = extent.apply(that, args),
  15086. p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
  15087. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  15088. a = that.__zoom,
  15089. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  15090. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  15091. return function(t) {
  15092. if (t === 1) t = b; // Avoid rounding error on end.
  15093. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  15094. g.zoom(null, t);
  15095. };
  15096. });
  15097. }
  15098. function gesture(that, args, clean) {
  15099. return (!clean && that.__zooming) || new Gesture(that, args);
  15100. }
  15101. function Gesture(that, args) {
  15102. this.that = that;
  15103. this.args = args;
  15104. this.active = 0;
  15105. this.extent = extent.apply(that, args);
  15106. this.taps = 0;
  15107. }
  15108. Gesture.prototype = {
  15109. start: function() {
  15110. if (++this.active === 1) {
  15111. this.that.__zooming = this;
  15112. this.emit("start");
  15113. }
  15114. return this;
  15115. },
  15116. zoom: function(key, transform) {
  15117. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  15118. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  15119. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  15120. this.that.__zoom = transform;
  15121. this.emit("zoom");
  15122. return this;
  15123. },
  15124. end: function() {
  15125. if (--this.active === 0) {
  15126. delete this.that.__zooming;
  15127. this.emit("end");
  15128. }
  15129. return this;
  15130. },
  15131. emit: function(type) {
  15132. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  15133. }
  15134. };
  15135. function wheeled() {
  15136. if (!filter.apply(this, arguments)) return;
  15137. var g = gesture(this, arguments),
  15138. t = this.__zoom,
  15139. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  15140. p = mouse(this);
  15141. // If the mouse is in the same location as before, reuse it.
  15142. // If there were recent wheel events, reset the wheel idle timeout.
  15143. if (g.wheel) {
  15144. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  15145. g.mouse[1] = t.invert(g.mouse[0] = p);
  15146. }
  15147. clearTimeout(g.wheel);
  15148. }
  15149. // If this wheel event won’t trigger a transform change, ignore it.
  15150. else if (t.k === k) return;
  15151. // Otherwise, capture the mouse point and location at the start.
  15152. else {
  15153. g.mouse = [p, t.invert(p)];
  15154. interrupt(this);
  15155. g.start();
  15156. }
  15157. noevent$2();
  15158. g.wheel = setTimeout(wheelidled, wheelDelay);
  15159. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  15160. function wheelidled() {
  15161. g.wheel = null;
  15162. g.end();
  15163. }
  15164. }
  15165. function mousedowned() {
  15166. if (touchending || !filter.apply(this, arguments)) return;
  15167. var g = gesture(this, arguments, true),
  15168. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  15169. p = mouse(this),
  15170. x0 = exports.event.clientX,
  15171. y0 = exports.event.clientY;
  15172. dragDisable(exports.event.view);
  15173. nopropagation$2();
  15174. g.mouse = [p, this.__zoom.invert(p)];
  15175. interrupt(this);
  15176. g.start();
  15177. function mousemoved() {
  15178. noevent$2();
  15179. if (!g.moved) {
  15180. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  15181. g.moved = dx * dx + dy * dy > clickDistance2;
  15182. }
  15183. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  15184. }
  15185. function mouseupped() {
  15186. v.on("mousemove.zoom mouseup.zoom", null);
  15187. yesdrag(exports.event.view, g.moved);
  15188. noevent$2();
  15189. g.end();
  15190. }
  15191. }
  15192. function dblclicked() {
  15193. if (!filter.apply(this, arguments)) return;
  15194. var t0 = this.__zoom,
  15195. p0 = mouse(this),
  15196. p1 = t0.invert(p0),
  15197. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  15198. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  15199. noevent$2();
  15200. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  15201. else select(this).call(zoom.transform, t1);
  15202. }
  15203. function touchstarted() {
  15204. if (!filter.apply(this, arguments)) return;
  15205. var touches = exports.event.touches,
  15206. n = touches.length,
  15207. g = gesture(this, arguments, exports.event.changedTouches.length === n),
  15208. started, i, t, p;
  15209. nopropagation$2();
  15210. for (i = 0; i < n; ++i) {
  15211. t = touches[i], p = touch(this, touches, t.identifier);
  15212. p = [p, this.__zoom.invert(p), t.identifier];
  15213. if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
  15214. else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
  15215. }
  15216. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  15217. if (started) {
  15218. if (g.taps < 2) touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  15219. interrupt(this);
  15220. g.start();
  15221. }
  15222. }
  15223. function touchmoved() {
  15224. if (!this.__zooming) return;
  15225. var g = gesture(this, arguments),
  15226. touches = exports.event.changedTouches,
  15227. n = touches.length, i, t, p, l;
  15228. noevent$2();
  15229. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  15230. g.taps = 0;
  15231. for (i = 0; i < n; ++i) {
  15232. t = touches[i], p = touch(this, touches, t.identifier);
  15233. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  15234. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  15235. }
  15236. t = g.that.__zoom;
  15237. if (g.touch1) {
  15238. var p0 = g.touch0[0], l0 = g.touch0[1],
  15239. p1 = g.touch1[0], l1 = g.touch1[1],
  15240. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  15241. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  15242. t = scale(t, Math.sqrt(dp / dl));
  15243. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  15244. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  15245. }
  15246. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  15247. else return;
  15248. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  15249. }
  15250. function touchended() {
  15251. if (!this.__zooming) return;
  15252. var g = gesture(this, arguments),
  15253. touches = exports.event.changedTouches,
  15254. n = touches.length, i, t;
  15255. nopropagation$2();
  15256. if (touchending) clearTimeout(touchending);
  15257. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  15258. for (i = 0; i < n; ++i) {
  15259. t = touches[i];
  15260. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  15261. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  15262. }
  15263. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  15264. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  15265. else {
  15266. g.end();
  15267. // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
  15268. if (g.taps === 2) {
  15269. var p = select(this).on("dblclick.zoom");
  15270. if (p) p.apply(this, arguments);
  15271. }
  15272. }
  15273. }
  15274. zoom.wheelDelta = function(_) {
  15275. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$d(+_), zoom) : wheelDelta;
  15276. };
  15277. zoom.filter = function(_) {
  15278. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$d(!!_), zoom) : filter;
  15279. };
  15280. zoom.touchable = function(_) {
  15281. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$d(!!_), zoom) : touchable;
  15282. };
  15283. zoom.extent = function(_) {
  15284. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$d([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  15285. };
  15286. zoom.scaleExtent = function(_) {
  15287. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  15288. };
  15289. zoom.translateExtent = function(_) {
  15290. 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]]];
  15291. };
  15292. zoom.constrain = function(_) {
  15293. return arguments.length ? (constrain = _, zoom) : constrain;
  15294. };
  15295. zoom.duration = function(_) {
  15296. return arguments.length ? (duration = +_, zoom) : duration;
  15297. };
  15298. zoom.interpolate = function(_) {
  15299. return arguments.length ? (interpolate = _, zoom) : interpolate;
  15300. };
  15301. zoom.on = function() {
  15302. var value = listeners.on.apply(listeners, arguments);
  15303. return value === listeners ? zoom : value;
  15304. };
  15305. zoom.clickDistance = function(_) {
  15306. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  15307. };
  15308. return zoom;
  15309. }
  15310. exports.FormatSpecifier = FormatSpecifier;
  15311. exports.active = active;
  15312. exports.arc = arc;
  15313. exports.area = area$3;
  15314. exports.areaRadial = areaRadial;
  15315. exports.ascending = ascending;
  15316. exports.autoType = autoType;
  15317. exports.axisBottom = axisBottom;
  15318. exports.axisLeft = axisLeft;
  15319. exports.axisRight = axisRight;
  15320. exports.axisTop = axisTop;
  15321. exports.bisect = bisectRight;
  15322. exports.bisectLeft = bisectLeft;
  15323. exports.bisectRight = bisectRight;
  15324. exports.bisector = bisector;
  15325. exports.blob = blob;
  15326. exports.brush = brush;
  15327. exports.brushSelection = brushSelection;
  15328. exports.brushX = brushX;
  15329. exports.brushY = brushY;
  15330. exports.buffer = buffer;
  15331. exports.chord = chord;
  15332. exports.clientPoint = point;
  15333. exports.cluster = cluster;
  15334. exports.color = color;
  15335. exports.contourDensity = density;
  15336. exports.contours = contours;
  15337. exports.create = create;
  15338. exports.creator = creator;
  15339. exports.cross = cross;
  15340. exports.csv = csv$1;
  15341. exports.csvFormat = csvFormat;
  15342. exports.csvFormatBody = csvFormatBody;
  15343. exports.csvFormatRow = csvFormatRow;
  15344. exports.csvFormatRows = csvFormatRows;
  15345. exports.csvFormatValue = csvFormatValue;
  15346. exports.csvParse = csvParse;
  15347. exports.csvParseRows = csvParseRows;
  15348. exports.cubehelix = cubehelix;
  15349. exports.curveBasis = basis$2;
  15350. exports.curveBasisClosed = basisClosed$1;
  15351. exports.curveBasisOpen = basisOpen;
  15352. exports.curveBundle = bundle;
  15353. exports.curveCardinal = cardinal;
  15354. exports.curveCardinalClosed = cardinalClosed;
  15355. exports.curveCardinalOpen = cardinalOpen;
  15356. exports.curveCatmullRom = catmullRom;
  15357. exports.curveCatmullRomClosed = catmullRomClosed;
  15358. exports.curveCatmullRomOpen = catmullRomOpen;
  15359. exports.curveLinear = curveLinear;
  15360. exports.curveLinearClosed = linearClosed;
  15361. exports.curveMonotoneX = monotoneX;
  15362. exports.curveMonotoneY = monotoneY;
  15363. exports.curveNatural = natural;
  15364. exports.curveStep = step;
  15365. exports.curveStepAfter = stepAfter;
  15366. exports.curveStepBefore = stepBefore;
  15367. exports.customEvent = customEvent;
  15368. exports.descending = descending;
  15369. exports.deviation = deviation;
  15370. exports.dispatch = dispatch;
  15371. exports.drag = drag;
  15372. exports.dragDisable = dragDisable;
  15373. exports.dragEnable = yesdrag;
  15374. exports.dsv = dsv;
  15375. exports.dsvFormat = dsvFormat;
  15376. exports.easeBack = backInOut;
  15377. exports.easeBackIn = backIn;
  15378. exports.easeBackInOut = backInOut;
  15379. exports.easeBackOut = backOut;
  15380. exports.easeBounce = bounceOut;
  15381. exports.easeBounceIn = bounceIn;
  15382. exports.easeBounceInOut = bounceInOut;
  15383. exports.easeBounceOut = bounceOut;
  15384. exports.easeCircle = circleInOut;
  15385. exports.easeCircleIn = circleIn;
  15386. exports.easeCircleInOut = circleInOut;
  15387. exports.easeCircleOut = circleOut;
  15388. exports.easeCubic = cubicInOut;
  15389. exports.easeCubicIn = cubicIn;
  15390. exports.easeCubicInOut = cubicInOut;
  15391. exports.easeCubicOut = cubicOut;
  15392. exports.easeElastic = elasticOut;
  15393. exports.easeElasticIn = elasticIn;
  15394. exports.easeElasticInOut = elasticInOut;
  15395. exports.easeElasticOut = elasticOut;
  15396. exports.easeExp = expInOut;
  15397. exports.easeExpIn = expIn;
  15398. exports.easeExpInOut = expInOut;
  15399. exports.easeExpOut = expOut;
  15400. exports.easeLinear = linear$1;
  15401. exports.easePoly = polyInOut;
  15402. exports.easePolyIn = polyIn;
  15403. exports.easePolyInOut = polyInOut;
  15404. exports.easePolyOut = polyOut;
  15405. exports.easeQuad = quadInOut;
  15406. exports.easeQuadIn = quadIn;
  15407. exports.easeQuadInOut = quadInOut;
  15408. exports.easeQuadOut = quadOut;
  15409. exports.easeSin = sinInOut;
  15410. exports.easeSinIn = sinIn;
  15411. exports.easeSinInOut = sinInOut;
  15412. exports.easeSinOut = sinOut;
  15413. exports.entries = entries;
  15414. exports.extent = extent;
  15415. exports.forceCenter = center$1;
  15416. exports.forceCollide = collide;
  15417. exports.forceLink = link;
  15418. exports.forceManyBody = manyBody;
  15419. exports.forceRadial = radial;
  15420. exports.forceSimulation = simulation;
  15421. exports.forceX = x$2;
  15422. exports.forceY = y$2;
  15423. exports.formatDefaultLocale = defaultLocale;
  15424. exports.formatLocale = formatLocale;
  15425. exports.formatSpecifier = formatSpecifier;
  15426. exports.geoAlbers = albers;
  15427. exports.geoAlbersUsa = albersUsa;
  15428. exports.geoArea = area$1;
  15429. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  15430. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  15431. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  15432. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  15433. exports.geoBounds = bounds;
  15434. exports.geoCentroid = centroid;
  15435. exports.geoCircle = circle;
  15436. exports.geoClipAntimeridian = clipAntimeridian;
  15437. exports.geoClipCircle = clipCircle;
  15438. exports.geoClipExtent = extent$1;
  15439. exports.geoClipRectangle = clipRectangle;
  15440. exports.geoConicConformal = conicConformal;
  15441. exports.geoConicConformalRaw = conicConformalRaw;
  15442. exports.geoConicEqualArea = conicEqualArea;
  15443. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  15444. exports.geoConicEquidistant = conicEquidistant;
  15445. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  15446. exports.geoContains = contains$1;
  15447. exports.geoDistance = distance;
  15448. exports.geoEqualEarth = equalEarth;
  15449. exports.geoEqualEarthRaw = equalEarthRaw;
  15450. exports.geoEquirectangular = equirectangular;
  15451. exports.geoEquirectangularRaw = equirectangularRaw;
  15452. exports.geoGnomonic = gnomonic;
  15453. exports.geoGnomonicRaw = gnomonicRaw;
  15454. exports.geoGraticule = graticule;
  15455. exports.geoGraticule10 = graticule10;
  15456. exports.geoIdentity = identity$5;
  15457. exports.geoInterpolate = interpolate$1;
  15458. exports.geoLength = length$1;
  15459. exports.geoMercator = mercator;
  15460. exports.geoMercatorRaw = mercatorRaw;
  15461. exports.geoNaturalEarth1 = naturalEarth1;
  15462. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  15463. exports.geoOrthographic = orthographic;
  15464. exports.geoOrthographicRaw = orthographicRaw;
  15465. exports.geoPath = index$1;
  15466. exports.geoProjection = projection;
  15467. exports.geoProjectionMutator = projectionMutator;
  15468. exports.geoRotation = rotation;
  15469. exports.geoStereographic = stereographic;
  15470. exports.geoStereographicRaw = stereographicRaw;
  15471. exports.geoStream = geoStream;
  15472. exports.geoTransform = transform;
  15473. exports.geoTransverseMercator = transverseMercator;
  15474. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  15475. exports.gray = gray;
  15476. exports.hcl = hcl;
  15477. exports.hierarchy = hierarchy;
  15478. exports.histogram = histogram;
  15479. exports.hsl = hsl;
  15480. exports.html = html;
  15481. exports.image = image;
  15482. exports.interpolate = interpolateValue;
  15483. exports.interpolateArray = array$1;
  15484. exports.interpolateBasis = basis$1;
  15485. exports.interpolateBasisClosed = basisClosed;
  15486. exports.interpolateBlues = Blues;
  15487. exports.interpolateBrBG = BrBG;
  15488. exports.interpolateBuGn = BuGn;
  15489. exports.interpolateBuPu = BuPu;
  15490. exports.interpolateCividis = cividis;
  15491. exports.interpolateCool = cool;
  15492. exports.interpolateCubehelix = cubehelix$2;
  15493. exports.interpolateCubehelixDefault = cubehelix$3;
  15494. exports.interpolateCubehelixLong = cubehelixLong;
  15495. exports.interpolateDate = date;
  15496. exports.interpolateDiscrete = discrete;
  15497. exports.interpolateGnBu = GnBu;
  15498. exports.interpolateGreens = Greens;
  15499. exports.interpolateGreys = Greys;
  15500. exports.interpolateHcl = hcl$2;
  15501. exports.interpolateHclLong = hclLong;
  15502. exports.interpolateHsl = hsl$2;
  15503. exports.interpolateHslLong = hslLong;
  15504. exports.interpolateHue = hue$1;
  15505. exports.interpolateInferno = inferno;
  15506. exports.interpolateLab = lab$1;
  15507. exports.interpolateMagma = magma;
  15508. exports.interpolateNumber = interpolateNumber;
  15509. exports.interpolateNumberArray = numberArray;
  15510. exports.interpolateObject = object;
  15511. exports.interpolateOrRd = OrRd;
  15512. exports.interpolateOranges = Oranges;
  15513. exports.interpolatePRGn = PRGn;
  15514. exports.interpolatePiYG = PiYG;
  15515. exports.interpolatePlasma = plasma;
  15516. exports.interpolatePuBu = PuBu;
  15517. exports.interpolatePuBuGn = PuBuGn;
  15518. exports.interpolatePuOr = PuOr;
  15519. exports.interpolatePuRd = PuRd;
  15520. exports.interpolatePurples = Purples;
  15521. exports.interpolateRainbow = rainbow;
  15522. exports.interpolateRdBu = RdBu;
  15523. exports.interpolateRdGy = RdGy;
  15524. exports.interpolateRdPu = RdPu;
  15525. exports.interpolateRdYlBu = RdYlBu;
  15526. exports.interpolateRdYlGn = RdYlGn;
  15527. exports.interpolateReds = Reds;
  15528. exports.interpolateRgb = interpolateRgb;
  15529. exports.interpolateRgbBasis = rgbBasis;
  15530. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  15531. exports.interpolateRound = interpolateRound;
  15532. exports.interpolateSinebow = sinebow;
  15533. exports.interpolateSpectral = Spectral;
  15534. exports.interpolateString = interpolateString;
  15535. exports.interpolateTransformCss = interpolateTransformCss;
  15536. exports.interpolateTransformSvg = interpolateTransformSvg;
  15537. exports.interpolateTurbo = turbo;
  15538. exports.interpolateViridis = viridis;
  15539. exports.interpolateWarm = warm;
  15540. exports.interpolateYlGn = YlGn;
  15541. exports.interpolateYlGnBu = YlGnBu;
  15542. exports.interpolateYlOrBr = YlOrBr;
  15543. exports.interpolateYlOrRd = YlOrRd;
  15544. exports.interpolateZoom = interpolateZoom;
  15545. exports.interrupt = interrupt;
  15546. exports.interval = interval$1;
  15547. exports.isoFormat = formatIso;
  15548. exports.isoParse = parseIso;
  15549. exports.json = json;
  15550. exports.keys = keys;
  15551. exports.lab = lab;
  15552. exports.lch = lch;
  15553. exports.line = line;
  15554. exports.lineRadial = lineRadial$1;
  15555. exports.linkHorizontal = linkHorizontal;
  15556. exports.linkRadial = linkRadial;
  15557. exports.linkVertical = linkVertical;
  15558. exports.local = local;
  15559. exports.map = map$1;
  15560. exports.matcher = matcher;
  15561. exports.max = max;
  15562. exports.mean = mean;
  15563. exports.median = median;
  15564. exports.merge = merge;
  15565. exports.min = min;
  15566. exports.mouse = mouse;
  15567. exports.namespace = namespace;
  15568. exports.namespaces = namespaces;
  15569. exports.nest = nest;
  15570. exports.now = now;
  15571. exports.pack = index$2;
  15572. exports.packEnclose = enclose;
  15573. exports.packSiblings = siblings;
  15574. exports.pairs = pairs;
  15575. exports.partition = partition;
  15576. exports.path = path;
  15577. exports.permute = permute;
  15578. exports.pie = pie;
  15579. exports.piecewise = piecewise;
  15580. exports.pointRadial = pointRadial;
  15581. exports.polygonArea = area$2;
  15582. exports.polygonCentroid = centroid$1;
  15583. exports.polygonContains = contains$2;
  15584. exports.polygonHull = hull;
  15585. exports.polygonLength = length$2;
  15586. exports.precisionFixed = precisionFixed;
  15587. exports.precisionPrefix = precisionPrefix;
  15588. exports.precisionRound = precisionRound;
  15589. exports.quadtree = quadtree;
  15590. exports.quantile = threshold;
  15591. exports.quantize = quantize;
  15592. exports.radialArea = areaRadial;
  15593. exports.radialLine = lineRadial$1;
  15594. exports.randomBates = bates;
  15595. exports.randomExponential = exponential$1;
  15596. exports.randomIrwinHall = irwinHall;
  15597. exports.randomLogNormal = logNormal;
  15598. exports.randomNormal = normal;
  15599. exports.randomUniform = uniform;
  15600. exports.range = sequence;
  15601. exports.rgb = rgb;
  15602. exports.ribbon = ribbon;
  15603. exports.scaleBand = band;
  15604. exports.scaleDiverging = diverging;
  15605. exports.scaleDivergingLog = divergingLog;
  15606. exports.scaleDivergingPow = divergingPow;
  15607. exports.scaleDivergingSqrt = divergingSqrt;
  15608. exports.scaleDivergingSymlog = divergingSymlog;
  15609. exports.scaleIdentity = identity$7;
  15610. exports.scaleImplicit = implicit;
  15611. exports.scaleLinear = linear$2;
  15612. exports.scaleLog = log$1;
  15613. exports.scaleOrdinal = ordinal;
  15614. exports.scalePoint = point$1;
  15615. exports.scalePow = pow$1;
  15616. exports.scaleQuantile = quantile;
  15617. exports.scaleQuantize = quantize$1;
  15618. exports.scaleSequential = sequential;
  15619. exports.scaleSequentialLog = sequentialLog;
  15620. exports.scaleSequentialPow = sequentialPow;
  15621. exports.scaleSequentialQuantile = sequentialQuantile;
  15622. exports.scaleSequentialSqrt = sequentialSqrt;
  15623. exports.scaleSequentialSymlog = sequentialSymlog;
  15624. exports.scaleSqrt = sqrt$1;
  15625. exports.scaleSymlog = symlog;
  15626. exports.scaleThreshold = threshold$1;
  15627. exports.scaleTime = time;
  15628. exports.scaleUtc = utcTime;
  15629. exports.scan = scan;
  15630. exports.schemeAccent = Accent;
  15631. exports.schemeBlues = scheme$l;
  15632. exports.schemeBrBG = scheme;
  15633. exports.schemeBuGn = scheme$9;
  15634. exports.schemeBuPu = scheme$a;
  15635. exports.schemeCategory10 = category10;
  15636. exports.schemeDark2 = Dark2;
  15637. exports.schemeGnBu = scheme$b;
  15638. exports.schemeGreens = scheme$m;
  15639. exports.schemeGreys = scheme$n;
  15640. exports.schemeOrRd = scheme$c;
  15641. exports.schemeOranges = scheme$q;
  15642. exports.schemePRGn = scheme$1;
  15643. exports.schemePaired = Paired;
  15644. exports.schemePastel1 = Pastel1;
  15645. exports.schemePastel2 = Pastel2;
  15646. exports.schemePiYG = scheme$2;
  15647. exports.schemePuBu = scheme$e;
  15648. exports.schemePuBuGn = scheme$d;
  15649. exports.schemePuOr = scheme$3;
  15650. exports.schemePuRd = scheme$f;
  15651. exports.schemePurples = scheme$o;
  15652. exports.schemeRdBu = scheme$4;
  15653. exports.schemeRdGy = scheme$5;
  15654. exports.schemeRdPu = scheme$g;
  15655. exports.schemeRdYlBu = scheme$6;
  15656. exports.schemeRdYlGn = scheme$7;
  15657. exports.schemeReds = scheme$p;
  15658. exports.schemeSet1 = Set1;
  15659. exports.schemeSet2 = Set2;
  15660. exports.schemeSet3 = Set3;
  15661. exports.schemeSpectral = scheme$8;
  15662. exports.schemeTableau10 = Tableau10;
  15663. exports.schemeYlGn = scheme$i;
  15664. exports.schemeYlGnBu = scheme$h;
  15665. exports.schemeYlOrBr = scheme$j;
  15666. exports.schemeYlOrRd = scheme$k;
  15667. exports.select = select;
  15668. exports.selectAll = selectAll;
  15669. exports.selection = selection;
  15670. exports.selector = selector;
  15671. exports.selectorAll = selectorAll;
  15672. exports.set = set$2;
  15673. exports.shuffle = shuffle;
  15674. exports.stack = stack;
  15675. exports.stackOffsetDiverging = diverging$1;
  15676. exports.stackOffsetExpand = expand;
  15677. exports.stackOffsetNone = none$1;
  15678. exports.stackOffsetSilhouette = silhouette;
  15679. exports.stackOffsetWiggle = wiggle;
  15680. exports.stackOrderAppearance = appearance;
  15681. exports.stackOrderAscending = ascending$3;
  15682. exports.stackOrderDescending = descending$2;
  15683. exports.stackOrderInsideOut = insideOut;
  15684. exports.stackOrderNone = none$2;
  15685. exports.stackOrderReverse = reverse;
  15686. exports.stratify = stratify;
  15687. exports.style = styleValue;
  15688. exports.sum = sum;
  15689. exports.svg = svg;
  15690. exports.symbol = symbol;
  15691. exports.symbolCircle = circle$2;
  15692. exports.symbolCross = cross$2;
  15693. exports.symbolDiamond = diamond;
  15694. exports.symbolSquare = square;
  15695. exports.symbolStar = star;
  15696. exports.symbolTriangle = triangle;
  15697. exports.symbolWye = wye;
  15698. exports.symbols = symbols;
  15699. exports.text = text;
  15700. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  15701. exports.thresholdScott = scott;
  15702. exports.thresholdSturges = thresholdSturges;
  15703. exports.tickFormat = tickFormat;
  15704. exports.tickIncrement = tickIncrement;
  15705. exports.tickStep = tickStep;
  15706. exports.ticks = ticks;
  15707. exports.timeDay = day;
  15708. exports.timeDays = days;
  15709. exports.timeFormatDefaultLocale = defaultLocale$1;
  15710. exports.timeFormatLocale = formatLocale$1;
  15711. exports.timeFriday = friday;
  15712. exports.timeFridays = fridays;
  15713. exports.timeHour = hour;
  15714. exports.timeHours = hours;
  15715. exports.timeInterval = newInterval;
  15716. exports.timeMillisecond = millisecond;
  15717. exports.timeMilliseconds = milliseconds;
  15718. exports.timeMinute = minute;
  15719. exports.timeMinutes = minutes;
  15720. exports.timeMonday = monday;
  15721. exports.timeMondays = mondays;
  15722. exports.timeMonth = month;
  15723. exports.timeMonths = months;
  15724. exports.timeSaturday = saturday;
  15725. exports.timeSaturdays = saturdays;
  15726. exports.timeSecond = second;
  15727. exports.timeSeconds = seconds;
  15728. exports.timeSunday = sunday;
  15729. exports.timeSundays = sundays;
  15730. exports.timeThursday = thursday;
  15731. exports.timeThursdays = thursdays;
  15732. exports.timeTuesday = tuesday;
  15733. exports.timeTuesdays = tuesdays;
  15734. exports.timeWednesday = wednesday;
  15735. exports.timeWednesdays = wednesdays;
  15736. exports.timeWeek = sunday;
  15737. exports.timeWeeks = sundays;
  15738. exports.timeYear = year;
  15739. exports.timeYears = years;
  15740. exports.timeout = timeout$1;
  15741. exports.timer = timer;
  15742. exports.timerFlush = timerFlush;
  15743. exports.touch = touch;
  15744. exports.touches = touches;
  15745. exports.transition = transition;
  15746. exports.transpose = transpose;
  15747. exports.tree = tree;
  15748. exports.treemap = index$3;
  15749. exports.treemapBinary = binary;
  15750. exports.treemapDice = treemapDice;
  15751. exports.treemapResquarify = resquarify;
  15752. exports.treemapSlice = treemapSlice;
  15753. exports.treemapSliceDice = sliceDice;
  15754. exports.treemapSquarify = squarify;
  15755. exports.tsv = tsv$1;
  15756. exports.tsvFormat = tsvFormat;
  15757. exports.tsvFormatBody = tsvFormatBody;
  15758. exports.tsvFormatRow = tsvFormatRow;
  15759. exports.tsvFormatRows = tsvFormatRows;
  15760. exports.tsvFormatValue = tsvFormatValue;
  15761. exports.tsvParse = tsvParse;
  15762. exports.tsvParseRows = tsvParseRows;
  15763. exports.utcDay = utcDay;
  15764. exports.utcDays = utcDays;
  15765. exports.utcFriday = utcFriday;
  15766. exports.utcFridays = utcFridays;
  15767. exports.utcHour = utcHour;
  15768. exports.utcHours = utcHours;
  15769. exports.utcMillisecond = millisecond;
  15770. exports.utcMilliseconds = milliseconds;
  15771. exports.utcMinute = utcMinute;
  15772. exports.utcMinutes = utcMinutes;
  15773. exports.utcMonday = utcMonday;
  15774. exports.utcMondays = utcMondays;
  15775. exports.utcMonth = utcMonth;
  15776. exports.utcMonths = utcMonths;
  15777. exports.utcSaturday = utcSaturday;
  15778. exports.utcSaturdays = utcSaturdays;
  15779. exports.utcSecond = second;
  15780. exports.utcSeconds = seconds;
  15781. exports.utcSunday = utcSunday;
  15782. exports.utcSundays = utcSundays;
  15783. exports.utcThursday = utcThursday;
  15784. exports.utcThursdays = utcThursdays;
  15785. exports.utcTuesday = utcTuesday;
  15786. exports.utcTuesdays = utcTuesdays;
  15787. exports.utcWednesday = utcWednesday;
  15788. exports.utcWednesdays = utcWednesdays;
  15789. exports.utcWeek = utcSunday;
  15790. exports.utcWeeks = utcSundays;
  15791. exports.utcYear = utcYear;
  15792. exports.utcYears = utcYears;
  15793. exports.values = values;
  15794. exports.variance = variance;
  15795. exports.version = version;
  15796. exports.voronoi = voronoi;
  15797. exports.window = defaultView;
  15798. exports.xml = xml;
  15799. exports.zip = zip;
  15800. exports.zoom = zoom;
  15801. exports.zoomIdentity = identity$9;
  15802. exports.zoomTransform = transform$1;
  15803. Object.defineProperty(exports, '__esModule', { value: true });
  15804. }));