d3.js 538 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503
  1. // https://d3js.org v5.14.2 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.14.2";
  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 array$1(a, b) {
  2288. var nb = b ? b.length : 0,
  2289. na = a ? Math.min(nb, a.length) : 0,
  2290. x = new Array(na),
  2291. c = new Array(nb),
  2292. i;
  2293. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2294. for (; i < nb; ++i) c[i] = b[i];
  2295. return function(t) {
  2296. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2297. return c;
  2298. };
  2299. }
  2300. function date(a, b) {
  2301. var d = new Date;
  2302. return a = +a, b -= a, function(t) {
  2303. return d.setTime(a + b * t), d;
  2304. };
  2305. }
  2306. function interpolateNumber(a, b) {
  2307. return a = +a, b -= a, function(t) {
  2308. return a + b * t;
  2309. };
  2310. }
  2311. function object(a, b) {
  2312. var i = {},
  2313. c = {},
  2314. k;
  2315. if (a === null || typeof a !== "object") a = {};
  2316. if (b === null || typeof b !== "object") b = {};
  2317. for (k in b) {
  2318. if (k in a) {
  2319. i[k] = interpolateValue(a[k], b[k]);
  2320. } else {
  2321. c[k] = b[k];
  2322. }
  2323. }
  2324. return function(t) {
  2325. for (k in i) c[k] = i[k](t);
  2326. return c;
  2327. };
  2328. }
  2329. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  2330. reB = new RegExp(reA.source, "g");
  2331. function zero(b) {
  2332. return function() {
  2333. return b;
  2334. };
  2335. }
  2336. function one(b) {
  2337. return function(t) {
  2338. return b(t) + "";
  2339. };
  2340. }
  2341. function interpolateString(a, b) {
  2342. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2343. am, // current match in a
  2344. bm, // current match in b
  2345. bs, // string preceding current number in b, if any
  2346. i = -1, // index in s
  2347. s = [], // string constants and placeholders
  2348. q = []; // number interpolators
  2349. // Coerce inputs to strings.
  2350. a = a + "", b = b + "";
  2351. // Interpolate pairs of numbers in a & b.
  2352. while ((am = reA.exec(a))
  2353. && (bm = reB.exec(b))) {
  2354. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2355. bs = b.slice(bi, bs);
  2356. if (s[i]) s[i] += bs; // coalesce with previous string
  2357. else s[++i] = bs;
  2358. }
  2359. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2360. if (s[i]) s[i] += bm; // coalesce with previous string
  2361. else s[++i] = bm;
  2362. } else { // interpolate non-matching numbers
  2363. s[++i] = null;
  2364. q.push({i: i, x: interpolateNumber(am, bm)});
  2365. }
  2366. bi = reB.lastIndex;
  2367. }
  2368. // Add remains of b.
  2369. if (bi < b.length) {
  2370. bs = b.slice(bi);
  2371. if (s[i]) s[i] += bs; // coalesce with previous string
  2372. else s[++i] = bs;
  2373. }
  2374. // Special optimization for only a single match.
  2375. // Otherwise, interpolate each of the numbers and rejoin the string.
  2376. return s.length < 2 ? (q[0]
  2377. ? one(q[0].x)
  2378. : zero(b))
  2379. : (b = q.length, function(t) {
  2380. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2381. return s.join("");
  2382. });
  2383. }
  2384. function interpolateValue(a, b) {
  2385. var t = typeof b, c;
  2386. return b == null || t === "boolean" ? constant$3(b)
  2387. : (t === "number" ? interpolateNumber
  2388. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2389. : b instanceof color ? interpolateRgb
  2390. : b instanceof Date ? date
  2391. : Array.isArray(b) ? array$1
  2392. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2393. : interpolateNumber)(a, b);
  2394. }
  2395. function discrete(range) {
  2396. var n = range.length;
  2397. return function(t) {
  2398. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  2399. };
  2400. }
  2401. function hue$1(a, b) {
  2402. var i = hue(+a, +b);
  2403. return function(t) {
  2404. var x = i(t);
  2405. return x - 360 * Math.floor(x / 360);
  2406. };
  2407. }
  2408. function interpolateRound(a, b) {
  2409. return a = +a, b -= a, function(t) {
  2410. return Math.round(a + b * t);
  2411. };
  2412. }
  2413. var degrees = 180 / Math.PI;
  2414. var identity$2 = {
  2415. translateX: 0,
  2416. translateY: 0,
  2417. rotate: 0,
  2418. skewX: 0,
  2419. scaleX: 1,
  2420. scaleY: 1
  2421. };
  2422. function decompose(a, b, c, d, e, f) {
  2423. var scaleX, scaleY, skewX;
  2424. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2425. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2426. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2427. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2428. return {
  2429. translateX: e,
  2430. translateY: f,
  2431. rotate: Math.atan2(b, a) * degrees,
  2432. skewX: Math.atan(skewX) * degrees,
  2433. scaleX: scaleX,
  2434. scaleY: scaleY
  2435. };
  2436. }
  2437. var cssNode,
  2438. cssRoot,
  2439. cssView,
  2440. svgNode;
  2441. function parseCss(value) {
  2442. if (value === "none") return identity$2;
  2443. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2444. cssNode.style.transform = value;
  2445. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2446. cssRoot.removeChild(cssNode);
  2447. value = value.slice(7, -1).split(",");
  2448. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2449. }
  2450. function parseSvg(value) {
  2451. if (value == null) return identity$2;
  2452. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2453. svgNode.setAttribute("transform", value);
  2454. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2455. value = value.matrix;
  2456. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2457. }
  2458. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2459. function pop(s) {
  2460. return s.length ? s.pop() + " " : "";
  2461. }
  2462. function translate(xa, ya, xb, yb, s, q) {
  2463. if (xa !== xb || ya !== yb) {
  2464. var i = s.push("translate(", null, pxComma, null, pxParen);
  2465. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2466. } else if (xb || yb) {
  2467. s.push("translate(" + xb + pxComma + yb + pxParen);
  2468. }
  2469. }
  2470. function rotate(a, b, s, q) {
  2471. if (a !== b) {
  2472. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2473. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2474. } else if (b) {
  2475. s.push(pop(s) + "rotate(" + b + degParen);
  2476. }
  2477. }
  2478. function skewX(a, b, s, q) {
  2479. if (a !== b) {
  2480. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2481. } else if (b) {
  2482. s.push(pop(s) + "skewX(" + b + degParen);
  2483. }
  2484. }
  2485. function scale(xa, ya, xb, yb, s, q) {
  2486. if (xa !== xb || ya !== yb) {
  2487. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2488. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2489. } else if (xb !== 1 || yb !== 1) {
  2490. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2491. }
  2492. }
  2493. return function(a, b) {
  2494. var s = [], // string constants and placeholders
  2495. q = []; // number interpolators
  2496. a = parse(a), b = parse(b);
  2497. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2498. rotate(a.rotate, b.rotate, s, q);
  2499. skewX(a.skewX, b.skewX, s, q);
  2500. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2501. a = b = null; // gc
  2502. return function(t) {
  2503. var i = -1, n = q.length, o;
  2504. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2505. return s.join("");
  2506. };
  2507. };
  2508. }
  2509. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2510. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2511. var rho = Math.SQRT2,
  2512. rho2 = 2,
  2513. rho4 = 4,
  2514. epsilon2 = 1e-12;
  2515. function cosh(x) {
  2516. return ((x = Math.exp(x)) + 1 / x) / 2;
  2517. }
  2518. function sinh(x) {
  2519. return ((x = Math.exp(x)) - 1 / x) / 2;
  2520. }
  2521. function tanh(x) {
  2522. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2523. }
  2524. // p0 = [ux0, uy0, w0]
  2525. // p1 = [ux1, uy1, w1]
  2526. function interpolateZoom(p0, p1) {
  2527. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2528. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2529. dx = ux1 - ux0,
  2530. dy = uy1 - uy0,
  2531. d2 = dx * dx + dy * dy,
  2532. i,
  2533. S;
  2534. // Special case for u0 ≅ u1.
  2535. if (d2 < epsilon2) {
  2536. S = Math.log(w1 / w0) / rho;
  2537. i = function(t) {
  2538. return [
  2539. ux0 + t * dx,
  2540. uy0 + t * dy,
  2541. w0 * Math.exp(rho * t * S)
  2542. ];
  2543. };
  2544. }
  2545. // General case.
  2546. else {
  2547. var d1 = Math.sqrt(d2),
  2548. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2549. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2550. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2551. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2552. S = (r1 - r0) / rho;
  2553. i = function(t) {
  2554. var s = t * S,
  2555. coshr0 = cosh(r0),
  2556. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2557. return [
  2558. ux0 + u * dx,
  2559. uy0 + u * dy,
  2560. w0 * coshr0 / cosh(rho * s + r0)
  2561. ];
  2562. };
  2563. }
  2564. i.duration = S * 1000;
  2565. return i;
  2566. }
  2567. function hsl$1(hue) {
  2568. return function(start, end) {
  2569. var h = hue((start = hsl(start)).h, (end = hsl(end)).h),
  2570. s = nogamma(start.s, end.s),
  2571. l = nogamma(start.l, end.l),
  2572. opacity = nogamma(start.opacity, end.opacity);
  2573. return function(t) {
  2574. start.h = h(t);
  2575. start.s = s(t);
  2576. start.l = l(t);
  2577. start.opacity = opacity(t);
  2578. return start + "";
  2579. };
  2580. }
  2581. }
  2582. var hsl$2 = hsl$1(hue);
  2583. var hslLong = hsl$1(nogamma);
  2584. function lab$1(start, end) {
  2585. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2586. a = nogamma(start.a, end.a),
  2587. b = nogamma(start.b, end.b),
  2588. opacity = nogamma(start.opacity, end.opacity);
  2589. return function(t) {
  2590. start.l = l(t);
  2591. start.a = a(t);
  2592. start.b = b(t);
  2593. start.opacity = opacity(t);
  2594. return start + "";
  2595. };
  2596. }
  2597. function hcl$1(hue) {
  2598. return function(start, end) {
  2599. var h = hue((start = hcl(start)).h, (end = hcl(end)).h),
  2600. c = nogamma(start.c, end.c),
  2601. l = nogamma(start.l, end.l),
  2602. opacity = nogamma(start.opacity, end.opacity);
  2603. return function(t) {
  2604. start.h = h(t);
  2605. start.c = c(t);
  2606. start.l = l(t);
  2607. start.opacity = opacity(t);
  2608. return start + "";
  2609. };
  2610. }
  2611. }
  2612. var hcl$2 = hcl$1(hue);
  2613. var hclLong = hcl$1(nogamma);
  2614. function cubehelix$1(hue) {
  2615. return (function cubehelixGamma(y) {
  2616. y = +y;
  2617. function cubehelix$1(start, end) {
  2618. var h = hue((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2619. s = nogamma(start.s, end.s),
  2620. l = nogamma(start.l, end.l),
  2621. opacity = nogamma(start.opacity, end.opacity);
  2622. return function(t) {
  2623. start.h = h(t);
  2624. start.s = s(t);
  2625. start.l = l(Math.pow(t, y));
  2626. start.opacity = opacity(t);
  2627. return start + "";
  2628. };
  2629. }
  2630. cubehelix$1.gamma = cubehelixGamma;
  2631. return cubehelix$1;
  2632. })(1);
  2633. }
  2634. var cubehelix$2 = cubehelix$1(hue);
  2635. var cubehelixLong = cubehelix$1(nogamma);
  2636. function piecewise(interpolate, values) {
  2637. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  2638. while (i < n) I[i] = interpolate(v, v = values[++i]);
  2639. return function(t) {
  2640. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  2641. return I[i](t - i);
  2642. };
  2643. }
  2644. function quantize(interpolator, n) {
  2645. var samples = new Array(n);
  2646. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2647. return samples;
  2648. }
  2649. var frame = 0, // is an animation frame pending?
  2650. timeout = 0, // is a timeout pending?
  2651. interval = 0, // are any timers active?
  2652. pokeDelay = 1000, // how frequently we check for clock skew
  2653. taskHead,
  2654. taskTail,
  2655. clockLast = 0,
  2656. clockNow = 0,
  2657. clockSkew = 0,
  2658. clock = typeof performance === "object" && performance.now ? performance : Date,
  2659. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2660. function now() {
  2661. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2662. }
  2663. function clearNow() {
  2664. clockNow = 0;
  2665. }
  2666. function Timer() {
  2667. this._call =
  2668. this._time =
  2669. this._next = null;
  2670. }
  2671. Timer.prototype = timer.prototype = {
  2672. constructor: Timer,
  2673. restart: function(callback, delay, time) {
  2674. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2675. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2676. if (!this._next && taskTail !== this) {
  2677. if (taskTail) taskTail._next = this;
  2678. else taskHead = this;
  2679. taskTail = this;
  2680. }
  2681. this._call = callback;
  2682. this._time = time;
  2683. sleep();
  2684. },
  2685. stop: function() {
  2686. if (this._call) {
  2687. this._call = null;
  2688. this._time = Infinity;
  2689. sleep();
  2690. }
  2691. }
  2692. };
  2693. function timer(callback, delay, time) {
  2694. var t = new Timer;
  2695. t.restart(callback, delay, time);
  2696. return t;
  2697. }
  2698. function timerFlush() {
  2699. now(); // Get the current time, if not already set.
  2700. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2701. var t = taskHead, e;
  2702. while (t) {
  2703. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2704. t = t._next;
  2705. }
  2706. --frame;
  2707. }
  2708. function wake() {
  2709. clockNow = (clockLast = clock.now()) + clockSkew;
  2710. frame = timeout = 0;
  2711. try {
  2712. timerFlush();
  2713. } finally {
  2714. frame = 0;
  2715. nap();
  2716. clockNow = 0;
  2717. }
  2718. }
  2719. function poke() {
  2720. var now = clock.now(), delay = now - clockLast;
  2721. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2722. }
  2723. function nap() {
  2724. var t0, t1 = taskHead, t2, time = Infinity;
  2725. while (t1) {
  2726. if (t1._call) {
  2727. if (time > t1._time) time = t1._time;
  2728. t0 = t1, t1 = t1._next;
  2729. } else {
  2730. t2 = t1._next, t1._next = null;
  2731. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2732. }
  2733. }
  2734. taskTail = t0;
  2735. sleep(time);
  2736. }
  2737. function sleep(time) {
  2738. if (frame) return; // Soonest alarm already set, or will be.
  2739. if (timeout) timeout = clearTimeout(timeout);
  2740. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2741. if (delay > 24) {
  2742. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2743. if (interval) interval = clearInterval(interval);
  2744. } else {
  2745. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2746. frame = 1, setFrame(wake);
  2747. }
  2748. }
  2749. function timeout$1(callback, delay, time) {
  2750. var t = new Timer;
  2751. delay = delay == null ? 0 : +delay;
  2752. t.restart(function(elapsed) {
  2753. t.stop();
  2754. callback(elapsed + delay);
  2755. }, delay, time);
  2756. return t;
  2757. }
  2758. function interval$1(callback, delay, time) {
  2759. var t = new Timer, total = delay;
  2760. if (delay == null) return t.restart(callback, delay, time), t;
  2761. delay = +delay, time = time == null ? now() : +time;
  2762. t.restart(function tick(elapsed) {
  2763. elapsed += total;
  2764. t.restart(tick, total += delay, time);
  2765. callback(elapsed);
  2766. }, delay, time);
  2767. return t;
  2768. }
  2769. var emptyOn = dispatch("start", "end", "cancel", "interrupt");
  2770. var emptyTween = [];
  2771. var CREATED = 0;
  2772. var SCHEDULED = 1;
  2773. var STARTING = 2;
  2774. var STARTED = 3;
  2775. var RUNNING = 4;
  2776. var ENDING = 5;
  2777. var ENDED = 6;
  2778. function schedule(node, name, id, index, group, timing) {
  2779. var schedules = node.__transition;
  2780. if (!schedules) node.__transition = {};
  2781. else if (id in schedules) return;
  2782. create$1(node, id, {
  2783. name: name,
  2784. index: index, // For context during callback.
  2785. group: group, // For context during callback.
  2786. on: emptyOn,
  2787. tween: emptyTween,
  2788. time: timing.time,
  2789. delay: timing.delay,
  2790. duration: timing.duration,
  2791. ease: timing.ease,
  2792. timer: null,
  2793. state: CREATED
  2794. });
  2795. }
  2796. function init(node, id) {
  2797. var schedule = get$1(node, id);
  2798. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  2799. return schedule;
  2800. }
  2801. function set$1(node, id) {
  2802. var schedule = get$1(node, id);
  2803. if (schedule.state > STARTED) throw new Error("too late; already running");
  2804. return schedule;
  2805. }
  2806. function get$1(node, id) {
  2807. var schedule = node.__transition;
  2808. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  2809. return schedule;
  2810. }
  2811. function create$1(node, id, self) {
  2812. var schedules = node.__transition,
  2813. tween;
  2814. // Initialize the self timer when the transition is created.
  2815. // Note the actual delay is not known until the first callback!
  2816. schedules[id] = self;
  2817. self.timer = timer(schedule, 0, self.time);
  2818. function schedule(elapsed) {
  2819. self.state = SCHEDULED;
  2820. self.timer.restart(start, self.delay, self.time);
  2821. // If the elapsed delay is less than our first sleep, start immediately.
  2822. if (self.delay <= elapsed) start(elapsed - self.delay);
  2823. }
  2824. function start(elapsed) {
  2825. var i, j, n, o;
  2826. // If the state is not SCHEDULED, then we previously errored on start.
  2827. if (self.state !== SCHEDULED) return stop();
  2828. for (i in schedules) {
  2829. o = schedules[i];
  2830. if (o.name !== self.name) continue;
  2831. // While this element already has a starting transition during this frame,
  2832. // defer starting an interrupting transition until that transition has a
  2833. // chance to tick (and possibly end); see d3/d3-transition#54!
  2834. if (o.state === STARTED) return timeout$1(start);
  2835. // Interrupt the active transition, if any.
  2836. if (o.state === RUNNING) {
  2837. o.state = ENDED;
  2838. o.timer.stop();
  2839. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2840. delete schedules[i];
  2841. }
  2842. // Cancel any pre-empted transitions.
  2843. else if (+i < id) {
  2844. o.state = ENDED;
  2845. o.timer.stop();
  2846. o.on.call("cancel", node, node.__data__, o.index, o.group);
  2847. delete schedules[i];
  2848. }
  2849. }
  2850. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2851. // Note the transition may be canceled after start and before the first tick!
  2852. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2853. // Assuming this is successful, subsequent callbacks go straight to tick.
  2854. timeout$1(function() {
  2855. if (self.state === STARTED) {
  2856. self.state = RUNNING;
  2857. self.timer.restart(tick, self.delay, self.time);
  2858. tick(elapsed);
  2859. }
  2860. });
  2861. // Dispatch the start event.
  2862. // Note this must be done before the tween are initialized.
  2863. self.state = STARTING;
  2864. self.on.call("start", node, node.__data__, self.index, self.group);
  2865. if (self.state !== STARTING) return; // interrupted
  2866. self.state = STARTED;
  2867. // Initialize the tween, deleting null tween.
  2868. tween = new Array(n = self.tween.length);
  2869. for (i = 0, j = -1; i < n; ++i) {
  2870. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2871. tween[++j] = o;
  2872. }
  2873. }
  2874. tween.length = j + 1;
  2875. }
  2876. function tick(elapsed) {
  2877. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2878. i = -1,
  2879. n = tween.length;
  2880. while (++i < n) {
  2881. tween[i].call(node, t);
  2882. }
  2883. // Dispatch the end event.
  2884. if (self.state === ENDING) {
  2885. self.on.call("end", node, node.__data__, self.index, self.group);
  2886. stop();
  2887. }
  2888. }
  2889. function stop() {
  2890. self.state = ENDED;
  2891. self.timer.stop();
  2892. delete schedules[id];
  2893. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2894. delete node.__transition;
  2895. }
  2896. }
  2897. function interrupt(node, name) {
  2898. var schedules = node.__transition,
  2899. schedule,
  2900. active,
  2901. empty = true,
  2902. i;
  2903. if (!schedules) return;
  2904. name = name == null ? null : name + "";
  2905. for (i in schedules) {
  2906. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  2907. active = schedule.state > STARTING && schedule.state < ENDING;
  2908. schedule.state = ENDED;
  2909. schedule.timer.stop();
  2910. schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
  2911. delete schedules[i];
  2912. }
  2913. if (empty) delete node.__transition;
  2914. }
  2915. function selection_interrupt(name) {
  2916. return this.each(function() {
  2917. interrupt(this, name);
  2918. });
  2919. }
  2920. function tweenRemove(id, name) {
  2921. var tween0, tween1;
  2922. return function() {
  2923. var schedule = set$1(this, id),
  2924. tween = schedule.tween;
  2925. // If this node shared tween with the previous node,
  2926. // just assign the updated shared tween and we’re done!
  2927. // Otherwise, copy-on-write.
  2928. if (tween !== tween0) {
  2929. tween1 = tween0 = tween;
  2930. for (var i = 0, n = tween1.length; i < n; ++i) {
  2931. if (tween1[i].name === name) {
  2932. tween1 = tween1.slice();
  2933. tween1.splice(i, 1);
  2934. break;
  2935. }
  2936. }
  2937. }
  2938. schedule.tween = tween1;
  2939. };
  2940. }
  2941. function tweenFunction(id, name, value) {
  2942. var tween0, tween1;
  2943. if (typeof value !== "function") throw new Error;
  2944. return function() {
  2945. var schedule = set$1(this, id),
  2946. tween = schedule.tween;
  2947. // If this node shared tween with the previous node,
  2948. // just assign the updated shared tween and we’re done!
  2949. // Otherwise, copy-on-write.
  2950. if (tween !== tween0) {
  2951. tween1 = (tween0 = tween).slice();
  2952. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2953. if (tween1[i].name === name) {
  2954. tween1[i] = t;
  2955. break;
  2956. }
  2957. }
  2958. if (i === n) tween1.push(t);
  2959. }
  2960. schedule.tween = tween1;
  2961. };
  2962. }
  2963. function transition_tween(name, value) {
  2964. var id = this._id;
  2965. name += "";
  2966. if (arguments.length < 2) {
  2967. var tween = get$1(this.node(), id).tween;
  2968. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2969. if ((t = tween[i]).name === name) {
  2970. return t.value;
  2971. }
  2972. }
  2973. return null;
  2974. }
  2975. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2976. }
  2977. function tweenValue(transition, name, value) {
  2978. var id = transition._id;
  2979. transition.each(function() {
  2980. var schedule = set$1(this, id);
  2981. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  2982. });
  2983. return function(node) {
  2984. return get$1(node, id).value[name];
  2985. };
  2986. }
  2987. function interpolate(a, b) {
  2988. var c;
  2989. return (typeof b === "number" ? interpolateNumber
  2990. : b instanceof color ? interpolateRgb
  2991. : (c = color(b)) ? (b = c, interpolateRgb)
  2992. : interpolateString)(a, b);
  2993. }
  2994. function attrRemove$1(name) {
  2995. return function() {
  2996. this.removeAttribute(name);
  2997. };
  2998. }
  2999. function attrRemoveNS$1(fullname) {
  3000. return function() {
  3001. this.removeAttributeNS(fullname.space, fullname.local);
  3002. };
  3003. }
  3004. function attrConstant$1(name, interpolate, value1) {
  3005. var string00,
  3006. string1 = value1 + "",
  3007. interpolate0;
  3008. return function() {
  3009. var string0 = this.getAttribute(name);
  3010. return string0 === string1 ? null
  3011. : string0 === string00 ? interpolate0
  3012. : interpolate0 = interpolate(string00 = string0, value1);
  3013. };
  3014. }
  3015. function attrConstantNS$1(fullname, interpolate, value1) {
  3016. var string00,
  3017. string1 = value1 + "",
  3018. interpolate0;
  3019. return function() {
  3020. var string0 = this.getAttributeNS(fullname.space, fullname.local);
  3021. return string0 === string1 ? null
  3022. : string0 === string00 ? interpolate0
  3023. : interpolate0 = interpolate(string00 = string0, value1);
  3024. };
  3025. }
  3026. function attrFunction$1(name, interpolate, value) {
  3027. var string00,
  3028. string10,
  3029. interpolate0;
  3030. return function() {
  3031. var string0, value1 = value(this), string1;
  3032. if (value1 == null) return void this.removeAttribute(name);
  3033. string0 = this.getAttribute(name);
  3034. string1 = value1 + "";
  3035. return string0 === string1 ? null
  3036. : string0 === string00 && string1 === string10 ? interpolate0
  3037. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3038. };
  3039. }
  3040. function attrFunctionNS$1(fullname, interpolate, value) {
  3041. var string00,
  3042. string10,
  3043. interpolate0;
  3044. return function() {
  3045. var string0, value1 = value(this), string1;
  3046. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3047. string0 = this.getAttributeNS(fullname.space, fullname.local);
  3048. string1 = value1 + "";
  3049. return string0 === string1 ? null
  3050. : string0 === string00 && string1 === string10 ? interpolate0
  3051. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3052. };
  3053. }
  3054. function transition_attr(name, value) {
  3055. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  3056. return this.attrTween(name, typeof value === "function"
  3057. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  3058. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  3059. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
  3060. }
  3061. function attrInterpolate(name, i) {
  3062. return function(t) {
  3063. this.setAttribute(name, i.call(this, t));
  3064. };
  3065. }
  3066. function attrInterpolateNS(fullname, i) {
  3067. return function(t) {
  3068. this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
  3069. };
  3070. }
  3071. function attrTweenNS(fullname, value) {
  3072. var t0, i0;
  3073. function tween() {
  3074. var i = value.apply(this, arguments);
  3075. if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
  3076. return t0;
  3077. }
  3078. tween._value = value;
  3079. return tween;
  3080. }
  3081. function attrTween(name, value) {
  3082. var t0, i0;
  3083. function tween() {
  3084. var i = value.apply(this, arguments);
  3085. if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
  3086. return t0;
  3087. }
  3088. tween._value = value;
  3089. return tween;
  3090. }
  3091. function transition_attrTween(name, value) {
  3092. var key = "attr." + name;
  3093. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3094. if (value == null) return this.tween(key, null);
  3095. if (typeof value !== "function") throw new Error;
  3096. var fullname = namespace(name);
  3097. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3098. }
  3099. function delayFunction(id, value) {
  3100. return function() {
  3101. init(this, id).delay = +value.apply(this, arguments);
  3102. };
  3103. }
  3104. function delayConstant(id, value) {
  3105. return value = +value, function() {
  3106. init(this, id).delay = value;
  3107. };
  3108. }
  3109. function transition_delay(value) {
  3110. var id = this._id;
  3111. return arguments.length
  3112. ? this.each((typeof value === "function"
  3113. ? delayFunction
  3114. : delayConstant)(id, value))
  3115. : get$1(this.node(), id).delay;
  3116. }
  3117. function durationFunction(id, value) {
  3118. return function() {
  3119. set$1(this, id).duration = +value.apply(this, arguments);
  3120. };
  3121. }
  3122. function durationConstant(id, value) {
  3123. return value = +value, function() {
  3124. set$1(this, id).duration = value;
  3125. };
  3126. }
  3127. function transition_duration(value) {
  3128. var id = this._id;
  3129. return arguments.length
  3130. ? this.each((typeof value === "function"
  3131. ? durationFunction
  3132. : durationConstant)(id, value))
  3133. : get$1(this.node(), id).duration;
  3134. }
  3135. function easeConstant(id, value) {
  3136. if (typeof value !== "function") throw new Error;
  3137. return function() {
  3138. set$1(this, id).ease = value;
  3139. };
  3140. }
  3141. function transition_ease(value) {
  3142. var id = this._id;
  3143. return arguments.length
  3144. ? this.each(easeConstant(id, value))
  3145. : get$1(this.node(), id).ease;
  3146. }
  3147. function transition_filter(match) {
  3148. if (typeof match !== "function") match = matcher(match);
  3149. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3150. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3151. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3152. subgroup.push(node);
  3153. }
  3154. }
  3155. }
  3156. return new Transition(subgroups, this._parents, this._name, this._id);
  3157. }
  3158. function transition_merge(transition) {
  3159. if (transition._id !== this._id) throw new Error;
  3160. 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) {
  3161. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3162. if (node = group0[i] || group1[i]) {
  3163. merge[i] = node;
  3164. }
  3165. }
  3166. }
  3167. for (; j < m0; ++j) {
  3168. merges[j] = groups0[j];
  3169. }
  3170. return new Transition(merges, this._parents, this._name, this._id);
  3171. }
  3172. function start(name) {
  3173. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3174. var i = t.indexOf(".");
  3175. if (i >= 0) t = t.slice(0, i);
  3176. return !t || t === "start";
  3177. });
  3178. }
  3179. function onFunction(id, name, listener) {
  3180. var on0, on1, sit = start(name) ? init : set$1;
  3181. return function() {
  3182. var schedule = sit(this, id),
  3183. on = schedule.on;
  3184. // If this node shared a dispatch with the previous node,
  3185. // just assign the updated shared dispatch and we’re done!
  3186. // Otherwise, copy-on-write.
  3187. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3188. schedule.on = on1;
  3189. };
  3190. }
  3191. function transition_on(name, listener) {
  3192. var id = this._id;
  3193. return arguments.length < 2
  3194. ? get$1(this.node(), id).on.on(name)
  3195. : this.each(onFunction(id, name, listener));
  3196. }
  3197. function removeFunction(id) {
  3198. return function() {
  3199. var parent = this.parentNode;
  3200. for (var i in this.__transition) if (+i !== id) return;
  3201. if (parent) parent.removeChild(this);
  3202. };
  3203. }
  3204. function transition_remove() {
  3205. return this.on("end.remove", removeFunction(this._id));
  3206. }
  3207. function transition_select(select) {
  3208. var name = this._name,
  3209. id = this._id;
  3210. if (typeof select !== "function") select = selector(select);
  3211. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3212. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3213. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  3214. if ("__data__" in node) subnode.__data__ = node.__data__;
  3215. subgroup[i] = subnode;
  3216. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3217. }
  3218. }
  3219. }
  3220. return new Transition(subgroups, this._parents, name, id);
  3221. }
  3222. function transition_selectAll(select) {
  3223. var name = this._name,
  3224. id = this._id;
  3225. if (typeof select !== "function") select = selectorAll(select);
  3226. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3227. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3228. if (node = group[i]) {
  3229. for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3230. if (child = children[k]) {
  3231. schedule(child, name, id, k, children, inherit);
  3232. }
  3233. }
  3234. subgroups.push(children);
  3235. parents.push(node);
  3236. }
  3237. }
  3238. }
  3239. return new Transition(subgroups, parents, name, id);
  3240. }
  3241. var Selection$1 = selection.prototype.constructor;
  3242. function transition_selection() {
  3243. return new Selection$1(this._groups, this._parents);
  3244. }
  3245. function styleNull(name, interpolate) {
  3246. var string00,
  3247. string10,
  3248. interpolate0;
  3249. return function() {
  3250. var string0 = styleValue(this, name),
  3251. string1 = (this.style.removeProperty(name), styleValue(this, name));
  3252. return string0 === string1 ? null
  3253. : string0 === string00 && string1 === string10 ? interpolate0
  3254. : interpolate0 = interpolate(string00 = string0, string10 = string1);
  3255. };
  3256. }
  3257. function styleRemove$1(name) {
  3258. return function() {
  3259. this.style.removeProperty(name);
  3260. };
  3261. }
  3262. function styleConstant$1(name, interpolate, value1) {
  3263. var string00,
  3264. string1 = value1 + "",
  3265. interpolate0;
  3266. return function() {
  3267. var string0 = styleValue(this, name);
  3268. return string0 === string1 ? null
  3269. : string0 === string00 ? interpolate0
  3270. : interpolate0 = interpolate(string00 = string0, value1);
  3271. };
  3272. }
  3273. function styleFunction$1(name, interpolate, value) {
  3274. var string00,
  3275. string10,
  3276. interpolate0;
  3277. return function() {
  3278. var string0 = styleValue(this, name),
  3279. value1 = value(this),
  3280. string1 = value1 + "";
  3281. if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
  3282. return string0 === string1 ? null
  3283. : string0 === string00 && string1 === string10 ? interpolate0
  3284. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3285. };
  3286. }
  3287. function styleMaybeRemove(id, name) {
  3288. var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
  3289. return function() {
  3290. var schedule = set$1(this, id),
  3291. on = schedule.on,
  3292. listener = schedule.value[key] == null ? remove || (remove = styleRemove$1(name)) : undefined;
  3293. // If this node shared a dispatch with the previous node,
  3294. // just assign the updated shared dispatch and we’re done!
  3295. // Otherwise, copy-on-write.
  3296. if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
  3297. schedule.on = on1;
  3298. };
  3299. }
  3300. function transition_style(name, value, priority) {
  3301. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3302. return value == null ? this
  3303. .styleTween(name, styleNull(name, i))
  3304. .on("end.style." + name, styleRemove$1(name))
  3305. : typeof value === "function" ? this
  3306. .styleTween(name, styleFunction$1(name, i, tweenValue(this, "style." + name, value)))
  3307. .each(styleMaybeRemove(this._id, name))
  3308. : this
  3309. .styleTween(name, styleConstant$1(name, i, value), priority)
  3310. .on("end.style." + name, null);
  3311. }
  3312. function styleInterpolate(name, i, priority) {
  3313. return function(t) {
  3314. this.style.setProperty(name, i.call(this, t), priority);
  3315. };
  3316. }
  3317. function styleTween(name, value, priority) {
  3318. var t, i0;
  3319. function tween() {
  3320. var i = value.apply(this, arguments);
  3321. if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
  3322. return t;
  3323. }
  3324. tween._value = value;
  3325. return tween;
  3326. }
  3327. function transition_styleTween(name, value, priority) {
  3328. var key = "style." + (name += "");
  3329. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3330. if (value == null) return this.tween(key, null);
  3331. if (typeof value !== "function") throw new Error;
  3332. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3333. }
  3334. function textConstant$1(value) {
  3335. return function() {
  3336. this.textContent = value;
  3337. };
  3338. }
  3339. function textFunction$1(value) {
  3340. return function() {
  3341. var value1 = value(this);
  3342. this.textContent = value1 == null ? "" : value1;
  3343. };
  3344. }
  3345. function transition_text(value) {
  3346. return this.tween("text", typeof value === "function"
  3347. ? textFunction$1(tweenValue(this, "text", value))
  3348. : textConstant$1(value == null ? "" : value + ""));
  3349. }
  3350. function textInterpolate(i) {
  3351. return function(t) {
  3352. this.textContent = i.call(this, t);
  3353. };
  3354. }
  3355. function textTween(value) {
  3356. var t0, i0;
  3357. function tween() {
  3358. var i = value.apply(this, arguments);
  3359. if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
  3360. return t0;
  3361. }
  3362. tween._value = value;
  3363. return tween;
  3364. }
  3365. function transition_textTween(value) {
  3366. var key = "text";
  3367. if (arguments.length < 1) return (key = this.tween(key)) && key._value;
  3368. if (value == null) return this.tween(key, null);
  3369. if (typeof value !== "function") throw new Error;
  3370. return this.tween(key, textTween(value));
  3371. }
  3372. function transition_transition() {
  3373. var name = this._name,
  3374. id0 = this._id,
  3375. id1 = newId();
  3376. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3377. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3378. if (node = group[i]) {
  3379. var inherit = get$1(node, id0);
  3380. schedule(node, name, id1, i, group, {
  3381. time: inherit.time + inherit.delay + inherit.duration,
  3382. delay: 0,
  3383. duration: inherit.duration,
  3384. ease: inherit.ease
  3385. });
  3386. }
  3387. }
  3388. }
  3389. return new Transition(groups, this._parents, name, id1);
  3390. }
  3391. function transition_end() {
  3392. var on0, on1, that = this, id = that._id, size = that.size();
  3393. return new Promise(function(resolve, reject) {
  3394. var cancel = {value: reject},
  3395. end = {value: function() { if (--size === 0) resolve(); }};
  3396. that.each(function() {
  3397. var schedule = set$1(this, id),
  3398. on = schedule.on;
  3399. // If this node shared a dispatch with the previous node,
  3400. // just assign the updated shared dispatch and we’re done!
  3401. // Otherwise, copy-on-write.
  3402. if (on !== on0) {
  3403. on1 = (on0 = on).copy();
  3404. on1._.cancel.push(cancel);
  3405. on1._.interrupt.push(cancel);
  3406. on1._.end.push(end);
  3407. }
  3408. schedule.on = on1;
  3409. });
  3410. });
  3411. }
  3412. var id = 0;
  3413. function Transition(groups, parents, name, id) {
  3414. this._groups = groups;
  3415. this._parents = parents;
  3416. this._name = name;
  3417. this._id = id;
  3418. }
  3419. function transition(name) {
  3420. return selection().transition(name);
  3421. }
  3422. function newId() {
  3423. return ++id;
  3424. }
  3425. var selection_prototype = selection.prototype;
  3426. Transition.prototype = transition.prototype = {
  3427. constructor: Transition,
  3428. select: transition_select,
  3429. selectAll: transition_selectAll,
  3430. filter: transition_filter,
  3431. merge: transition_merge,
  3432. selection: transition_selection,
  3433. transition: transition_transition,
  3434. call: selection_prototype.call,
  3435. nodes: selection_prototype.nodes,
  3436. node: selection_prototype.node,
  3437. size: selection_prototype.size,
  3438. empty: selection_prototype.empty,
  3439. each: selection_prototype.each,
  3440. on: transition_on,
  3441. attr: transition_attr,
  3442. attrTween: transition_attrTween,
  3443. style: transition_style,
  3444. styleTween: transition_styleTween,
  3445. text: transition_text,
  3446. textTween: transition_textTween,
  3447. remove: transition_remove,
  3448. tween: transition_tween,
  3449. delay: transition_delay,
  3450. duration: transition_duration,
  3451. ease: transition_ease,
  3452. end: transition_end
  3453. };
  3454. function linear$1(t) {
  3455. return +t;
  3456. }
  3457. function quadIn(t) {
  3458. return t * t;
  3459. }
  3460. function quadOut(t) {
  3461. return t * (2 - t);
  3462. }
  3463. function quadInOut(t) {
  3464. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3465. }
  3466. function cubicIn(t) {
  3467. return t * t * t;
  3468. }
  3469. function cubicOut(t) {
  3470. return --t * t * t + 1;
  3471. }
  3472. function cubicInOut(t) {
  3473. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3474. }
  3475. var exponent = 3;
  3476. var polyIn = (function custom(e) {
  3477. e = +e;
  3478. function polyIn(t) {
  3479. return Math.pow(t, e);
  3480. }
  3481. polyIn.exponent = custom;
  3482. return polyIn;
  3483. })(exponent);
  3484. var polyOut = (function custom(e) {
  3485. e = +e;
  3486. function polyOut(t) {
  3487. return 1 - Math.pow(1 - t, e);
  3488. }
  3489. polyOut.exponent = custom;
  3490. return polyOut;
  3491. })(exponent);
  3492. var polyInOut = (function custom(e) {
  3493. e = +e;
  3494. function polyInOut(t) {
  3495. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3496. }
  3497. polyInOut.exponent = custom;
  3498. return polyInOut;
  3499. })(exponent);
  3500. var pi = Math.PI,
  3501. halfPi = pi / 2;
  3502. function sinIn(t) {
  3503. return 1 - Math.cos(t * halfPi);
  3504. }
  3505. function sinOut(t) {
  3506. return Math.sin(t * halfPi);
  3507. }
  3508. function sinInOut(t) {
  3509. return (1 - Math.cos(pi * t)) / 2;
  3510. }
  3511. function expIn(t) {
  3512. return Math.pow(2, 10 * t - 10);
  3513. }
  3514. function expOut(t) {
  3515. return 1 - Math.pow(2, -10 * t);
  3516. }
  3517. function expInOut(t) {
  3518. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3519. }
  3520. function circleIn(t) {
  3521. return 1 - Math.sqrt(1 - t * t);
  3522. }
  3523. function circleOut(t) {
  3524. return Math.sqrt(1 - --t * t);
  3525. }
  3526. function circleInOut(t) {
  3527. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3528. }
  3529. var b1 = 4 / 11,
  3530. b2 = 6 / 11,
  3531. b3 = 8 / 11,
  3532. b4 = 3 / 4,
  3533. b5 = 9 / 11,
  3534. b6 = 10 / 11,
  3535. b7 = 15 / 16,
  3536. b8 = 21 / 22,
  3537. b9 = 63 / 64,
  3538. b0 = 1 / b1 / b1;
  3539. function bounceIn(t) {
  3540. return 1 - bounceOut(1 - t);
  3541. }
  3542. function bounceOut(t) {
  3543. 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;
  3544. }
  3545. function bounceInOut(t) {
  3546. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3547. }
  3548. var overshoot = 1.70158;
  3549. var backIn = (function custom(s) {
  3550. s = +s;
  3551. function backIn(t) {
  3552. return t * t * ((s + 1) * t - s);
  3553. }
  3554. backIn.overshoot = custom;
  3555. return backIn;
  3556. })(overshoot);
  3557. var backOut = (function custom(s) {
  3558. s = +s;
  3559. function backOut(t) {
  3560. return --t * t * ((s + 1) * t + s) + 1;
  3561. }
  3562. backOut.overshoot = custom;
  3563. return backOut;
  3564. })(overshoot);
  3565. var backInOut = (function custom(s) {
  3566. s = +s;
  3567. function backInOut(t) {
  3568. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3569. }
  3570. backInOut.overshoot = custom;
  3571. return backInOut;
  3572. })(overshoot);
  3573. var tau = 2 * Math.PI,
  3574. amplitude = 1,
  3575. period = 0.3;
  3576. var elasticIn = (function custom(a, p) {
  3577. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3578. function elasticIn(t) {
  3579. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3580. }
  3581. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3582. elasticIn.period = function(p) { return custom(a, p); };
  3583. return elasticIn;
  3584. })(amplitude, period);
  3585. var elasticOut = (function custom(a, p) {
  3586. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3587. function elasticOut(t) {
  3588. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3589. }
  3590. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3591. elasticOut.period = function(p) { return custom(a, p); };
  3592. return elasticOut;
  3593. })(amplitude, period);
  3594. var elasticInOut = (function custom(a, p) {
  3595. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3596. function elasticInOut(t) {
  3597. return ((t = t * 2 - 1) < 0
  3598. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3599. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3600. }
  3601. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3602. elasticInOut.period = function(p) { return custom(a, p); };
  3603. return elasticInOut;
  3604. })(amplitude, period);
  3605. var defaultTiming = {
  3606. time: null, // Set on use.
  3607. delay: 0,
  3608. duration: 250,
  3609. ease: cubicInOut
  3610. };
  3611. function inherit(node, id) {
  3612. var timing;
  3613. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3614. if (!(node = node.parentNode)) {
  3615. return defaultTiming.time = now(), defaultTiming;
  3616. }
  3617. }
  3618. return timing;
  3619. }
  3620. function selection_transition(name) {
  3621. var id,
  3622. timing;
  3623. if (name instanceof Transition) {
  3624. id = name._id, name = name._name;
  3625. } else {
  3626. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3627. }
  3628. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3629. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3630. if (node = group[i]) {
  3631. schedule(node, name, id, i, group, timing || inherit(node, id));
  3632. }
  3633. }
  3634. }
  3635. return new Transition(groups, this._parents, name, id);
  3636. }
  3637. selection.prototype.interrupt = selection_interrupt;
  3638. selection.prototype.transition = selection_transition;
  3639. var root$1 = [null];
  3640. function active(node, name) {
  3641. var schedules = node.__transition,
  3642. schedule,
  3643. i;
  3644. if (schedules) {
  3645. name = name == null ? null : name + "";
  3646. for (i in schedules) {
  3647. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  3648. return new Transition([[node]], root$1, name, +i);
  3649. }
  3650. }
  3651. }
  3652. return null;
  3653. }
  3654. function constant$4(x) {
  3655. return function() {
  3656. return x;
  3657. };
  3658. }
  3659. function BrushEvent(target, type, selection) {
  3660. this.target = target;
  3661. this.type = type;
  3662. this.selection = selection;
  3663. }
  3664. function nopropagation$1() {
  3665. exports.event.stopImmediatePropagation();
  3666. }
  3667. function noevent$1() {
  3668. exports.event.preventDefault();
  3669. exports.event.stopImmediatePropagation();
  3670. }
  3671. var MODE_DRAG = {name: "drag"},
  3672. MODE_SPACE = {name: "space"},
  3673. MODE_HANDLE = {name: "handle"},
  3674. MODE_CENTER = {name: "center"};
  3675. function number1(e) {
  3676. return [+e[0], +e[1]];
  3677. }
  3678. function number2(e) {
  3679. return [number1(e[0]), number1(e[1])];
  3680. }
  3681. function toucher(identifier) {
  3682. return function(target) {
  3683. return touch(target, exports.event.touches, identifier);
  3684. };
  3685. }
  3686. var X = {
  3687. name: "x",
  3688. handles: ["w", "e"].map(type),
  3689. input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
  3690. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3691. };
  3692. var Y = {
  3693. name: "y",
  3694. handles: ["n", "s"].map(type),
  3695. input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
  3696. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3697. };
  3698. var XY = {
  3699. name: "xy",
  3700. handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
  3701. input: function(xy) { return xy == null ? null : number2(xy); },
  3702. output: function(xy) { return xy; }
  3703. };
  3704. var cursors = {
  3705. overlay: "crosshair",
  3706. selection: "move",
  3707. n: "ns-resize",
  3708. e: "ew-resize",
  3709. s: "ns-resize",
  3710. w: "ew-resize",
  3711. nw: "nwse-resize",
  3712. ne: "nesw-resize",
  3713. se: "nwse-resize",
  3714. sw: "nesw-resize"
  3715. };
  3716. var flipX = {
  3717. e: "w",
  3718. w: "e",
  3719. nw: "ne",
  3720. ne: "nw",
  3721. se: "sw",
  3722. sw: "se"
  3723. };
  3724. var flipY = {
  3725. n: "s",
  3726. s: "n",
  3727. nw: "sw",
  3728. ne: "se",
  3729. se: "ne",
  3730. sw: "nw"
  3731. };
  3732. var signsX = {
  3733. overlay: +1,
  3734. selection: +1,
  3735. n: null,
  3736. e: +1,
  3737. s: null,
  3738. w: -1,
  3739. nw: -1,
  3740. ne: +1,
  3741. se: +1,
  3742. sw: -1
  3743. };
  3744. var signsY = {
  3745. overlay: +1,
  3746. selection: +1,
  3747. n: -1,
  3748. e: null,
  3749. s: +1,
  3750. w: null,
  3751. nw: -1,
  3752. ne: -1,
  3753. se: +1,
  3754. sw: +1
  3755. };
  3756. function type(t) {
  3757. return {type: t};
  3758. }
  3759. // Ignore right-click, since that should open the context menu.
  3760. function defaultFilter$1() {
  3761. return !exports.event.ctrlKey && !exports.event.button;
  3762. }
  3763. function defaultExtent() {
  3764. var svg = this.ownerSVGElement || this;
  3765. if (svg.hasAttribute("viewBox")) {
  3766. svg = svg.viewBox.baseVal;
  3767. return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
  3768. }
  3769. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3770. }
  3771. function defaultTouchable$1() {
  3772. return navigator.maxTouchPoints || ("ontouchstart" in this);
  3773. }
  3774. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3775. function local$1(node) {
  3776. while (!node.__brush) if (!(node = node.parentNode)) return;
  3777. return node.__brush;
  3778. }
  3779. function empty$1(extent) {
  3780. return extent[0][0] === extent[1][0]
  3781. || extent[0][1] === extent[1][1];
  3782. }
  3783. function brushSelection(node) {
  3784. var state = node.__brush;
  3785. return state ? state.dim.output(state.selection) : null;
  3786. }
  3787. function brushX() {
  3788. return brush$1(X);
  3789. }
  3790. function brushY() {
  3791. return brush$1(Y);
  3792. }
  3793. function brush() {
  3794. return brush$1(XY);
  3795. }
  3796. function brush$1(dim) {
  3797. var extent = defaultExtent,
  3798. filter = defaultFilter$1,
  3799. touchable = defaultTouchable$1,
  3800. keys = true,
  3801. listeners = dispatch("start", "brush", "end"),
  3802. handleSize = 6,
  3803. touchending;
  3804. function brush(group) {
  3805. var overlay = group
  3806. .property("__brush", initialize)
  3807. .selectAll(".overlay")
  3808. .data([type("overlay")]);
  3809. overlay.enter().append("rect")
  3810. .attr("class", "overlay")
  3811. .attr("pointer-events", "all")
  3812. .attr("cursor", cursors.overlay)
  3813. .merge(overlay)
  3814. .each(function() {
  3815. var extent = local$1(this).extent;
  3816. select(this)
  3817. .attr("x", extent[0][0])
  3818. .attr("y", extent[0][1])
  3819. .attr("width", extent[1][0] - extent[0][0])
  3820. .attr("height", extent[1][1] - extent[0][1]);
  3821. });
  3822. group.selectAll(".selection")
  3823. .data([type("selection")])
  3824. .enter().append("rect")
  3825. .attr("class", "selection")
  3826. .attr("cursor", cursors.selection)
  3827. .attr("fill", "#777")
  3828. .attr("fill-opacity", 0.3)
  3829. .attr("stroke", "#fff")
  3830. .attr("shape-rendering", "crispEdges");
  3831. var handle = group.selectAll(".handle")
  3832. .data(dim.handles, function(d) { return d.type; });
  3833. handle.exit().remove();
  3834. handle.enter().append("rect")
  3835. .attr("class", function(d) { return "handle handle--" + d.type; })
  3836. .attr("cursor", function(d) { return cursors[d.type]; });
  3837. group
  3838. .each(redraw)
  3839. .attr("fill", "none")
  3840. .attr("pointer-events", "all")
  3841. .on("mousedown.brush", started)
  3842. .filter(touchable)
  3843. .on("touchstart.brush", started)
  3844. .on("touchmove.brush", touchmoved)
  3845. .on("touchend.brush touchcancel.brush", touchended)
  3846. .style("touch-action", "none")
  3847. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  3848. }
  3849. brush.move = function(group, selection) {
  3850. if (group.selection) {
  3851. group
  3852. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3853. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3854. .tween("brush", function() {
  3855. var that = this,
  3856. state = that.__brush,
  3857. emit = emitter(that, arguments),
  3858. selection0 = state.selection,
  3859. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  3860. i = interpolateValue(selection0, selection1);
  3861. function tween(t) {
  3862. state.selection = t === 1 && selection1 === null ? null : i(t);
  3863. redraw.call(that);
  3864. emit.brush();
  3865. }
  3866. return selection0 !== null && selection1 !== null ? tween : tween(1);
  3867. });
  3868. } else {
  3869. group
  3870. .each(function() {
  3871. var that = this,
  3872. args = arguments,
  3873. state = that.__brush,
  3874. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  3875. emit = emitter(that, args).beforestart();
  3876. interrupt(that);
  3877. state.selection = selection1 === null ? null : selection1;
  3878. redraw.call(that);
  3879. emit.start().brush().end();
  3880. });
  3881. }
  3882. };
  3883. brush.clear = function(group) {
  3884. brush.move(group, null);
  3885. };
  3886. function redraw() {
  3887. var group = select(this),
  3888. selection = local$1(this).selection;
  3889. if (selection) {
  3890. group.selectAll(".selection")
  3891. .style("display", null)
  3892. .attr("x", selection[0][0])
  3893. .attr("y", selection[0][1])
  3894. .attr("width", selection[1][0] - selection[0][0])
  3895. .attr("height", selection[1][1] - selection[0][1]);
  3896. group.selectAll(".handle")
  3897. .style("display", null)
  3898. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  3899. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  3900. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  3901. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  3902. }
  3903. else {
  3904. group.selectAll(".selection,.handle")
  3905. .style("display", "none")
  3906. .attr("x", null)
  3907. .attr("y", null)
  3908. .attr("width", null)
  3909. .attr("height", null);
  3910. }
  3911. }
  3912. function emitter(that, args, clean) {
  3913. return (!clean && that.__brush.emitter) || new Emitter(that, args);
  3914. }
  3915. function Emitter(that, args) {
  3916. this.that = that;
  3917. this.args = args;
  3918. this.state = that.__brush;
  3919. this.active = 0;
  3920. }
  3921. Emitter.prototype = {
  3922. beforestart: function() {
  3923. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3924. return this;
  3925. },
  3926. start: function() {
  3927. if (this.starting) this.starting = false, this.emit("start");
  3928. else this.emit("brush");
  3929. return this;
  3930. },
  3931. brush: function() {
  3932. this.emit("brush");
  3933. return this;
  3934. },
  3935. end: function() {
  3936. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3937. return this;
  3938. },
  3939. emit: function(type) {
  3940. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3941. }
  3942. };
  3943. function started() {
  3944. if (touchending && !exports.event.touches) return;
  3945. if (!filter.apply(this, arguments)) return;
  3946. var that = this,
  3947. type = exports.event.target.__data__.type,
  3948. mode = (keys && exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3949. signX = dim === Y ? null : signsX[type],
  3950. signY = dim === X ? null : signsY[type],
  3951. state = local$1(that),
  3952. extent = state.extent,
  3953. selection = state.selection,
  3954. W = extent[0][0], w0, w1,
  3955. N = extent[0][1], n0, n1,
  3956. E = extent[1][0], e0, e1,
  3957. S = extent[1][1], s0, s1,
  3958. dx = 0,
  3959. dy = 0,
  3960. moving,
  3961. shifting = signX && signY && keys && exports.event.shiftKey,
  3962. lockX,
  3963. lockY,
  3964. pointer = exports.event.touches ? toucher(exports.event.changedTouches[0].identifier) : mouse,
  3965. point0 = pointer(that),
  3966. point = point0,
  3967. emit = emitter(that, arguments, true).beforestart();
  3968. if (type === "overlay") {
  3969. if (selection) moving = true;
  3970. state.selection = selection = [
  3971. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3972. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3973. ];
  3974. } else {
  3975. w0 = selection[0][0];
  3976. n0 = selection[0][1];
  3977. e0 = selection[1][0];
  3978. s0 = selection[1][1];
  3979. }
  3980. w1 = w0;
  3981. n1 = n0;
  3982. e1 = e0;
  3983. s1 = s0;
  3984. var group = select(that)
  3985. .attr("pointer-events", "none");
  3986. var overlay = group.selectAll(".overlay")
  3987. .attr("cursor", cursors[type]);
  3988. if (exports.event.touches) {
  3989. emit.moved = moved;
  3990. emit.ended = ended;
  3991. } else {
  3992. var view = select(exports.event.view)
  3993. .on("mousemove.brush", moved, true)
  3994. .on("mouseup.brush", ended, true);
  3995. if (keys) view
  3996. .on("keydown.brush", keydowned, true)
  3997. .on("keyup.brush", keyupped, true);
  3998. dragDisable(exports.event.view);
  3999. }
  4000. nopropagation$1();
  4001. interrupt(that);
  4002. redraw.call(that);
  4003. emit.start();
  4004. function moved() {
  4005. var point1 = pointer(that);
  4006. if (shifting && !lockX && !lockY) {
  4007. if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
  4008. else lockX = true;
  4009. }
  4010. point = point1;
  4011. moving = true;
  4012. noevent$1();
  4013. move();
  4014. }
  4015. function move() {
  4016. var t;
  4017. dx = point[0] - point0[0];
  4018. dy = point[1] - point0[1];
  4019. switch (mode) {
  4020. case MODE_SPACE:
  4021. case MODE_DRAG: {
  4022. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  4023. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  4024. break;
  4025. }
  4026. case MODE_HANDLE: {
  4027. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  4028. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  4029. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  4030. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  4031. break;
  4032. }
  4033. case MODE_CENTER: {
  4034. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  4035. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  4036. break;
  4037. }
  4038. }
  4039. if (e1 < w1) {
  4040. signX *= -1;
  4041. t = w0, w0 = e0, e0 = t;
  4042. t = w1, w1 = e1, e1 = t;
  4043. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  4044. }
  4045. if (s1 < n1) {
  4046. signY *= -1;
  4047. t = n0, n0 = s0, s0 = t;
  4048. t = n1, n1 = s1, s1 = t;
  4049. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  4050. }
  4051. if (state.selection) selection = state.selection; // May be set by brush.move!
  4052. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  4053. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  4054. if (selection[0][0] !== w1
  4055. || selection[0][1] !== n1
  4056. || selection[1][0] !== e1
  4057. || selection[1][1] !== s1) {
  4058. state.selection = [[w1, n1], [e1, s1]];
  4059. redraw.call(that);
  4060. emit.brush();
  4061. }
  4062. }
  4063. function ended() {
  4064. nopropagation$1();
  4065. if (exports.event.touches) {
  4066. if (exports.event.touches.length) return;
  4067. if (touchending) clearTimeout(touchending);
  4068. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  4069. } else {
  4070. yesdrag(exports.event.view, moving);
  4071. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  4072. }
  4073. group.attr("pointer-events", "all");
  4074. overlay.attr("cursor", cursors.overlay);
  4075. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  4076. if (empty$1(selection)) state.selection = null, redraw.call(that);
  4077. emit.end();
  4078. }
  4079. function keydowned() {
  4080. switch (exports.event.keyCode) {
  4081. case 16: { // SHIFT
  4082. shifting = signX && signY;
  4083. break;
  4084. }
  4085. case 18: { // ALT
  4086. if (mode === MODE_HANDLE) {
  4087. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4088. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4089. mode = MODE_CENTER;
  4090. move();
  4091. }
  4092. break;
  4093. }
  4094. case 32: { // SPACE; takes priority over ALT
  4095. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  4096. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  4097. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  4098. mode = MODE_SPACE;
  4099. overlay.attr("cursor", cursors.selection);
  4100. move();
  4101. }
  4102. break;
  4103. }
  4104. default: return;
  4105. }
  4106. noevent$1();
  4107. }
  4108. function keyupped() {
  4109. switch (exports.event.keyCode) {
  4110. case 16: { // SHIFT
  4111. if (shifting) {
  4112. lockX = lockY = shifting = false;
  4113. move();
  4114. }
  4115. break;
  4116. }
  4117. case 18: { // ALT
  4118. if (mode === MODE_CENTER) {
  4119. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4120. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4121. mode = MODE_HANDLE;
  4122. move();
  4123. }
  4124. break;
  4125. }
  4126. case 32: { // SPACE
  4127. if (mode === MODE_SPACE) {
  4128. if (exports.event.altKey) {
  4129. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4130. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4131. mode = MODE_CENTER;
  4132. } else {
  4133. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4134. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4135. mode = MODE_HANDLE;
  4136. }
  4137. overlay.attr("cursor", cursors[type]);
  4138. move();
  4139. }
  4140. break;
  4141. }
  4142. default: return;
  4143. }
  4144. noevent$1();
  4145. }
  4146. }
  4147. function touchmoved() {
  4148. emitter(this, arguments).moved();
  4149. }
  4150. function touchended() {
  4151. emitter(this, arguments).ended();
  4152. }
  4153. function initialize() {
  4154. var state = this.__brush || {selection: null};
  4155. state.extent = number2(extent.apply(this, arguments));
  4156. state.dim = dim;
  4157. return state;
  4158. }
  4159. brush.extent = function(_) {
  4160. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4(number2(_)), brush) : extent;
  4161. };
  4162. brush.filter = function(_) {
  4163. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  4164. };
  4165. brush.touchable = function(_) {
  4166. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$4(!!_), brush) : touchable;
  4167. };
  4168. brush.handleSize = function(_) {
  4169. return arguments.length ? (handleSize = +_, brush) : handleSize;
  4170. };
  4171. brush.keyModifiers = function(_) {
  4172. return arguments.length ? (keys = !!_, brush) : keys;
  4173. };
  4174. brush.on = function() {
  4175. var value = listeners.on.apply(listeners, arguments);
  4176. return value === listeners ? brush : value;
  4177. };
  4178. return brush;
  4179. }
  4180. var cos = Math.cos;
  4181. var sin = Math.sin;
  4182. var pi$1 = Math.PI;
  4183. var halfPi$1 = pi$1 / 2;
  4184. var tau$1 = pi$1 * 2;
  4185. var max$1 = Math.max;
  4186. function compareValue(compare) {
  4187. return function(a, b) {
  4188. return compare(
  4189. a.source.value + a.target.value,
  4190. b.source.value + b.target.value
  4191. );
  4192. };
  4193. }
  4194. function chord() {
  4195. var padAngle = 0,
  4196. sortGroups = null,
  4197. sortSubgroups = null,
  4198. sortChords = null;
  4199. function chord(matrix) {
  4200. var n = matrix.length,
  4201. groupSums = [],
  4202. groupIndex = sequence(n),
  4203. subgroupIndex = [],
  4204. chords = [],
  4205. groups = chords.groups = new Array(n),
  4206. subgroups = new Array(n * n),
  4207. k,
  4208. x,
  4209. x0,
  4210. dx,
  4211. i,
  4212. j;
  4213. // Compute the sum.
  4214. k = 0, i = -1; while (++i < n) {
  4215. x = 0, j = -1; while (++j < n) {
  4216. x += matrix[i][j];
  4217. }
  4218. groupSums.push(x);
  4219. subgroupIndex.push(sequence(n));
  4220. k += x;
  4221. }
  4222. // Sort groups…
  4223. if (sortGroups) groupIndex.sort(function(a, b) {
  4224. return sortGroups(groupSums[a], groupSums[b]);
  4225. });
  4226. // Sort subgroups…
  4227. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4228. d.sort(function(a, b) {
  4229. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4230. });
  4231. });
  4232. // Convert the sum to scaling factor for [0, 2pi].
  4233. // TODO Allow start and end angle to be specified?
  4234. // TODO Allow padding to be specified as percentage?
  4235. k = max$1(0, tau$1 - padAngle * n) / k;
  4236. dx = k ? padAngle : tau$1 / n;
  4237. // Compute the start and end angle for each group and subgroup.
  4238. // Note: Opera has a bug reordering object literal properties!
  4239. x = 0, i = -1; while (++i < n) {
  4240. x0 = x, j = -1; while (++j < n) {
  4241. var di = groupIndex[i],
  4242. dj = subgroupIndex[di][j],
  4243. v = matrix[di][dj],
  4244. a0 = x,
  4245. a1 = x += v * k;
  4246. subgroups[dj * n + di] = {
  4247. index: di,
  4248. subindex: dj,
  4249. startAngle: a0,
  4250. endAngle: a1,
  4251. value: v
  4252. };
  4253. }
  4254. groups[di] = {
  4255. index: di,
  4256. startAngle: x0,
  4257. endAngle: x,
  4258. value: groupSums[di]
  4259. };
  4260. x += dx;
  4261. }
  4262. // Generate chords for each (non-empty) subgroup-subgroup link.
  4263. i = -1; while (++i < n) {
  4264. j = i - 1; while (++j < n) {
  4265. var source = subgroups[j * n + i],
  4266. target = subgroups[i * n + j];
  4267. if (source.value || target.value) {
  4268. chords.push(source.value < target.value
  4269. ? {source: target, target: source}
  4270. : {source: source, target: target});
  4271. }
  4272. }
  4273. }
  4274. return sortChords ? chords.sort(sortChords) : chords;
  4275. }
  4276. chord.padAngle = function(_) {
  4277. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4278. };
  4279. chord.sortGroups = function(_) {
  4280. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4281. };
  4282. chord.sortSubgroups = function(_) {
  4283. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4284. };
  4285. chord.sortChords = function(_) {
  4286. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4287. };
  4288. return chord;
  4289. }
  4290. var slice$2 = Array.prototype.slice;
  4291. function constant$5(x) {
  4292. return function() {
  4293. return x;
  4294. };
  4295. }
  4296. var pi$2 = Math.PI,
  4297. tau$2 = 2 * pi$2,
  4298. epsilon$1 = 1e-6,
  4299. tauEpsilon = tau$2 - epsilon$1;
  4300. function Path() {
  4301. this._x0 = this._y0 = // start of current subpath
  4302. this._x1 = this._y1 = null; // end of current subpath
  4303. this._ = "";
  4304. }
  4305. function path() {
  4306. return new Path;
  4307. }
  4308. Path.prototype = path.prototype = {
  4309. constructor: Path,
  4310. moveTo: function(x, y) {
  4311. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4312. },
  4313. closePath: function() {
  4314. if (this._x1 !== null) {
  4315. this._x1 = this._x0, this._y1 = this._y0;
  4316. this._ += "Z";
  4317. }
  4318. },
  4319. lineTo: function(x, y) {
  4320. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4321. },
  4322. quadraticCurveTo: function(x1, y1, x, y) {
  4323. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4324. },
  4325. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4326. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4327. },
  4328. arcTo: function(x1, y1, x2, y2, r) {
  4329. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4330. var x0 = this._x1,
  4331. y0 = this._y1,
  4332. x21 = x2 - x1,
  4333. y21 = y2 - y1,
  4334. x01 = x0 - x1,
  4335. y01 = y0 - y1,
  4336. l01_2 = x01 * x01 + y01 * y01;
  4337. // Is the radius negative? Error.
  4338. if (r < 0) throw new Error("negative radius: " + r);
  4339. // Is this path empty? Move to (x1,y1).
  4340. if (this._x1 === null) {
  4341. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4342. }
  4343. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4344. else if (!(l01_2 > epsilon$1));
  4345. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4346. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4347. // Or, is the radius zero? Line to (x1,y1).
  4348. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4349. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4350. }
  4351. // Otherwise, draw an arc!
  4352. else {
  4353. var x20 = x2 - x0,
  4354. y20 = y2 - y0,
  4355. l21_2 = x21 * x21 + y21 * y21,
  4356. l20_2 = x20 * x20 + y20 * y20,
  4357. l21 = Math.sqrt(l21_2),
  4358. l01 = Math.sqrt(l01_2),
  4359. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4360. t01 = l / l01,
  4361. t21 = l / l21;
  4362. // If the start tangent is not coincident with (x0,y0), line to.
  4363. if (Math.abs(t01 - 1) > epsilon$1) {
  4364. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4365. }
  4366. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4367. }
  4368. },
  4369. arc: function(x, y, r, a0, a1, ccw) {
  4370. x = +x, y = +y, r = +r, ccw = !!ccw;
  4371. var dx = r * Math.cos(a0),
  4372. dy = r * Math.sin(a0),
  4373. x0 = x + dx,
  4374. y0 = y + dy,
  4375. cw = 1 ^ ccw,
  4376. da = ccw ? a0 - a1 : a1 - a0;
  4377. // Is the radius negative? Error.
  4378. if (r < 0) throw new Error("negative radius: " + r);
  4379. // Is this path empty? Move to (x0,y0).
  4380. if (this._x1 === null) {
  4381. this._ += "M" + x0 + "," + y0;
  4382. }
  4383. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4384. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4385. this._ += "L" + x0 + "," + y0;
  4386. }
  4387. // Is this arc empty? We’re done.
  4388. if (!r) return;
  4389. // Does the angle go the wrong way? Flip the direction.
  4390. if (da < 0) da = da % tau$2 + tau$2;
  4391. // Is this a complete circle? Draw two arcs to complete the circle.
  4392. if (da > tauEpsilon) {
  4393. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4394. }
  4395. // Is this arc non-empty? Draw an arc!
  4396. else if (da > epsilon$1) {
  4397. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4398. }
  4399. },
  4400. rect: function(x, y, w, h) {
  4401. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4402. },
  4403. toString: function() {
  4404. return this._;
  4405. }
  4406. };
  4407. function defaultSource(d) {
  4408. return d.source;
  4409. }
  4410. function defaultTarget(d) {
  4411. return d.target;
  4412. }
  4413. function defaultRadius(d) {
  4414. return d.radius;
  4415. }
  4416. function defaultStartAngle(d) {
  4417. return d.startAngle;
  4418. }
  4419. function defaultEndAngle(d) {
  4420. return d.endAngle;
  4421. }
  4422. function ribbon() {
  4423. var source = defaultSource,
  4424. target = defaultTarget,
  4425. radius = defaultRadius,
  4426. startAngle = defaultStartAngle,
  4427. endAngle = defaultEndAngle,
  4428. context = null;
  4429. function ribbon() {
  4430. var buffer,
  4431. argv = slice$2.call(arguments),
  4432. s = source.apply(this, argv),
  4433. t = target.apply(this, argv),
  4434. sr = +radius.apply(this, (argv[0] = s, argv)),
  4435. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4436. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4437. sx0 = sr * cos(sa0),
  4438. sy0 = sr * sin(sa0),
  4439. tr = +radius.apply(this, (argv[0] = t, argv)),
  4440. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4441. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4442. if (!context) context = buffer = path();
  4443. context.moveTo(sx0, sy0);
  4444. context.arc(0, 0, sr, sa0, sa1);
  4445. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4446. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4447. context.arc(0, 0, tr, ta0, ta1);
  4448. }
  4449. context.quadraticCurveTo(0, 0, sx0, sy0);
  4450. context.closePath();
  4451. if (buffer) return context = null, buffer + "" || null;
  4452. }
  4453. ribbon.radius = function(_) {
  4454. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4455. };
  4456. ribbon.startAngle = function(_) {
  4457. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4458. };
  4459. ribbon.endAngle = function(_) {
  4460. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4461. };
  4462. ribbon.source = function(_) {
  4463. return arguments.length ? (source = _, ribbon) : source;
  4464. };
  4465. ribbon.target = function(_) {
  4466. return arguments.length ? (target = _, ribbon) : target;
  4467. };
  4468. ribbon.context = function(_) {
  4469. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  4470. };
  4471. return ribbon;
  4472. }
  4473. var prefix = "$";
  4474. function Map() {}
  4475. Map.prototype = map$1.prototype = {
  4476. constructor: Map,
  4477. has: function(key) {
  4478. return (prefix + key) in this;
  4479. },
  4480. get: function(key) {
  4481. return this[prefix + key];
  4482. },
  4483. set: function(key, value) {
  4484. this[prefix + key] = value;
  4485. return this;
  4486. },
  4487. remove: function(key) {
  4488. var property = prefix + key;
  4489. return property in this && delete this[property];
  4490. },
  4491. clear: function() {
  4492. for (var property in this) if (property[0] === prefix) delete this[property];
  4493. },
  4494. keys: function() {
  4495. var keys = [];
  4496. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4497. return keys;
  4498. },
  4499. values: function() {
  4500. var values = [];
  4501. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4502. return values;
  4503. },
  4504. entries: function() {
  4505. var entries = [];
  4506. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4507. return entries;
  4508. },
  4509. size: function() {
  4510. var size = 0;
  4511. for (var property in this) if (property[0] === prefix) ++size;
  4512. return size;
  4513. },
  4514. empty: function() {
  4515. for (var property in this) if (property[0] === prefix) return false;
  4516. return true;
  4517. },
  4518. each: function(f) {
  4519. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4520. }
  4521. };
  4522. function map$1(object, f) {
  4523. var map = new Map;
  4524. // Copy constructor.
  4525. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4526. // Index array by numeric index or specified key function.
  4527. else if (Array.isArray(object)) {
  4528. var i = -1,
  4529. n = object.length,
  4530. o;
  4531. if (f == null) while (++i < n) map.set(i, object[i]);
  4532. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4533. }
  4534. // Convert object to map.
  4535. else if (object) for (var key in object) map.set(key, object[key]);
  4536. return map;
  4537. }
  4538. function nest() {
  4539. var keys = [],
  4540. sortKeys = [],
  4541. sortValues,
  4542. rollup,
  4543. nest;
  4544. function apply(array, depth, createResult, setResult) {
  4545. if (depth >= keys.length) {
  4546. if (sortValues != null) array.sort(sortValues);
  4547. return rollup != null ? rollup(array) : array;
  4548. }
  4549. var i = -1,
  4550. n = array.length,
  4551. key = keys[depth++],
  4552. keyValue,
  4553. value,
  4554. valuesByKey = map$1(),
  4555. values,
  4556. result = createResult();
  4557. while (++i < n) {
  4558. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4559. values.push(value);
  4560. } else {
  4561. valuesByKey.set(keyValue, [value]);
  4562. }
  4563. }
  4564. valuesByKey.each(function(values, key) {
  4565. setResult(result, key, apply(values, depth, createResult, setResult));
  4566. });
  4567. return result;
  4568. }
  4569. function entries(map, depth) {
  4570. if (++depth > keys.length) return map;
  4571. var array, sortKey = sortKeys[depth - 1];
  4572. if (rollup != null && depth >= keys.length) array = map.entries();
  4573. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4574. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4575. }
  4576. return nest = {
  4577. object: function(array) { return apply(array, 0, createObject, setObject); },
  4578. map: function(array) { return apply(array, 0, createMap, setMap); },
  4579. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4580. key: function(d) { keys.push(d); return nest; },
  4581. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4582. sortValues: function(order) { sortValues = order; return nest; },
  4583. rollup: function(f) { rollup = f; return nest; }
  4584. };
  4585. }
  4586. function createObject() {
  4587. return {};
  4588. }
  4589. function setObject(object, key, value) {
  4590. object[key] = value;
  4591. }
  4592. function createMap() {
  4593. return map$1();
  4594. }
  4595. function setMap(map, key, value) {
  4596. map.set(key, value);
  4597. }
  4598. function Set() {}
  4599. var proto = map$1.prototype;
  4600. Set.prototype = set$2.prototype = {
  4601. constructor: Set,
  4602. has: proto.has,
  4603. add: function(value) {
  4604. value += "";
  4605. this[prefix + value] = value;
  4606. return this;
  4607. },
  4608. remove: proto.remove,
  4609. clear: proto.clear,
  4610. values: proto.keys,
  4611. size: proto.size,
  4612. empty: proto.empty,
  4613. each: proto.each
  4614. };
  4615. function set$2(object, f) {
  4616. var set = new Set;
  4617. // Copy constructor.
  4618. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4619. // Otherwise, assume it’s an array.
  4620. else if (object) {
  4621. var i = -1, n = object.length;
  4622. if (f == null) while (++i < n) set.add(object[i]);
  4623. else while (++i < n) set.add(f(object[i], i, object));
  4624. }
  4625. return set;
  4626. }
  4627. function keys(map) {
  4628. var keys = [];
  4629. for (var key in map) keys.push(key);
  4630. return keys;
  4631. }
  4632. function values(map) {
  4633. var values = [];
  4634. for (var key in map) values.push(map[key]);
  4635. return values;
  4636. }
  4637. function entries(map) {
  4638. var entries = [];
  4639. for (var key in map) entries.push({key: key, value: map[key]});
  4640. return entries;
  4641. }
  4642. var array$2 = Array.prototype;
  4643. var slice$3 = array$2.slice;
  4644. function ascending$2(a, b) {
  4645. return a - b;
  4646. }
  4647. function area(ring) {
  4648. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  4649. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  4650. return area;
  4651. }
  4652. function constant$6(x) {
  4653. return function() {
  4654. return x;
  4655. };
  4656. }
  4657. function contains(ring, hole) {
  4658. var i = -1, n = hole.length, c;
  4659. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  4660. return 0;
  4661. }
  4662. function ringContains(ring, point) {
  4663. var x = point[0], y = point[1], contains = -1;
  4664. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  4665. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  4666. if (segmentContains(pi, pj, point)) return 0;
  4667. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  4668. }
  4669. return contains;
  4670. }
  4671. function segmentContains(a, b, c) {
  4672. var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  4673. }
  4674. function collinear(a, b, c) {
  4675. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  4676. }
  4677. function within(p, q, r) {
  4678. return p <= q && q <= r || r <= q && q <= p;
  4679. }
  4680. function noop$1() {}
  4681. var cases = [
  4682. [],
  4683. [[[1.0, 1.5], [0.5, 1.0]]],
  4684. [[[1.5, 1.0], [1.0, 1.5]]],
  4685. [[[1.5, 1.0], [0.5, 1.0]]],
  4686. [[[1.0, 0.5], [1.5, 1.0]]],
  4687. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  4688. [[[1.0, 0.5], [1.0, 1.5]]],
  4689. [[[1.0, 0.5], [0.5, 1.0]]],
  4690. [[[0.5, 1.0], [1.0, 0.5]]],
  4691. [[[1.0, 1.5], [1.0, 0.5]]],
  4692. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  4693. [[[1.5, 1.0], [1.0, 0.5]]],
  4694. [[[0.5, 1.0], [1.5, 1.0]]],
  4695. [[[1.0, 1.5], [1.5, 1.0]]],
  4696. [[[0.5, 1.0], [1.0, 1.5]]],
  4697. []
  4698. ];
  4699. function contours() {
  4700. var dx = 1,
  4701. dy = 1,
  4702. threshold = thresholdSturges,
  4703. smooth = smoothLinear;
  4704. function contours(values) {
  4705. var tz = threshold(values);
  4706. // Convert number of thresholds into uniform thresholds.
  4707. if (!Array.isArray(tz)) {
  4708. var domain = extent(values), start = domain[0], stop = domain[1];
  4709. tz = tickStep(start, stop, tz);
  4710. tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
  4711. } else {
  4712. tz = tz.slice().sort(ascending$2);
  4713. }
  4714. return tz.map(function(value) {
  4715. return contour(values, value);
  4716. });
  4717. }
  4718. // Accumulate, smooth contour rings, assign holes to exterior rings.
  4719. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  4720. function contour(values, value) {
  4721. var polygons = [],
  4722. holes = [];
  4723. isorings(values, value, function(ring) {
  4724. smooth(ring, values, value);
  4725. if (area(ring) > 0) polygons.push([ring]);
  4726. else holes.push(ring);
  4727. });
  4728. holes.forEach(function(hole) {
  4729. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  4730. if (contains((polygon = polygons[i])[0], hole) !== -1) {
  4731. polygon.push(hole);
  4732. return;
  4733. }
  4734. }
  4735. });
  4736. return {
  4737. type: "MultiPolygon",
  4738. value: value,
  4739. coordinates: polygons
  4740. };
  4741. }
  4742. // Marching squares with isolines stitched into rings.
  4743. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  4744. function isorings(values, value, callback) {
  4745. var fragmentByStart = new Array,
  4746. fragmentByEnd = new Array,
  4747. x, y, t0, t1, t2, t3;
  4748. // Special case for the first row (y = -1, t2 = t3 = 0).
  4749. x = y = -1;
  4750. t1 = values[0] >= value;
  4751. cases[t1 << 1].forEach(stitch);
  4752. while (++x < dx - 1) {
  4753. t0 = t1, t1 = values[x + 1] >= value;
  4754. cases[t0 | t1 << 1].forEach(stitch);
  4755. }
  4756. cases[t1 << 0].forEach(stitch);
  4757. // General case for the intermediate rows.
  4758. while (++y < dy - 1) {
  4759. x = -1;
  4760. t1 = values[y * dx + dx] >= value;
  4761. t2 = values[y * dx] >= value;
  4762. cases[t1 << 1 | t2 << 2].forEach(stitch);
  4763. while (++x < dx - 1) {
  4764. t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
  4765. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4766. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  4767. }
  4768. cases[t1 | t2 << 3].forEach(stitch);
  4769. }
  4770. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  4771. x = -1;
  4772. t2 = values[y * dx] >= value;
  4773. cases[t2 << 2].forEach(stitch);
  4774. while (++x < dx - 1) {
  4775. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4776. cases[t2 << 2 | t3 << 3].forEach(stitch);
  4777. }
  4778. cases[t2 << 3].forEach(stitch);
  4779. function stitch(line) {
  4780. var start = [line[0][0] + x, line[0][1] + y],
  4781. end = [line[1][0] + x, line[1][1] + y],
  4782. startIndex = index(start),
  4783. endIndex = index(end),
  4784. f, g;
  4785. if (f = fragmentByEnd[startIndex]) {
  4786. if (g = fragmentByStart[endIndex]) {
  4787. delete fragmentByEnd[f.end];
  4788. delete fragmentByStart[g.start];
  4789. if (f === g) {
  4790. f.ring.push(end);
  4791. callback(f.ring);
  4792. } else {
  4793. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  4794. }
  4795. } else {
  4796. delete fragmentByEnd[f.end];
  4797. f.ring.push(end);
  4798. fragmentByEnd[f.end = endIndex] = f;
  4799. }
  4800. } else if (f = fragmentByStart[endIndex]) {
  4801. if (g = fragmentByEnd[startIndex]) {
  4802. delete fragmentByStart[f.start];
  4803. delete fragmentByEnd[g.end];
  4804. if (f === g) {
  4805. f.ring.push(end);
  4806. callback(f.ring);
  4807. } else {
  4808. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  4809. }
  4810. } else {
  4811. delete fragmentByStart[f.start];
  4812. f.ring.unshift(start);
  4813. fragmentByStart[f.start = startIndex] = f;
  4814. }
  4815. } else {
  4816. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  4817. }
  4818. }
  4819. }
  4820. function index(point) {
  4821. return point[0] * 2 + point[1] * (dx + 1) * 4;
  4822. }
  4823. function smoothLinear(ring, values, value) {
  4824. ring.forEach(function(point) {
  4825. var x = point[0],
  4826. y = point[1],
  4827. xt = x | 0,
  4828. yt = y | 0,
  4829. v0,
  4830. v1 = values[yt * dx + xt];
  4831. if (x > 0 && x < dx && xt === x) {
  4832. v0 = values[yt * dx + xt - 1];
  4833. point[0] = x + (value - v0) / (v1 - v0) - 0.5;
  4834. }
  4835. if (y > 0 && y < dy && yt === y) {
  4836. v0 = values[(yt - 1) * dx + xt];
  4837. point[1] = y + (value - v0) / (v1 - v0) - 0.5;
  4838. }
  4839. });
  4840. }
  4841. contours.contour = contour;
  4842. contours.size = function(_) {
  4843. if (!arguments.length) return [dx, dy];
  4844. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4845. if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
  4846. return dx = _0, dy = _1, contours;
  4847. };
  4848. contours.thresholds = function(_) {
  4849. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold;
  4850. };
  4851. contours.smooth = function(_) {
  4852. return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
  4853. };
  4854. return contours;
  4855. }
  4856. // TODO Optimize edge cases.
  4857. // TODO Optimize index calculation.
  4858. // TODO Optimize arguments.
  4859. function blurX(source, target, r) {
  4860. var n = source.width,
  4861. m = source.height,
  4862. w = (r << 1) + 1;
  4863. for (var j = 0; j < m; ++j) {
  4864. for (var i = 0, sr = 0; i < n + r; ++i) {
  4865. if (i < n) {
  4866. sr += source.data[i + j * n];
  4867. }
  4868. if (i >= r) {
  4869. if (i >= w) {
  4870. sr -= source.data[i - w + j * n];
  4871. }
  4872. target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
  4873. }
  4874. }
  4875. }
  4876. }
  4877. // TODO Optimize edge cases.
  4878. // TODO Optimize index calculation.
  4879. // TODO Optimize arguments.
  4880. function blurY(source, target, r) {
  4881. var n = source.width,
  4882. m = source.height,
  4883. w = (r << 1) + 1;
  4884. for (var i = 0; i < n; ++i) {
  4885. for (var j = 0, sr = 0; j < m + r; ++j) {
  4886. if (j < m) {
  4887. sr += source.data[i + j * n];
  4888. }
  4889. if (j >= r) {
  4890. if (j >= w) {
  4891. sr -= source.data[i + (j - w) * n];
  4892. }
  4893. target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
  4894. }
  4895. }
  4896. }
  4897. }
  4898. function defaultX(d) {
  4899. return d[0];
  4900. }
  4901. function defaultY(d) {
  4902. return d[1];
  4903. }
  4904. function defaultWeight() {
  4905. return 1;
  4906. }
  4907. function density() {
  4908. var x = defaultX,
  4909. y = defaultY,
  4910. weight = defaultWeight,
  4911. dx = 960,
  4912. dy = 500,
  4913. r = 20, // blur radius
  4914. k = 2, // log2(grid cell size)
  4915. o = r * 3, // grid offset, to pad for blur
  4916. n = (dx + o * 2) >> k, // grid width
  4917. m = (dy + o * 2) >> k, // grid height
  4918. threshold = constant$6(20);
  4919. function density(data) {
  4920. var values0 = new Float32Array(n * m),
  4921. values1 = new Float32Array(n * m);
  4922. data.forEach(function(d, i, data) {
  4923. var xi = (+x(d, i, data) + o) >> k,
  4924. yi = (+y(d, i, data) + o) >> k,
  4925. wi = +weight(d, i, data);
  4926. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  4927. values0[xi + yi * n] += wi;
  4928. }
  4929. });
  4930. // TODO Optimize.
  4931. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4932. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4933. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4934. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4935. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4936. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4937. var tz = threshold(values0);
  4938. // Convert number of thresholds into uniform thresholds.
  4939. if (!Array.isArray(tz)) {
  4940. var stop = max(values0);
  4941. tz = tickStep(0, stop, tz);
  4942. tz = sequence(0, Math.floor(stop / tz) * tz, tz);
  4943. tz.shift();
  4944. }
  4945. return contours()
  4946. .thresholds(tz)
  4947. .size([n, m])
  4948. (values0)
  4949. .map(transform);
  4950. }
  4951. function transform(geometry) {
  4952. geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
  4953. geometry.coordinates.forEach(transformPolygon);
  4954. return geometry;
  4955. }
  4956. function transformPolygon(coordinates) {
  4957. coordinates.forEach(transformRing);
  4958. }
  4959. function transformRing(coordinates) {
  4960. coordinates.forEach(transformPoint);
  4961. }
  4962. // TODO Optimize.
  4963. function transformPoint(coordinates) {
  4964. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  4965. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  4966. }
  4967. function resize() {
  4968. o = r * 3;
  4969. n = (dx + o * 2) >> k;
  4970. m = (dy + o * 2) >> k;
  4971. return density;
  4972. }
  4973. density.x = function(_) {
  4974. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
  4975. };
  4976. density.y = function(_) {
  4977. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
  4978. };
  4979. density.weight = function(_) {
  4980. return arguments.length ? (weight = typeof _ === "function" ? _ : constant$6(+_), density) : weight;
  4981. };
  4982. density.size = function(_) {
  4983. if (!arguments.length) return [dx, dy];
  4984. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4985. if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
  4986. return dx = _0, dy = _1, resize();
  4987. };
  4988. density.cellSize = function(_) {
  4989. if (!arguments.length) return 1 << k;
  4990. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  4991. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  4992. };
  4993. density.thresholds = function(_) {
  4994. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold;
  4995. };
  4996. density.bandwidth = function(_) {
  4997. if (!arguments.length) return Math.sqrt(r * (r + 1));
  4998. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  4999. return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
  5000. };
  5001. return density;
  5002. }
  5003. var EOL = {},
  5004. EOF = {},
  5005. QUOTE = 34,
  5006. NEWLINE = 10,
  5007. RETURN = 13;
  5008. function objectConverter(columns) {
  5009. return new Function("d", "return {" + columns.map(function(name, i) {
  5010. return JSON.stringify(name) + ": d[" + i + "] || \"\"";
  5011. }).join(",") + "}");
  5012. }
  5013. function customConverter(columns, f) {
  5014. var object = objectConverter(columns);
  5015. return function(row, i) {
  5016. return f(object(row), i, columns);
  5017. };
  5018. }
  5019. // Compute unique columns in order of discovery.
  5020. function inferColumns(rows) {
  5021. var columnSet = Object.create(null),
  5022. columns = [];
  5023. rows.forEach(function(row) {
  5024. for (var column in row) {
  5025. if (!(column in columnSet)) {
  5026. columns.push(columnSet[column] = column);
  5027. }
  5028. }
  5029. });
  5030. return columns;
  5031. }
  5032. function pad(value, width) {
  5033. var s = value + "", length = s.length;
  5034. return length < width ? new Array(width - length + 1).join(0) + s : s;
  5035. }
  5036. function formatYear(year) {
  5037. return year < 0 ? "-" + pad(-year, 6)
  5038. : year > 9999 ? "+" + pad(year, 6)
  5039. : pad(year, 4);
  5040. }
  5041. function formatDate(date) {
  5042. var hours = date.getUTCHours(),
  5043. minutes = date.getUTCMinutes(),
  5044. seconds = date.getUTCSeconds(),
  5045. milliseconds = date.getUTCMilliseconds();
  5046. return isNaN(date) ? "Invalid Date"
  5047. : formatYear(date.getUTCFullYear()) + "-" + pad(date.getUTCMonth() + 1, 2) + "-" + pad(date.getUTCDate(), 2)
  5048. + (milliseconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "." + pad(milliseconds, 3) + "Z"
  5049. : seconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "Z"
  5050. : minutes || hours ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + "Z"
  5051. : "");
  5052. }
  5053. function dsvFormat(delimiter) {
  5054. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  5055. DELIMITER = delimiter.charCodeAt(0);
  5056. function parse(text, f) {
  5057. var convert, columns, rows = parseRows(text, function(row, i) {
  5058. if (convert) return convert(row, i - 1);
  5059. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  5060. });
  5061. rows.columns = columns || [];
  5062. return rows;
  5063. }
  5064. function parseRows(text, f) {
  5065. var rows = [], // output rows
  5066. N = text.length,
  5067. I = 0, // current character index
  5068. n = 0, // current line number
  5069. t, // current token
  5070. eof = N <= 0, // current token followed by EOF?
  5071. eol = false; // current token followed by EOL?
  5072. // Strip the trailing newline.
  5073. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  5074. if (text.charCodeAt(N - 1) === RETURN) --N;
  5075. function token() {
  5076. if (eof) return EOF;
  5077. if (eol) return eol = false, EOL;
  5078. // Unescape quotes.
  5079. var i, j = I, c;
  5080. if (text.charCodeAt(j) === QUOTE) {
  5081. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  5082. if ((i = I) >= N) eof = true;
  5083. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  5084. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  5085. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  5086. }
  5087. // Find next delimiter or newline.
  5088. while (I < N) {
  5089. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  5090. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  5091. else if (c !== DELIMITER) continue;
  5092. return text.slice(j, i);
  5093. }
  5094. // Return last token before EOF.
  5095. return eof = true, text.slice(j, N);
  5096. }
  5097. while ((t = token()) !== EOF) {
  5098. var row = [];
  5099. while (t !== EOL && t !== EOF) row.push(t), t = token();
  5100. if (f && (row = f(row, n++)) == null) continue;
  5101. rows.push(row);
  5102. }
  5103. return rows;
  5104. }
  5105. function preformatBody(rows, columns) {
  5106. return rows.map(function(row) {
  5107. return columns.map(function(column) {
  5108. return formatValue(row[column]);
  5109. }).join(delimiter);
  5110. });
  5111. }
  5112. function format(rows, columns) {
  5113. if (columns == null) columns = inferColumns(rows);
  5114. return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
  5115. }
  5116. function formatBody(rows, columns) {
  5117. if (columns == null) columns = inferColumns(rows);
  5118. return preformatBody(rows, columns).join("\n");
  5119. }
  5120. function formatRows(rows) {
  5121. return rows.map(formatRow).join("\n");
  5122. }
  5123. function formatRow(row) {
  5124. return row.map(formatValue).join(delimiter);
  5125. }
  5126. function formatValue(value) {
  5127. return value == null ? ""
  5128. : value instanceof Date ? formatDate(value)
  5129. : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
  5130. : value;
  5131. }
  5132. return {
  5133. parse: parse,
  5134. parseRows: parseRows,
  5135. format: format,
  5136. formatBody: formatBody,
  5137. formatRows: formatRows,
  5138. formatRow: formatRow,
  5139. formatValue: formatValue
  5140. };
  5141. }
  5142. var csv = dsvFormat(",");
  5143. var csvParse = csv.parse;
  5144. var csvParseRows = csv.parseRows;
  5145. var csvFormat = csv.format;
  5146. var csvFormatBody = csv.formatBody;
  5147. var csvFormatRows = csv.formatRows;
  5148. var csvFormatRow = csv.formatRow;
  5149. var csvFormatValue = csv.formatValue;
  5150. var tsv = dsvFormat("\t");
  5151. var tsvParse = tsv.parse;
  5152. var tsvParseRows = tsv.parseRows;
  5153. var tsvFormat = tsv.format;
  5154. var tsvFormatBody = tsv.formatBody;
  5155. var tsvFormatRows = tsv.formatRows;
  5156. var tsvFormatRow = tsv.formatRow;
  5157. var tsvFormatValue = tsv.formatValue;
  5158. function autoType(object) {
  5159. for (var key in object) {
  5160. var value = object[key].trim(), number, m;
  5161. if (!value) value = null;
  5162. else if (value === "true") value = true;
  5163. else if (value === "false") value = false;
  5164. else if (value === "NaN") value = NaN;
  5165. else if (!isNaN(number = +value)) value = number;
  5166. 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})?)?$/)) {
  5167. if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
  5168. value = new Date(value);
  5169. }
  5170. else continue;
  5171. object[key] = value;
  5172. }
  5173. return object;
  5174. }
  5175. // https://github.com/d3/d3-dsv/issues/45
  5176. var fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
  5177. function responseBlob(response) {
  5178. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5179. return response.blob();
  5180. }
  5181. function blob(input, init) {
  5182. return fetch(input, init).then(responseBlob);
  5183. }
  5184. function responseArrayBuffer(response) {
  5185. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5186. return response.arrayBuffer();
  5187. }
  5188. function buffer(input, init) {
  5189. return fetch(input, init).then(responseArrayBuffer);
  5190. }
  5191. function responseText(response) {
  5192. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5193. return response.text();
  5194. }
  5195. function text(input, init) {
  5196. return fetch(input, init).then(responseText);
  5197. }
  5198. function dsvParse(parse) {
  5199. return function(input, init, row) {
  5200. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  5201. return text(input, init).then(function(response) {
  5202. return parse(response, row);
  5203. });
  5204. };
  5205. }
  5206. function dsv(delimiter, input, init, row) {
  5207. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  5208. var format = dsvFormat(delimiter);
  5209. return text(input, init).then(function(response) {
  5210. return format.parse(response, row);
  5211. });
  5212. }
  5213. var csv$1 = dsvParse(csvParse);
  5214. var tsv$1 = dsvParse(tsvParse);
  5215. function image(input, init) {
  5216. return new Promise(function(resolve, reject) {
  5217. var image = new Image;
  5218. for (var key in init) image[key] = init[key];
  5219. image.onerror = reject;
  5220. image.onload = function() { resolve(image); };
  5221. image.src = input;
  5222. });
  5223. }
  5224. function responseJson(response) {
  5225. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5226. return response.json();
  5227. }
  5228. function json(input, init) {
  5229. return fetch(input, init).then(responseJson);
  5230. }
  5231. function parser(type) {
  5232. return function(input, init) {
  5233. return text(input, init).then(function(text) {
  5234. return (new DOMParser).parseFromString(text, type);
  5235. });
  5236. };
  5237. }
  5238. var xml = parser("application/xml");
  5239. var html = parser("text/html");
  5240. var svg = parser("image/svg+xml");
  5241. function center$1(x, y) {
  5242. var nodes;
  5243. if (x == null) x = 0;
  5244. if (y == null) y = 0;
  5245. function force() {
  5246. var i,
  5247. n = nodes.length,
  5248. node,
  5249. sx = 0,
  5250. sy = 0;
  5251. for (i = 0; i < n; ++i) {
  5252. node = nodes[i], sx += node.x, sy += node.y;
  5253. }
  5254. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  5255. node = nodes[i], node.x -= sx, node.y -= sy;
  5256. }
  5257. }
  5258. force.initialize = function(_) {
  5259. nodes = _;
  5260. };
  5261. force.x = function(_) {
  5262. return arguments.length ? (x = +_, force) : x;
  5263. };
  5264. force.y = function(_) {
  5265. return arguments.length ? (y = +_, force) : y;
  5266. };
  5267. return force;
  5268. }
  5269. function constant$7(x) {
  5270. return function() {
  5271. return x;
  5272. };
  5273. }
  5274. function jiggle() {
  5275. return (Math.random() - 0.5) * 1e-6;
  5276. }
  5277. function tree_add(d) {
  5278. var x = +this._x.call(null, d),
  5279. y = +this._y.call(null, d);
  5280. return add(this.cover(x, y), x, y, d);
  5281. }
  5282. function add(tree, x, y, d) {
  5283. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  5284. var parent,
  5285. node = tree._root,
  5286. leaf = {data: d},
  5287. x0 = tree._x0,
  5288. y0 = tree._y0,
  5289. x1 = tree._x1,
  5290. y1 = tree._y1,
  5291. xm,
  5292. ym,
  5293. xp,
  5294. yp,
  5295. right,
  5296. bottom,
  5297. i,
  5298. j;
  5299. // If the tree is empty, initialize the root as a leaf.
  5300. if (!node) return tree._root = leaf, tree;
  5301. // Find the existing leaf for the new point, or add it.
  5302. while (node.length) {
  5303. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5304. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5305. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  5306. }
  5307. // Is the new point is exactly coincident with the existing point?
  5308. xp = +tree._x.call(null, node.data);
  5309. yp = +tree._y.call(null, node.data);
  5310. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  5311. // Otherwise, split the leaf node until the old and new point are separated.
  5312. do {
  5313. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  5314. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5315. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5316. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  5317. return parent[j] = node, parent[i] = leaf, tree;
  5318. }
  5319. function addAll(data) {
  5320. var d, i, n = data.length,
  5321. x,
  5322. y,
  5323. xz = new Array(n),
  5324. yz = new Array(n),
  5325. x0 = Infinity,
  5326. y0 = Infinity,
  5327. x1 = -Infinity,
  5328. y1 = -Infinity;
  5329. // Compute the points and their extent.
  5330. for (i = 0; i < n; ++i) {
  5331. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  5332. xz[i] = x;
  5333. yz[i] = y;
  5334. if (x < x0) x0 = x;
  5335. if (x > x1) x1 = x;
  5336. if (y < y0) y0 = y;
  5337. if (y > y1) y1 = y;
  5338. }
  5339. // If there were no (valid) points, abort.
  5340. if (x0 > x1 || y0 > y1) return this;
  5341. // Expand the tree to cover the new points.
  5342. this.cover(x0, y0).cover(x1, y1);
  5343. // Add the new points.
  5344. for (i = 0; i < n; ++i) {
  5345. add(this, xz[i], yz[i], data[i]);
  5346. }
  5347. return this;
  5348. }
  5349. function tree_cover(x, y) {
  5350. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  5351. var x0 = this._x0,
  5352. y0 = this._y0,
  5353. x1 = this._x1,
  5354. y1 = this._y1;
  5355. // If the quadtree has no extent, initialize them.
  5356. // Integer extent are necessary so that if we later double the extent,
  5357. // the existing quadrant boundaries don’t change due to floating point error!
  5358. if (isNaN(x0)) {
  5359. x1 = (x0 = Math.floor(x)) + 1;
  5360. y1 = (y0 = Math.floor(y)) + 1;
  5361. }
  5362. // Otherwise, double repeatedly to cover.
  5363. else {
  5364. var z = x1 - x0,
  5365. node = this._root,
  5366. parent,
  5367. i;
  5368. while (x0 > x || x >= x1 || y0 > y || y >= y1) {
  5369. i = (y < y0) << 1 | (x < x0);
  5370. parent = new Array(4), parent[i] = node, node = parent, z *= 2;
  5371. switch (i) {
  5372. case 0: x1 = x0 + z, y1 = y0 + z; break;
  5373. case 1: x0 = x1 - z, y1 = y0 + z; break;
  5374. case 2: x1 = x0 + z, y0 = y1 - z; break;
  5375. case 3: x0 = x1 - z, y0 = y1 - z; break;
  5376. }
  5377. }
  5378. if (this._root && this._root.length) this._root = node;
  5379. }
  5380. this._x0 = x0;
  5381. this._y0 = y0;
  5382. this._x1 = x1;
  5383. this._y1 = y1;
  5384. return this;
  5385. }
  5386. function tree_data() {
  5387. var data = [];
  5388. this.visit(function(node) {
  5389. if (!node.length) do data.push(node.data); while (node = node.next)
  5390. });
  5391. return data;
  5392. }
  5393. function tree_extent(_) {
  5394. return arguments.length
  5395. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  5396. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  5397. }
  5398. function Quad(node, x0, y0, x1, y1) {
  5399. this.node = node;
  5400. this.x0 = x0;
  5401. this.y0 = y0;
  5402. this.x1 = x1;
  5403. this.y1 = y1;
  5404. }
  5405. function tree_find(x, y, radius) {
  5406. var data,
  5407. x0 = this._x0,
  5408. y0 = this._y0,
  5409. x1,
  5410. y1,
  5411. x2,
  5412. y2,
  5413. x3 = this._x1,
  5414. y3 = this._y1,
  5415. quads = [],
  5416. node = this._root,
  5417. q,
  5418. i;
  5419. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  5420. if (radius == null) radius = Infinity;
  5421. else {
  5422. x0 = x - radius, y0 = y - radius;
  5423. x3 = x + radius, y3 = y + radius;
  5424. radius *= radius;
  5425. }
  5426. while (q = quads.pop()) {
  5427. // Stop searching if this quadrant can’t contain a closer node.
  5428. if (!(node = q.node)
  5429. || (x1 = q.x0) > x3
  5430. || (y1 = q.y0) > y3
  5431. || (x2 = q.x1) < x0
  5432. || (y2 = q.y1) < y0) continue;
  5433. // Bisect the current quadrant.
  5434. if (node.length) {
  5435. var xm = (x1 + x2) / 2,
  5436. ym = (y1 + y2) / 2;
  5437. quads.push(
  5438. new Quad(node[3], xm, ym, x2, y2),
  5439. new Quad(node[2], x1, ym, xm, y2),
  5440. new Quad(node[1], xm, y1, x2, ym),
  5441. new Quad(node[0], x1, y1, xm, ym)
  5442. );
  5443. // Visit the closest quadrant first.
  5444. if (i = (y >= ym) << 1 | (x >= xm)) {
  5445. q = quads[quads.length - 1];
  5446. quads[quads.length - 1] = quads[quads.length - 1 - i];
  5447. quads[quads.length - 1 - i] = q;
  5448. }
  5449. }
  5450. // Visit this point. (Visiting coincident points isn’t necessary!)
  5451. else {
  5452. var dx = x - +this._x.call(null, node.data),
  5453. dy = y - +this._y.call(null, node.data),
  5454. d2 = dx * dx + dy * dy;
  5455. if (d2 < radius) {
  5456. var d = Math.sqrt(radius = d2);
  5457. x0 = x - d, y0 = y - d;
  5458. x3 = x + d, y3 = y + d;
  5459. data = node.data;
  5460. }
  5461. }
  5462. }
  5463. return data;
  5464. }
  5465. function tree_remove(d) {
  5466. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  5467. var parent,
  5468. node = this._root,
  5469. retainer,
  5470. previous,
  5471. next,
  5472. x0 = this._x0,
  5473. y0 = this._y0,
  5474. x1 = this._x1,
  5475. y1 = this._y1,
  5476. x,
  5477. y,
  5478. xm,
  5479. ym,
  5480. right,
  5481. bottom,
  5482. i,
  5483. j;
  5484. // If the tree is empty, initialize the root as a leaf.
  5485. if (!node) return this;
  5486. // Find the leaf node for the point.
  5487. // While descending, also retain the deepest parent with a non-removed sibling.
  5488. if (node.length) while (true) {
  5489. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5490. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5491. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  5492. if (!node.length) break;
  5493. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  5494. }
  5495. // Find the point to remove.
  5496. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  5497. if (next = node.next) delete node.next;
  5498. // If there are multiple coincident points, remove just the point.
  5499. if (previous) return (next ? previous.next = next : delete previous.next), this;
  5500. // If this is the root point, remove it.
  5501. if (!parent) return this._root = next, this;
  5502. // Remove this leaf.
  5503. next ? parent[i] = next : delete parent[i];
  5504. // If the parent now contains exactly one leaf, collapse superfluous parents.
  5505. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  5506. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  5507. && !node.length) {
  5508. if (retainer) retainer[j] = node;
  5509. else this._root = node;
  5510. }
  5511. return this;
  5512. }
  5513. function removeAll(data) {
  5514. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  5515. return this;
  5516. }
  5517. function tree_root() {
  5518. return this._root;
  5519. }
  5520. function tree_size() {
  5521. var size = 0;
  5522. this.visit(function(node) {
  5523. if (!node.length) do ++size; while (node = node.next)
  5524. });
  5525. return size;
  5526. }
  5527. function tree_visit(callback) {
  5528. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  5529. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  5530. while (q = quads.pop()) {
  5531. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  5532. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5533. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5534. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5535. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5536. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5537. }
  5538. }
  5539. return this;
  5540. }
  5541. function tree_visitAfter(callback) {
  5542. var quads = [], next = [], q;
  5543. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  5544. while (q = quads.pop()) {
  5545. var node = q.node;
  5546. if (node.length) {
  5547. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5548. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5549. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5550. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5551. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5552. }
  5553. next.push(q);
  5554. }
  5555. while (q = next.pop()) {
  5556. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  5557. }
  5558. return this;
  5559. }
  5560. function defaultX$1(d) {
  5561. return d[0];
  5562. }
  5563. function tree_x(_) {
  5564. return arguments.length ? (this._x = _, this) : this._x;
  5565. }
  5566. function defaultY$1(d) {
  5567. return d[1];
  5568. }
  5569. function tree_y(_) {
  5570. return arguments.length ? (this._y = _, this) : this._y;
  5571. }
  5572. function quadtree(nodes, x, y) {
  5573. var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
  5574. return nodes == null ? tree : tree.addAll(nodes);
  5575. }
  5576. function Quadtree(x, y, x0, y0, x1, y1) {
  5577. this._x = x;
  5578. this._y = y;
  5579. this._x0 = x0;
  5580. this._y0 = y0;
  5581. this._x1 = x1;
  5582. this._y1 = y1;
  5583. this._root = undefined;
  5584. }
  5585. function leaf_copy(leaf) {
  5586. var copy = {data: leaf.data}, next = copy;
  5587. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  5588. return copy;
  5589. }
  5590. var treeProto = quadtree.prototype = Quadtree.prototype;
  5591. treeProto.copy = function() {
  5592. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  5593. node = this._root,
  5594. nodes,
  5595. child;
  5596. if (!node) return copy;
  5597. if (!node.length) return copy._root = leaf_copy(node), copy;
  5598. nodes = [{source: node, target: copy._root = new Array(4)}];
  5599. while (node = nodes.pop()) {
  5600. for (var i = 0; i < 4; ++i) {
  5601. if (child = node.source[i]) {
  5602. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  5603. else node.target[i] = leaf_copy(child);
  5604. }
  5605. }
  5606. }
  5607. return copy;
  5608. };
  5609. treeProto.add = tree_add;
  5610. treeProto.addAll = addAll;
  5611. treeProto.cover = tree_cover;
  5612. treeProto.data = tree_data;
  5613. treeProto.extent = tree_extent;
  5614. treeProto.find = tree_find;
  5615. treeProto.remove = tree_remove;
  5616. treeProto.removeAll = removeAll;
  5617. treeProto.root = tree_root;
  5618. treeProto.size = tree_size;
  5619. treeProto.visit = tree_visit;
  5620. treeProto.visitAfter = tree_visitAfter;
  5621. treeProto.x = tree_x;
  5622. treeProto.y = tree_y;
  5623. function x(d) {
  5624. return d.x + d.vx;
  5625. }
  5626. function y(d) {
  5627. return d.y + d.vy;
  5628. }
  5629. function collide(radius) {
  5630. var nodes,
  5631. radii,
  5632. strength = 1,
  5633. iterations = 1;
  5634. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  5635. function force() {
  5636. var i, n = nodes.length,
  5637. tree,
  5638. node,
  5639. xi,
  5640. yi,
  5641. ri,
  5642. ri2;
  5643. for (var k = 0; k < iterations; ++k) {
  5644. tree = quadtree(nodes, x, y).visitAfter(prepare);
  5645. for (i = 0; i < n; ++i) {
  5646. node = nodes[i];
  5647. ri = radii[node.index], ri2 = ri * ri;
  5648. xi = node.x + node.vx;
  5649. yi = node.y + node.vy;
  5650. tree.visit(apply);
  5651. }
  5652. }
  5653. function apply(quad, x0, y0, x1, y1) {
  5654. var data = quad.data, rj = quad.r, r = ri + rj;
  5655. if (data) {
  5656. if (data.index > node.index) {
  5657. var x = xi - data.x - data.vx,
  5658. y = yi - data.y - data.vy,
  5659. l = x * x + y * y;
  5660. if (l < r * r) {
  5661. if (x === 0) x = jiggle(), l += x * x;
  5662. if (y === 0) y = jiggle(), l += y * y;
  5663. l = (r - (l = Math.sqrt(l))) / l * strength;
  5664. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5665. node.vy += (y *= l) * r;
  5666. data.vx -= x * (r = 1 - r);
  5667. data.vy -= y * r;
  5668. }
  5669. }
  5670. return;
  5671. }
  5672. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5673. }
  5674. }
  5675. function prepare(quad) {
  5676. if (quad.data) return quad.r = radii[quad.data.index];
  5677. for (var i = quad.r = 0; i < 4; ++i) {
  5678. if (quad[i] && quad[i].r > quad.r) {
  5679. quad.r = quad[i].r;
  5680. }
  5681. }
  5682. }
  5683. function initialize() {
  5684. if (!nodes) return;
  5685. var i, n = nodes.length, node;
  5686. radii = new Array(n);
  5687. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5688. }
  5689. force.initialize = function(_) {
  5690. nodes = _;
  5691. initialize();
  5692. };
  5693. force.iterations = function(_) {
  5694. return arguments.length ? (iterations = +_, force) : iterations;
  5695. };
  5696. force.strength = function(_) {
  5697. return arguments.length ? (strength = +_, force) : strength;
  5698. };
  5699. force.radius = function(_) {
  5700. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5701. };
  5702. return force;
  5703. }
  5704. function index(d) {
  5705. return d.index;
  5706. }
  5707. function find(nodeById, nodeId) {
  5708. var node = nodeById.get(nodeId);
  5709. if (!node) throw new Error("missing: " + nodeId);
  5710. return node;
  5711. }
  5712. function link(links) {
  5713. var id = index,
  5714. strength = defaultStrength,
  5715. strengths,
  5716. distance = constant$7(30),
  5717. distances,
  5718. nodes,
  5719. count,
  5720. bias,
  5721. iterations = 1;
  5722. if (links == null) links = [];
  5723. function defaultStrength(link) {
  5724. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5725. }
  5726. function force(alpha) {
  5727. for (var k = 0, n = links.length; k < iterations; ++k) {
  5728. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5729. link = links[i], source = link.source, target = link.target;
  5730. x = target.x + target.vx - source.x - source.vx || jiggle();
  5731. y = target.y + target.vy - source.y - source.vy || jiggle();
  5732. l = Math.sqrt(x * x + y * y);
  5733. l = (l - distances[i]) / l * alpha * strengths[i];
  5734. x *= l, y *= l;
  5735. target.vx -= x * (b = bias[i]);
  5736. target.vy -= y * b;
  5737. source.vx += x * (b = 1 - b);
  5738. source.vy += y * b;
  5739. }
  5740. }
  5741. }
  5742. function initialize() {
  5743. if (!nodes) return;
  5744. var i,
  5745. n = nodes.length,
  5746. m = links.length,
  5747. nodeById = map$1(nodes, id),
  5748. link;
  5749. for (i = 0, count = new Array(n); i < m; ++i) {
  5750. link = links[i], link.index = i;
  5751. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5752. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5753. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5754. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5755. }
  5756. for (i = 0, bias = new Array(m); i < m; ++i) {
  5757. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5758. }
  5759. strengths = new Array(m), initializeStrength();
  5760. distances = new Array(m), initializeDistance();
  5761. }
  5762. function initializeStrength() {
  5763. if (!nodes) return;
  5764. for (var i = 0, n = links.length; i < n; ++i) {
  5765. strengths[i] = +strength(links[i], i, links);
  5766. }
  5767. }
  5768. function initializeDistance() {
  5769. if (!nodes) return;
  5770. for (var i = 0, n = links.length; i < n; ++i) {
  5771. distances[i] = +distance(links[i], i, links);
  5772. }
  5773. }
  5774. force.initialize = function(_) {
  5775. nodes = _;
  5776. initialize();
  5777. };
  5778. force.links = function(_) {
  5779. return arguments.length ? (links = _, initialize(), force) : links;
  5780. };
  5781. force.id = function(_) {
  5782. return arguments.length ? (id = _, force) : id;
  5783. };
  5784. force.iterations = function(_) {
  5785. return arguments.length ? (iterations = +_, force) : iterations;
  5786. };
  5787. force.strength = function(_) {
  5788. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  5789. };
  5790. force.distance = function(_) {
  5791. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  5792. };
  5793. return force;
  5794. }
  5795. function x$1(d) {
  5796. return d.x;
  5797. }
  5798. function y$1(d) {
  5799. return d.y;
  5800. }
  5801. var initialRadius = 10,
  5802. initialAngle = Math.PI * (3 - Math.sqrt(5));
  5803. function simulation(nodes) {
  5804. var simulation,
  5805. alpha = 1,
  5806. alphaMin = 0.001,
  5807. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5808. alphaTarget = 0,
  5809. velocityDecay = 0.6,
  5810. forces = map$1(),
  5811. stepper = timer(step),
  5812. event = dispatch("tick", "end");
  5813. if (nodes == null) nodes = [];
  5814. function step() {
  5815. tick();
  5816. event.call("tick", simulation);
  5817. if (alpha < alphaMin) {
  5818. stepper.stop();
  5819. event.call("end", simulation);
  5820. }
  5821. }
  5822. function tick(iterations) {
  5823. var i, n = nodes.length, node;
  5824. if (iterations === undefined) iterations = 1;
  5825. for (var k = 0; k < iterations; ++k) {
  5826. alpha += (alphaTarget - alpha) * alphaDecay;
  5827. forces.each(function (force) {
  5828. force(alpha);
  5829. });
  5830. for (i = 0; i < n; ++i) {
  5831. node = nodes[i];
  5832. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5833. else node.x = node.fx, node.vx = 0;
  5834. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5835. else node.y = node.fy, node.vy = 0;
  5836. }
  5837. }
  5838. return simulation;
  5839. }
  5840. function initializeNodes() {
  5841. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5842. node = nodes[i], node.index = i;
  5843. if (node.fx != null) node.x = node.fx;
  5844. if (node.fy != null) node.y = node.fy;
  5845. if (isNaN(node.x) || isNaN(node.y)) {
  5846. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5847. node.x = radius * Math.cos(angle);
  5848. node.y = radius * Math.sin(angle);
  5849. }
  5850. if (isNaN(node.vx) || isNaN(node.vy)) {
  5851. node.vx = node.vy = 0;
  5852. }
  5853. }
  5854. }
  5855. function initializeForce(force) {
  5856. if (force.initialize) force.initialize(nodes);
  5857. return force;
  5858. }
  5859. initializeNodes();
  5860. return simulation = {
  5861. tick: tick,
  5862. restart: function() {
  5863. return stepper.restart(step), simulation;
  5864. },
  5865. stop: function() {
  5866. return stepper.stop(), simulation;
  5867. },
  5868. nodes: function(_) {
  5869. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5870. },
  5871. alpha: function(_) {
  5872. return arguments.length ? (alpha = +_, simulation) : alpha;
  5873. },
  5874. alphaMin: function(_) {
  5875. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5876. },
  5877. alphaDecay: function(_) {
  5878. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5879. },
  5880. alphaTarget: function(_) {
  5881. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5882. },
  5883. velocityDecay: function(_) {
  5884. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5885. },
  5886. force: function(name, _) {
  5887. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  5888. },
  5889. find: function(x, y, radius) {
  5890. var i = 0,
  5891. n = nodes.length,
  5892. dx,
  5893. dy,
  5894. d2,
  5895. node,
  5896. closest;
  5897. if (radius == null) radius = Infinity;
  5898. else radius *= radius;
  5899. for (i = 0; i < n; ++i) {
  5900. node = nodes[i];
  5901. dx = x - node.x;
  5902. dy = y - node.y;
  5903. d2 = dx * dx + dy * dy;
  5904. if (d2 < radius) closest = node, radius = d2;
  5905. }
  5906. return closest;
  5907. },
  5908. on: function(name, _) {
  5909. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5910. }
  5911. };
  5912. }
  5913. function manyBody() {
  5914. var nodes,
  5915. node,
  5916. alpha,
  5917. strength = constant$7(-30),
  5918. strengths,
  5919. distanceMin2 = 1,
  5920. distanceMax2 = Infinity,
  5921. theta2 = 0.81;
  5922. function force(_) {
  5923. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5924. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5925. }
  5926. function initialize() {
  5927. if (!nodes) return;
  5928. var i, n = nodes.length, node;
  5929. strengths = new Array(n);
  5930. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5931. }
  5932. function accumulate(quad) {
  5933. var strength = 0, q, c, weight = 0, x, y, i;
  5934. // For internal nodes, accumulate forces from child quadrants.
  5935. if (quad.length) {
  5936. for (x = y = i = 0; i < 4; ++i) {
  5937. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5938. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5939. }
  5940. }
  5941. quad.x = x / weight;
  5942. quad.y = y / weight;
  5943. }
  5944. // For leaf nodes, accumulate forces from coincident quadrants.
  5945. else {
  5946. q = quad;
  5947. q.x = q.data.x;
  5948. q.y = q.data.y;
  5949. do strength += strengths[q.data.index];
  5950. while (q = q.next);
  5951. }
  5952. quad.value = strength;
  5953. }
  5954. function apply(quad, x1, _, x2) {
  5955. if (!quad.value) return true;
  5956. var x = quad.x - node.x,
  5957. y = quad.y - node.y,
  5958. w = x2 - x1,
  5959. l = x * x + y * y;
  5960. // Apply the Barnes-Hut approximation if possible.
  5961. // Limit forces for very close nodes; randomize direction if coincident.
  5962. if (w * w / theta2 < l) {
  5963. if (l < distanceMax2) {
  5964. if (x === 0) x = jiggle(), l += x * x;
  5965. if (y === 0) y = jiggle(), l += y * y;
  5966. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5967. node.vx += x * quad.value * alpha / l;
  5968. node.vy += y * quad.value * alpha / l;
  5969. }
  5970. return true;
  5971. }
  5972. // Otherwise, process points directly.
  5973. else if (quad.length || l >= distanceMax2) return;
  5974. // Limit forces for very close nodes; randomize direction if coincident.
  5975. if (quad.data !== node || quad.next) {
  5976. if (x === 0) x = jiggle(), l += x * x;
  5977. if (y === 0) y = jiggle(), l += y * y;
  5978. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5979. }
  5980. do if (quad.data !== node) {
  5981. w = strengths[quad.data.index] * alpha / l;
  5982. node.vx += x * w;
  5983. node.vy += y * w;
  5984. } while (quad = quad.next);
  5985. }
  5986. force.initialize = function(_) {
  5987. nodes = _;
  5988. initialize();
  5989. };
  5990. force.strength = function(_) {
  5991. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5992. };
  5993. force.distanceMin = function(_) {
  5994. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5995. };
  5996. force.distanceMax = function(_) {
  5997. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5998. };
  5999. force.theta = function(_) {
  6000. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  6001. };
  6002. return force;
  6003. }
  6004. function radial(radius, x, y) {
  6005. var nodes,
  6006. strength = constant$7(0.1),
  6007. strengths,
  6008. radiuses;
  6009. if (typeof radius !== "function") radius = constant$7(+radius);
  6010. if (x == null) x = 0;
  6011. if (y == null) y = 0;
  6012. function force(alpha) {
  6013. for (var i = 0, n = nodes.length; i < n; ++i) {
  6014. var node = nodes[i],
  6015. dx = node.x - x || 1e-6,
  6016. dy = node.y - y || 1e-6,
  6017. r = Math.sqrt(dx * dx + dy * dy),
  6018. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  6019. node.vx += dx * k;
  6020. node.vy += dy * k;
  6021. }
  6022. }
  6023. function initialize() {
  6024. if (!nodes) return;
  6025. var i, n = nodes.length;
  6026. strengths = new Array(n);
  6027. radiuses = new Array(n);
  6028. for (i = 0; i < n; ++i) {
  6029. radiuses[i] = +radius(nodes[i], i, nodes);
  6030. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  6031. }
  6032. }
  6033. force.initialize = function(_) {
  6034. nodes = _, initialize();
  6035. };
  6036. force.strength = function(_) {
  6037. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6038. };
  6039. force.radius = function(_) {
  6040. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  6041. };
  6042. force.x = function(_) {
  6043. return arguments.length ? (x = +_, force) : x;
  6044. };
  6045. force.y = function(_) {
  6046. return arguments.length ? (y = +_, force) : y;
  6047. };
  6048. return force;
  6049. }
  6050. function x$2(x) {
  6051. var strength = constant$7(0.1),
  6052. nodes,
  6053. strengths,
  6054. xz;
  6055. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  6056. function force(alpha) {
  6057. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  6058. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  6059. }
  6060. }
  6061. function initialize() {
  6062. if (!nodes) return;
  6063. var i, n = nodes.length;
  6064. strengths = new Array(n);
  6065. xz = new Array(n);
  6066. for (i = 0; i < n; ++i) {
  6067. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  6068. }
  6069. }
  6070. force.initialize = function(_) {
  6071. nodes = _;
  6072. initialize();
  6073. };
  6074. force.strength = function(_) {
  6075. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6076. };
  6077. force.x = function(_) {
  6078. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  6079. };
  6080. return force;
  6081. }
  6082. function y$2(y) {
  6083. var strength = constant$7(0.1),
  6084. nodes,
  6085. strengths,
  6086. yz;
  6087. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  6088. function force(alpha) {
  6089. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  6090. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  6091. }
  6092. }
  6093. function initialize() {
  6094. if (!nodes) return;
  6095. var i, n = nodes.length;
  6096. strengths = new Array(n);
  6097. yz = new Array(n);
  6098. for (i = 0; i < n; ++i) {
  6099. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  6100. }
  6101. }
  6102. force.initialize = function(_) {
  6103. nodes = _;
  6104. initialize();
  6105. };
  6106. force.strength = function(_) {
  6107. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6108. };
  6109. force.y = function(_) {
  6110. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  6111. };
  6112. return force;
  6113. }
  6114. // Computes the decimal coefficient and exponent of the specified number x with
  6115. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  6116. // For example, formatDecimal(1.23) returns ["123", 0].
  6117. function formatDecimal(x, p) {
  6118. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  6119. var i, coefficient = x.slice(0, i);
  6120. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  6121. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  6122. return [
  6123. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  6124. +x.slice(i + 1)
  6125. ];
  6126. }
  6127. function exponent$1(x) {
  6128. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  6129. }
  6130. function formatGroup(grouping, thousands) {
  6131. return function(value, width) {
  6132. var i = value.length,
  6133. t = [],
  6134. j = 0,
  6135. g = grouping[0],
  6136. length = 0;
  6137. while (i > 0 && g > 0) {
  6138. if (length + g + 1 > width) g = Math.max(1, width - length);
  6139. t.push(value.substring(i -= g, i + g));
  6140. if ((length += g + 1) > width) break;
  6141. g = grouping[j = (j + 1) % grouping.length];
  6142. }
  6143. return t.reverse().join(thousands);
  6144. };
  6145. }
  6146. function formatNumerals(numerals) {
  6147. return function(value) {
  6148. return value.replace(/[0-9]/g, function(i) {
  6149. return numerals[+i];
  6150. });
  6151. };
  6152. }
  6153. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  6154. var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  6155. function formatSpecifier(specifier) {
  6156. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  6157. var match;
  6158. return new FormatSpecifier({
  6159. fill: match[1],
  6160. align: match[2],
  6161. sign: match[3],
  6162. symbol: match[4],
  6163. zero: match[5],
  6164. width: match[6],
  6165. comma: match[7],
  6166. precision: match[8] && match[8].slice(1),
  6167. trim: match[9],
  6168. type: match[10]
  6169. });
  6170. }
  6171. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  6172. function FormatSpecifier(specifier) {
  6173. this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
  6174. this.align = specifier.align === undefined ? ">" : specifier.align + "";
  6175. this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
  6176. this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
  6177. this.zero = !!specifier.zero;
  6178. this.width = specifier.width === undefined ? undefined : +specifier.width;
  6179. this.comma = !!specifier.comma;
  6180. this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
  6181. this.trim = !!specifier.trim;
  6182. this.type = specifier.type === undefined ? "" : specifier.type + "";
  6183. }
  6184. FormatSpecifier.prototype.toString = function() {
  6185. return this.fill
  6186. + this.align
  6187. + this.sign
  6188. + this.symbol
  6189. + (this.zero ? "0" : "")
  6190. + (this.width === undefined ? "" : Math.max(1, this.width | 0))
  6191. + (this.comma ? "," : "")
  6192. + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
  6193. + (this.trim ? "~" : "")
  6194. + this.type;
  6195. };
  6196. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  6197. function formatTrim(s) {
  6198. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  6199. switch (s[i]) {
  6200. case ".": i0 = i1 = i; break;
  6201. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  6202. default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
  6203. }
  6204. }
  6205. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  6206. }
  6207. var prefixExponent;
  6208. function formatPrefixAuto(x, p) {
  6209. var d = formatDecimal(x, p);
  6210. if (!d) return x + "";
  6211. var coefficient = d[0],
  6212. exponent = d[1],
  6213. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  6214. n = coefficient.length;
  6215. return i === n ? coefficient
  6216. : i > n ? coefficient + new Array(i - n + 1).join("0")
  6217. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  6218. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  6219. }
  6220. function formatRounded(x, p) {
  6221. var d = formatDecimal(x, p);
  6222. if (!d) return x + "";
  6223. var coefficient = d[0],
  6224. exponent = d[1];
  6225. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  6226. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  6227. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  6228. }
  6229. var formatTypes = {
  6230. "%": function(x, p) { return (x * 100).toFixed(p); },
  6231. "b": function(x) { return Math.round(x).toString(2); },
  6232. "c": function(x) { return x + ""; },
  6233. "d": function(x) { return Math.round(x).toString(10); },
  6234. "e": function(x, p) { return x.toExponential(p); },
  6235. "f": function(x, p) { return x.toFixed(p); },
  6236. "g": function(x, p) { return x.toPrecision(p); },
  6237. "o": function(x) { return Math.round(x).toString(8); },
  6238. "p": function(x, p) { return formatRounded(x * 100, p); },
  6239. "r": formatRounded,
  6240. "s": formatPrefixAuto,
  6241. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  6242. "x": function(x) { return Math.round(x).toString(16); }
  6243. };
  6244. function identity$3(x) {
  6245. return x;
  6246. }
  6247. var map$2 = Array.prototype.map,
  6248. prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  6249. function formatLocale(locale) {
  6250. var group = locale.grouping === undefined || locale.thousands === undefined ? identity$3 : formatGroup(map$2.call(locale.grouping, Number), locale.thousands + ""),
  6251. currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
  6252. currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
  6253. decimal = locale.decimal === undefined ? "." : locale.decimal + "",
  6254. numerals = locale.numerals === undefined ? identity$3 : formatNumerals(map$2.call(locale.numerals, String)),
  6255. percent = locale.percent === undefined ? "%" : locale.percent + "",
  6256. minus = locale.minus === undefined ? "-" : locale.minus + "",
  6257. nan = locale.nan === undefined ? "NaN" : locale.nan + "";
  6258. function newFormat(specifier) {
  6259. specifier = formatSpecifier(specifier);
  6260. var fill = specifier.fill,
  6261. align = specifier.align,
  6262. sign = specifier.sign,
  6263. symbol = specifier.symbol,
  6264. zero = specifier.zero,
  6265. width = specifier.width,
  6266. comma = specifier.comma,
  6267. precision = specifier.precision,
  6268. trim = specifier.trim,
  6269. type = specifier.type;
  6270. // The "n" type is an alias for ",g".
  6271. if (type === "n") comma = true, type = "g";
  6272. // The "" type, and any invalid type, is an alias for ".12~g".
  6273. else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
  6274. // If zero fill is specified, padding goes after sign and before digits.
  6275. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  6276. // Compute the prefix and suffix.
  6277. // For SI-prefix, the suffix is lazily computed.
  6278. var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  6279. suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
  6280. // What format function should we use?
  6281. // Is this an integer type?
  6282. // Can this type generate exponential notation?
  6283. var formatType = formatTypes[type],
  6284. maybeSuffix = /[defgprs%]/.test(type);
  6285. // Set the default precision if not specified,
  6286. // or clamp the specified precision to the supported range.
  6287. // For significant precision, it must be in [1, 21].
  6288. // For fixed precision, it must be in [0, 20].
  6289. precision = precision === undefined ? 6
  6290. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  6291. : Math.max(0, Math.min(20, precision));
  6292. function format(value) {
  6293. var valuePrefix = prefix,
  6294. valueSuffix = suffix,
  6295. i, n, c;
  6296. if (type === "c") {
  6297. valueSuffix = formatType(value) + valueSuffix;
  6298. value = "";
  6299. } else {
  6300. value = +value;
  6301. // Perform the initial formatting.
  6302. var valueNegative = value < 0;
  6303. value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
  6304. // Trim insignificant zeros.
  6305. if (trim) value = formatTrim(value);
  6306. // If a negative value rounds to zero during formatting, treat as positive.
  6307. if (valueNegative && +value === 0) valueNegative = false;
  6308. // Compute the prefix and suffix.
  6309. valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  6310. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  6311. // Break the formatted value into the integer “value” part that can be
  6312. // grouped, and fractional or exponential “suffix” part that is not.
  6313. if (maybeSuffix) {
  6314. i = -1, n = value.length;
  6315. while (++i < n) {
  6316. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  6317. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  6318. value = value.slice(0, i);
  6319. break;
  6320. }
  6321. }
  6322. }
  6323. }
  6324. // If the fill character is not "0", grouping is applied before padding.
  6325. if (comma && !zero) value = group(value, Infinity);
  6326. // Compute the padding.
  6327. var length = valuePrefix.length + value.length + valueSuffix.length,
  6328. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  6329. // If the fill character is "0", grouping is applied after padding.
  6330. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  6331. // Reconstruct the final output based on the desired alignment.
  6332. switch (align) {
  6333. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  6334. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  6335. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  6336. default: value = padding + valuePrefix + value + valueSuffix; break;
  6337. }
  6338. return numerals(value);
  6339. }
  6340. format.toString = function() {
  6341. return specifier + "";
  6342. };
  6343. return format;
  6344. }
  6345. function formatPrefix(specifier, value) {
  6346. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  6347. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  6348. k = Math.pow(10, -e),
  6349. prefix = prefixes[8 + e / 3];
  6350. return function(value) {
  6351. return f(k * value) + prefix;
  6352. };
  6353. }
  6354. return {
  6355. format: newFormat,
  6356. formatPrefix: formatPrefix
  6357. };
  6358. }
  6359. var locale;
  6360. defaultLocale({
  6361. decimal: ".",
  6362. thousands: ",",
  6363. grouping: [3],
  6364. currency: ["$", ""],
  6365. minus: "-"
  6366. });
  6367. function defaultLocale(definition) {
  6368. locale = formatLocale(definition);
  6369. exports.format = locale.format;
  6370. exports.formatPrefix = locale.formatPrefix;
  6371. return locale;
  6372. }
  6373. function precisionFixed(step) {
  6374. return Math.max(0, -exponent$1(Math.abs(step)));
  6375. }
  6376. function precisionPrefix(step, value) {
  6377. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  6378. }
  6379. function precisionRound(step, max) {
  6380. step = Math.abs(step), max = Math.abs(max) - step;
  6381. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  6382. }
  6383. // Adds floating point numbers with twice the normal precision.
  6384. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  6385. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  6386. // 305–363 (1997).
  6387. // Code adapted from GeographicLib by Charles F. F. Karney,
  6388. // http://geographiclib.sourceforge.net/
  6389. function adder() {
  6390. return new Adder;
  6391. }
  6392. function Adder() {
  6393. this.reset();
  6394. }
  6395. Adder.prototype = {
  6396. constructor: Adder,
  6397. reset: function() {
  6398. this.s = // rounded value
  6399. this.t = 0; // exact error
  6400. },
  6401. add: function(y) {
  6402. add$1(temp, y, this.t);
  6403. add$1(this, temp.s, this.s);
  6404. if (this.s) this.t += temp.t;
  6405. else this.s = temp.t;
  6406. },
  6407. valueOf: function() {
  6408. return this.s;
  6409. }
  6410. };
  6411. var temp = new Adder;
  6412. function add$1(adder, a, b) {
  6413. var x = adder.s = a + b,
  6414. bv = x - a,
  6415. av = x - bv;
  6416. adder.t = (a - av) + (b - bv);
  6417. }
  6418. var epsilon$2 = 1e-6;
  6419. var epsilon2$1 = 1e-12;
  6420. var pi$3 = Math.PI;
  6421. var halfPi$2 = pi$3 / 2;
  6422. var quarterPi = pi$3 / 4;
  6423. var tau$3 = pi$3 * 2;
  6424. var degrees$1 = 180 / pi$3;
  6425. var radians = pi$3 / 180;
  6426. var abs = Math.abs;
  6427. var atan = Math.atan;
  6428. var atan2 = Math.atan2;
  6429. var cos$1 = Math.cos;
  6430. var ceil = Math.ceil;
  6431. var exp = Math.exp;
  6432. var log = Math.log;
  6433. var pow = Math.pow;
  6434. var sin$1 = Math.sin;
  6435. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  6436. var sqrt = Math.sqrt;
  6437. var tan = Math.tan;
  6438. function acos(x) {
  6439. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  6440. }
  6441. function asin(x) {
  6442. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  6443. }
  6444. function haversin(x) {
  6445. return (x = sin$1(x / 2)) * x;
  6446. }
  6447. function noop$2() {}
  6448. function streamGeometry(geometry, stream) {
  6449. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  6450. streamGeometryType[geometry.type](geometry, stream);
  6451. }
  6452. }
  6453. var streamObjectType = {
  6454. Feature: function(object, stream) {
  6455. streamGeometry(object.geometry, stream);
  6456. },
  6457. FeatureCollection: function(object, stream) {
  6458. var features = object.features, i = -1, n = features.length;
  6459. while (++i < n) streamGeometry(features[i].geometry, stream);
  6460. }
  6461. };
  6462. var streamGeometryType = {
  6463. Sphere: function(object, stream) {
  6464. stream.sphere();
  6465. },
  6466. Point: function(object, stream) {
  6467. object = object.coordinates;
  6468. stream.point(object[0], object[1], object[2]);
  6469. },
  6470. MultiPoint: function(object, stream) {
  6471. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6472. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  6473. },
  6474. LineString: function(object, stream) {
  6475. streamLine(object.coordinates, stream, 0);
  6476. },
  6477. MultiLineString: function(object, stream) {
  6478. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6479. while (++i < n) streamLine(coordinates[i], stream, 0);
  6480. },
  6481. Polygon: function(object, stream) {
  6482. streamPolygon(object.coordinates, stream);
  6483. },
  6484. MultiPolygon: function(object, stream) {
  6485. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6486. while (++i < n) streamPolygon(coordinates[i], stream);
  6487. },
  6488. GeometryCollection: function(object, stream) {
  6489. var geometries = object.geometries, i = -1, n = geometries.length;
  6490. while (++i < n) streamGeometry(geometries[i], stream);
  6491. }
  6492. };
  6493. function streamLine(coordinates, stream, closed) {
  6494. var i = -1, n = coordinates.length - closed, coordinate;
  6495. stream.lineStart();
  6496. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  6497. stream.lineEnd();
  6498. }
  6499. function streamPolygon(coordinates, stream) {
  6500. var i = -1, n = coordinates.length;
  6501. stream.polygonStart();
  6502. while (++i < n) streamLine(coordinates[i], stream, 1);
  6503. stream.polygonEnd();
  6504. }
  6505. function geoStream(object, stream) {
  6506. if (object && streamObjectType.hasOwnProperty(object.type)) {
  6507. streamObjectType[object.type](object, stream);
  6508. } else {
  6509. streamGeometry(object, stream);
  6510. }
  6511. }
  6512. var areaRingSum = adder();
  6513. var areaSum = adder(),
  6514. lambda00,
  6515. phi00,
  6516. lambda0,
  6517. cosPhi0,
  6518. sinPhi0;
  6519. var areaStream = {
  6520. point: noop$2,
  6521. lineStart: noop$2,
  6522. lineEnd: noop$2,
  6523. polygonStart: function() {
  6524. areaRingSum.reset();
  6525. areaStream.lineStart = areaRingStart;
  6526. areaStream.lineEnd = areaRingEnd;
  6527. },
  6528. polygonEnd: function() {
  6529. var areaRing = +areaRingSum;
  6530. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  6531. this.lineStart = this.lineEnd = this.point = noop$2;
  6532. },
  6533. sphere: function() {
  6534. areaSum.add(tau$3);
  6535. }
  6536. };
  6537. function areaRingStart() {
  6538. areaStream.point = areaPointFirst;
  6539. }
  6540. function areaRingEnd() {
  6541. areaPoint(lambda00, phi00);
  6542. }
  6543. function areaPointFirst(lambda, phi) {
  6544. areaStream.point = areaPoint;
  6545. lambda00 = lambda, phi00 = phi;
  6546. lambda *= radians, phi *= radians;
  6547. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  6548. }
  6549. function areaPoint(lambda, phi) {
  6550. lambda *= radians, phi *= radians;
  6551. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  6552. // Spherical excess E for a spherical triangle with vertices: south pole,
  6553. // previous point, current point. Uses a formula derived from Cagnoli’s
  6554. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  6555. var dLambda = lambda - lambda0,
  6556. sdLambda = dLambda >= 0 ? 1 : -1,
  6557. adLambda = sdLambda * dLambda,
  6558. cosPhi = cos$1(phi),
  6559. sinPhi = sin$1(phi),
  6560. k = sinPhi0 * sinPhi,
  6561. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  6562. v = k * sdLambda * sin$1(adLambda);
  6563. areaRingSum.add(atan2(v, u));
  6564. // Advance the previous points.
  6565. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  6566. }
  6567. function area$1(object) {
  6568. areaSum.reset();
  6569. geoStream(object, areaStream);
  6570. return areaSum * 2;
  6571. }
  6572. function spherical(cartesian) {
  6573. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  6574. }
  6575. function cartesian(spherical) {
  6576. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  6577. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  6578. }
  6579. function cartesianDot(a, b) {
  6580. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6581. }
  6582. function cartesianCross(a, b) {
  6583. 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]];
  6584. }
  6585. // TODO return a
  6586. function cartesianAddInPlace(a, b) {
  6587. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  6588. }
  6589. function cartesianScale(vector, k) {
  6590. return [vector[0] * k, vector[1] * k, vector[2] * k];
  6591. }
  6592. // TODO return d
  6593. function cartesianNormalizeInPlace(d) {
  6594. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  6595. d[0] /= l, d[1] /= l, d[2] /= l;
  6596. }
  6597. var lambda0$1, phi0, lambda1, phi1, // bounds
  6598. lambda2, // previous lambda-coordinate
  6599. lambda00$1, phi00$1, // first point
  6600. p0, // previous 3D point
  6601. deltaSum = adder(),
  6602. ranges,
  6603. range;
  6604. var boundsStream = {
  6605. point: boundsPoint,
  6606. lineStart: boundsLineStart,
  6607. lineEnd: boundsLineEnd,
  6608. polygonStart: function() {
  6609. boundsStream.point = boundsRingPoint;
  6610. boundsStream.lineStart = boundsRingStart;
  6611. boundsStream.lineEnd = boundsRingEnd;
  6612. deltaSum.reset();
  6613. areaStream.polygonStart();
  6614. },
  6615. polygonEnd: function() {
  6616. areaStream.polygonEnd();
  6617. boundsStream.point = boundsPoint;
  6618. boundsStream.lineStart = boundsLineStart;
  6619. boundsStream.lineEnd = boundsLineEnd;
  6620. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6621. else if (deltaSum > epsilon$2) phi1 = 90;
  6622. else if (deltaSum < -epsilon$2) phi0 = -90;
  6623. range[0] = lambda0$1, range[1] = lambda1;
  6624. },
  6625. sphere: function() {
  6626. lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6627. }
  6628. };
  6629. function boundsPoint(lambda, phi) {
  6630. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6631. if (phi < phi0) phi0 = phi;
  6632. if (phi > phi1) phi1 = phi;
  6633. }
  6634. function linePoint(lambda, phi) {
  6635. var p = cartesian([lambda * radians, phi * radians]);
  6636. if (p0) {
  6637. var normal = cartesianCross(p0, p),
  6638. equatorial = [normal[1], -normal[0], 0],
  6639. inflection = cartesianCross(equatorial, normal);
  6640. cartesianNormalizeInPlace(inflection);
  6641. inflection = spherical(inflection);
  6642. var delta = lambda - lambda2,
  6643. sign = delta > 0 ? 1 : -1,
  6644. lambdai = inflection[0] * degrees$1 * sign,
  6645. phii,
  6646. antimeridian = abs(delta) > 180;
  6647. if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  6648. phii = inflection[1] * degrees$1;
  6649. if (phii > phi1) phi1 = phii;
  6650. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  6651. phii = -inflection[1] * degrees$1;
  6652. if (phii < phi0) phi0 = phii;
  6653. } else {
  6654. if (phi < phi0) phi0 = phi;
  6655. if (phi > phi1) phi1 = phi;
  6656. }
  6657. if (antimeridian) {
  6658. if (lambda < lambda2) {
  6659. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6660. } else {
  6661. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6662. }
  6663. } else {
  6664. if (lambda1 >= lambda0$1) {
  6665. if (lambda < lambda0$1) lambda0$1 = lambda;
  6666. if (lambda > lambda1) lambda1 = lambda;
  6667. } else {
  6668. if (lambda > lambda2) {
  6669. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6670. } else {
  6671. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6672. }
  6673. }
  6674. }
  6675. } else {
  6676. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6677. }
  6678. if (phi < phi0) phi0 = phi;
  6679. if (phi > phi1) phi1 = phi;
  6680. p0 = p, lambda2 = lambda;
  6681. }
  6682. function boundsLineStart() {
  6683. boundsStream.point = linePoint;
  6684. }
  6685. function boundsLineEnd() {
  6686. range[0] = lambda0$1, range[1] = lambda1;
  6687. boundsStream.point = boundsPoint;
  6688. p0 = null;
  6689. }
  6690. function boundsRingPoint(lambda, phi) {
  6691. if (p0) {
  6692. var delta = lambda - lambda2;
  6693. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6694. } else {
  6695. lambda00$1 = lambda, phi00$1 = phi;
  6696. }
  6697. areaStream.point(lambda, phi);
  6698. linePoint(lambda, phi);
  6699. }
  6700. function boundsRingStart() {
  6701. areaStream.lineStart();
  6702. }
  6703. function boundsRingEnd() {
  6704. boundsRingPoint(lambda00$1, phi00$1);
  6705. areaStream.lineEnd();
  6706. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6707. range[0] = lambda0$1, range[1] = lambda1;
  6708. p0 = null;
  6709. }
  6710. // Finds the left-right distance between two longitudes.
  6711. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6712. // the distance between ±180° to be 360°.
  6713. function angle(lambda0, lambda1) {
  6714. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6715. }
  6716. function rangeCompare(a, b) {
  6717. return a[0] - b[0];
  6718. }
  6719. function rangeContains(range, x) {
  6720. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6721. }
  6722. function bounds(feature) {
  6723. var i, n, a, b, merged, deltaMax, delta;
  6724. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6725. ranges = [];
  6726. geoStream(feature, boundsStream);
  6727. // First, sort ranges by their minimum longitudes.
  6728. if (n = ranges.length) {
  6729. ranges.sort(rangeCompare);
  6730. // Then, merge any ranges that overlap.
  6731. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6732. b = ranges[i];
  6733. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6734. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6735. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6736. } else {
  6737. merged.push(a = b);
  6738. }
  6739. }
  6740. // Finally, find the largest gap between the merged ranges.
  6741. // The final bounding box will be the inverse of this gap.
  6742. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6743. b = merged[i];
  6744. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6745. }
  6746. }
  6747. ranges = range = null;
  6748. return lambda0$1 === Infinity || phi0 === Infinity
  6749. ? [[NaN, NaN], [NaN, NaN]]
  6750. : [[lambda0$1, phi0], [lambda1, phi1]];
  6751. }
  6752. var W0, W1,
  6753. X0, Y0, Z0,
  6754. X1, Y1, Z1,
  6755. X2, Y2, Z2,
  6756. lambda00$2, phi00$2, // first point
  6757. x0, y0, z0; // previous point
  6758. var centroidStream = {
  6759. sphere: noop$2,
  6760. point: centroidPoint,
  6761. lineStart: centroidLineStart,
  6762. lineEnd: centroidLineEnd,
  6763. polygonStart: function() {
  6764. centroidStream.lineStart = centroidRingStart;
  6765. centroidStream.lineEnd = centroidRingEnd;
  6766. },
  6767. polygonEnd: function() {
  6768. centroidStream.lineStart = centroidLineStart;
  6769. centroidStream.lineEnd = centroidLineEnd;
  6770. }
  6771. };
  6772. // Arithmetic mean of Cartesian vectors.
  6773. function centroidPoint(lambda, phi) {
  6774. lambda *= radians, phi *= radians;
  6775. var cosPhi = cos$1(phi);
  6776. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6777. }
  6778. function centroidPointCartesian(x, y, z) {
  6779. ++W0;
  6780. X0 += (x - X0) / W0;
  6781. Y0 += (y - Y0) / W0;
  6782. Z0 += (z - Z0) / W0;
  6783. }
  6784. function centroidLineStart() {
  6785. centroidStream.point = centroidLinePointFirst;
  6786. }
  6787. function centroidLinePointFirst(lambda, phi) {
  6788. lambda *= radians, phi *= radians;
  6789. var cosPhi = cos$1(phi);
  6790. x0 = cosPhi * cos$1(lambda);
  6791. y0 = cosPhi * sin$1(lambda);
  6792. z0 = sin$1(phi);
  6793. centroidStream.point = centroidLinePoint;
  6794. centroidPointCartesian(x0, y0, z0);
  6795. }
  6796. function centroidLinePoint(lambda, phi) {
  6797. lambda *= radians, phi *= radians;
  6798. var cosPhi = cos$1(phi),
  6799. x = cosPhi * cos$1(lambda),
  6800. y = cosPhi * sin$1(lambda),
  6801. z = sin$1(phi),
  6802. 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);
  6803. W1 += w;
  6804. X1 += w * (x0 + (x0 = x));
  6805. Y1 += w * (y0 + (y0 = y));
  6806. Z1 += w * (z0 + (z0 = z));
  6807. centroidPointCartesian(x0, y0, z0);
  6808. }
  6809. function centroidLineEnd() {
  6810. centroidStream.point = centroidPoint;
  6811. }
  6812. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6813. // J. Applied Mechanics 42, 239 (1975).
  6814. function centroidRingStart() {
  6815. centroidStream.point = centroidRingPointFirst;
  6816. }
  6817. function centroidRingEnd() {
  6818. centroidRingPoint(lambda00$2, phi00$2);
  6819. centroidStream.point = centroidPoint;
  6820. }
  6821. function centroidRingPointFirst(lambda, phi) {
  6822. lambda00$2 = lambda, phi00$2 = phi;
  6823. lambda *= radians, phi *= radians;
  6824. centroidStream.point = centroidRingPoint;
  6825. var cosPhi = cos$1(phi);
  6826. x0 = cosPhi * cos$1(lambda);
  6827. y0 = cosPhi * sin$1(lambda);
  6828. z0 = sin$1(phi);
  6829. centroidPointCartesian(x0, y0, z0);
  6830. }
  6831. function centroidRingPoint(lambda, phi) {
  6832. lambda *= radians, phi *= radians;
  6833. var cosPhi = cos$1(phi),
  6834. x = cosPhi * cos$1(lambda),
  6835. y = cosPhi * sin$1(lambda),
  6836. z = sin$1(phi),
  6837. cx = y0 * z - z0 * y,
  6838. cy = z0 * x - x0 * z,
  6839. cz = x0 * y - y0 * x,
  6840. m = sqrt(cx * cx + cy * cy + cz * cz),
  6841. w = asin(m), // line weight = angle
  6842. v = m && -w / m; // area weight multiplier
  6843. X2 += v * cx;
  6844. Y2 += v * cy;
  6845. Z2 += v * cz;
  6846. W1 += w;
  6847. X1 += w * (x0 + (x0 = x));
  6848. Y1 += w * (y0 + (y0 = y));
  6849. Z1 += w * (z0 + (z0 = z));
  6850. centroidPointCartesian(x0, y0, z0);
  6851. }
  6852. function centroid(object) {
  6853. W0 = W1 =
  6854. X0 = Y0 = Z0 =
  6855. X1 = Y1 = Z1 =
  6856. X2 = Y2 = Z2 = 0;
  6857. geoStream(object, centroidStream);
  6858. var x = X2,
  6859. y = Y2,
  6860. z = Z2,
  6861. m = x * x + y * y + z * z;
  6862. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6863. if (m < epsilon2$1) {
  6864. x = X1, y = Y1, z = Z1;
  6865. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6866. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6867. m = x * x + y * y + z * z;
  6868. // If the feature still has an undefined ccentroid, then return.
  6869. if (m < epsilon2$1) return [NaN, NaN];
  6870. }
  6871. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6872. }
  6873. function constant$8(x) {
  6874. return function() {
  6875. return x;
  6876. };
  6877. }
  6878. function compose(a, b) {
  6879. function compose(x, y) {
  6880. return x = a(x, y), b(x[0], x[1]);
  6881. }
  6882. if (a.invert && b.invert) compose.invert = function(x, y) {
  6883. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6884. };
  6885. return compose;
  6886. }
  6887. function rotationIdentity(lambda, phi) {
  6888. return [abs(lambda) > pi$3 ? lambda + Math.round(-lambda / tau$3) * tau$3 : lambda, phi];
  6889. }
  6890. rotationIdentity.invert = rotationIdentity;
  6891. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6892. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6893. : rotationLambda(deltaLambda))
  6894. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6895. : rotationIdentity);
  6896. }
  6897. function forwardRotationLambda(deltaLambda) {
  6898. return function(lambda, phi) {
  6899. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6900. };
  6901. }
  6902. function rotationLambda(deltaLambda) {
  6903. var rotation = forwardRotationLambda(deltaLambda);
  6904. rotation.invert = forwardRotationLambda(-deltaLambda);
  6905. return rotation;
  6906. }
  6907. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6908. var cosDeltaPhi = cos$1(deltaPhi),
  6909. sinDeltaPhi = sin$1(deltaPhi),
  6910. cosDeltaGamma = cos$1(deltaGamma),
  6911. sinDeltaGamma = sin$1(deltaGamma);
  6912. function rotation(lambda, phi) {
  6913. var cosPhi = cos$1(phi),
  6914. x = cos$1(lambda) * cosPhi,
  6915. y = sin$1(lambda) * cosPhi,
  6916. z = sin$1(phi),
  6917. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6918. return [
  6919. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6920. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6921. ];
  6922. }
  6923. rotation.invert = function(lambda, phi) {
  6924. var cosPhi = cos$1(phi),
  6925. x = cos$1(lambda) * cosPhi,
  6926. y = sin$1(lambda) * cosPhi,
  6927. z = sin$1(phi),
  6928. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6929. return [
  6930. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6931. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6932. ];
  6933. };
  6934. return rotation;
  6935. }
  6936. function rotation(rotate) {
  6937. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6938. function forward(coordinates) {
  6939. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6940. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6941. }
  6942. forward.invert = function(coordinates) {
  6943. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6944. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6945. };
  6946. return forward;
  6947. }
  6948. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6949. function circleStream(stream, radius, delta, direction, t0, t1) {
  6950. if (!delta) return;
  6951. var cosRadius = cos$1(radius),
  6952. sinRadius = sin$1(radius),
  6953. step = direction * delta;
  6954. if (t0 == null) {
  6955. t0 = radius + direction * tau$3;
  6956. t1 = radius - step / 2;
  6957. } else {
  6958. t0 = circleRadius(cosRadius, t0);
  6959. t1 = circleRadius(cosRadius, t1);
  6960. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6961. }
  6962. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6963. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6964. stream.point(point[0], point[1]);
  6965. }
  6966. }
  6967. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6968. function circleRadius(cosRadius, point) {
  6969. point = cartesian(point), point[0] -= cosRadius;
  6970. cartesianNormalizeInPlace(point);
  6971. var radius = acos(-point[1]);
  6972. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6973. }
  6974. function circle() {
  6975. var center = constant$8([0, 0]),
  6976. radius = constant$8(90),
  6977. precision = constant$8(6),
  6978. ring,
  6979. rotate,
  6980. stream = {point: point};
  6981. function point(x, y) {
  6982. ring.push(x = rotate(x, y));
  6983. x[0] *= degrees$1, x[1] *= degrees$1;
  6984. }
  6985. function circle() {
  6986. var c = center.apply(this, arguments),
  6987. r = radius.apply(this, arguments) * radians,
  6988. p = precision.apply(this, arguments) * radians;
  6989. ring = [];
  6990. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6991. circleStream(stream, r, p, 1);
  6992. c = {type: "Polygon", coordinates: [ring]};
  6993. ring = rotate = null;
  6994. return c;
  6995. }
  6996. circle.center = function(_) {
  6997. return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
  6998. };
  6999. circle.radius = function(_) {
  7000. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
  7001. };
  7002. circle.precision = function(_) {
  7003. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
  7004. };
  7005. return circle;
  7006. }
  7007. function clipBuffer() {
  7008. var lines = [],
  7009. line;
  7010. return {
  7011. point: function(x, y) {
  7012. line.push([x, y]);
  7013. },
  7014. lineStart: function() {
  7015. lines.push(line = []);
  7016. },
  7017. lineEnd: noop$2,
  7018. rejoin: function() {
  7019. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  7020. },
  7021. result: function() {
  7022. var result = lines;
  7023. lines = [];
  7024. line = null;
  7025. return result;
  7026. }
  7027. };
  7028. }
  7029. function pointEqual(a, b) {
  7030. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  7031. }
  7032. function Intersection(point, points, other, entry) {
  7033. this.x = point;
  7034. this.z = points;
  7035. this.o = other; // another intersection
  7036. this.e = entry; // is an entry?
  7037. this.v = false; // visited
  7038. this.n = this.p = null; // next & previous
  7039. }
  7040. // A generalized polygon clipping algorithm: given a polygon that has been cut
  7041. // into its visible line segments, and rejoins the segments by interpolating
  7042. // along the clip edge.
  7043. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  7044. var subject = [],
  7045. clip = [],
  7046. i,
  7047. n;
  7048. segments.forEach(function(segment) {
  7049. if ((n = segment.length - 1) <= 0) return;
  7050. var n, p0 = segment[0], p1 = segment[n], x;
  7051. // If the first and last points of a segment are coincident, then treat as a
  7052. // closed ring. TODO if all rings are closed, then the winding order of the
  7053. // exterior ring should be checked.
  7054. if (pointEqual(p0, p1)) {
  7055. stream.lineStart();
  7056. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  7057. stream.lineEnd();
  7058. return;
  7059. }
  7060. subject.push(x = new Intersection(p0, segment, null, true));
  7061. clip.push(x.o = new Intersection(p0, null, x, false));
  7062. subject.push(x = new Intersection(p1, segment, null, false));
  7063. clip.push(x.o = new Intersection(p1, null, x, true));
  7064. });
  7065. if (!subject.length) return;
  7066. clip.sort(compareIntersection);
  7067. link$1(subject);
  7068. link$1(clip);
  7069. for (i = 0, n = clip.length; i < n; ++i) {
  7070. clip[i].e = startInside = !startInside;
  7071. }
  7072. var start = subject[0],
  7073. points,
  7074. point;
  7075. while (1) {
  7076. // Find first unvisited intersection.
  7077. var current = start,
  7078. isSubject = true;
  7079. while (current.v) if ((current = current.n) === start) return;
  7080. points = current.z;
  7081. stream.lineStart();
  7082. do {
  7083. current.v = current.o.v = true;
  7084. if (current.e) {
  7085. if (isSubject) {
  7086. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  7087. } else {
  7088. interpolate(current.x, current.n.x, 1, stream);
  7089. }
  7090. current = current.n;
  7091. } else {
  7092. if (isSubject) {
  7093. points = current.p.z;
  7094. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  7095. } else {
  7096. interpolate(current.x, current.p.x, -1, stream);
  7097. }
  7098. current = current.p;
  7099. }
  7100. current = current.o;
  7101. points = current.z;
  7102. isSubject = !isSubject;
  7103. } while (!current.v);
  7104. stream.lineEnd();
  7105. }
  7106. }
  7107. function link$1(array) {
  7108. if (!(n = array.length)) return;
  7109. var n,
  7110. i = 0,
  7111. a = array[0],
  7112. b;
  7113. while (++i < n) {
  7114. a.n = b = array[i];
  7115. b.p = a;
  7116. a = b;
  7117. }
  7118. a.n = b = array[0];
  7119. b.p = a;
  7120. }
  7121. var sum$1 = adder();
  7122. function longitude(point) {
  7123. if (abs(point[0]) <= pi$3)
  7124. return point[0];
  7125. else
  7126. return sign(point[0]) * ((abs(point[0]) + pi$3) % tau$3 - pi$3);
  7127. }
  7128. function polygonContains(polygon, point) {
  7129. var lambda = longitude(point),
  7130. phi = point[1],
  7131. sinPhi = sin$1(phi),
  7132. normal = [sin$1(lambda), -cos$1(lambda), 0],
  7133. angle = 0,
  7134. winding = 0;
  7135. sum$1.reset();
  7136. if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
  7137. else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
  7138. for (var i = 0, n = polygon.length; i < n; ++i) {
  7139. if (!(m = (ring = polygon[i]).length)) continue;
  7140. var ring,
  7141. m,
  7142. point0 = ring[m - 1],
  7143. lambda0 = longitude(point0),
  7144. phi0 = point0[1] / 2 + quarterPi,
  7145. sinPhi0 = sin$1(phi0),
  7146. cosPhi0 = cos$1(phi0);
  7147. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  7148. var point1 = ring[j],
  7149. lambda1 = longitude(point1),
  7150. phi1 = point1[1] / 2 + quarterPi,
  7151. sinPhi1 = sin$1(phi1),
  7152. cosPhi1 = cos$1(phi1),
  7153. delta = lambda1 - lambda0,
  7154. sign = delta >= 0 ? 1 : -1,
  7155. absDelta = sign * delta,
  7156. antimeridian = absDelta > pi$3,
  7157. k = sinPhi0 * sinPhi1;
  7158. sum$1.add(atan2(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  7159. angle += antimeridian ? delta + sign * tau$3 : delta;
  7160. // Are the longitudes either side of the point’s meridian (lambda),
  7161. // and are the latitudes smaller than the parallel (phi)?
  7162. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  7163. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  7164. cartesianNormalizeInPlace(arc);
  7165. var intersection = cartesianCross(normal, arc);
  7166. cartesianNormalizeInPlace(intersection);
  7167. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  7168. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  7169. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  7170. }
  7171. }
  7172. }
  7173. }
  7174. // First, determine whether the South pole is inside or outside:
  7175. //
  7176. // It is inside if:
  7177. // * the polygon winds around it in a clockwise direction.
  7178. // * the polygon does not (cumulatively) wind around it, but has a negative
  7179. // (counter-clockwise) area.
  7180. //
  7181. // Second, count the (signed) number of times a segment crosses a lambda
  7182. // from the point to the South pole. If it is zero, then the point is the
  7183. // same side as the South pole.
  7184. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  7185. }
  7186. function clip(pointVisible, clipLine, interpolate, start) {
  7187. return function(sink) {
  7188. var line = clipLine(sink),
  7189. ringBuffer = clipBuffer(),
  7190. ringSink = clipLine(ringBuffer),
  7191. polygonStarted = false,
  7192. polygon,
  7193. segments,
  7194. ring;
  7195. var clip = {
  7196. point: point,
  7197. lineStart: lineStart,
  7198. lineEnd: lineEnd,
  7199. polygonStart: function() {
  7200. clip.point = pointRing;
  7201. clip.lineStart = ringStart;
  7202. clip.lineEnd = ringEnd;
  7203. segments = [];
  7204. polygon = [];
  7205. },
  7206. polygonEnd: function() {
  7207. clip.point = point;
  7208. clip.lineStart = lineStart;
  7209. clip.lineEnd = lineEnd;
  7210. segments = merge(segments);
  7211. var startInside = polygonContains(polygon, start);
  7212. if (segments.length) {
  7213. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7214. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  7215. } else if (startInside) {
  7216. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7217. sink.lineStart();
  7218. interpolate(null, null, 1, sink);
  7219. sink.lineEnd();
  7220. }
  7221. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  7222. segments = polygon = null;
  7223. },
  7224. sphere: function() {
  7225. sink.polygonStart();
  7226. sink.lineStart();
  7227. interpolate(null, null, 1, sink);
  7228. sink.lineEnd();
  7229. sink.polygonEnd();
  7230. }
  7231. };
  7232. function point(lambda, phi) {
  7233. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  7234. }
  7235. function pointLine(lambda, phi) {
  7236. line.point(lambda, phi);
  7237. }
  7238. function lineStart() {
  7239. clip.point = pointLine;
  7240. line.lineStart();
  7241. }
  7242. function lineEnd() {
  7243. clip.point = point;
  7244. line.lineEnd();
  7245. }
  7246. function pointRing(lambda, phi) {
  7247. ring.push([lambda, phi]);
  7248. ringSink.point(lambda, phi);
  7249. }
  7250. function ringStart() {
  7251. ringSink.lineStart();
  7252. ring = [];
  7253. }
  7254. function ringEnd() {
  7255. pointRing(ring[0][0], ring[0][1]);
  7256. ringSink.lineEnd();
  7257. var clean = ringSink.clean(),
  7258. ringSegments = ringBuffer.result(),
  7259. i, n = ringSegments.length, m,
  7260. segment,
  7261. point;
  7262. ring.pop();
  7263. polygon.push(ring);
  7264. ring = null;
  7265. if (!n) return;
  7266. // No intersections.
  7267. if (clean & 1) {
  7268. segment = ringSegments[0];
  7269. if ((m = segment.length - 1) > 0) {
  7270. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7271. sink.lineStart();
  7272. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7273. sink.lineEnd();
  7274. }
  7275. return;
  7276. }
  7277. // Rejoin connected segments.
  7278. // TODO reuse ringBuffer.rejoin()?
  7279. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7280. segments.push(ringSegments.filter(validSegment));
  7281. }
  7282. return clip;
  7283. };
  7284. }
  7285. function validSegment(segment) {
  7286. return segment.length > 1;
  7287. }
  7288. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7289. // and circle clipping, the same comparison is used.
  7290. function compareIntersection(a, b) {
  7291. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7292. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7293. }
  7294. var clipAntimeridian = clip(
  7295. function() { return true; },
  7296. clipAntimeridianLine,
  7297. clipAntimeridianInterpolate,
  7298. [-pi$3, -halfPi$2]
  7299. );
  7300. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7301. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7302. // intersections, and the first and last segments should be rejoined.
  7303. function clipAntimeridianLine(stream) {
  7304. var lambda0 = NaN,
  7305. phi0 = NaN,
  7306. sign0 = NaN,
  7307. clean; // no intersections
  7308. return {
  7309. lineStart: function() {
  7310. stream.lineStart();
  7311. clean = 1;
  7312. },
  7313. point: function(lambda1, phi1) {
  7314. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7315. delta = abs(lambda1 - lambda0);
  7316. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7317. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7318. stream.point(sign0, phi0);
  7319. stream.lineEnd();
  7320. stream.lineStart();
  7321. stream.point(sign1, phi0);
  7322. stream.point(lambda1, phi0);
  7323. clean = 0;
  7324. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7325. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7326. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7327. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7328. stream.point(sign0, phi0);
  7329. stream.lineEnd();
  7330. stream.lineStart();
  7331. stream.point(sign1, phi0);
  7332. clean = 0;
  7333. }
  7334. stream.point(lambda0 = lambda1, phi0 = phi1);
  7335. sign0 = sign1;
  7336. },
  7337. lineEnd: function() {
  7338. stream.lineEnd();
  7339. lambda0 = phi0 = NaN;
  7340. },
  7341. clean: function() {
  7342. return 2 - clean; // if intersections, rejoin first and last segments
  7343. }
  7344. };
  7345. }
  7346. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7347. var cosPhi0,
  7348. cosPhi1,
  7349. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7350. return abs(sinLambda0Lambda1) > epsilon$2
  7351. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7352. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7353. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7354. : (phi0 + phi1) / 2;
  7355. }
  7356. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7357. var phi;
  7358. if (from == null) {
  7359. phi = direction * halfPi$2;
  7360. stream.point(-pi$3, phi);
  7361. stream.point(0, phi);
  7362. stream.point(pi$3, phi);
  7363. stream.point(pi$3, 0);
  7364. stream.point(pi$3, -phi);
  7365. stream.point(0, -phi);
  7366. stream.point(-pi$3, -phi);
  7367. stream.point(-pi$3, 0);
  7368. stream.point(-pi$3, phi);
  7369. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7370. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7371. phi = direction * lambda / 2;
  7372. stream.point(-lambda, phi);
  7373. stream.point(0, phi);
  7374. stream.point(lambda, phi);
  7375. } else {
  7376. stream.point(to[0], to[1]);
  7377. }
  7378. }
  7379. function clipCircle(radius) {
  7380. var cr = cos$1(radius),
  7381. delta = 6 * radians,
  7382. smallRadius = cr > 0,
  7383. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7384. function interpolate(from, to, direction, stream) {
  7385. circleStream(stream, radius, delta, direction, from, to);
  7386. }
  7387. function visible(lambda, phi) {
  7388. return cos$1(lambda) * cos$1(phi) > cr;
  7389. }
  7390. // Takes a line and cuts into visible segments. Return values used for polygon
  7391. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7392. // intersections 2 - there were intersections, and the first and last segments
  7393. // should be rejoined.
  7394. function clipLine(stream) {
  7395. var point0, // previous point
  7396. c0, // code for previous point
  7397. v0, // visibility of previous point
  7398. v00, // visibility of first point
  7399. clean; // no intersections
  7400. return {
  7401. lineStart: function() {
  7402. v00 = v0 = false;
  7403. clean = 1;
  7404. },
  7405. point: function(lambda, phi) {
  7406. var point1 = [lambda, phi],
  7407. point2,
  7408. v = visible(lambda, phi),
  7409. c = smallRadius
  7410. ? v ? 0 : code(lambda, phi)
  7411. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7412. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7413. // Handle degeneracies.
  7414. // TODO ignore if not clipping polygons.
  7415. if (v !== v0) {
  7416. point2 = intersect(point0, point1);
  7417. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7418. point1[0] += epsilon$2;
  7419. point1[1] += epsilon$2;
  7420. v = visible(point1[0], point1[1]);
  7421. }
  7422. }
  7423. if (v !== v0) {
  7424. clean = 0;
  7425. if (v) {
  7426. // outside going in
  7427. stream.lineStart();
  7428. point2 = intersect(point1, point0);
  7429. stream.point(point2[0], point2[1]);
  7430. } else {
  7431. // inside going out
  7432. point2 = intersect(point0, point1);
  7433. stream.point(point2[0], point2[1]);
  7434. stream.lineEnd();
  7435. }
  7436. point0 = point2;
  7437. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7438. var t;
  7439. // If the codes for two points are different, or are both zero,
  7440. // and there this segment intersects with the small circle.
  7441. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7442. clean = 0;
  7443. if (smallRadius) {
  7444. stream.lineStart();
  7445. stream.point(t[0][0], t[0][1]);
  7446. stream.point(t[1][0], t[1][1]);
  7447. stream.lineEnd();
  7448. } else {
  7449. stream.point(t[1][0], t[1][1]);
  7450. stream.lineEnd();
  7451. stream.lineStart();
  7452. stream.point(t[0][0], t[0][1]);
  7453. }
  7454. }
  7455. }
  7456. if (v && (!point0 || !pointEqual(point0, point1))) {
  7457. stream.point(point1[0], point1[1]);
  7458. }
  7459. point0 = point1, v0 = v, c0 = c;
  7460. },
  7461. lineEnd: function() {
  7462. if (v0) stream.lineEnd();
  7463. point0 = null;
  7464. },
  7465. // Rejoin first and last segments if there were intersections and the first
  7466. // and last points were visible.
  7467. clean: function() {
  7468. return clean | ((v00 && v0) << 1);
  7469. }
  7470. };
  7471. }
  7472. // Intersects the great circle between a and b with the clip circle.
  7473. function intersect(a, b, two) {
  7474. var pa = cartesian(a),
  7475. pb = cartesian(b);
  7476. // We have two planes, n1.p = d1 and n2.p = d2.
  7477. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7478. var n1 = [1, 0, 0], // normal
  7479. n2 = cartesianCross(pa, pb),
  7480. n2n2 = cartesianDot(n2, n2),
  7481. n1n2 = n2[0], // cartesianDot(n1, n2),
  7482. determinant = n2n2 - n1n2 * n1n2;
  7483. // Two polar points.
  7484. if (!determinant) return !two && a;
  7485. var c1 = cr * n2n2 / determinant,
  7486. c2 = -cr * n1n2 / determinant,
  7487. n1xn2 = cartesianCross(n1, n2),
  7488. A = cartesianScale(n1, c1),
  7489. B = cartesianScale(n2, c2);
  7490. cartesianAddInPlace(A, B);
  7491. // Solve |p(t)|^2 = 1.
  7492. var u = n1xn2,
  7493. w = cartesianDot(A, u),
  7494. uu = cartesianDot(u, u),
  7495. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7496. if (t2 < 0) return;
  7497. var t = sqrt(t2),
  7498. q = cartesianScale(u, (-w - t) / uu);
  7499. cartesianAddInPlace(q, A);
  7500. q = spherical(q);
  7501. if (!two) return q;
  7502. // Two intersection points.
  7503. var lambda0 = a[0],
  7504. lambda1 = b[0],
  7505. phi0 = a[1],
  7506. phi1 = b[1],
  7507. z;
  7508. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7509. var delta = lambda1 - lambda0,
  7510. polar = abs(delta - pi$3) < epsilon$2,
  7511. meridian = polar || delta < epsilon$2;
  7512. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7513. // Check that the first point is between a and b.
  7514. if (meridian
  7515. ? polar
  7516. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7517. : phi0 <= q[1] && q[1] <= phi1
  7518. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7519. var q1 = cartesianScale(u, (-w + t) / uu);
  7520. cartesianAddInPlace(q1, A);
  7521. return [q, spherical(q1)];
  7522. }
  7523. }
  7524. // Generates a 4-bit vector representing the location of a point relative to
  7525. // the small circle's bounding box.
  7526. function code(lambda, phi) {
  7527. var r = smallRadius ? radius : pi$3 - radius,
  7528. code = 0;
  7529. if (lambda < -r) code |= 1; // left
  7530. else if (lambda > r) code |= 2; // right
  7531. if (phi < -r) code |= 4; // below
  7532. else if (phi > r) code |= 8; // above
  7533. return code;
  7534. }
  7535. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7536. }
  7537. function clipLine(a, b, x0, y0, x1, y1) {
  7538. var ax = a[0],
  7539. ay = a[1],
  7540. bx = b[0],
  7541. by = b[1],
  7542. t0 = 0,
  7543. t1 = 1,
  7544. dx = bx - ax,
  7545. dy = by - ay,
  7546. r;
  7547. r = x0 - ax;
  7548. if (!dx && r > 0) return;
  7549. r /= dx;
  7550. if (dx < 0) {
  7551. if (r < t0) return;
  7552. if (r < t1) t1 = r;
  7553. } else if (dx > 0) {
  7554. if (r > t1) return;
  7555. if (r > t0) t0 = r;
  7556. }
  7557. r = x1 - ax;
  7558. if (!dx && r < 0) return;
  7559. r /= dx;
  7560. if (dx < 0) {
  7561. if (r > t1) return;
  7562. if (r > t0) t0 = r;
  7563. } else if (dx > 0) {
  7564. if (r < t0) return;
  7565. if (r < t1) t1 = r;
  7566. }
  7567. r = y0 - ay;
  7568. if (!dy && r > 0) return;
  7569. r /= dy;
  7570. if (dy < 0) {
  7571. if (r < t0) return;
  7572. if (r < t1) t1 = r;
  7573. } else if (dy > 0) {
  7574. if (r > t1) return;
  7575. if (r > t0) t0 = r;
  7576. }
  7577. r = y1 - ay;
  7578. if (!dy && r < 0) return;
  7579. r /= dy;
  7580. if (dy < 0) {
  7581. if (r > t1) return;
  7582. if (r > t0) t0 = r;
  7583. } else if (dy > 0) {
  7584. if (r < t0) return;
  7585. if (r < t1) t1 = r;
  7586. }
  7587. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  7588. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  7589. return true;
  7590. }
  7591. var clipMax = 1e9, clipMin = -clipMax;
  7592. // TODO Use d3-polygon’s polygonContains here for the ring check?
  7593. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  7594. function clipRectangle(x0, y0, x1, y1) {
  7595. function visible(x, y) {
  7596. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  7597. }
  7598. function interpolate(from, to, direction, stream) {
  7599. var a = 0, a1 = 0;
  7600. if (from == null
  7601. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  7602. || comparePoint(from, to) < 0 ^ direction > 0) {
  7603. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  7604. while ((a = (a + direction + 4) % 4) !== a1);
  7605. } else {
  7606. stream.point(to[0], to[1]);
  7607. }
  7608. }
  7609. function corner(p, direction) {
  7610. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  7611. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  7612. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  7613. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  7614. }
  7615. function compareIntersection(a, b) {
  7616. return comparePoint(a.x, b.x);
  7617. }
  7618. function comparePoint(a, b) {
  7619. var ca = corner(a, 1),
  7620. cb = corner(b, 1);
  7621. return ca !== cb ? ca - cb
  7622. : ca === 0 ? b[1] - a[1]
  7623. : ca === 1 ? a[0] - b[0]
  7624. : ca === 2 ? a[1] - b[1]
  7625. : b[0] - a[0];
  7626. }
  7627. return function(stream) {
  7628. var activeStream = stream,
  7629. bufferStream = clipBuffer(),
  7630. segments,
  7631. polygon,
  7632. ring,
  7633. x__, y__, v__, // first point
  7634. x_, y_, v_, // previous point
  7635. first,
  7636. clean;
  7637. var clipStream = {
  7638. point: point,
  7639. lineStart: lineStart,
  7640. lineEnd: lineEnd,
  7641. polygonStart: polygonStart,
  7642. polygonEnd: polygonEnd
  7643. };
  7644. function point(x, y) {
  7645. if (visible(x, y)) activeStream.point(x, y);
  7646. }
  7647. function polygonInside() {
  7648. var winding = 0;
  7649. for (var i = 0, n = polygon.length; i < n; ++i) {
  7650. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  7651. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  7652. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  7653. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  7654. }
  7655. }
  7656. return winding;
  7657. }
  7658. // Buffer geometry within a polygon and then clip it en masse.
  7659. function polygonStart() {
  7660. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  7661. }
  7662. function polygonEnd() {
  7663. var startInside = polygonInside(),
  7664. cleanInside = clean && startInside,
  7665. visible = (segments = merge(segments)).length;
  7666. if (cleanInside || visible) {
  7667. stream.polygonStart();
  7668. if (cleanInside) {
  7669. stream.lineStart();
  7670. interpolate(null, null, 1, stream);
  7671. stream.lineEnd();
  7672. }
  7673. if (visible) {
  7674. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  7675. }
  7676. stream.polygonEnd();
  7677. }
  7678. activeStream = stream, segments = polygon = ring = null;
  7679. }
  7680. function lineStart() {
  7681. clipStream.point = linePoint;
  7682. if (polygon) polygon.push(ring = []);
  7683. first = true;
  7684. v_ = false;
  7685. x_ = y_ = NaN;
  7686. }
  7687. // TODO rather than special-case polygons, simply handle them separately.
  7688. // Ideally, coincident intersection points should be jittered to avoid
  7689. // clipping issues.
  7690. function lineEnd() {
  7691. if (segments) {
  7692. linePoint(x__, y__);
  7693. if (v__ && v_) bufferStream.rejoin();
  7694. segments.push(bufferStream.result());
  7695. }
  7696. clipStream.point = point;
  7697. if (v_) activeStream.lineEnd();
  7698. }
  7699. function linePoint(x, y) {
  7700. var v = visible(x, y);
  7701. if (polygon) ring.push([x, y]);
  7702. if (first) {
  7703. x__ = x, y__ = y, v__ = v;
  7704. first = false;
  7705. if (v) {
  7706. activeStream.lineStart();
  7707. activeStream.point(x, y);
  7708. }
  7709. } else {
  7710. if (v && v_) activeStream.point(x, y);
  7711. else {
  7712. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7713. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7714. if (clipLine(a, b, x0, y0, x1, y1)) {
  7715. if (!v_) {
  7716. activeStream.lineStart();
  7717. activeStream.point(a[0], a[1]);
  7718. }
  7719. activeStream.point(b[0], b[1]);
  7720. if (!v) activeStream.lineEnd();
  7721. clean = false;
  7722. } else if (v) {
  7723. activeStream.lineStart();
  7724. activeStream.point(x, y);
  7725. clean = false;
  7726. }
  7727. }
  7728. }
  7729. x_ = x, y_ = y, v_ = v;
  7730. }
  7731. return clipStream;
  7732. };
  7733. }
  7734. function extent$1() {
  7735. var x0 = 0,
  7736. y0 = 0,
  7737. x1 = 960,
  7738. y1 = 500,
  7739. cache,
  7740. cacheStream,
  7741. clip;
  7742. return clip = {
  7743. stream: function(stream) {
  7744. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7745. },
  7746. extent: function(_) {
  7747. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7748. }
  7749. };
  7750. }
  7751. var lengthSum = adder(),
  7752. lambda0$2,
  7753. sinPhi0$1,
  7754. cosPhi0$1;
  7755. var lengthStream = {
  7756. sphere: noop$2,
  7757. point: noop$2,
  7758. lineStart: lengthLineStart,
  7759. lineEnd: noop$2,
  7760. polygonStart: noop$2,
  7761. polygonEnd: noop$2
  7762. };
  7763. function lengthLineStart() {
  7764. lengthStream.point = lengthPointFirst;
  7765. lengthStream.lineEnd = lengthLineEnd;
  7766. }
  7767. function lengthLineEnd() {
  7768. lengthStream.point = lengthStream.lineEnd = noop$2;
  7769. }
  7770. function lengthPointFirst(lambda, phi) {
  7771. lambda *= radians, phi *= radians;
  7772. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7773. lengthStream.point = lengthPoint;
  7774. }
  7775. function lengthPoint(lambda, phi) {
  7776. lambda *= radians, phi *= radians;
  7777. var sinPhi = sin$1(phi),
  7778. cosPhi = cos$1(phi),
  7779. delta = abs(lambda - lambda0$2),
  7780. cosDelta = cos$1(delta),
  7781. sinDelta = sin$1(delta),
  7782. x = cosPhi * sinDelta,
  7783. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7784. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7785. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7786. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7787. }
  7788. function length$1(object) {
  7789. lengthSum.reset();
  7790. geoStream(object, lengthStream);
  7791. return +lengthSum;
  7792. }
  7793. var coordinates = [null, null],
  7794. object$1 = {type: "LineString", coordinates: coordinates};
  7795. function distance(a, b) {
  7796. coordinates[0] = a;
  7797. coordinates[1] = b;
  7798. return length$1(object$1);
  7799. }
  7800. var containsObjectType = {
  7801. Feature: function(object, point) {
  7802. return containsGeometry(object.geometry, point);
  7803. },
  7804. FeatureCollection: function(object, point) {
  7805. var features = object.features, i = -1, n = features.length;
  7806. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7807. return false;
  7808. }
  7809. };
  7810. var containsGeometryType = {
  7811. Sphere: function() {
  7812. return true;
  7813. },
  7814. Point: function(object, point) {
  7815. return containsPoint(object.coordinates, point);
  7816. },
  7817. MultiPoint: function(object, point) {
  7818. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7819. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7820. return false;
  7821. },
  7822. LineString: function(object, point) {
  7823. return containsLine(object.coordinates, point);
  7824. },
  7825. MultiLineString: function(object, point) {
  7826. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7827. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7828. return false;
  7829. },
  7830. Polygon: function(object, point) {
  7831. return containsPolygon(object.coordinates, point);
  7832. },
  7833. MultiPolygon: function(object, point) {
  7834. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7835. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7836. return false;
  7837. },
  7838. GeometryCollection: function(object, point) {
  7839. var geometries = object.geometries, i = -1, n = geometries.length;
  7840. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7841. return false;
  7842. }
  7843. };
  7844. function containsGeometry(geometry, point) {
  7845. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7846. ? containsGeometryType[geometry.type](geometry, point)
  7847. : false;
  7848. }
  7849. function containsPoint(coordinates, point) {
  7850. return distance(coordinates, point) === 0;
  7851. }
  7852. function containsLine(coordinates, point) {
  7853. var ao, bo, ab;
  7854. for (var i = 0, n = coordinates.length; i < n; i++) {
  7855. bo = distance(coordinates[i], point);
  7856. if (bo === 0) return true;
  7857. if (i > 0) {
  7858. ab = distance(coordinates[i], coordinates[i - 1]);
  7859. if (
  7860. ab > 0 &&
  7861. ao <= ab &&
  7862. bo <= ab &&
  7863. (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2$1 * ab
  7864. )
  7865. return true;
  7866. }
  7867. ao = bo;
  7868. }
  7869. return false;
  7870. }
  7871. function containsPolygon(coordinates, point) {
  7872. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7873. }
  7874. function ringRadians(ring) {
  7875. return ring = ring.map(pointRadians), ring.pop(), ring;
  7876. }
  7877. function pointRadians(point) {
  7878. return [point[0] * radians, point[1] * radians];
  7879. }
  7880. function contains$1(object, point) {
  7881. return (object && containsObjectType.hasOwnProperty(object.type)
  7882. ? containsObjectType[object.type]
  7883. : containsGeometry)(object, point);
  7884. }
  7885. function graticuleX(y0, y1, dy) {
  7886. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7887. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7888. }
  7889. function graticuleY(x0, x1, dx) {
  7890. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7891. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7892. }
  7893. function graticule() {
  7894. var x1, x0, X1, X0,
  7895. y1, y0, Y1, Y0,
  7896. dx = 10, dy = dx, DX = 90, DY = 360,
  7897. x, y, X, Y,
  7898. precision = 2.5;
  7899. function graticule() {
  7900. return {type: "MultiLineString", coordinates: lines()};
  7901. }
  7902. function lines() {
  7903. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7904. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7905. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7906. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7907. }
  7908. graticule.lines = function() {
  7909. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7910. };
  7911. graticule.outline = function() {
  7912. return {
  7913. type: "Polygon",
  7914. coordinates: [
  7915. X(X0).concat(
  7916. Y(Y1).slice(1),
  7917. X(X1).reverse().slice(1),
  7918. Y(Y0).reverse().slice(1))
  7919. ]
  7920. };
  7921. };
  7922. graticule.extent = function(_) {
  7923. if (!arguments.length) return graticule.extentMinor();
  7924. return graticule.extentMajor(_).extentMinor(_);
  7925. };
  7926. graticule.extentMajor = function(_) {
  7927. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7928. X0 = +_[0][0], X1 = +_[1][0];
  7929. Y0 = +_[0][1], Y1 = +_[1][1];
  7930. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7931. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7932. return graticule.precision(precision);
  7933. };
  7934. graticule.extentMinor = function(_) {
  7935. if (!arguments.length) return [[x0, y0], [x1, y1]];
  7936. x0 = +_[0][0], x1 = +_[1][0];
  7937. y0 = +_[0][1], y1 = +_[1][1];
  7938. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  7939. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  7940. return graticule.precision(precision);
  7941. };
  7942. graticule.step = function(_) {
  7943. if (!arguments.length) return graticule.stepMinor();
  7944. return graticule.stepMajor(_).stepMinor(_);
  7945. };
  7946. graticule.stepMajor = function(_) {
  7947. if (!arguments.length) return [DX, DY];
  7948. DX = +_[0], DY = +_[1];
  7949. return graticule;
  7950. };
  7951. graticule.stepMinor = function(_) {
  7952. if (!arguments.length) return [dx, dy];
  7953. dx = +_[0], dy = +_[1];
  7954. return graticule;
  7955. };
  7956. graticule.precision = function(_) {
  7957. if (!arguments.length) return precision;
  7958. precision = +_;
  7959. x = graticuleX(y0, y1, 90);
  7960. y = graticuleY(x0, x1, precision);
  7961. X = graticuleX(Y0, Y1, 90);
  7962. Y = graticuleY(X0, X1, precision);
  7963. return graticule;
  7964. };
  7965. return graticule
  7966. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7967. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7968. }
  7969. function graticule10() {
  7970. return graticule()();
  7971. }
  7972. function interpolate$1(a, b) {
  7973. var x0 = a[0] * radians,
  7974. y0 = a[1] * radians,
  7975. x1 = b[0] * radians,
  7976. y1 = b[1] * radians,
  7977. cy0 = cos$1(y0),
  7978. sy0 = sin$1(y0),
  7979. cy1 = cos$1(y1),
  7980. sy1 = sin$1(y1),
  7981. kx0 = cy0 * cos$1(x0),
  7982. ky0 = cy0 * sin$1(x0),
  7983. kx1 = cy1 * cos$1(x1),
  7984. ky1 = cy1 * sin$1(x1),
  7985. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  7986. k = sin$1(d);
  7987. var interpolate = d ? function(t) {
  7988. var B = sin$1(t *= d) / k,
  7989. A = sin$1(d - t) / k,
  7990. x = A * kx0 + B * kx1,
  7991. y = A * ky0 + B * ky1,
  7992. z = A * sy0 + B * sy1;
  7993. return [
  7994. atan2(y, x) * degrees$1,
  7995. atan2(z, sqrt(x * x + y * y)) * degrees$1
  7996. ];
  7997. } : function() {
  7998. return [x0 * degrees$1, y0 * degrees$1];
  7999. };
  8000. interpolate.distance = d;
  8001. return interpolate;
  8002. }
  8003. function identity$4(x) {
  8004. return x;
  8005. }
  8006. var areaSum$1 = adder(),
  8007. areaRingSum$1 = adder(),
  8008. x00,
  8009. y00,
  8010. x0$1,
  8011. y0$1;
  8012. var areaStream$1 = {
  8013. point: noop$2,
  8014. lineStart: noop$2,
  8015. lineEnd: noop$2,
  8016. polygonStart: function() {
  8017. areaStream$1.lineStart = areaRingStart$1;
  8018. areaStream$1.lineEnd = areaRingEnd$1;
  8019. },
  8020. polygonEnd: function() {
  8021. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  8022. areaSum$1.add(abs(areaRingSum$1));
  8023. areaRingSum$1.reset();
  8024. },
  8025. result: function() {
  8026. var area = areaSum$1 / 2;
  8027. areaSum$1.reset();
  8028. return area;
  8029. }
  8030. };
  8031. function areaRingStart$1() {
  8032. areaStream$1.point = areaPointFirst$1;
  8033. }
  8034. function areaPointFirst$1(x, y) {
  8035. areaStream$1.point = areaPoint$1;
  8036. x00 = x0$1 = x, y00 = y0$1 = y;
  8037. }
  8038. function areaPoint$1(x, y) {
  8039. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  8040. x0$1 = x, y0$1 = y;
  8041. }
  8042. function areaRingEnd$1() {
  8043. areaPoint$1(x00, y00);
  8044. }
  8045. var x0$2 = Infinity,
  8046. y0$2 = x0$2,
  8047. x1 = -x0$2,
  8048. y1 = x1;
  8049. var boundsStream$1 = {
  8050. point: boundsPoint$1,
  8051. lineStart: noop$2,
  8052. lineEnd: noop$2,
  8053. polygonStart: noop$2,
  8054. polygonEnd: noop$2,
  8055. result: function() {
  8056. var bounds = [[x0$2, y0$2], [x1, y1]];
  8057. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  8058. return bounds;
  8059. }
  8060. };
  8061. function boundsPoint$1(x, y) {
  8062. if (x < x0$2) x0$2 = x;
  8063. if (x > x1) x1 = x;
  8064. if (y < y0$2) y0$2 = y;
  8065. if (y > y1) y1 = y;
  8066. }
  8067. // TODO Enforce positive area for exterior, negative area for interior?
  8068. var X0$1 = 0,
  8069. Y0$1 = 0,
  8070. Z0$1 = 0,
  8071. X1$1 = 0,
  8072. Y1$1 = 0,
  8073. Z1$1 = 0,
  8074. X2$1 = 0,
  8075. Y2$1 = 0,
  8076. Z2$1 = 0,
  8077. x00$1,
  8078. y00$1,
  8079. x0$3,
  8080. y0$3;
  8081. var centroidStream$1 = {
  8082. point: centroidPoint$1,
  8083. lineStart: centroidLineStart$1,
  8084. lineEnd: centroidLineEnd$1,
  8085. polygonStart: function() {
  8086. centroidStream$1.lineStart = centroidRingStart$1;
  8087. centroidStream$1.lineEnd = centroidRingEnd$1;
  8088. },
  8089. polygonEnd: function() {
  8090. centroidStream$1.point = centroidPoint$1;
  8091. centroidStream$1.lineStart = centroidLineStart$1;
  8092. centroidStream$1.lineEnd = centroidLineEnd$1;
  8093. },
  8094. result: function() {
  8095. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  8096. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  8097. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  8098. : [NaN, NaN];
  8099. X0$1 = Y0$1 = Z0$1 =
  8100. X1$1 = Y1$1 = Z1$1 =
  8101. X2$1 = Y2$1 = Z2$1 = 0;
  8102. return centroid;
  8103. }
  8104. };
  8105. function centroidPoint$1(x, y) {
  8106. X0$1 += x;
  8107. Y0$1 += y;
  8108. ++Z0$1;
  8109. }
  8110. function centroidLineStart$1() {
  8111. centroidStream$1.point = centroidPointFirstLine;
  8112. }
  8113. function centroidPointFirstLine(x, y) {
  8114. centroidStream$1.point = centroidPointLine;
  8115. centroidPoint$1(x0$3 = x, y0$3 = y);
  8116. }
  8117. function centroidPointLine(x, y) {
  8118. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  8119. X1$1 += z * (x0$3 + x) / 2;
  8120. Y1$1 += z * (y0$3 + y) / 2;
  8121. Z1$1 += z;
  8122. centroidPoint$1(x0$3 = x, y0$3 = y);
  8123. }
  8124. function centroidLineEnd$1() {
  8125. centroidStream$1.point = centroidPoint$1;
  8126. }
  8127. function centroidRingStart$1() {
  8128. centroidStream$1.point = centroidPointFirstRing;
  8129. }
  8130. function centroidRingEnd$1() {
  8131. centroidPointRing(x00$1, y00$1);
  8132. }
  8133. function centroidPointFirstRing(x, y) {
  8134. centroidStream$1.point = centroidPointRing;
  8135. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  8136. }
  8137. function centroidPointRing(x, y) {
  8138. var dx = x - x0$3,
  8139. dy = y - y0$3,
  8140. z = sqrt(dx * dx + dy * dy);
  8141. X1$1 += z * (x0$3 + x) / 2;
  8142. Y1$1 += z * (y0$3 + y) / 2;
  8143. Z1$1 += z;
  8144. z = y0$3 * x - x0$3 * y;
  8145. X2$1 += z * (x0$3 + x);
  8146. Y2$1 += z * (y0$3 + y);
  8147. Z2$1 += z * 3;
  8148. centroidPoint$1(x0$3 = x, y0$3 = y);
  8149. }
  8150. function PathContext(context) {
  8151. this._context = context;
  8152. }
  8153. PathContext.prototype = {
  8154. _radius: 4.5,
  8155. pointRadius: function(_) {
  8156. return this._radius = _, this;
  8157. },
  8158. polygonStart: function() {
  8159. this._line = 0;
  8160. },
  8161. polygonEnd: function() {
  8162. this._line = NaN;
  8163. },
  8164. lineStart: function() {
  8165. this._point = 0;
  8166. },
  8167. lineEnd: function() {
  8168. if (this._line === 0) this._context.closePath();
  8169. this._point = NaN;
  8170. },
  8171. point: function(x, y) {
  8172. switch (this._point) {
  8173. case 0: {
  8174. this._context.moveTo(x, y);
  8175. this._point = 1;
  8176. break;
  8177. }
  8178. case 1: {
  8179. this._context.lineTo(x, y);
  8180. break;
  8181. }
  8182. default: {
  8183. this._context.moveTo(x + this._radius, y);
  8184. this._context.arc(x, y, this._radius, 0, tau$3);
  8185. break;
  8186. }
  8187. }
  8188. },
  8189. result: noop$2
  8190. };
  8191. var lengthSum$1 = adder(),
  8192. lengthRing,
  8193. x00$2,
  8194. y00$2,
  8195. x0$4,
  8196. y0$4;
  8197. var lengthStream$1 = {
  8198. point: noop$2,
  8199. lineStart: function() {
  8200. lengthStream$1.point = lengthPointFirst$1;
  8201. },
  8202. lineEnd: function() {
  8203. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  8204. lengthStream$1.point = noop$2;
  8205. },
  8206. polygonStart: function() {
  8207. lengthRing = true;
  8208. },
  8209. polygonEnd: function() {
  8210. lengthRing = null;
  8211. },
  8212. result: function() {
  8213. var length = +lengthSum$1;
  8214. lengthSum$1.reset();
  8215. return length;
  8216. }
  8217. };
  8218. function lengthPointFirst$1(x, y) {
  8219. lengthStream$1.point = lengthPoint$1;
  8220. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  8221. }
  8222. function lengthPoint$1(x, y) {
  8223. x0$4 -= x, y0$4 -= y;
  8224. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  8225. x0$4 = x, y0$4 = y;
  8226. }
  8227. function PathString() {
  8228. this._string = [];
  8229. }
  8230. PathString.prototype = {
  8231. _radius: 4.5,
  8232. _circle: circle$1(4.5),
  8233. pointRadius: function(_) {
  8234. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  8235. return this;
  8236. },
  8237. polygonStart: function() {
  8238. this._line = 0;
  8239. },
  8240. polygonEnd: function() {
  8241. this._line = NaN;
  8242. },
  8243. lineStart: function() {
  8244. this._point = 0;
  8245. },
  8246. lineEnd: function() {
  8247. if (this._line === 0) this._string.push("Z");
  8248. this._point = NaN;
  8249. },
  8250. point: function(x, y) {
  8251. switch (this._point) {
  8252. case 0: {
  8253. this._string.push("M", x, ",", y);
  8254. this._point = 1;
  8255. break;
  8256. }
  8257. case 1: {
  8258. this._string.push("L", x, ",", y);
  8259. break;
  8260. }
  8261. default: {
  8262. if (this._circle == null) this._circle = circle$1(this._radius);
  8263. this._string.push("M", x, ",", y, this._circle);
  8264. break;
  8265. }
  8266. }
  8267. },
  8268. result: function() {
  8269. if (this._string.length) {
  8270. var result = this._string.join("");
  8271. this._string = [];
  8272. return result;
  8273. } else {
  8274. return null;
  8275. }
  8276. }
  8277. };
  8278. function circle$1(radius) {
  8279. return "m0," + radius
  8280. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  8281. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  8282. + "z";
  8283. }
  8284. function index$1(projection, context) {
  8285. var pointRadius = 4.5,
  8286. projectionStream,
  8287. contextStream;
  8288. function path(object) {
  8289. if (object) {
  8290. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  8291. geoStream(object, projectionStream(contextStream));
  8292. }
  8293. return contextStream.result();
  8294. }
  8295. path.area = function(object) {
  8296. geoStream(object, projectionStream(areaStream$1));
  8297. return areaStream$1.result();
  8298. };
  8299. path.measure = function(object) {
  8300. geoStream(object, projectionStream(lengthStream$1));
  8301. return lengthStream$1.result();
  8302. };
  8303. path.bounds = function(object) {
  8304. geoStream(object, projectionStream(boundsStream$1));
  8305. return boundsStream$1.result();
  8306. };
  8307. path.centroid = function(object) {
  8308. geoStream(object, projectionStream(centroidStream$1));
  8309. return centroidStream$1.result();
  8310. };
  8311. path.projection = function(_) {
  8312. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  8313. };
  8314. path.context = function(_) {
  8315. if (!arguments.length) return context;
  8316. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  8317. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  8318. return path;
  8319. };
  8320. path.pointRadius = function(_) {
  8321. if (!arguments.length) return pointRadius;
  8322. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  8323. return path;
  8324. };
  8325. return path.projection(projection).context(context);
  8326. }
  8327. function transform(methods) {
  8328. return {
  8329. stream: transformer(methods)
  8330. };
  8331. }
  8332. function transformer(methods) {
  8333. return function(stream) {
  8334. var s = new TransformStream;
  8335. for (var key in methods) s[key] = methods[key];
  8336. s.stream = stream;
  8337. return s;
  8338. };
  8339. }
  8340. function TransformStream() {}
  8341. TransformStream.prototype = {
  8342. constructor: TransformStream,
  8343. point: function(x, y) { this.stream.point(x, y); },
  8344. sphere: function() { this.stream.sphere(); },
  8345. lineStart: function() { this.stream.lineStart(); },
  8346. lineEnd: function() { this.stream.lineEnd(); },
  8347. polygonStart: function() { this.stream.polygonStart(); },
  8348. polygonEnd: function() { this.stream.polygonEnd(); }
  8349. };
  8350. function fit(projection, fitBounds, object) {
  8351. var clip = projection.clipExtent && projection.clipExtent();
  8352. projection.scale(150).translate([0, 0]);
  8353. if (clip != null) projection.clipExtent(null);
  8354. geoStream(object, projection.stream(boundsStream$1));
  8355. fitBounds(boundsStream$1.result());
  8356. if (clip != null) projection.clipExtent(clip);
  8357. return projection;
  8358. }
  8359. function fitExtent(projection, extent, object) {
  8360. return fit(projection, function(b) {
  8361. var w = extent[1][0] - extent[0][0],
  8362. h = extent[1][1] - extent[0][1],
  8363. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  8364. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  8365. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  8366. projection.scale(150 * k).translate([x, y]);
  8367. }, object);
  8368. }
  8369. function fitSize(projection, size, object) {
  8370. return fitExtent(projection, [[0, 0], size], object);
  8371. }
  8372. function fitWidth(projection, width, object) {
  8373. return fit(projection, function(b) {
  8374. var w = +width,
  8375. k = w / (b[1][0] - b[0][0]),
  8376. x = (w - k * (b[1][0] + b[0][0])) / 2,
  8377. y = -k * b[0][1];
  8378. projection.scale(150 * k).translate([x, y]);
  8379. }, object);
  8380. }
  8381. function fitHeight(projection, height, object) {
  8382. return fit(projection, function(b) {
  8383. var h = +height,
  8384. k = h / (b[1][1] - b[0][1]),
  8385. x = -k * b[0][0],
  8386. y = (h - k * (b[1][1] + b[0][1])) / 2;
  8387. projection.scale(150 * k).translate([x, y]);
  8388. }, object);
  8389. }
  8390. var maxDepth = 16, // maximum depth of subdivision
  8391. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  8392. function resample(project, delta2) {
  8393. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  8394. }
  8395. function resampleNone(project) {
  8396. return transformer({
  8397. point: function(x, y) {
  8398. x = project(x, y);
  8399. this.stream.point(x[0], x[1]);
  8400. }
  8401. });
  8402. }
  8403. function resample$1(project, delta2) {
  8404. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  8405. var dx = x1 - x0,
  8406. dy = y1 - y0,
  8407. d2 = dx * dx + dy * dy;
  8408. if (d2 > 4 * delta2 && depth--) {
  8409. var a = a0 + a1,
  8410. b = b0 + b1,
  8411. c = c0 + c1,
  8412. m = sqrt(a * a + b * b + c * c),
  8413. phi2 = asin(c /= m),
  8414. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  8415. p = project(lambda2, phi2),
  8416. x2 = p[0],
  8417. y2 = p[1],
  8418. dx2 = x2 - x0,
  8419. dy2 = y2 - y0,
  8420. dz = dy * dx2 - dx * dy2;
  8421. if (dz * dz / d2 > delta2 // perpendicular projected distance
  8422. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  8423. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  8424. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  8425. stream.point(x2, y2);
  8426. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  8427. }
  8428. }
  8429. }
  8430. return function(stream) {
  8431. var lambda00, x00, y00, a00, b00, c00, // first point
  8432. lambda0, x0, y0, a0, b0, c0; // previous point
  8433. var resampleStream = {
  8434. point: point,
  8435. lineStart: lineStart,
  8436. lineEnd: lineEnd,
  8437. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  8438. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  8439. };
  8440. function point(x, y) {
  8441. x = project(x, y);
  8442. stream.point(x[0], x[1]);
  8443. }
  8444. function lineStart() {
  8445. x0 = NaN;
  8446. resampleStream.point = linePoint;
  8447. stream.lineStart();
  8448. }
  8449. function linePoint(lambda, phi) {
  8450. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  8451. 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);
  8452. stream.point(x0, y0);
  8453. }
  8454. function lineEnd() {
  8455. resampleStream.point = point;
  8456. stream.lineEnd();
  8457. }
  8458. function ringStart() {
  8459. lineStart();
  8460. resampleStream.point = ringPoint;
  8461. resampleStream.lineEnd = ringEnd;
  8462. }
  8463. function ringPoint(lambda, phi) {
  8464. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  8465. resampleStream.point = linePoint;
  8466. }
  8467. function ringEnd() {
  8468. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  8469. resampleStream.lineEnd = lineEnd;
  8470. lineEnd();
  8471. }
  8472. return resampleStream;
  8473. };
  8474. }
  8475. var transformRadians = transformer({
  8476. point: function(x, y) {
  8477. this.stream.point(x * radians, y * radians);
  8478. }
  8479. });
  8480. function transformRotate(rotate) {
  8481. return transformer({
  8482. point: function(x, y) {
  8483. var r = rotate(x, y);
  8484. return this.stream.point(r[0], r[1]);
  8485. }
  8486. });
  8487. }
  8488. function scaleTranslate(k, dx, dy) {
  8489. function transform(x, y) {
  8490. return [dx + k * x, dy - k * y];
  8491. }
  8492. transform.invert = function(x, y) {
  8493. return [(x - dx) / k, (dy - y) / k];
  8494. };
  8495. return transform;
  8496. }
  8497. function scaleTranslateRotate(k, dx, dy, alpha) {
  8498. var cosAlpha = cos$1(alpha),
  8499. sinAlpha = sin$1(alpha),
  8500. a = cosAlpha * k,
  8501. b = sinAlpha * k,
  8502. ai = cosAlpha / k,
  8503. bi = sinAlpha / k,
  8504. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  8505. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  8506. function transform(x, y) {
  8507. return [a * x - b * y + dx, dy - b * x - a * y];
  8508. }
  8509. transform.invert = function(x, y) {
  8510. return [ai * x - bi * y + ci, fi - bi * x - ai * y];
  8511. };
  8512. return transform;
  8513. }
  8514. function projection(project) {
  8515. return projectionMutator(function() { return project; })();
  8516. }
  8517. function projectionMutator(projectAt) {
  8518. var project,
  8519. k = 150, // scale
  8520. x = 480, y = 250, // translate
  8521. lambda = 0, phi = 0, // center
  8522. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  8523. alpha = 0, // post-rotate
  8524. theta = null, preclip = clipAntimeridian, // pre-clip angle
  8525. x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
  8526. delta2 = 0.5, // precision
  8527. projectResample,
  8528. projectTransform,
  8529. projectRotateTransform,
  8530. cache,
  8531. cacheStream;
  8532. function projection(point) {
  8533. return projectRotateTransform(point[0] * radians, point[1] * radians);
  8534. }
  8535. function invert(point) {
  8536. point = projectRotateTransform.invert(point[0], point[1]);
  8537. return point && [point[0] * degrees$1, point[1] * degrees$1];
  8538. }
  8539. projection.stream = function(stream) {
  8540. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  8541. };
  8542. projection.preclip = function(_) {
  8543. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  8544. };
  8545. projection.postclip = function(_) {
  8546. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8547. };
  8548. projection.clipAngle = function(_) {
  8549. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  8550. };
  8551. projection.clipExtent = function(_) {
  8552. 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]];
  8553. };
  8554. projection.scale = function(_) {
  8555. return arguments.length ? (k = +_, recenter()) : k;
  8556. };
  8557. projection.translate = function(_) {
  8558. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  8559. };
  8560. projection.center = function(_) {
  8561. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  8562. };
  8563. projection.rotate = function(_) {
  8564. 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];
  8565. };
  8566. projection.angle = function(_) {
  8567. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
  8568. };
  8569. projection.precision = function(_) {
  8570. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  8571. };
  8572. projection.fitExtent = function(extent, object) {
  8573. return fitExtent(projection, extent, object);
  8574. };
  8575. projection.fitSize = function(size, object) {
  8576. return fitSize(projection, size, object);
  8577. };
  8578. projection.fitWidth = function(width, object) {
  8579. return fitWidth(projection, width, object);
  8580. };
  8581. projection.fitHeight = function(height, object) {
  8582. return fitHeight(projection, height, object);
  8583. };
  8584. function recenter() {
  8585. var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
  8586. transform = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
  8587. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  8588. projectTransform = compose(project, transform);
  8589. projectRotateTransform = compose(rotate, projectTransform);
  8590. projectResample = resample(projectTransform, delta2);
  8591. return reset();
  8592. }
  8593. function reset() {
  8594. cache = cacheStream = null;
  8595. return projection;
  8596. }
  8597. return function() {
  8598. project = projectAt.apply(this, arguments);
  8599. projection.invert = project.invert && invert;
  8600. return recenter();
  8601. };
  8602. }
  8603. function conicProjection(projectAt) {
  8604. var phi0 = 0,
  8605. phi1 = pi$3 / 3,
  8606. m = projectionMutator(projectAt),
  8607. p = m(phi0, phi1);
  8608. p.parallels = function(_) {
  8609. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  8610. };
  8611. return p;
  8612. }
  8613. function cylindricalEqualAreaRaw(phi0) {
  8614. var cosPhi0 = cos$1(phi0);
  8615. function forward(lambda, phi) {
  8616. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  8617. }
  8618. forward.invert = function(x, y) {
  8619. return [x / cosPhi0, asin(y * cosPhi0)];
  8620. };
  8621. return forward;
  8622. }
  8623. function conicEqualAreaRaw(y0, y1) {
  8624. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  8625. // Are the parallels symmetrical around the Equator?
  8626. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  8627. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  8628. function project(x, y) {
  8629. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  8630. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  8631. }
  8632. project.invert = function(x, y) {
  8633. var r0y = r0 - y;
  8634. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  8635. };
  8636. return project;
  8637. }
  8638. function conicEqualArea() {
  8639. return conicProjection(conicEqualAreaRaw)
  8640. .scale(155.424)
  8641. .center([0, 33.6442]);
  8642. }
  8643. function albers() {
  8644. return conicEqualArea()
  8645. .parallels([29.5, 45.5])
  8646. .scale(1070)
  8647. .translate([480, 250])
  8648. .rotate([96, 0])
  8649. .center([-0.6, 38.7]);
  8650. }
  8651. // The projections must have mutually exclusive clip regions on the sphere,
  8652. // as this will avoid emitting interleaving lines and polygons.
  8653. function multiplex(streams) {
  8654. var n = streams.length;
  8655. return {
  8656. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  8657. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  8658. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  8659. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  8660. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  8661. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  8662. };
  8663. }
  8664. // A composite projection for the United States, configured by default for
  8665. // 960×500. The projection also works quite well at 960×600 if you change the
  8666. // scale to 1285 and adjust the translate accordingly. The set of standard
  8667. // parallels for each region comes from USGS, which is published here:
  8668. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  8669. function albersUsa() {
  8670. var cache,
  8671. cacheStream,
  8672. lower48 = albers(), lower48Point,
  8673. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  8674. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  8675. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  8676. function albersUsa(coordinates) {
  8677. var x = coordinates[0], y = coordinates[1];
  8678. return point = null,
  8679. (lower48Point.point(x, y), point)
  8680. || (alaskaPoint.point(x, y), point)
  8681. || (hawaiiPoint.point(x, y), point);
  8682. }
  8683. albersUsa.invert = function(coordinates) {
  8684. var k = lower48.scale(),
  8685. t = lower48.translate(),
  8686. x = (coordinates[0] - t[0]) / k,
  8687. y = (coordinates[1] - t[1]) / k;
  8688. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  8689. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  8690. : lower48).invert(coordinates);
  8691. };
  8692. albersUsa.stream = function(stream) {
  8693. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  8694. };
  8695. albersUsa.precision = function(_) {
  8696. if (!arguments.length) return lower48.precision();
  8697. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  8698. return reset();
  8699. };
  8700. albersUsa.scale = function(_) {
  8701. if (!arguments.length) return lower48.scale();
  8702. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  8703. return albersUsa.translate(lower48.translate());
  8704. };
  8705. albersUsa.translate = function(_) {
  8706. if (!arguments.length) return lower48.translate();
  8707. var k = lower48.scale(), x = +_[0], y = +_[1];
  8708. lower48Point = lower48
  8709. .translate(_)
  8710. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  8711. .stream(pointStream);
  8712. alaskaPoint = alaska
  8713. .translate([x - 0.307 * k, y + 0.201 * k])
  8714. .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]])
  8715. .stream(pointStream);
  8716. hawaiiPoint = hawaii
  8717. .translate([x - 0.205 * k, y + 0.212 * k])
  8718. .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]])
  8719. .stream(pointStream);
  8720. return reset();
  8721. };
  8722. albersUsa.fitExtent = function(extent, object) {
  8723. return fitExtent(albersUsa, extent, object);
  8724. };
  8725. albersUsa.fitSize = function(size, object) {
  8726. return fitSize(albersUsa, size, object);
  8727. };
  8728. albersUsa.fitWidth = function(width, object) {
  8729. return fitWidth(albersUsa, width, object);
  8730. };
  8731. albersUsa.fitHeight = function(height, object) {
  8732. return fitHeight(albersUsa, height, object);
  8733. };
  8734. function reset() {
  8735. cache = cacheStream = null;
  8736. return albersUsa;
  8737. }
  8738. return albersUsa.scale(1070);
  8739. }
  8740. function azimuthalRaw(scale) {
  8741. return function(x, y) {
  8742. var cx = cos$1(x),
  8743. cy = cos$1(y),
  8744. k = scale(cx * cy);
  8745. return [
  8746. k * cy * sin$1(x),
  8747. k * sin$1(y)
  8748. ];
  8749. }
  8750. }
  8751. function azimuthalInvert(angle) {
  8752. return function(x, y) {
  8753. var z = sqrt(x * x + y * y),
  8754. c = angle(z),
  8755. sc = sin$1(c),
  8756. cc = cos$1(c);
  8757. return [
  8758. atan2(x * sc, z * cc),
  8759. asin(z && y * sc / z)
  8760. ];
  8761. }
  8762. }
  8763. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8764. return sqrt(2 / (1 + cxcy));
  8765. });
  8766. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8767. return 2 * asin(z / 2);
  8768. });
  8769. function azimuthalEqualArea() {
  8770. return projection(azimuthalEqualAreaRaw)
  8771. .scale(124.75)
  8772. .clipAngle(180 - 1e-3);
  8773. }
  8774. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8775. return (c = acos(c)) && c / sin$1(c);
  8776. });
  8777. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8778. return z;
  8779. });
  8780. function azimuthalEquidistant() {
  8781. return projection(azimuthalEquidistantRaw)
  8782. .scale(79.4188)
  8783. .clipAngle(180 - 1e-3);
  8784. }
  8785. function mercatorRaw(lambda, phi) {
  8786. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8787. }
  8788. mercatorRaw.invert = function(x, y) {
  8789. return [x, 2 * atan(exp(y)) - halfPi$2];
  8790. };
  8791. function mercator() {
  8792. return mercatorProjection(mercatorRaw)
  8793. .scale(961 / tau$3);
  8794. }
  8795. function mercatorProjection(project) {
  8796. var m = projection(project),
  8797. center = m.center,
  8798. scale = m.scale,
  8799. translate = m.translate,
  8800. clipExtent = m.clipExtent,
  8801. x0 = null, y0, x1, y1; // clip extent
  8802. m.scale = function(_) {
  8803. return arguments.length ? (scale(_), reclip()) : scale();
  8804. };
  8805. m.translate = function(_) {
  8806. return arguments.length ? (translate(_), reclip()) : translate();
  8807. };
  8808. m.center = function(_) {
  8809. return arguments.length ? (center(_), reclip()) : center();
  8810. };
  8811. m.clipExtent = function(_) {
  8812. 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]];
  8813. };
  8814. function reclip() {
  8815. var k = pi$3 * scale(),
  8816. t = m(rotation(m.rotate()).invert([0, 0]));
  8817. return clipExtent(x0 == null
  8818. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8819. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8820. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8821. }
  8822. return reclip();
  8823. }
  8824. function tany(y) {
  8825. return tan((halfPi$2 + y) / 2);
  8826. }
  8827. function conicConformalRaw(y0, y1) {
  8828. var cy0 = cos$1(y0),
  8829. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8830. f = cy0 * pow(tany(y0), n) / n;
  8831. if (!n) return mercatorRaw;
  8832. function project(x, y) {
  8833. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8834. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8835. var r = f / pow(tany(y), n);
  8836. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8837. }
  8838. project.invert = function(x, y) {
  8839. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8840. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8841. };
  8842. return project;
  8843. }
  8844. function conicConformal() {
  8845. return conicProjection(conicConformalRaw)
  8846. .scale(109.5)
  8847. .parallels([30, 30]);
  8848. }
  8849. function equirectangularRaw(lambda, phi) {
  8850. return [lambda, phi];
  8851. }
  8852. equirectangularRaw.invert = equirectangularRaw;
  8853. function equirectangular() {
  8854. return projection(equirectangularRaw)
  8855. .scale(152.63);
  8856. }
  8857. function conicEquidistantRaw(y0, y1) {
  8858. var cy0 = cos$1(y0),
  8859. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8860. g = cy0 / n + y0;
  8861. if (abs(n) < epsilon$2) return equirectangularRaw;
  8862. function project(x, y) {
  8863. var gy = g - y, nx = n * x;
  8864. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8865. }
  8866. project.invert = function(x, y) {
  8867. var gy = g - y;
  8868. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8869. };
  8870. return project;
  8871. }
  8872. function conicEquidistant() {
  8873. return conicProjection(conicEquidistantRaw)
  8874. .scale(131.154)
  8875. .center([0, 13.9389]);
  8876. }
  8877. var A1 = 1.340264,
  8878. A2 = -0.081106,
  8879. A3 = 0.000893,
  8880. A4 = 0.003796,
  8881. M = sqrt(3) / 2,
  8882. iterations = 12;
  8883. function equalEarthRaw(lambda, phi) {
  8884. var l = asin(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
  8885. return [
  8886. lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
  8887. l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
  8888. ];
  8889. }
  8890. equalEarthRaw.invert = function(x, y) {
  8891. var l = y, l2 = l * l, l6 = l2 * l2 * l2;
  8892. for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
  8893. fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
  8894. fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
  8895. l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
  8896. if (abs(delta) < epsilon2$1) break;
  8897. }
  8898. return [
  8899. M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
  8900. asin(sin$1(l) / M)
  8901. ];
  8902. };
  8903. function equalEarth() {
  8904. return projection(equalEarthRaw)
  8905. .scale(177.158);
  8906. }
  8907. function gnomonicRaw(x, y) {
  8908. var cy = cos$1(y), k = cos$1(x) * cy;
  8909. return [cy * sin$1(x) / k, sin$1(y) / k];
  8910. }
  8911. gnomonicRaw.invert = azimuthalInvert(atan);
  8912. function gnomonic() {
  8913. return projection(gnomonicRaw)
  8914. .scale(144.049)
  8915. .clipAngle(60);
  8916. }
  8917. function scaleTranslate$1(kx, ky, tx, ty) {
  8918. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8919. point: function(x, y) {
  8920. this.stream.point(x * kx + tx, y * ky + ty);
  8921. }
  8922. });
  8923. }
  8924. function identity$5() {
  8925. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform = identity$4, // scale, translate and reflect
  8926. x0 = null, y0, x1, y1, // clip extent
  8927. postclip = identity$4,
  8928. cache,
  8929. cacheStream,
  8930. projection;
  8931. function reset() {
  8932. cache = cacheStream = null;
  8933. return projection;
  8934. }
  8935. return projection = {
  8936. stream: function(stream) {
  8937. return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
  8938. },
  8939. postclip: function(_) {
  8940. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8941. },
  8942. clipExtent: function(_) {
  8943. 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]];
  8944. },
  8945. scale: function(_) {
  8946. return arguments.length ? (transform = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8947. },
  8948. translate: function(_) {
  8949. return arguments.length ? (transform = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8950. },
  8951. reflectX: function(_) {
  8952. return arguments.length ? (transform = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8953. },
  8954. reflectY: function(_) {
  8955. return arguments.length ? (transform = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8956. },
  8957. fitExtent: function(extent, object) {
  8958. return fitExtent(projection, extent, object);
  8959. },
  8960. fitSize: function(size, object) {
  8961. return fitSize(projection, size, object);
  8962. },
  8963. fitWidth: function(width, object) {
  8964. return fitWidth(projection, width, object);
  8965. },
  8966. fitHeight: function(height, object) {
  8967. return fitHeight(projection, height, object);
  8968. }
  8969. };
  8970. }
  8971. function naturalEarth1Raw(lambda, phi) {
  8972. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8973. return [
  8974. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  8975. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  8976. ];
  8977. }
  8978. naturalEarth1Raw.invert = function(x, y) {
  8979. var phi = y, i = 25, delta;
  8980. do {
  8981. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8982. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  8983. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  8984. } while (abs(delta) > epsilon$2 && --i > 0);
  8985. return [
  8986. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  8987. phi
  8988. ];
  8989. };
  8990. function naturalEarth1() {
  8991. return projection(naturalEarth1Raw)
  8992. .scale(175.295);
  8993. }
  8994. function orthographicRaw(x, y) {
  8995. return [cos$1(y) * sin$1(x), sin$1(y)];
  8996. }
  8997. orthographicRaw.invert = azimuthalInvert(asin);
  8998. function orthographic() {
  8999. return projection(orthographicRaw)
  9000. .scale(249.5)
  9001. .clipAngle(90 + epsilon$2);
  9002. }
  9003. function stereographicRaw(x, y) {
  9004. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  9005. return [cy * sin$1(x) / k, sin$1(y) / k];
  9006. }
  9007. stereographicRaw.invert = azimuthalInvert(function(z) {
  9008. return 2 * atan(z);
  9009. });
  9010. function stereographic() {
  9011. return projection(stereographicRaw)
  9012. .scale(250)
  9013. .clipAngle(142);
  9014. }
  9015. function transverseMercatorRaw(lambda, phi) {
  9016. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  9017. }
  9018. transverseMercatorRaw.invert = function(x, y) {
  9019. return [-y, 2 * atan(exp(x)) - halfPi$2];
  9020. };
  9021. function transverseMercator() {
  9022. var m = mercatorProjection(transverseMercatorRaw),
  9023. center = m.center,
  9024. rotate = m.rotate;
  9025. m.center = function(_) {
  9026. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  9027. };
  9028. m.rotate = function(_) {
  9029. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  9030. };
  9031. return rotate([0, 0, 90])
  9032. .scale(159.155);
  9033. }
  9034. function defaultSeparation(a, b) {
  9035. return a.parent === b.parent ? 1 : 2;
  9036. }
  9037. function meanX(children) {
  9038. return children.reduce(meanXReduce, 0) / children.length;
  9039. }
  9040. function meanXReduce(x, c) {
  9041. return x + c.x;
  9042. }
  9043. function maxY(children) {
  9044. return 1 + children.reduce(maxYReduce, 0);
  9045. }
  9046. function maxYReduce(y, c) {
  9047. return Math.max(y, c.y);
  9048. }
  9049. function leafLeft(node) {
  9050. var children;
  9051. while (children = node.children) node = children[0];
  9052. return node;
  9053. }
  9054. function leafRight(node) {
  9055. var children;
  9056. while (children = node.children) node = children[children.length - 1];
  9057. return node;
  9058. }
  9059. function cluster() {
  9060. var separation = defaultSeparation,
  9061. dx = 1,
  9062. dy = 1,
  9063. nodeSize = false;
  9064. function cluster(root) {
  9065. var previousNode,
  9066. x = 0;
  9067. // First walk, computing the initial x & y values.
  9068. root.eachAfter(function(node) {
  9069. var children = node.children;
  9070. if (children) {
  9071. node.x = meanX(children);
  9072. node.y = maxY(children);
  9073. } else {
  9074. node.x = previousNode ? x += separation(node, previousNode) : 0;
  9075. node.y = 0;
  9076. previousNode = node;
  9077. }
  9078. });
  9079. var left = leafLeft(root),
  9080. right = leafRight(root),
  9081. x0 = left.x - separation(left, right) / 2,
  9082. x1 = right.x + separation(right, left) / 2;
  9083. // Second walk, normalizing x & y to the desired size.
  9084. return root.eachAfter(nodeSize ? function(node) {
  9085. node.x = (node.x - root.x) * dx;
  9086. node.y = (root.y - node.y) * dy;
  9087. } : function(node) {
  9088. node.x = (node.x - x0) / (x1 - x0) * dx;
  9089. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  9090. });
  9091. }
  9092. cluster.separation = function(x) {
  9093. return arguments.length ? (separation = x, cluster) : separation;
  9094. };
  9095. cluster.size = function(x) {
  9096. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  9097. };
  9098. cluster.nodeSize = function(x) {
  9099. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  9100. };
  9101. return cluster;
  9102. }
  9103. function count(node) {
  9104. var sum = 0,
  9105. children = node.children,
  9106. i = children && children.length;
  9107. if (!i) sum = 1;
  9108. else while (--i >= 0) sum += children[i].value;
  9109. node.value = sum;
  9110. }
  9111. function node_count() {
  9112. return this.eachAfter(count);
  9113. }
  9114. function node_each(callback) {
  9115. var node = this, current, next = [node], children, i, n;
  9116. do {
  9117. current = next.reverse(), next = [];
  9118. while (node = current.pop()) {
  9119. callback(node), children = node.children;
  9120. if (children) for (i = 0, n = children.length; i < n; ++i) {
  9121. next.push(children[i]);
  9122. }
  9123. }
  9124. } while (next.length);
  9125. return this;
  9126. }
  9127. function node_eachBefore(callback) {
  9128. var node = this, nodes = [node], children, i;
  9129. while (node = nodes.pop()) {
  9130. callback(node), children = node.children;
  9131. if (children) for (i = children.length - 1; i >= 0; --i) {
  9132. nodes.push(children[i]);
  9133. }
  9134. }
  9135. return this;
  9136. }
  9137. function node_eachAfter(callback) {
  9138. var node = this, nodes = [node], next = [], children, i, n;
  9139. while (node = nodes.pop()) {
  9140. next.push(node), children = node.children;
  9141. if (children) for (i = 0, n = children.length; i < n; ++i) {
  9142. nodes.push(children[i]);
  9143. }
  9144. }
  9145. while (node = next.pop()) {
  9146. callback(node);
  9147. }
  9148. return this;
  9149. }
  9150. function node_sum(value) {
  9151. return this.eachAfter(function(node) {
  9152. var sum = +value(node.data) || 0,
  9153. children = node.children,
  9154. i = children && children.length;
  9155. while (--i >= 0) sum += children[i].value;
  9156. node.value = sum;
  9157. });
  9158. }
  9159. function node_sort(compare) {
  9160. return this.eachBefore(function(node) {
  9161. if (node.children) {
  9162. node.children.sort(compare);
  9163. }
  9164. });
  9165. }
  9166. function node_path(end) {
  9167. var start = this,
  9168. ancestor = leastCommonAncestor(start, end),
  9169. nodes = [start];
  9170. while (start !== ancestor) {
  9171. start = start.parent;
  9172. nodes.push(start);
  9173. }
  9174. var k = nodes.length;
  9175. while (end !== ancestor) {
  9176. nodes.splice(k, 0, end);
  9177. end = end.parent;
  9178. }
  9179. return nodes;
  9180. }
  9181. function leastCommonAncestor(a, b) {
  9182. if (a === b) return a;
  9183. var aNodes = a.ancestors(),
  9184. bNodes = b.ancestors(),
  9185. c = null;
  9186. a = aNodes.pop();
  9187. b = bNodes.pop();
  9188. while (a === b) {
  9189. c = a;
  9190. a = aNodes.pop();
  9191. b = bNodes.pop();
  9192. }
  9193. return c;
  9194. }
  9195. function node_ancestors() {
  9196. var node = this, nodes = [node];
  9197. while (node = node.parent) {
  9198. nodes.push(node);
  9199. }
  9200. return nodes;
  9201. }
  9202. function node_descendants() {
  9203. var nodes = [];
  9204. this.each(function(node) {
  9205. nodes.push(node);
  9206. });
  9207. return nodes;
  9208. }
  9209. function node_leaves() {
  9210. var leaves = [];
  9211. this.eachBefore(function(node) {
  9212. if (!node.children) {
  9213. leaves.push(node);
  9214. }
  9215. });
  9216. return leaves;
  9217. }
  9218. function node_links() {
  9219. var root = this, links = [];
  9220. root.each(function(node) {
  9221. if (node !== root) { // Don’t include the root’s parent, if any.
  9222. links.push({source: node.parent, target: node});
  9223. }
  9224. });
  9225. return links;
  9226. }
  9227. function hierarchy(data, children) {
  9228. var root = new Node(data),
  9229. valued = +data.value && (root.value = data.value),
  9230. node,
  9231. nodes = [root],
  9232. child,
  9233. childs,
  9234. i,
  9235. n;
  9236. if (children == null) children = defaultChildren;
  9237. while (node = nodes.pop()) {
  9238. if (valued) node.value = +node.data.value;
  9239. if ((childs = children(node.data)) && (n = childs.length)) {
  9240. node.children = new Array(n);
  9241. for (i = n - 1; i >= 0; --i) {
  9242. nodes.push(child = node.children[i] = new Node(childs[i]));
  9243. child.parent = node;
  9244. child.depth = node.depth + 1;
  9245. }
  9246. }
  9247. }
  9248. return root.eachBefore(computeHeight);
  9249. }
  9250. function node_copy() {
  9251. return hierarchy(this).eachBefore(copyData);
  9252. }
  9253. function defaultChildren(d) {
  9254. return d.children;
  9255. }
  9256. function copyData(node) {
  9257. node.data = node.data.data;
  9258. }
  9259. function computeHeight(node) {
  9260. var height = 0;
  9261. do node.height = height;
  9262. while ((node = node.parent) && (node.height < ++height));
  9263. }
  9264. function Node(data) {
  9265. this.data = data;
  9266. this.depth =
  9267. this.height = 0;
  9268. this.parent = null;
  9269. }
  9270. Node.prototype = hierarchy.prototype = {
  9271. constructor: Node,
  9272. count: node_count,
  9273. each: node_each,
  9274. eachAfter: node_eachAfter,
  9275. eachBefore: node_eachBefore,
  9276. sum: node_sum,
  9277. sort: node_sort,
  9278. path: node_path,
  9279. ancestors: node_ancestors,
  9280. descendants: node_descendants,
  9281. leaves: node_leaves,
  9282. links: node_links,
  9283. copy: node_copy
  9284. };
  9285. var slice$4 = Array.prototype.slice;
  9286. function shuffle$1(array) {
  9287. var m = array.length,
  9288. t,
  9289. i;
  9290. while (m) {
  9291. i = Math.random() * m-- | 0;
  9292. t = array[m];
  9293. array[m] = array[i];
  9294. array[i] = t;
  9295. }
  9296. return array;
  9297. }
  9298. function enclose(circles) {
  9299. var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
  9300. while (i < n) {
  9301. p = circles[i];
  9302. if (e && enclosesWeak(e, p)) ++i;
  9303. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  9304. }
  9305. return e;
  9306. }
  9307. function extendBasis(B, p) {
  9308. var i, j;
  9309. if (enclosesWeakAll(p, B)) return [p];
  9310. // If we get here then B must have at least one element.
  9311. for (i = 0; i < B.length; ++i) {
  9312. if (enclosesNot(p, B[i])
  9313. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  9314. return [B[i], p];
  9315. }
  9316. }
  9317. // If we get here then B must have at least two elements.
  9318. for (i = 0; i < B.length - 1; ++i) {
  9319. for (j = i + 1; j < B.length; ++j) {
  9320. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  9321. && enclosesNot(encloseBasis2(B[i], p), B[j])
  9322. && enclosesNot(encloseBasis2(B[j], p), B[i])
  9323. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  9324. return [B[i], B[j], p];
  9325. }
  9326. }
  9327. }
  9328. // If we get here then something is very wrong.
  9329. throw new Error;
  9330. }
  9331. function enclosesNot(a, b) {
  9332. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  9333. return dr < 0 || dr * dr < dx * dx + dy * dy;
  9334. }
  9335. function enclosesWeak(a, b) {
  9336. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9337. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9338. }
  9339. function enclosesWeakAll(a, B) {
  9340. for (var i = 0; i < B.length; ++i) {
  9341. if (!enclosesWeak(a, B[i])) {
  9342. return false;
  9343. }
  9344. }
  9345. return true;
  9346. }
  9347. function encloseBasis(B) {
  9348. switch (B.length) {
  9349. case 1: return encloseBasis1(B[0]);
  9350. case 2: return encloseBasis2(B[0], B[1]);
  9351. case 3: return encloseBasis3(B[0], B[1], B[2]);
  9352. }
  9353. }
  9354. function encloseBasis1(a) {
  9355. return {
  9356. x: a.x,
  9357. y: a.y,
  9358. r: a.r
  9359. };
  9360. }
  9361. function encloseBasis2(a, b) {
  9362. var x1 = a.x, y1 = a.y, r1 = a.r,
  9363. x2 = b.x, y2 = b.y, r2 = b.r,
  9364. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  9365. l = Math.sqrt(x21 * x21 + y21 * y21);
  9366. return {
  9367. x: (x1 + x2 + x21 / l * r21) / 2,
  9368. y: (y1 + y2 + y21 / l * r21) / 2,
  9369. r: (l + r1 + r2) / 2
  9370. };
  9371. }
  9372. function encloseBasis3(a, b, c) {
  9373. var x1 = a.x, y1 = a.y, r1 = a.r,
  9374. x2 = b.x, y2 = b.y, r2 = b.r,
  9375. x3 = c.x, y3 = c.y, r3 = c.r,
  9376. a2 = x1 - x2,
  9377. a3 = x1 - x3,
  9378. b2 = y1 - y2,
  9379. b3 = y1 - y3,
  9380. c2 = r2 - r1,
  9381. c3 = r3 - r1,
  9382. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  9383. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  9384. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  9385. ab = a3 * b2 - a2 * b3,
  9386. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  9387. xb = (b3 * c2 - b2 * c3) / ab,
  9388. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  9389. yb = (a2 * c3 - a3 * c2) / ab,
  9390. A = xb * xb + yb * yb - 1,
  9391. B = 2 * (r1 + xa * xb + ya * yb),
  9392. C = xa * xa + ya * ya - r1 * r1,
  9393. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  9394. return {
  9395. x: x1 + xa + xb * r,
  9396. y: y1 + ya + yb * r,
  9397. r: r
  9398. };
  9399. }
  9400. function place(b, a, c) {
  9401. var dx = b.x - a.x, x, a2,
  9402. dy = b.y - a.y, y, b2,
  9403. d2 = dx * dx + dy * dy;
  9404. if (d2) {
  9405. a2 = a.r + c.r, a2 *= a2;
  9406. b2 = b.r + c.r, b2 *= b2;
  9407. if (a2 > b2) {
  9408. x = (d2 + b2 - a2) / (2 * d2);
  9409. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  9410. c.x = b.x - x * dx - y * dy;
  9411. c.y = b.y - x * dy + y * dx;
  9412. } else {
  9413. x = (d2 + a2 - b2) / (2 * d2);
  9414. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  9415. c.x = a.x + x * dx - y * dy;
  9416. c.y = a.y + x * dy + y * dx;
  9417. }
  9418. } else {
  9419. c.x = a.x + c.r;
  9420. c.y = a.y;
  9421. }
  9422. }
  9423. function intersects(a, b) {
  9424. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9425. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9426. }
  9427. function score(node) {
  9428. var a = node._,
  9429. b = node.next._,
  9430. ab = a.r + b.r,
  9431. dx = (a.x * b.r + b.x * a.r) / ab,
  9432. dy = (a.y * b.r + b.y * a.r) / ab;
  9433. return dx * dx + dy * dy;
  9434. }
  9435. function Node$1(circle) {
  9436. this._ = circle;
  9437. this.next = null;
  9438. this.previous = null;
  9439. }
  9440. function packEnclose(circles) {
  9441. if (!(n = circles.length)) return 0;
  9442. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  9443. // Place the first circle.
  9444. a = circles[0], a.x = 0, a.y = 0;
  9445. if (!(n > 1)) return a.r;
  9446. // Place the second circle.
  9447. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  9448. if (!(n > 2)) return a.r + b.r;
  9449. // Place the third circle.
  9450. place(b, a, c = circles[2]);
  9451. // Initialize the front-chain using the first three circles a, b and c.
  9452. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  9453. a.next = c.previous = b;
  9454. b.next = a.previous = c;
  9455. c.next = b.previous = a;
  9456. // Attempt to place each remaining circle…
  9457. pack: for (i = 3; i < n; ++i) {
  9458. place(a._, b._, c = circles[i]), c = new Node$1(c);
  9459. // Find the closest intersecting circle on the front-chain, if any.
  9460. // “Closeness” is determined by linear distance along the front-chain.
  9461. // “Ahead” or “behind” is likewise determined by linear distance.
  9462. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  9463. do {
  9464. if (sj <= sk) {
  9465. if (intersects(j._, c._)) {
  9466. b = j, a.next = b, b.previous = a, --i;
  9467. continue pack;
  9468. }
  9469. sj += j._.r, j = j.next;
  9470. } else {
  9471. if (intersects(k._, c._)) {
  9472. a = k, a.next = b, b.previous = a, --i;
  9473. continue pack;
  9474. }
  9475. sk += k._.r, k = k.previous;
  9476. }
  9477. } while (j !== k.next);
  9478. // Success! Insert the new circle c between a and b.
  9479. c.previous = a, c.next = b, a.next = b.previous = b = c;
  9480. // Compute the new closest circle pair to the centroid.
  9481. aa = score(a);
  9482. while ((c = c.next) !== b) {
  9483. if ((ca = score(c)) < aa) {
  9484. a = c, aa = ca;
  9485. }
  9486. }
  9487. b = a.next;
  9488. }
  9489. // Compute the enclosing circle of the front chain.
  9490. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  9491. // Translate the circles to put the enclosing circle around the origin.
  9492. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  9493. return c.r;
  9494. }
  9495. function siblings(circles) {
  9496. packEnclose(circles);
  9497. return circles;
  9498. }
  9499. function optional(f) {
  9500. return f == null ? null : required(f);
  9501. }
  9502. function required(f) {
  9503. if (typeof f !== "function") throw new Error;
  9504. return f;
  9505. }
  9506. function constantZero() {
  9507. return 0;
  9508. }
  9509. function constant$9(x) {
  9510. return function() {
  9511. return x;
  9512. };
  9513. }
  9514. function defaultRadius$1(d) {
  9515. return Math.sqrt(d.value);
  9516. }
  9517. function index$2() {
  9518. var radius = null,
  9519. dx = 1,
  9520. dy = 1,
  9521. padding = constantZero;
  9522. function pack(root) {
  9523. root.x = dx / 2, root.y = dy / 2;
  9524. if (radius) {
  9525. root.eachBefore(radiusLeaf(radius))
  9526. .eachAfter(packChildren(padding, 0.5))
  9527. .eachBefore(translateChild(1));
  9528. } else {
  9529. root.eachBefore(radiusLeaf(defaultRadius$1))
  9530. .eachAfter(packChildren(constantZero, 1))
  9531. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  9532. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  9533. }
  9534. return root;
  9535. }
  9536. pack.radius = function(x) {
  9537. return arguments.length ? (radius = optional(x), pack) : radius;
  9538. };
  9539. pack.size = function(x) {
  9540. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  9541. };
  9542. pack.padding = function(x) {
  9543. return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
  9544. };
  9545. return pack;
  9546. }
  9547. function radiusLeaf(radius) {
  9548. return function(node) {
  9549. if (!node.children) {
  9550. node.r = Math.max(0, +radius(node) || 0);
  9551. }
  9552. };
  9553. }
  9554. function packChildren(padding, k) {
  9555. return function(node) {
  9556. if (children = node.children) {
  9557. var children,
  9558. i,
  9559. n = children.length,
  9560. r = padding(node) * k || 0,
  9561. e;
  9562. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  9563. e = packEnclose(children);
  9564. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  9565. node.r = e + r;
  9566. }
  9567. };
  9568. }
  9569. function translateChild(k) {
  9570. return function(node) {
  9571. var parent = node.parent;
  9572. node.r *= k;
  9573. if (parent) {
  9574. node.x = parent.x + k * node.x;
  9575. node.y = parent.y + k * node.y;
  9576. }
  9577. };
  9578. }
  9579. function roundNode(node) {
  9580. node.x0 = Math.round(node.x0);
  9581. node.y0 = Math.round(node.y0);
  9582. node.x1 = Math.round(node.x1);
  9583. node.y1 = Math.round(node.y1);
  9584. }
  9585. function treemapDice(parent, x0, y0, x1, y1) {
  9586. var nodes = parent.children,
  9587. node,
  9588. i = -1,
  9589. n = nodes.length,
  9590. k = parent.value && (x1 - x0) / parent.value;
  9591. while (++i < n) {
  9592. node = nodes[i], node.y0 = y0, node.y1 = y1;
  9593. node.x0 = x0, node.x1 = x0 += node.value * k;
  9594. }
  9595. }
  9596. function partition() {
  9597. var dx = 1,
  9598. dy = 1,
  9599. padding = 0,
  9600. round = false;
  9601. function partition(root) {
  9602. var n = root.height + 1;
  9603. root.x0 =
  9604. root.y0 = padding;
  9605. root.x1 = dx;
  9606. root.y1 = dy / n;
  9607. root.eachBefore(positionNode(dy, n));
  9608. if (round) root.eachBefore(roundNode);
  9609. return root;
  9610. }
  9611. function positionNode(dy, n) {
  9612. return function(node) {
  9613. if (node.children) {
  9614. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  9615. }
  9616. var x0 = node.x0,
  9617. y0 = node.y0,
  9618. x1 = node.x1 - padding,
  9619. y1 = node.y1 - padding;
  9620. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9621. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9622. node.x0 = x0;
  9623. node.y0 = y0;
  9624. node.x1 = x1;
  9625. node.y1 = y1;
  9626. };
  9627. }
  9628. partition.round = function(x) {
  9629. return arguments.length ? (round = !!x, partition) : round;
  9630. };
  9631. partition.size = function(x) {
  9632. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  9633. };
  9634. partition.padding = function(x) {
  9635. return arguments.length ? (padding = +x, partition) : padding;
  9636. };
  9637. return partition;
  9638. }
  9639. var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
  9640. preroot = {depth: -1},
  9641. ambiguous = {};
  9642. function defaultId(d) {
  9643. return d.id;
  9644. }
  9645. function defaultParentId(d) {
  9646. return d.parentId;
  9647. }
  9648. function stratify() {
  9649. var id = defaultId,
  9650. parentId = defaultParentId;
  9651. function stratify(data) {
  9652. var d,
  9653. i,
  9654. n = data.length,
  9655. root,
  9656. parent,
  9657. node,
  9658. nodes = new Array(n),
  9659. nodeId,
  9660. nodeKey,
  9661. nodeByKey = {};
  9662. for (i = 0; i < n; ++i) {
  9663. d = data[i], node = nodes[i] = new Node(d);
  9664. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  9665. nodeKey = keyPrefix$1 + (node.id = nodeId);
  9666. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  9667. }
  9668. }
  9669. for (i = 0; i < n; ++i) {
  9670. node = nodes[i], nodeId = parentId(data[i], i, data);
  9671. if (nodeId == null || !(nodeId += "")) {
  9672. if (root) throw new Error("multiple roots");
  9673. root = node;
  9674. } else {
  9675. parent = nodeByKey[keyPrefix$1 + nodeId];
  9676. if (!parent) throw new Error("missing: " + nodeId);
  9677. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  9678. if (parent.children) parent.children.push(node);
  9679. else parent.children = [node];
  9680. node.parent = parent;
  9681. }
  9682. }
  9683. if (!root) throw new Error("no root");
  9684. root.parent = preroot;
  9685. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  9686. root.parent = null;
  9687. if (n > 0) throw new Error("cycle");
  9688. return root;
  9689. }
  9690. stratify.id = function(x) {
  9691. return arguments.length ? (id = required(x), stratify) : id;
  9692. };
  9693. stratify.parentId = function(x) {
  9694. return arguments.length ? (parentId = required(x), stratify) : parentId;
  9695. };
  9696. return stratify;
  9697. }
  9698. function defaultSeparation$1(a, b) {
  9699. return a.parent === b.parent ? 1 : 2;
  9700. }
  9701. // function radialSeparation(a, b) {
  9702. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  9703. // }
  9704. // This function is used to traverse the left contour of a subtree (or
  9705. // subforest). It returns the successor of v on this contour. This successor is
  9706. // either given by the leftmost child of v or by the thread of v. The function
  9707. // returns null if and only if v is on the highest level of its subtree.
  9708. function nextLeft(v) {
  9709. var children = v.children;
  9710. return children ? children[0] : v.t;
  9711. }
  9712. // This function works analogously to nextLeft.
  9713. function nextRight(v) {
  9714. var children = v.children;
  9715. return children ? children[children.length - 1] : v.t;
  9716. }
  9717. // Shifts the current subtree rooted at w+. This is done by increasing
  9718. // prelim(w+) and mod(w+) by shift.
  9719. function moveSubtree(wm, wp, shift) {
  9720. var change = shift / (wp.i - wm.i);
  9721. wp.c -= change;
  9722. wp.s += shift;
  9723. wm.c += change;
  9724. wp.z += shift;
  9725. wp.m += shift;
  9726. }
  9727. // All other shifts, applied to the smaller subtrees between w- and w+, are
  9728. // performed by this function. To prepare the shifts, we have to adjust
  9729. // change(w+), shift(w+), and change(w-).
  9730. function executeShifts(v) {
  9731. var shift = 0,
  9732. change = 0,
  9733. children = v.children,
  9734. i = children.length,
  9735. w;
  9736. while (--i >= 0) {
  9737. w = children[i];
  9738. w.z += shift;
  9739. w.m += shift;
  9740. shift += w.s + (change += w.c);
  9741. }
  9742. }
  9743. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  9744. // returns the specified (default) ancestor.
  9745. function nextAncestor(vim, v, ancestor) {
  9746. return vim.a.parent === v.parent ? vim.a : ancestor;
  9747. }
  9748. function TreeNode(node, i) {
  9749. this._ = node;
  9750. this.parent = null;
  9751. this.children = null;
  9752. this.A = null; // default ancestor
  9753. this.a = this; // ancestor
  9754. this.z = 0; // prelim
  9755. this.m = 0; // mod
  9756. this.c = 0; // change
  9757. this.s = 0; // shift
  9758. this.t = null; // thread
  9759. this.i = i; // number
  9760. }
  9761. TreeNode.prototype = Object.create(Node.prototype);
  9762. function treeRoot(root) {
  9763. var tree = new TreeNode(root, 0),
  9764. node,
  9765. nodes = [tree],
  9766. child,
  9767. children,
  9768. i,
  9769. n;
  9770. while (node = nodes.pop()) {
  9771. if (children = node._.children) {
  9772. node.children = new Array(n = children.length);
  9773. for (i = n - 1; i >= 0; --i) {
  9774. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  9775. child.parent = node;
  9776. }
  9777. }
  9778. }
  9779. (tree.parent = new TreeNode(null, 0)).children = [tree];
  9780. return tree;
  9781. }
  9782. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  9783. function tree() {
  9784. var separation = defaultSeparation$1,
  9785. dx = 1,
  9786. dy = 1,
  9787. nodeSize = null;
  9788. function tree(root) {
  9789. var t = treeRoot(root);
  9790. // Compute the layout using Buchheim et al.’s algorithm.
  9791. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9792. t.eachBefore(secondWalk);
  9793. // If a fixed node size is specified, scale x and y.
  9794. if (nodeSize) root.eachBefore(sizeNode);
  9795. // If a fixed tree size is specified, scale x and y based on the extent.
  9796. // Compute the left-most, right-most, and depth-most nodes for extents.
  9797. else {
  9798. var left = root,
  9799. right = root,
  9800. bottom = root;
  9801. root.eachBefore(function(node) {
  9802. if (node.x < left.x) left = node;
  9803. if (node.x > right.x) right = node;
  9804. if (node.depth > bottom.depth) bottom = node;
  9805. });
  9806. var s = left === right ? 1 : separation(left, right) / 2,
  9807. tx = s - left.x,
  9808. kx = dx / (right.x + s + tx),
  9809. ky = dy / (bottom.depth || 1);
  9810. root.eachBefore(function(node) {
  9811. node.x = (node.x + tx) * kx;
  9812. node.y = node.depth * ky;
  9813. });
  9814. }
  9815. return root;
  9816. }
  9817. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9818. // applied recursively to the children of v, as well as the function
  9819. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9820. // node v is placed to the midpoint of its outermost children.
  9821. function firstWalk(v) {
  9822. var children = v.children,
  9823. siblings = v.parent.children,
  9824. w = v.i ? siblings[v.i - 1] : null;
  9825. if (children) {
  9826. executeShifts(v);
  9827. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9828. if (w) {
  9829. v.z = w.z + separation(v._, w._);
  9830. v.m = v.z - midpoint;
  9831. } else {
  9832. v.z = midpoint;
  9833. }
  9834. } else if (w) {
  9835. v.z = w.z + separation(v._, w._);
  9836. }
  9837. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9838. }
  9839. // Computes all real x-coordinates by summing up the modifiers recursively.
  9840. function secondWalk(v) {
  9841. v._.x = v.z + v.parent.m;
  9842. v.m += v.parent.m;
  9843. }
  9844. // The core of the algorithm. Here, a new subtree is combined with the
  9845. // previous subtrees. Threads are used to traverse the inside and outside
  9846. // contours of the left and right subtree up to the highest common level. The
  9847. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9848. // superscript o means outside and i means inside, the subscript - means left
  9849. // subtree and + means right subtree. For summing up the modifiers along the
  9850. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9851. // nodes of the inside contours conflict, we compute the left one of the
  9852. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9853. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9854. // Finally, we add a new thread (if necessary).
  9855. function apportion(v, w, ancestor) {
  9856. if (w) {
  9857. var vip = v,
  9858. vop = v,
  9859. vim = w,
  9860. vom = vip.parent.children[0],
  9861. sip = vip.m,
  9862. sop = vop.m,
  9863. sim = vim.m,
  9864. som = vom.m,
  9865. shift;
  9866. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9867. vom = nextLeft(vom);
  9868. vop = nextRight(vop);
  9869. vop.a = v;
  9870. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9871. if (shift > 0) {
  9872. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9873. sip += shift;
  9874. sop += shift;
  9875. }
  9876. sim += vim.m;
  9877. sip += vip.m;
  9878. som += vom.m;
  9879. sop += vop.m;
  9880. }
  9881. if (vim && !nextRight(vop)) {
  9882. vop.t = vim;
  9883. vop.m += sim - sop;
  9884. }
  9885. if (vip && !nextLeft(vom)) {
  9886. vom.t = vip;
  9887. vom.m += sip - som;
  9888. ancestor = v;
  9889. }
  9890. }
  9891. return ancestor;
  9892. }
  9893. function sizeNode(node) {
  9894. node.x *= dx;
  9895. node.y = node.depth * dy;
  9896. }
  9897. tree.separation = function(x) {
  9898. return arguments.length ? (separation = x, tree) : separation;
  9899. };
  9900. tree.size = function(x) {
  9901. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9902. };
  9903. tree.nodeSize = function(x) {
  9904. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9905. };
  9906. return tree;
  9907. }
  9908. function treemapSlice(parent, x0, y0, x1, y1) {
  9909. var nodes = parent.children,
  9910. node,
  9911. i = -1,
  9912. n = nodes.length,
  9913. k = parent.value && (y1 - y0) / parent.value;
  9914. while (++i < n) {
  9915. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9916. node.y0 = y0, node.y1 = y0 += node.value * k;
  9917. }
  9918. }
  9919. var phi = (1 + Math.sqrt(5)) / 2;
  9920. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9921. var rows = [],
  9922. nodes = parent.children,
  9923. row,
  9924. nodeValue,
  9925. i0 = 0,
  9926. i1 = 0,
  9927. n = nodes.length,
  9928. dx, dy,
  9929. value = parent.value,
  9930. sumValue,
  9931. minValue,
  9932. maxValue,
  9933. newRatio,
  9934. minRatio,
  9935. alpha,
  9936. beta;
  9937. while (i0 < n) {
  9938. dx = x1 - x0, dy = y1 - y0;
  9939. // Find the next non-empty node.
  9940. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9941. minValue = maxValue = sumValue;
  9942. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9943. beta = sumValue * sumValue * alpha;
  9944. minRatio = Math.max(maxValue / beta, beta / minValue);
  9945. // Keep adding nodes while the aspect ratio maintains or improves.
  9946. for (; i1 < n; ++i1) {
  9947. sumValue += nodeValue = nodes[i1].value;
  9948. if (nodeValue < minValue) minValue = nodeValue;
  9949. if (nodeValue > maxValue) maxValue = nodeValue;
  9950. beta = sumValue * sumValue * alpha;
  9951. newRatio = Math.max(maxValue / beta, beta / minValue);
  9952. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9953. minRatio = newRatio;
  9954. }
  9955. // Position and record the row orientation.
  9956. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9957. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9958. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9959. value -= sumValue, i0 = i1;
  9960. }
  9961. return rows;
  9962. }
  9963. var squarify = (function custom(ratio) {
  9964. function squarify(parent, x0, y0, x1, y1) {
  9965. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9966. }
  9967. squarify.ratio = function(x) {
  9968. return custom((x = +x) > 1 ? x : 1);
  9969. };
  9970. return squarify;
  9971. })(phi);
  9972. function index$3() {
  9973. var tile = squarify,
  9974. round = false,
  9975. dx = 1,
  9976. dy = 1,
  9977. paddingStack = [0],
  9978. paddingInner = constantZero,
  9979. paddingTop = constantZero,
  9980. paddingRight = constantZero,
  9981. paddingBottom = constantZero,
  9982. paddingLeft = constantZero;
  9983. function treemap(root) {
  9984. root.x0 =
  9985. root.y0 = 0;
  9986. root.x1 = dx;
  9987. root.y1 = dy;
  9988. root.eachBefore(positionNode);
  9989. paddingStack = [0];
  9990. if (round) root.eachBefore(roundNode);
  9991. return root;
  9992. }
  9993. function positionNode(node) {
  9994. var p = paddingStack[node.depth],
  9995. x0 = node.x0 + p,
  9996. y0 = node.y0 + p,
  9997. x1 = node.x1 - p,
  9998. y1 = node.y1 - p;
  9999. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  10000. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  10001. node.x0 = x0;
  10002. node.y0 = y0;
  10003. node.x1 = x1;
  10004. node.y1 = y1;
  10005. if (node.children) {
  10006. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  10007. x0 += paddingLeft(node) - p;
  10008. y0 += paddingTop(node) - p;
  10009. x1 -= paddingRight(node) - p;
  10010. y1 -= paddingBottom(node) - p;
  10011. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  10012. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  10013. tile(node, x0, y0, x1, y1);
  10014. }
  10015. }
  10016. treemap.round = function(x) {
  10017. return arguments.length ? (round = !!x, treemap) : round;
  10018. };
  10019. treemap.size = function(x) {
  10020. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  10021. };
  10022. treemap.tile = function(x) {
  10023. return arguments.length ? (tile = required(x), treemap) : tile;
  10024. };
  10025. treemap.padding = function(x) {
  10026. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  10027. };
  10028. treemap.paddingInner = function(x) {
  10029. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
  10030. };
  10031. treemap.paddingOuter = function(x) {
  10032. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  10033. };
  10034. treemap.paddingTop = function(x) {
  10035. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
  10036. };
  10037. treemap.paddingRight = function(x) {
  10038. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
  10039. };
  10040. treemap.paddingBottom = function(x) {
  10041. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
  10042. };
  10043. treemap.paddingLeft = function(x) {
  10044. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
  10045. };
  10046. return treemap;
  10047. }
  10048. function binary(parent, x0, y0, x1, y1) {
  10049. var nodes = parent.children,
  10050. i, n = nodes.length,
  10051. sum, sums = new Array(n + 1);
  10052. for (sums[0] = sum = i = 0; i < n; ++i) {
  10053. sums[i + 1] = sum += nodes[i].value;
  10054. }
  10055. partition(0, n, parent.value, x0, y0, x1, y1);
  10056. function partition(i, j, value, x0, y0, x1, y1) {
  10057. if (i >= j - 1) {
  10058. var node = nodes[i];
  10059. node.x0 = x0, node.y0 = y0;
  10060. node.x1 = x1, node.y1 = y1;
  10061. return;
  10062. }
  10063. var valueOffset = sums[i],
  10064. valueTarget = (value / 2) + valueOffset,
  10065. k = i + 1,
  10066. hi = j - 1;
  10067. while (k < hi) {
  10068. var mid = k + hi >>> 1;
  10069. if (sums[mid] < valueTarget) k = mid + 1;
  10070. else hi = mid;
  10071. }
  10072. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  10073. var valueLeft = sums[k] - valueOffset,
  10074. valueRight = value - valueLeft;
  10075. if ((x1 - x0) > (y1 - y0)) {
  10076. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  10077. partition(i, k, valueLeft, x0, y0, xk, y1);
  10078. partition(k, j, valueRight, xk, y0, x1, y1);
  10079. } else {
  10080. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  10081. partition(i, k, valueLeft, x0, y0, x1, yk);
  10082. partition(k, j, valueRight, x0, yk, x1, y1);
  10083. }
  10084. }
  10085. }
  10086. function sliceDice(parent, x0, y0, x1, y1) {
  10087. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  10088. }
  10089. var resquarify = (function custom(ratio) {
  10090. function resquarify(parent, x0, y0, x1, y1) {
  10091. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  10092. var rows,
  10093. row,
  10094. nodes,
  10095. i,
  10096. j = -1,
  10097. n,
  10098. m = rows.length,
  10099. value = parent.value;
  10100. while (++j < m) {
  10101. row = rows[j], nodes = row.children;
  10102. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  10103. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  10104. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  10105. value -= row.value;
  10106. }
  10107. } else {
  10108. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  10109. rows.ratio = ratio;
  10110. }
  10111. }
  10112. resquarify.ratio = function(x) {
  10113. return custom((x = +x) > 1 ? x : 1);
  10114. };
  10115. return resquarify;
  10116. })(phi);
  10117. function area$2(polygon) {
  10118. var i = -1,
  10119. n = polygon.length,
  10120. a,
  10121. b = polygon[n - 1],
  10122. area = 0;
  10123. while (++i < n) {
  10124. a = b;
  10125. b = polygon[i];
  10126. area += a[1] * b[0] - a[0] * b[1];
  10127. }
  10128. return area / 2;
  10129. }
  10130. function centroid$1(polygon) {
  10131. var i = -1,
  10132. n = polygon.length,
  10133. x = 0,
  10134. y = 0,
  10135. a,
  10136. b = polygon[n - 1],
  10137. c,
  10138. k = 0;
  10139. while (++i < n) {
  10140. a = b;
  10141. b = polygon[i];
  10142. k += c = a[0] * b[1] - b[0] * a[1];
  10143. x += (a[0] + b[0]) * c;
  10144. y += (a[1] + b[1]) * c;
  10145. }
  10146. return k *= 3, [x / k, y / k];
  10147. }
  10148. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  10149. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  10150. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  10151. // negative if clockwise, and zero if the points are collinear.
  10152. function cross$1(a, b, c) {
  10153. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  10154. }
  10155. function lexicographicOrder(a, b) {
  10156. return a[0] - b[0] || a[1] - b[1];
  10157. }
  10158. // Computes the upper convex hull per the monotone chain algorithm.
  10159. // Assumes points.length >= 3, is sorted by x, unique in y.
  10160. // Returns an array of indices into points in left-to-right order.
  10161. function computeUpperHullIndexes(points) {
  10162. var n = points.length,
  10163. indexes = [0, 1],
  10164. size = 2;
  10165. for (var i = 2; i < n; ++i) {
  10166. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  10167. indexes[size++] = i;
  10168. }
  10169. return indexes.slice(0, size); // remove popped points
  10170. }
  10171. function hull(points) {
  10172. if ((n = points.length) < 3) return null;
  10173. var i,
  10174. n,
  10175. sortedPoints = new Array(n),
  10176. flippedPoints = new Array(n);
  10177. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  10178. sortedPoints.sort(lexicographicOrder);
  10179. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  10180. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  10181. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  10182. // Construct the hull polygon, removing possible duplicate endpoints.
  10183. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  10184. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  10185. hull = [];
  10186. // Add upper hull in right-to-l order.
  10187. // Then add lower hull in left-to-right order.
  10188. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  10189. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  10190. return hull;
  10191. }
  10192. function contains$2(polygon, point) {
  10193. var n = polygon.length,
  10194. p = polygon[n - 1],
  10195. x = point[0], y = point[1],
  10196. x0 = p[0], y0 = p[1],
  10197. x1, y1,
  10198. inside = false;
  10199. for (var i = 0; i < n; ++i) {
  10200. p = polygon[i], x1 = p[0], y1 = p[1];
  10201. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  10202. x0 = x1, y0 = y1;
  10203. }
  10204. return inside;
  10205. }
  10206. function length$2(polygon) {
  10207. var i = -1,
  10208. n = polygon.length,
  10209. b = polygon[n - 1],
  10210. xa,
  10211. ya,
  10212. xb = b[0],
  10213. yb = b[1],
  10214. perimeter = 0;
  10215. while (++i < n) {
  10216. xa = xb;
  10217. ya = yb;
  10218. b = polygon[i];
  10219. xb = b[0];
  10220. yb = b[1];
  10221. xa -= xb;
  10222. ya -= yb;
  10223. perimeter += Math.sqrt(xa * xa + ya * ya);
  10224. }
  10225. return perimeter;
  10226. }
  10227. function defaultSource$1() {
  10228. return Math.random();
  10229. }
  10230. var uniform = (function sourceRandomUniform(source) {
  10231. function randomUniform(min, max) {
  10232. min = min == null ? 0 : +min;
  10233. max = max == null ? 1 : +max;
  10234. if (arguments.length === 1) max = min, min = 0;
  10235. else max -= min;
  10236. return function() {
  10237. return source() * max + min;
  10238. };
  10239. }
  10240. randomUniform.source = sourceRandomUniform;
  10241. return randomUniform;
  10242. })(defaultSource$1);
  10243. var normal = (function sourceRandomNormal(source) {
  10244. function randomNormal(mu, sigma) {
  10245. var x, r;
  10246. mu = mu == null ? 0 : +mu;
  10247. sigma = sigma == null ? 1 : +sigma;
  10248. return function() {
  10249. var y;
  10250. // If available, use the second previously-generated uniform random.
  10251. if (x != null) y = x, x = null;
  10252. // Otherwise, generate a new x and y.
  10253. else do {
  10254. x = source() * 2 - 1;
  10255. y = source() * 2 - 1;
  10256. r = x * x + y * y;
  10257. } while (!r || r > 1);
  10258. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  10259. };
  10260. }
  10261. randomNormal.source = sourceRandomNormal;
  10262. return randomNormal;
  10263. })(defaultSource$1);
  10264. var logNormal = (function sourceRandomLogNormal(source) {
  10265. function randomLogNormal() {
  10266. var randomNormal = normal.source(source).apply(this, arguments);
  10267. return function() {
  10268. return Math.exp(randomNormal());
  10269. };
  10270. }
  10271. randomLogNormal.source = sourceRandomLogNormal;
  10272. return randomLogNormal;
  10273. })(defaultSource$1);
  10274. var irwinHall = (function sourceRandomIrwinHall(source) {
  10275. function randomIrwinHall(n) {
  10276. return function() {
  10277. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  10278. return sum;
  10279. };
  10280. }
  10281. randomIrwinHall.source = sourceRandomIrwinHall;
  10282. return randomIrwinHall;
  10283. })(defaultSource$1);
  10284. var bates = (function sourceRandomBates(source) {
  10285. function randomBates(n) {
  10286. var randomIrwinHall = irwinHall.source(source)(n);
  10287. return function() {
  10288. return randomIrwinHall() / n;
  10289. };
  10290. }
  10291. randomBates.source = sourceRandomBates;
  10292. return randomBates;
  10293. })(defaultSource$1);
  10294. var exponential$1 = (function sourceRandomExponential(source) {
  10295. function randomExponential(lambda) {
  10296. return function() {
  10297. return -Math.log(1 - source()) / lambda;
  10298. };
  10299. }
  10300. randomExponential.source = sourceRandomExponential;
  10301. return randomExponential;
  10302. })(defaultSource$1);
  10303. function initRange(domain, range) {
  10304. switch (arguments.length) {
  10305. case 0: break;
  10306. case 1: this.range(domain); break;
  10307. default: this.range(range).domain(domain); break;
  10308. }
  10309. return this;
  10310. }
  10311. function initInterpolator(domain, interpolator) {
  10312. switch (arguments.length) {
  10313. case 0: break;
  10314. case 1: this.interpolator(domain); break;
  10315. default: this.interpolator(interpolator).domain(domain); break;
  10316. }
  10317. return this;
  10318. }
  10319. var array$3 = Array.prototype;
  10320. var map$3 = array$3.map;
  10321. var slice$5 = array$3.slice;
  10322. var implicit = {name: "implicit"};
  10323. function ordinal() {
  10324. var index = map$1(),
  10325. domain = [],
  10326. range = [],
  10327. unknown = implicit;
  10328. function scale(d) {
  10329. var key = d + "", i = index.get(key);
  10330. if (!i) {
  10331. if (unknown !== implicit) return unknown;
  10332. index.set(key, i = domain.push(d));
  10333. }
  10334. return range[(i - 1) % range.length];
  10335. }
  10336. scale.domain = function(_) {
  10337. if (!arguments.length) return domain.slice();
  10338. domain = [], index = map$1();
  10339. var i = -1, n = _.length, d, key;
  10340. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  10341. return scale;
  10342. };
  10343. scale.range = function(_) {
  10344. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  10345. };
  10346. scale.unknown = function(_) {
  10347. return arguments.length ? (unknown = _, scale) : unknown;
  10348. };
  10349. scale.copy = function() {
  10350. return ordinal(domain, range).unknown(unknown);
  10351. };
  10352. initRange.apply(scale, arguments);
  10353. return scale;
  10354. }
  10355. function band() {
  10356. var scale = ordinal().unknown(undefined),
  10357. domain = scale.domain,
  10358. ordinalRange = scale.range,
  10359. range = [0, 1],
  10360. step,
  10361. bandwidth,
  10362. round = false,
  10363. paddingInner = 0,
  10364. paddingOuter = 0,
  10365. align = 0.5;
  10366. delete scale.unknown;
  10367. function rescale() {
  10368. var n = domain().length,
  10369. reverse = range[1] < range[0],
  10370. start = range[reverse - 0],
  10371. stop = range[1 - reverse];
  10372. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  10373. if (round) step = Math.floor(step);
  10374. start += (stop - start - step * (n - paddingInner)) * align;
  10375. bandwidth = step * (1 - paddingInner);
  10376. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  10377. var values = sequence(n).map(function(i) { return start + step * i; });
  10378. return ordinalRange(reverse ? values.reverse() : values);
  10379. }
  10380. scale.domain = function(_) {
  10381. return arguments.length ? (domain(_), rescale()) : domain();
  10382. };
  10383. scale.range = function(_) {
  10384. return arguments.length ? (range = [+_[0], +_[1]], rescale()) : range.slice();
  10385. };
  10386. scale.rangeRound = function(_) {
  10387. return range = [+_[0], +_[1]], round = true, rescale();
  10388. };
  10389. scale.bandwidth = function() {
  10390. return bandwidth;
  10391. };
  10392. scale.step = function() {
  10393. return step;
  10394. };
  10395. scale.round = function(_) {
  10396. return arguments.length ? (round = !!_, rescale()) : round;
  10397. };
  10398. scale.padding = function(_) {
  10399. return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
  10400. };
  10401. scale.paddingInner = function(_) {
  10402. return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
  10403. };
  10404. scale.paddingOuter = function(_) {
  10405. return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
  10406. };
  10407. scale.align = function(_) {
  10408. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  10409. };
  10410. scale.copy = function() {
  10411. return band(domain(), range)
  10412. .round(round)
  10413. .paddingInner(paddingInner)
  10414. .paddingOuter(paddingOuter)
  10415. .align(align);
  10416. };
  10417. return initRange.apply(rescale(), arguments);
  10418. }
  10419. function pointish(scale) {
  10420. var copy = scale.copy;
  10421. scale.padding = scale.paddingOuter;
  10422. delete scale.paddingInner;
  10423. delete scale.paddingOuter;
  10424. scale.copy = function() {
  10425. return pointish(copy());
  10426. };
  10427. return scale;
  10428. }
  10429. function point$1() {
  10430. return pointish(band.apply(null, arguments).paddingInner(1));
  10431. }
  10432. function constant$a(x) {
  10433. return function() {
  10434. return x;
  10435. };
  10436. }
  10437. function number$2(x) {
  10438. return +x;
  10439. }
  10440. var unit = [0, 1];
  10441. function identity$6(x) {
  10442. return x;
  10443. }
  10444. function normalize(a, b) {
  10445. return (b -= (a = +a))
  10446. ? function(x) { return (x - a) / b; }
  10447. : constant$a(isNaN(b) ? NaN : 0.5);
  10448. }
  10449. function clamper(domain) {
  10450. var a = domain[0], b = domain[domain.length - 1], t;
  10451. if (a > b) t = a, a = b, b = t;
  10452. return function(x) { return Math.max(a, Math.min(b, x)); };
  10453. }
  10454. // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  10455. // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
  10456. function bimap(domain, range, interpolate) {
  10457. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  10458. if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
  10459. else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
  10460. return function(x) { return r0(d0(x)); };
  10461. }
  10462. function polymap(domain, range, interpolate) {
  10463. var j = Math.min(domain.length, range.length) - 1,
  10464. d = new Array(j),
  10465. r = new Array(j),
  10466. i = -1;
  10467. // Reverse descending domains.
  10468. if (domain[j] < domain[0]) {
  10469. domain = domain.slice().reverse();
  10470. range = range.slice().reverse();
  10471. }
  10472. while (++i < j) {
  10473. d[i] = normalize(domain[i], domain[i + 1]);
  10474. r[i] = interpolate(range[i], range[i + 1]);
  10475. }
  10476. return function(x) {
  10477. var i = bisectRight(domain, x, 1, j) - 1;
  10478. return r[i](d[i](x));
  10479. };
  10480. }
  10481. function copy(source, target) {
  10482. return target
  10483. .domain(source.domain())
  10484. .range(source.range())
  10485. .interpolate(source.interpolate())
  10486. .clamp(source.clamp())
  10487. .unknown(source.unknown());
  10488. }
  10489. function transformer$1() {
  10490. var domain = unit,
  10491. range = unit,
  10492. interpolate = interpolateValue,
  10493. transform,
  10494. untransform,
  10495. unknown,
  10496. clamp = identity$6,
  10497. piecewise,
  10498. output,
  10499. input;
  10500. function rescale() {
  10501. piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  10502. output = input = null;
  10503. return scale;
  10504. }
  10505. function scale(x) {
  10506. return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
  10507. }
  10508. scale.invert = function(y) {
  10509. return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
  10510. };
  10511. scale.domain = function(_) {
  10512. return arguments.length ? (domain = map$3.call(_, number$2), clamp === identity$6 || (clamp = clamper(domain)), rescale()) : domain.slice();
  10513. };
  10514. scale.range = function(_) {
  10515. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10516. };
  10517. scale.rangeRound = function(_) {
  10518. return range = slice$5.call(_), interpolate = interpolateRound, rescale();
  10519. };
  10520. scale.clamp = function(_) {
  10521. return arguments.length ? (clamp = _ ? clamper(domain) : identity$6, scale) : clamp !== identity$6;
  10522. };
  10523. scale.interpolate = function(_) {
  10524. return arguments.length ? (interpolate = _, rescale()) : interpolate;
  10525. };
  10526. scale.unknown = function(_) {
  10527. return arguments.length ? (unknown = _, scale) : unknown;
  10528. };
  10529. return function(t, u) {
  10530. transform = t, untransform = u;
  10531. return rescale();
  10532. };
  10533. }
  10534. function continuous(transform, untransform) {
  10535. return transformer$1()(transform, untransform);
  10536. }
  10537. function tickFormat(start, stop, count, specifier) {
  10538. var step = tickStep(start, stop, count),
  10539. precision;
  10540. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10541. switch (specifier.type) {
  10542. case "s": {
  10543. var value = Math.max(Math.abs(start), Math.abs(stop));
  10544. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10545. return exports.formatPrefix(specifier, value);
  10546. }
  10547. case "":
  10548. case "e":
  10549. case "g":
  10550. case "p":
  10551. case "r": {
  10552. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10553. break;
  10554. }
  10555. case "f":
  10556. case "%": {
  10557. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10558. break;
  10559. }
  10560. }
  10561. return exports.format(specifier);
  10562. }
  10563. function linearish(scale) {
  10564. var domain = scale.domain;
  10565. scale.ticks = function(count) {
  10566. var d = domain();
  10567. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10568. };
  10569. scale.tickFormat = function(count, specifier) {
  10570. var d = domain();
  10571. return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
  10572. };
  10573. scale.nice = function(count) {
  10574. if (count == null) count = 10;
  10575. var d = domain(),
  10576. i0 = 0,
  10577. i1 = d.length - 1,
  10578. start = d[i0],
  10579. stop = d[i1],
  10580. step;
  10581. if (stop < start) {
  10582. step = start, start = stop, stop = step;
  10583. step = i0, i0 = i1, i1 = step;
  10584. }
  10585. step = tickIncrement(start, stop, count);
  10586. if (step > 0) {
  10587. start = Math.floor(start / step) * step;
  10588. stop = Math.ceil(stop / step) * step;
  10589. step = tickIncrement(start, stop, count);
  10590. } else if (step < 0) {
  10591. start = Math.ceil(start * step) / step;
  10592. stop = Math.floor(stop * step) / step;
  10593. step = tickIncrement(start, stop, count);
  10594. }
  10595. if (step > 0) {
  10596. d[i0] = Math.floor(start / step) * step;
  10597. d[i1] = Math.ceil(stop / step) * step;
  10598. domain(d);
  10599. } else if (step < 0) {
  10600. d[i0] = Math.ceil(start * step) / step;
  10601. d[i1] = Math.floor(stop * step) / step;
  10602. domain(d);
  10603. }
  10604. return scale;
  10605. };
  10606. return scale;
  10607. }
  10608. function linear$2() {
  10609. var scale = continuous(identity$6, identity$6);
  10610. scale.copy = function() {
  10611. return copy(scale, linear$2());
  10612. };
  10613. initRange.apply(scale, arguments);
  10614. return linearish(scale);
  10615. }
  10616. function identity$7(domain) {
  10617. var unknown;
  10618. function scale(x) {
  10619. return isNaN(x = +x) ? unknown : x;
  10620. }
  10621. scale.invert = scale;
  10622. scale.domain = scale.range = function(_) {
  10623. return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
  10624. };
  10625. scale.unknown = function(_) {
  10626. return arguments.length ? (unknown = _, scale) : unknown;
  10627. };
  10628. scale.copy = function() {
  10629. return identity$7(domain).unknown(unknown);
  10630. };
  10631. domain = arguments.length ? map$3.call(domain, number$2) : [0, 1];
  10632. return linearish(scale);
  10633. }
  10634. function nice(domain, interval) {
  10635. domain = domain.slice();
  10636. var i0 = 0,
  10637. i1 = domain.length - 1,
  10638. x0 = domain[i0],
  10639. x1 = domain[i1],
  10640. t;
  10641. if (x1 < x0) {
  10642. t = i0, i0 = i1, i1 = t;
  10643. t = x0, x0 = x1, x1 = t;
  10644. }
  10645. domain[i0] = interval.floor(x0);
  10646. domain[i1] = interval.ceil(x1);
  10647. return domain;
  10648. }
  10649. function transformLog(x) {
  10650. return Math.log(x);
  10651. }
  10652. function transformExp(x) {
  10653. return Math.exp(x);
  10654. }
  10655. function transformLogn(x) {
  10656. return -Math.log(-x);
  10657. }
  10658. function transformExpn(x) {
  10659. return -Math.exp(-x);
  10660. }
  10661. function pow10(x) {
  10662. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10663. }
  10664. function powp(base) {
  10665. return base === 10 ? pow10
  10666. : base === Math.E ? Math.exp
  10667. : function(x) { return Math.pow(base, x); };
  10668. }
  10669. function logp(base) {
  10670. return base === Math.E ? Math.log
  10671. : base === 10 && Math.log10
  10672. || base === 2 && Math.log2
  10673. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10674. }
  10675. function reflect(f) {
  10676. return function(x) {
  10677. return -f(-x);
  10678. };
  10679. }
  10680. function loggish(transform) {
  10681. var scale = transform(transformLog, transformExp),
  10682. domain = scale.domain,
  10683. base = 10,
  10684. logs,
  10685. pows;
  10686. function rescale() {
  10687. logs = logp(base), pows = powp(base);
  10688. if (domain()[0] < 0) {
  10689. logs = reflect(logs), pows = reflect(pows);
  10690. transform(transformLogn, transformExpn);
  10691. } else {
  10692. transform(transformLog, transformExp);
  10693. }
  10694. return scale;
  10695. }
  10696. scale.base = function(_) {
  10697. return arguments.length ? (base = +_, rescale()) : base;
  10698. };
  10699. scale.domain = function(_) {
  10700. return arguments.length ? (domain(_), rescale()) : domain();
  10701. };
  10702. scale.ticks = function(count) {
  10703. var d = domain(),
  10704. u = d[0],
  10705. v = d[d.length - 1],
  10706. r;
  10707. if (r = v < u) i = u, u = v, v = i;
  10708. var i = logs(u),
  10709. j = logs(v),
  10710. p,
  10711. k,
  10712. t,
  10713. n = count == null ? 10 : +count,
  10714. z = [];
  10715. if (!(base % 1) && j - i < n) {
  10716. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10717. if (u > 0) for (; i < j; ++i) {
  10718. for (k = 1, p = pows(i); k < base; ++k) {
  10719. t = p * k;
  10720. if (t < u) continue;
  10721. if (t > v) break;
  10722. z.push(t);
  10723. }
  10724. } else for (; i < j; ++i) {
  10725. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10726. t = p * k;
  10727. if (t < u) continue;
  10728. if (t > v) break;
  10729. z.push(t);
  10730. }
  10731. }
  10732. } else {
  10733. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10734. }
  10735. return r ? z.reverse() : z;
  10736. };
  10737. scale.tickFormat = function(count, specifier) {
  10738. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10739. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10740. if (count === Infinity) return specifier;
  10741. if (count == null) count = 10;
  10742. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10743. return function(d) {
  10744. var i = d / pows(Math.round(logs(d)));
  10745. if (i * base < base - 0.5) i *= base;
  10746. return i <= k ? specifier(d) : "";
  10747. };
  10748. };
  10749. scale.nice = function() {
  10750. return domain(nice(domain(), {
  10751. floor: function(x) { return pows(Math.floor(logs(x))); },
  10752. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10753. }));
  10754. };
  10755. return scale;
  10756. }
  10757. function log$1() {
  10758. var scale = loggish(transformer$1()).domain([1, 10]);
  10759. scale.copy = function() {
  10760. return copy(scale, log$1()).base(scale.base());
  10761. };
  10762. initRange.apply(scale, arguments);
  10763. return scale;
  10764. }
  10765. function transformSymlog(c) {
  10766. return function(x) {
  10767. return Math.sign(x) * Math.log1p(Math.abs(x / c));
  10768. };
  10769. }
  10770. function transformSymexp(c) {
  10771. return function(x) {
  10772. return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
  10773. };
  10774. }
  10775. function symlogish(transform) {
  10776. var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
  10777. scale.constant = function(_) {
  10778. return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
  10779. };
  10780. return linearish(scale);
  10781. }
  10782. function symlog() {
  10783. var scale = symlogish(transformer$1());
  10784. scale.copy = function() {
  10785. return copy(scale, symlog()).constant(scale.constant());
  10786. };
  10787. return initRange.apply(scale, arguments);
  10788. }
  10789. function transformPow(exponent) {
  10790. return function(x) {
  10791. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10792. };
  10793. }
  10794. function transformSqrt(x) {
  10795. return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
  10796. }
  10797. function transformSquare(x) {
  10798. return x < 0 ? -x * x : x * x;
  10799. }
  10800. function powish(transform) {
  10801. var scale = transform(identity$6, identity$6),
  10802. exponent = 1;
  10803. function rescale() {
  10804. return exponent === 1 ? transform(identity$6, identity$6)
  10805. : exponent === 0.5 ? transform(transformSqrt, transformSquare)
  10806. : transform(transformPow(exponent), transformPow(1 / exponent));
  10807. }
  10808. scale.exponent = function(_) {
  10809. return arguments.length ? (exponent = +_, rescale()) : exponent;
  10810. };
  10811. return linearish(scale);
  10812. }
  10813. function pow$1() {
  10814. var scale = powish(transformer$1());
  10815. scale.copy = function() {
  10816. return copy(scale, pow$1()).exponent(scale.exponent());
  10817. };
  10818. initRange.apply(scale, arguments);
  10819. return scale;
  10820. }
  10821. function sqrt$1() {
  10822. return pow$1.apply(null, arguments).exponent(0.5);
  10823. }
  10824. function quantile() {
  10825. var domain = [],
  10826. range = [],
  10827. thresholds = [],
  10828. unknown;
  10829. function rescale() {
  10830. var i = 0, n = Math.max(1, range.length);
  10831. thresholds = new Array(n - 1);
  10832. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10833. return scale;
  10834. }
  10835. function scale(x) {
  10836. return isNaN(x = +x) ? unknown : range[bisectRight(thresholds, x)];
  10837. }
  10838. scale.invertExtent = function(y) {
  10839. var i = range.indexOf(y);
  10840. return i < 0 ? [NaN, NaN] : [
  10841. i > 0 ? thresholds[i - 1] : domain[0],
  10842. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10843. ];
  10844. };
  10845. scale.domain = function(_) {
  10846. if (!arguments.length) return domain.slice();
  10847. domain = [];
  10848. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10849. domain.sort(ascending);
  10850. return rescale();
  10851. };
  10852. scale.range = function(_) {
  10853. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10854. };
  10855. scale.unknown = function(_) {
  10856. return arguments.length ? (unknown = _, scale) : unknown;
  10857. };
  10858. scale.quantiles = function() {
  10859. return thresholds.slice();
  10860. };
  10861. scale.copy = function() {
  10862. return quantile()
  10863. .domain(domain)
  10864. .range(range)
  10865. .unknown(unknown);
  10866. };
  10867. return initRange.apply(scale, arguments);
  10868. }
  10869. function quantize$1() {
  10870. var x0 = 0,
  10871. x1 = 1,
  10872. n = 1,
  10873. domain = [0.5],
  10874. range = [0, 1],
  10875. unknown;
  10876. function scale(x) {
  10877. return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
  10878. }
  10879. function rescale() {
  10880. var i = -1;
  10881. domain = new Array(n);
  10882. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10883. return scale;
  10884. }
  10885. scale.domain = function(_) {
  10886. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10887. };
  10888. scale.range = function(_) {
  10889. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10890. };
  10891. scale.invertExtent = function(y) {
  10892. var i = range.indexOf(y);
  10893. return i < 0 ? [NaN, NaN]
  10894. : i < 1 ? [x0, domain[0]]
  10895. : i >= n ? [domain[n - 1], x1]
  10896. : [domain[i - 1], domain[i]];
  10897. };
  10898. scale.unknown = function(_) {
  10899. return arguments.length ? (unknown = _, scale) : scale;
  10900. };
  10901. scale.thresholds = function() {
  10902. return domain.slice();
  10903. };
  10904. scale.copy = function() {
  10905. return quantize$1()
  10906. .domain([x0, x1])
  10907. .range(range)
  10908. .unknown(unknown);
  10909. };
  10910. return initRange.apply(linearish(scale), arguments);
  10911. }
  10912. function threshold$1() {
  10913. var domain = [0.5],
  10914. range = [0, 1],
  10915. unknown,
  10916. n = 1;
  10917. function scale(x) {
  10918. return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
  10919. }
  10920. scale.domain = function(_) {
  10921. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10922. };
  10923. scale.range = function(_) {
  10924. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10925. };
  10926. scale.invertExtent = function(y) {
  10927. var i = range.indexOf(y);
  10928. return [domain[i - 1], domain[i]];
  10929. };
  10930. scale.unknown = function(_) {
  10931. return arguments.length ? (unknown = _, scale) : unknown;
  10932. };
  10933. scale.copy = function() {
  10934. return threshold$1()
  10935. .domain(domain)
  10936. .range(range)
  10937. .unknown(unknown);
  10938. };
  10939. return initRange.apply(scale, arguments);
  10940. }
  10941. var t0$1 = new Date,
  10942. t1$1 = new Date;
  10943. function newInterval(floori, offseti, count, field) {
  10944. function interval(date) {
  10945. return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
  10946. }
  10947. interval.floor = function(date) {
  10948. return floori(date = new Date(+date)), date;
  10949. };
  10950. interval.ceil = function(date) {
  10951. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10952. };
  10953. interval.round = function(date) {
  10954. var d0 = interval(date),
  10955. d1 = interval.ceil(date);
  10956. return date - d0 < d1 - date ? d0 : d1;
  10957. };
  10958. interval.offset = function(date, step) {
  10959. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10960. };
  10961. interval.range = function(start, stop, step) {
  10962. var range = [], previous;
  10963. start = interval.ceil(start);
  10964. step = step == null ? 1 : Math.floor(step);
  10965. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10966. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  10967. while (previous < start && start < stop);
  10968. return range;
  10969. };
  10970. interval.filter = function(test) {
  10971. return newInterval(function(date) {
  10972. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10973. }, function(date, step) {
  10974. if (date >= date) {
  10975. if (step < 0) while (++step <= 0) {
  10976. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10977. } else while (--step >= 0) {
  10978. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10979. }
  10980. }
  10981. });
  10982. };
  10983. if (count) {
  10984. interval.count = function(start, end) {
  10985. t0$1.setTime(+start), t1$1.setTime(+end);
  10986. floori(t0$1), floori(t1$1);
  10987. return Math.floor(count(t0$1, t1$1));
  10988. };
  10989. interval.every = function(step) {
  10990. step = Math.floor(step);
  10991. return !isFinite(step) || !(step > 0) ? null
  10992. : !(step > 1) ? interval
  10993. : interval.filter(field
  10994. ? function(d) { return field(d) % step === 0; }
  10995. : function(d) { return interval.count(0, d) % step === 0; });
  10996. };
  10997. }
  10998. return interval;
  10999. }
  11000. var millisecond = newInterval(function() {
  11001. // noop
  11002. }, function(date, step) {
  11003. date.setTime(+date + step);
  11004. }, function(start, end) {
  11005. return end - start;
  11006. });
  11007. // An optimized implementation for this simple case.
  11008. millisecond.every = function(k) {
  11009. k = Math.floor(k);
  11010. if (!isFinite(k) || !(k > 0)) return null;
  11011. if (!(k > 1)) return millisecond;
  11012. return newInterval(function(date) {
  11013. date.setTime(Math.floor(date / k) * k);
  11014. }, function(date, step) {
  11015. date.setTime(+date + step * k);
  11016. }, function(start, end) {
  11017. return (end - start) / k;
  11018. });
  11019. };
  11020. var milliseconds = millisecond.range;
  11021. var durationSecond = 1e3;
  11022. var durationMinute = 6e4;
  11023. var durationHour = 36e5;
  11024. var durationDay = 864e5;
  11025. var durationWeek = 6048e5;
  11026. var second = newInterval(function(date) {
  11027. date.setTime(date - date.getMilliseconds());
  11028. }, function(date, step) {
  11029. date.setTime(+date + step * durationSecond);
  11030. }, function(start, end) {
  11031. return (end - start) / durationSecond;
  11032. }, function(date) {
  11033. return date.getUTCSeconds();
  11034. });
  11035. var seconds = second.range;
  11036. var minute = newInterval(function(date) {
  11037. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
  11038. }, function(date, step) {
  11039. date.setTime(+date + step * durationMinute);
  11040. }, function(start, end) {
  11041. return (end - start) / durationMinute;
  11042. }, function(date) {
  11043. return date.getMinutes();
  11044. });
  11045. var minutes = minute.range;
  11046. var hour = newInterval(function(date) {
  11047. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
  11048. }, function(date, step) {
  11049. date.setTime(+date + step * durationHour);
  11050. }, function(start, end) {
  11051. return (end - start) / durationHour;
  11052. }, function(date) {
  11053. return date.getHours();
  11054. });
  11055. var hours = hour.range;
  11056. var day = newInterval(function(date) {
  11057. date.setHours(0, 0, 0, 0);
  11058. }, function(date, step) {
  11059. date.setDate(date.getDate() + step);
  11060. }, function(start, end) {
  11061. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  11062. }, function(date) {
  11063. return date.getDate() - 1;
  11064. });
  11065. var days = day.range;
  11066. function weekday(i) {
  11067. return newInterval(function(date) {
  11068. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  11069. date.setHours(0, 0, 0, 0);
  11070. }, function(date, step) {
  11071. date.setDate(date.getDate() + step * 7);
  11072. }, function(start, end) {
  11073. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  11074. });
  11075. }
  11076. var sunday = weekday(0);
  11077. var monday = weekday(1);
  11078. var tuesday = weekday(2);
  11079. var wednesday = weekday(3);
  11080. var thursday = weekday(4);
  11081. var friday = weekday(5);
  11082. var saturday = weekday(6);
  11083. var sundays = sunday.range;
  11084. var mondays = monday.range;
  11085. var tuesdays = tuesday.range;
  11086. var wednesdays = wednesday.range;
  11087. var thursdays = thursday.range;
  11088. var fridays = friday.range;
  11089. var saturdays = saturday.range;
  11090. var month = newInterval(function(date) {
  11091. date.setDate(1);
  11092. date.setHours(0, 0, 0, 0);
  11093. }, function(date, step) {
  11094. date.setMonth(date.getMonth() + step);
  11095. }, function(start, end) {
  11096. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  11097. }, function(date) {
  11098. return date.getMonth();
  11099. });
  11100. var months = month.range;
  11101. var year = newInterval(function(date) {
  11102. date.setMonth(0, 1);
  11103. date.setHours(0, 0, 0, 0);
  11104. }, function(date, step) {
  11105. date.setFullYear(date.getFullYear() + step);
  11106. }, function(start, end) {
  11107. return end.getFullYear() - start.getFullYear();
  11108. }, function(date) {
  11109. return date.getFullYear();
  11110. });
  11111. // An optimized implementation for this simple case.
  11112. year.every = function(k) {
  11113. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  11114. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  11115. date.setMonth(0, 1);
  11116. date.setHours(0, 0, 0, 0);
  11117. }, function(date, step) {
  11118. date.setFullYear(date.getFullYear() + step * k);
  11119. });
  11120. };
  11121. var years = year.range;
  11122. var utcMinute = newInterval(function(date) {
  11123. date.setUTCSeconds(0, 0);
  11124. }, function(date, step) {
  11125. date.setTime(+date + step * durationMinute);
  11126. }, function(start, end) {
  11127. return (end - start) / durationMinute;
  11128. }, function(date) {
  11129. return date.getUTCMinutes();
  11130. });
  11131. var utcMinutes = utcMinute.range;
  11132. var utcHour = newInterval(function(date) {
  11133. date.setUTCMinutes(0, 0, 0);
  11134. }, function(date, step) {
  11135. date.setTime(+date + step * durationHour);
  11136. }, function(start, end) {
  11137. return (end - start) / durationHour;
  11138. }, function(date) {
  11139. return date.getUTCHours();
  11140. });
  11141. var utcHours = utcHour.range;
  11142. var utcDay = newInterval(function(date) {
  11143. date.setUTCHours(0, 0, 0, 0);
  11144. }, function(date, step) {
  11145. date.setUTCDate(date.getUTCDate() + step);
  11146. }, function(start, end) {
  11147. return (end - start) / durationDay;
  11148. }, function(date) {
  11149. return date.getUTCDate() - 1;
  11150. });
  11151. var utcDays = utcDay.range;
  11152. function utcWeekday(i) {
  11153. return newInterval(function(date) {
  11154. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  11155. date.setUTCHours(0, 0, 0, 0);
  11156. }, function(date, step) {
  11157. date.setUTCDate(date.getUTCDate() + step * 7);
  11158. }, function(start, end) {
  11159. return (end - start) / durationWeek;
  11160. });
  11161. }
  11162. var utcSunday = utcWeekday(0);
  11163. var utcMonday = utcWeekday(1);
  11164. var utcTuesday = utcWeekday(2);
  11165. var utcWednesday = utcWeekday(3);
  11166. var utcThursday = utcWeekday(4);
  11167. var utcFriday = utcWeekday(5);
  11168. var utcSaturday = utcWeekday(6);
  11169. var utcSundays = utcSunday.range;
  11170. var utcMondays = utcMonday.range;
  11171. var utcTuesdays = utcTuesday.range;
  11172. var utcWednesdays = utcWednesday.range;
  11173. var utcThursdays = utcThursday.range;
  11174. var utcFridays = utcFriday.range;
  11175. var utcSaturdays = utcSaturday.range;
  11176. var utcMonth = newInterval(function(date) {
  11177. date.setUTCDate(1);
  11178. date.setUTCHours(0, 0, 0, 0);
  11179. }, function(date, step) {
  11180. date.setUTCMonth(date.getUTCMonth() + step);
  11181. }, function(start, end) {
  11182. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  11183. }, function(date) {
  11184. return date.getUTCMonth();
  11185. });
  11186. var utcMonths = utcMonth.range;
  11187. var utcYear = newInterval(function(date) {
  11188. date.setUTCMonth(0, 1);
  11189. date.setUTCHours(0, 0, 0, 0);
  11190. }, function(date, step) {
  11191. date.setUTCFullYear(date.getUTCFullYear() + step);
  11192. }, function(start, end) {
  11193. return end.getUTCFullYear() - start.getUTCFullYear();
  11194. }, function(date) {
  11195. return date.getUTCFullYear();
  11196. });
  11197. // An optimized implementation for this simple case.
  11198. utcYear.every = function(k) {
  11199. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  11200. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  11201. date.setUTCMonth(0, 1);
  11202. date.setUTCHours(0, 0, 0, 0);
  11203. }, function(date, step) {
  11204. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  11205. });
  11206. };
  11207. var utcYears = utcYear.range;
  11208. function localDate(d) {
  11209. if (0 <= d.y && d.y < 100) {
  11210. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  11211. date.setFullYear(d.y);
  11212. return date;
  11213. }
  11214. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  11215. }
  11216. function utcDate(d) {
  11217. if (0 <= d.y && d.y < 100) {
  11218. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  11219. date.setUTCFullYear(d.y);
  11220. return date;
  11221. }
  11222. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  11223. }
  11224. function newDate(y, m, d) {
  11225. return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
  11226. }
  11227. function formatLocale$1(locale) {
  11228. var locale_dateTime = locale.dateTime,
  11229. locale_date = locale.date,
  11230. locale_time = locale.time,
  11231. locale_periods = locale.periods,
  11232. locale_weekdays = locale.days,
  11233. locale_shortWeekdays = locale.shortDays,
  11234. locale_months = locale.months,
  11235. locale_shortMonths = locale.shortMonths;
  11236. var periodRe = formatRe(locale_periods),
  11237. periodLookup = formatLookup(locale_periods),
  11238. weekdayRe = formatRe(locale_weekdays),
  11239. weekdayLookup = formatLookup(locale_weekdays),
  11240. shortWeekdayRe = formatRe(locale_shortWeekdays),
  11241. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  11242. monthRe = formatRe(locale_months),
  11243. monthLookup = formatLookup(locale_months),
  11244. shortMonthRe = formatRe(locale_shortMonths),
  11245. shortMonthLookup = formatLookup(locale_shortMonths);
  11246. var formats = {
  11247. "a": formatShortWeekday,
  11248. "A": formatWeekday,
  11249. "b": formatShortMonth,
  11250. "B": formatMonth,
  11251. "c": null,
  11252. "d": formatDayOfMonth,
  11253. "e": formatDayOfMonth,
  11254. "f": formatMicroseconds,
  11255. "H": formatHour24,
  11256. "I": formatHour12,
  11257. "j": formatDayOfYear,
  11258. "L": formatMilliseconds,
  11259. "m": formatMonthNumber,
  11260. "M": formatMinutes,
  11261. "p": formatPeriod,
  11262. "q": formatQuarter,
  11263. "Q": formatUnixTimestamp,
  11264. "s": formatUnixTimestampSeconds,
  11265. "S": formatSeconds,
  11266. "u": formatWeekdayNumberMonday,
  11267. "U": formatWeekNumberSunday,
  11268. "V": formatWeekNumberISO,
  11269. "w": formatWeekdayNumberSunday,
  11270. "W": formatWeekNumberMonday,
  11271. "x": null,
  11272. "X": null,
  11273. "y": formatYear$1,
  11274. "Y": formatFullYear,
  11275. "Z": formatZone,
  11276. "%": formatLiteralPercent
  11277. };
  11278. var utcFormats = {
  11279. "a": formatUTCShortWeekday,
  11280. "A": formatUTCWeekday,
  11281. "b": formatUTCShortMonth,
  11282. "B": formatUTCMonth,
  11283. "c": null,
  11284. "d": formatUTCDayOfMonth,
  11285. "e": formatUTCDayOfMonth,
  11286. "f": formatUTCMicroseconds,
  11287. "H": formatUTCHour24,
  11288. "I": formatUTCHour12,
  11289. "j": formatUTCDayOfYear,
  11290. "L": formatUTCMilliseconds,
  11291. "m": formatUTCMonthNumber,
  11292. "M": formatUTCMinutes,
  11293. "p": formatUTCPeriod,
  11294. "q": formatUTCQuarter,
  11295. "Q": formatUnixTimestamp,
  11296. "s": formatUnixTimestampSeconds,
  11297. "S": formatUTCSeconds,
  11298. "u": formatUTCWeekdayNumberMonday,
  11299. "U": formatUTCWeekNumberSunday,
  11300. "V": formatUTCWeekNumberISO,
  11301. "w": formatUTCWeekdayNumberSunday,
  11302. "W": formatUTCWeekNumberMonday,
  11303. "x": null,
  11304. "X": null,
  11305. "y": formatUTCYear,
  11306. "Y": formatUTCFullYear,
  11307. "Z": formatUTCZone,
  11308. "%": formatLiteralPercent
  11309. };
  11310. var parses = {
  11311. "a": parseShortWeekday,
  11312. "A": parseWeekday,
  11313. "b": parseShortMonth,
  11314. "B": parseMonth,
  11315. "c": parseLocaleDateTime,
  11316. "d": parseDayOfMonth,
  11317. "e": parseDayOfMonth,
  11318. "f": parseMicroseconds,
  11319. "H": parseHour24,
  11320. "I": parseHour24,
  11321. "j": parseDayOfYear,
  11322. "L": parseMilliseconds,
  11323. "m": parseMonthNumber,
  11324. "M": parseMinutes,
  11325. "p": parsePeriod,
  11326. "q": parseQuarter,
  11327. "Q": parseUnixTimestamp,
  11328. "s": parseUnixTimestampSeconds,
  11329. "S": parseSeconds,
  11330. "u": parseWeekdayNumberMonday,
  11331. "U": parseWeekNumberSunday,
  11332. "V": parseWeekNumberISO,
  11333. "w": parseWeekdayNumberSunday,
  11334. "W": parseWeekNumberMonday,
  11335. "x": parseLocaleDate,
  11336. "X": parseLocaleTime,
  11337. "y": parseYear,
  11338. "Y": parseFullYear,
  11339. "Z": parseZone,
  11340. "%": parseLiteralPercent
  11341. };
  11342. // These recursive directive definitions must be deferred.
  11343. formats.x = newFormat(locale_date, formats);
  11344. formats.X = newFormat(locale_time, formats);
  11345. formats.c = newFormat(locale_dateTime, formats);
  11346. utcFormats.x = newFormat(locale_date, utcFormats);
  11347. utcFormats.X = newFormat(locale_time, utcFormats);
  11348. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  11349. function newFormat(specifier, formats) {
  11350. return function(date) {
  11351. var string = [],
  11352. i = -1,
  11353. j = 0,
  11354. n = specifier.length,
  11355. c,
  11356. pad,
  11357. format;
  11358. if (!(date instanceof Date)) date = new Date(+date);
  11359. while (++i < n) {
  11360. if (specifier.charCodeAt(i) === 37) {
  11361. string.push(specifier.slice(j, i));
  11362. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  11363. else pad = c === "e" ? " " : "0";
  11364. if (format = formats[c]) c = format(date, pad);
  11365. string.push(c);
  11366. j = i + 1;
  11367. }
  11368. }
  11369. string.push(specifier.slice(j, i));
  11370. return string.join("");
  11371. };
  11372. }
  11373. function newParse(specifier, Z) {
  11374. return function(string) {
  11375. var d = newDate(1900, undefined, 1),
  11376. i = parseSpecifier(d, specifier, string += "", 0),
  11377. week, day$1;
  11378. if (i != string.length) return null;
  11379. // If a UNIX timestamp is specified, return it.
  11380. if ("Q" in d) return new Date(d.Q);
  11381. if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
  11382. // If this is utcParse, never use the local timezone.
  11383. if (Z && !("Z" in d)) d.Z = 0;
  11384. // The am-pm flag is 0 for AM, and 1 for PM.
  11385. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  11386. // If the month was not specified, inherit from the quarter.
  11387. if (d.m === undefined) d.m = "q" in d ? d.q : 0;
  11388. // Convert day-of-week and week-of-year to day-of-year.
  11389. if ("V" in d) {
  11390. if (d.V < 1 || d.V > 53) return null;
  11391. if (!("w" in d)) d.w = 1;
  11392. if ("Z" in d) {
  11393. week = utcDate(newDate(d.y, 0, 1)), day$1 = week.getUTCDay();
  11394. week = day$1 > 4 || day$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  11395. week = utcDay.offset(week, (d.V - 1) * 7);
  11396. d.y = week.getUTCFullYear();
  11397. d.m = week.getUTCMonth();
  11398. d.d = week.getUTCDate() + (d.w + 6) % 7;
  11399. } else {
  11400. week = localDate(newDate(d.y, 0, 1)), day$1 = week.getDay();
  11401. week = day$1 > 4 || day$1 === 0 ? monday.ceil(week) : monday(week);
  11402. week = day.offset(week, (d.V - 1) * 7);
  11403. d.y = week.getFullYear();
  11404. d.m = week.getMonth();
  11405. d.d = week.getDate() + (d.w + 6) % 7;
  11406. }
  11407. } else if ("W" in d || "U" in d) {
  11408. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  11409. day$1 = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
  11410. d.m = 0;
  11411. 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;
  11412. }
  11413. // If a time zone is specified, all fields are interpreted as UTC and then
  11414. // offset according to the specified time zone.
  11415. if ("Z" in d) {
  11416. d.H += d.Z / 100 | 0;
  11417. d.M += d.Z % 100;
  11418. return utcDate(d);
  11419. }
  11420. // Otherwise, all fields are in local time.
  11421. return localDate(d);
  11422. };
  11423. }
  11424. function parseSpecifier(d, specifier, string, j) {
  11425. var i = 0,
  11426. n = specifier.length,
  11427. m = string.length,
  11428. c,
  11429. parse;
  11430. while (i < n) {
  11431. if (j >= m) return -1;
  11432. c = specifier.charCodeAt(i++);
  11433. if (c === 37) {
  11434. c = specifier.charAt(i++);
  11435. parse = parses[c in pads ? specifier.charAt(i++) : c];
  11436. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  11437. } else if (c != string.charCodeAt(j++)) {
  11438. return -1;
  11439. }
  11440. }
  11441. return j;
  11442. }
  11443. function parsePeriod(d, string, i) {
  11444. var n = periodRe.exec(string.slice(i));
  11445. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11446. }
  11447. function parseShortWeekday(d, string, i) {
  11448. var n = shortWeekdayRe.exec(string.slice(i));
  11449. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11450. }
  11451. function parseWeekday(d, string, i) {
  11452. var n = weekdayRe.exec(string.slice(i));
  11453. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11454. }
  11455. function parseShortMonth(d, string, i) {
  11456. var n = shortMonthRe.exec(string.slice(i));
  11457. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11458. }
  11459. function parseMonth(d, string, i) {
  11460. var n = monthRe.exec(string.slice(i));
  11461. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11462. }
  11463. function parseLocaleDateTime(d, string, i) {
  11464. return parseSpecifier(d, locale_dateTime, string, i);
  11465. }
  11466. function parseLocaleDate(d, string, i) {
  11467. return parseSpecifier(d, locale_date, string, i);
  11468. }
  11469. function parseLocaleTime(d, string, i) {
  11470. return parseSpecifier(d, locale_time, string, i);
  11471. }
  11472. function formatShortWeekday(d) {
  11473. return locale_shortWeekdays[d.getDay()];
  11474. }
  11475. function formatWeekday(d) {
  11476. return locale_weekdays[d.getDay()];
  11477. }
  11478. function formatShortMonth(d) {
  11479. return locale_shortMonths[d.getMonth()];
  11480. }
  11481. function formatMonth(d) {
  11482. return locale_months[d.getMonth()];
  11483. }
  11484. function formatPeriod(d) {
  11485. return locale_periods[+(d.getHours() >= 12)];
  11486. }
  11487. function formatQuarter(d) {
  11488. return 1 + ~~(d.getMonth() / 3);
  11489. }
  11490. function formatUTCShortWeekday(d) {
  11491. return locale_shortWeekdays[d.getUTCDay()];
  11492. }
  11493. function formatUTCWeekday(d) {
  11494. return locale_weekdays[d.getUTCDay()];
  11495. }
  11496. function formatUTCShortMonth(d) {
  11497. return locale_shortMonths[d.getUTCMonth()];
  11498. }
  11499. function formatUTCMonth(d) {
  11500. return locale_months[d.getUTCMonth()];
  11501. }
  11502. function formatUTCPeriod(d) {
  11503. return locale_periods[+(d.getUTCHours() >= 12)];
  11504. }
  11505. function formatUTCQuarter(d) {
  11506. return 1 + ~~(d.getUTCMonth() / 3);
  11507. }
  11508. return {
  11509. format: function(specifier) {
  11510. var f = newFormat(specifier += "", formats);
  11511. f.toString = function() { return specifier; };
  11512. return f;
  11513. },
  11514. parse: function(specifier) {
  11515. var p = newParse(specifier += "", false);
  11516. p.toString = function() { return specifier; };
  11517. return p;
  11518. },
  11519. utcFormat: function(specifier) {
  11520. var f = newFormat(specifier += "", utcFormats);
  11521. f.toString = function() { return specifier; };
  11522. return f;
  11523. },
  11524. utcParse: function(specifier) {
  11525. var p = newParse(specifier += "", true);
  11526. p.toString = function() { return specifier; };
  11527. return p;
  11528. }
  11529. };
  11530. }
  11531. var pads = {"-": "", "_": " ", "0": "0"},
  11532. numberRe = /^\s*\d+/, // note: ignores next directive
  11533. percentRe = /^%/,
  11534. requoteRe = /[\\^$*+?|[\]().{}]/g;
  11535. function pad$1(value, fill, width) {
  11536. var sign = value < 0 ? "-" : "",
  11537. string = (sign ? -value : value) + "",
  11538. length = string.length;
  11539. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  11540. }
  11541. function requote(s) {
  11542. return s.replace(requoteRe, "\\$&");
  11543. }
  11544. function formatRe(names) {
  11545. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  11546. }
  11547. function formatLookup(names) {
  11548. var map = {}, i = -1, n = names.length;
  11549. while (++i < n) map[names[i].toLowerCase()] = i;
  11550. return map;
  11551. }
  11552. function parseWeekdayNumberSunday(d, string, i) {
  11553. var n = numberRe.exec(string.slice(i, i + 1));
  11554. return n ? (d.w = +n[0], i + n[0].length) : -1;
  11555. }
  11556. function parseWeekdayNumberMonday(d, string, i) {
  11557. var n = numberRe.exec(string.slice(i, i + 1));
  11558. return n ? (d.u = +n[0], i + n[0].length) : -1;
  11559. }
  11560. function parseWeekNumberSunday(d, string, i) {
  11561. var n = numberRe.exec(string.slice(i, i + 2));
  11562. return n ? (d.U = +n[0], i + n[0].length) : -1;
  11563. }
  11564. function parseWeekNumberISO(d, string, i) {
  11565. var n = numberRe.exec(string.slice(i, i + 2));
  11566. return n ? (d.V = +n[0], i + n[0].length) : -1;
  11567. }
  11568. function parseWeekNumberMonday(d, string, i) {
  11569. var n = numberRe.exec(string.slice(i, i + 2));
  11570. return n ? (d.W = +n[0], i + n[0].length) : -1;
  11571. }
  11572. function parseFullYear(d, string, i) {
  11573. var n = numberRe.exec(string.slice(i, i + 4));
  11574. return n ? (d.y = +n[0], i + n[0].length) : -1;
  11575. }
  11576. function parseYear(d, string, i) {
  11577. var n = numberRe.exec(string.slice(i, i + 2));
  11578. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  11579. }
  11580. function parseZone(d, string, i) {
  11581. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  11582. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  11583. }
  11584. function parseQuarter(d, string, i) {
  11585. var n = numberRe.exec(string.slice(i, i + 1));
  11586. return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
  11587. }
  11588. function parseMonthNumber(d, string, i) {
  11589. var n = numberRe.exec(string.slice(i, i + 2));
  11590. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  11591. }
  11592. function parseDayOfMonth(d, string, i) {
  11593. var n = numberRe.exec(string.slice(i, i + 2));
  11594. return n ? (d.d = +n[0], i + n[0].length) : -1;
  11595. }
  11596. function parseDayOfYear(d, string, i) {
  11597. var n = numberRe.exec(string.slice(i, i + 3));
  11598. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  11599. }
  11600. function parseHour24(d, string, i) {
  11601. var n = numberRe.exec(string.slice(i, i + 2));
  11602. return n ? (d.H = +n[0], i + n[0].length) : -1;
  11603. }
  11604. function parseMinutes(d, string, i) {
  11605. var n = numberRe.exec(string.slice(i, i + 2));
  11606. return n ? (d.M = +n[0], i + n[0].length) : -1;
  11607. }
  11608. function parseSeconds(d, string, i) {
  11609. var n = numberRe.exec(string.slice(i, i + 2));
  11610. return n ? (d.S = +n[0], i + n[0].length) : -1;
  11611. }
  11612. function parseMilliseconds(d, string, i) {
  11613. var n = numberRe.exec(string.slice(i, i + 3));
  11614. return n ? (d.L = +n[0], i + n[0].length) : -1;
  11615. }
  11616. function parseMicroseconds(d, string, i) {
  11617. var n = numberRe.exec(string.slice(i, i + 6));
  11618. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  11619. }
  11620. function parseLiteralPercent(d, string, i) {
  11621. var n = percentRe.exec(string.slice(i, i + 1));
  11622. return n ? i + n[0].length : -1;
  11623. }
  11624. function parseUnixTimestamp(d, string, i) {
  11625. var n = numberRe.exec(string.slice(i));
  11626. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  11627. }
  11628. function parseUnixTimestampSeconds(d, string, i) {
  11629. var n = numberRe.exec(string.slice(i));
  11630. return n ? (d.s = +n[0], i + n[0].length) : -1;
  11631. }
  11632. function formatDayOfMonth(d, p) {
  11633. return pad$1(d.getDate(), p, 2);
  11634. }
  11635. function formatHour24(d, p) {
  11636. return pad$1(d.getHours(), p, 2);
  11637. }
  11638. function formatHour12(d, p) {
  11639. return pad$1(d.getHours() % 12 || 12, p, 2);
  11640. }
  11641. function formatDayOfYear(d, p) {
  11642. return pad$1(1 + day.count(year(d), d), p, 3);
  11643. }
  11644. function formatMilliseconds(d, p) {
  11645. return pad$1(d.getMilliseconds(), p, 3);
  11646. }
  11647. function formatMicroseconds(d, p) {
  11648. return formatMilliseconds(d, p) + "000";
  11649. }
  11650. function formatMonthNumber(d, p) {
  11651. return pad$1(d.getMonth() + 1, p, 2);
  11652. }
  11653. function formatMinutes(d, p) {
  11654. return pad$1(d.getMinutes(), p, 2);
  11655. }
  11656. function formatSeconds(d, p) {
  11657. return pad$1(d.getSeconds(), p, 2);
  11658. }
  11659. function formatWeekdayNumberMonday(d) {
  11660. var day = d.getDay();
  11661. return day === 0 ? 7 : day;
  11662. }
  11663. function formatWeekNumberSunday(d, p) {
  11664. return pad$1(sunday.count(year(d) - 1, d), p, 2);
  11665. }
  11666. function formatWeekNumberISO(d, p) {
  11667. var day = d.getDay();
  11668. d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
  11669. return pad$1(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  11670. }
  11671. function formatWeekdayNumberSunday(d) {
  11672. return d.getDay();
  11673. }
  11674. function formatWeekNumberMonday(d, p) {
  11675. return pad$1(monday.count(year(d) - 1, d), p, 2);
  11676. }
  11677. function formatYear$1(d, p) {
  11678. return pad$1(d.getFullYear() % 100, p, 2);
  11679. }
  11680. function formatFullYear(d, p) {
  11681. return pad$1(d.getFullYear() % 10000, p, 4);
  11682. }
  11683. function formatZone(d) {
  11684. var z = d.getTimezoneOffset();
  11685. return (z > 0 ? "-" : (z *= -1, "+"))
  11686. + pad$1(z / 60 | 0, "0", 2)
  11687. + pad$1(z % 60, "0", 2);
  11688. }
  11689. function formatUTCDayOfMonth(d, p) {
  11690. return pad$1(d.getUTCDate(), p, 2);
  11691. }
  11692. function formatUTCHour24(d, p) {
  11693. return pad$1(d.getUTCHours(), p, 2);
  11694. }
  11695. function formatUTCHour12(d, p) {
  11696. return pad$1(d.getUTCHours() % 12 || 12, p, 2);
  11697. }
  11698. function formatUTCDayOfYear(d, p) {
  11699. return pad$1(1 + utcDay.count(utcYear(d), d), p, 3);
  11700. }
  11701. function formatUTCMilliseconds(d, p) {
  11702. return pad$1(d.getUTCMilliseconds(), p, 3);
  11703. }
  11704. function formatUTCMicroseconds(d, p) {
  11705. return formatUTCMilliseconds(d, p) + "000";
  11706. }
  11707. function formatUTCMonthNumber(d, p) {
  11708. return pad$1(d.getUTCMonth() + 1, p, 2);
  11709. }
  11710. function formatUTCMinutes(d, p) {
  11711. return pad$1(d.getUTCMinutes(), p, 2);
  11712. }
  11713. function formatUTCSeconds(d, p) {
  11714. return pad$1(d.getUTCSeconds(), p, 2);
  11715. }
  11716. function formatUTCWeekdayNumberMonday(d) {
  11717. var dow = d.getUTCDay();
  11718. return dow === 0 ? 7 : dow;
  11719. }
  11720. function formatUTCWeekNumberSunday(d, p) {
  11721. return pad$1(utcSunday.count(utcYear(d) - 1, d), p, 2);
  11722. }
  11723. function formatUTCWeekNumberISO(d, p) {
  11724. var day = d.getUTCDay();
  11725. d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  11726. return pad$1(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  11727. }
  11728. function formatUTCWeekdayNumberSunday(d) {
  11729. return d.getUTCDay();
  11730. }
  11731. function formatUTCWeekNumberMonday(d, p) {
  11732. return pad$1(utcMonday.count(utcYear(d) - 1, d), p, 2);
  11733. }
  11734. function formatUTCYear(d, p) {
  11735. return pad$1(d.getUTCFullYear() % 100, p, 2);
  11736. }
  11737. function formatUTCFullYear(d, p) {
  11738. return pad$1(d.getUTCFullYear() % 10000, p, 4);
  11739. }
  11740. function formatUTCZone() {
  11741. return "+0000";
  11742. }
  11743. function formatLiteralPercent() {
  11744. return "%";
  11745. }
  11746. function formatUnixTimestamp(d) {
  11747. return +d;
  11748. }
  11749. function formatUnixTimestampSeconds(d) {
  11750. return Math.floor(+d / 1000);
  11751. }
  11752. var locale$1;
  11753. defaultLocale$1({
  11754. dateTime: "%x, %X",
  11755. date: "%-m/%-d/%Y",
  11756. time: "%-I:%M:%S %p",
  11757. periods: ["AM", "PM"],
  11758. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11759. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11760. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11761. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11762. });
  11763. function defaultLocale$1(definition) {
  11764. locale$1 = formatLocale$1(definition);
  11765. exports.timeFormat = locale$1.format;
  11766. exports.timeParse = locale$1.parse;
  11767. exports.utcFormat = locale$1.utcFormat;
  11768. exports.utcParse = locale$1.utcParse;
  11769. return locale$1;
  11770. }
  11771. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11772. function formatIsoNative(date) {
  11773. return date.toISOString();
  11774. }
  11775. var formatIso = Date.prototype.toISOString
  11776. ? formatIsoNative
  11777. : exports.utcFormat(isoSpecifier);
  11778. function parseIsoNative(string) {
  11779. var date = new Date(string);
  11780. return isNaN(date) ? null : date;
  11781. }
  11782. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11783. ? parseIsoNative
  11784. : exports.utcParse(isoSpecifier);
  11785. var durationSecond$1 = 1000,
  11786. durationMinute$1 = durationSecond$1 * 60,
  11787. durationHour$1 = durationMinute$1 * 60,
  11788. durationDay$1 = durationHour$1 * 24,
  11789. durationWeek$1 = durationDay$1 * 7,
  11790. durationMonth = durationDay$1 * 30,
  11791. durationYear = durationDay$1 * 365;
  11792. function date$1(t) {
  11793. return new Date(t);
  11794. }
  11795. function number$3(t) {
  11796. return t instanceof Date ? +t : +new Date(+t);
  11797. }
  11798. function calendar(year, month, week, day, hour, minute, second, millisecond, format) {
  11799. var scale = continuous(identity$6, identity$6),
  11800. invert = scale.invert,
  11801. domain = scale.domain;
  11802. var formatMillisecond = format(".%L"),
  11803. formatSecond = format(":%S"),
  11804. formatMinute = format("%I:%M"),
  11805. formatHour = format("%I %p"),
  11806. formatDay = format("%a %d"),
  11807. formatWeek = format("%b %d"),
  11808. formatMonth = format("%B"),
  11809. formatYear = format("%Y");
  11810. var tickIntervals = [
  11811. [second, 1, durationSecond$1],
  11812. [second, 5, 5 * durationSecond$1],
  11813. [second, 15, 15 * durationSecond$1],
  11814. [second, 30, 30 * durationSecond$1],
  11815. [minute, 1, durationMinute$1],
  11816. [minute, 5, 5 * durationMinute$1],
  11817. [minute, 15, 15 * durationMinute$1],
  11818. [minute, 30, 30 * durationMinute$1],
  11819. [ hour, 1, durationHour$1 ],
  11820. [ hour, 3, 3 * durationHour$1 ],
  11821. [ hour, 6, 6 * durationHour$1 ],
  11822. [ hour, 12, 12 * durationHour$1 ],
  11823. [ day, 1, durationDay$1 ],
  11824. [ day, 2, 2 * durationDay$1 ],
  11825. [ week, 1, durationWeek$1 ],
  11826. [ month, 1, durationMonth ],
  11827. [ month, 3, 3 * durationMonth ],
  11828. [ year, 1, durationYear ]
  11829. ];
  11830. function tickFormat(date) {
  11831. return (second(date) < date ? formatMillisecond
  11832. : minute(date) < date ? formatSecond
  11833. : hour(date) < date ? formatMinute
  11834. : day(date) < date ? formatHour
  11835. : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
  11836. : year(date) < date ? formatMonth
  11837. : formatYear)(date);
  11838. }
  11839. function tickInterval(interval, start, stop, step) {
  11840. if (interval == null) interval = 10;
  11841. // If a desired tick count is specified, pick a reasonable tick interval
  11842. // based on the extent of the domain and a rough estimate of tick size.
  11843. // Otherwise, assume interval is already a time interval and use it.
  11844. if (typeof interval === "number") {
  11845. var target = Math.abs(stop - start) / interval,
  11846. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11847. if (i === tickIntervals.length) {
  11848. step = tickStep(start / durationYear, stop / durationYear, interval);
  11849. interval = year;
  11850. } else if (i) {
  11851. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11852. step = i[1];
  11853. interval = i[0];
  11854. } else {
  11855. step = Math.max(tickStep(start, stop, interval), 1);
  11856. interval = millisecond;
  11857. }
  11858. }
  11859. return step == null ? interval : interval.every(step);
  11860. }
  11861. scale.invert = function(y) {
  11862. return new Date(invert(y));
  11863. };
  11864. scale.domain = function(_) {
  11865. return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
  11866. };
  11867. scale.ticks = function(interval, step) {
  11868. var d = domain(),
  11869. t0 = d[0],
  11870. t1 = d[d.length - 1],
  11871. r = t1 < t0,
  11872. t;
  11873. if (r) t = t0, t0 = t1, t1 = t;
  11874. t = tickInterval(interval, t0, t1, step);
  11875. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11876. return r ? t.reverse() : t;
  11877. };
  11878. scale.tickFormat = function(count, specifier) {
  11879. return specifier == null ? tickFormat : format(specifier);
  11880. };
  11881. scale.nice = function(interval, step) {
  11882. var d = domain();
  11883. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11884. ? domain(nice(d, interval))
  11885. : scale;
  11886. };
  11887. scale.copy = function() {
  11888. return copy(scale, calendar(year, month, week, day, hour, minute, second, millisecond, format));
  11889. };
  11890. return scale;
  11891. }
  11892. function time() {
  11893. 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);
  11894. }
  11895. function utcTime() {
  11896. 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);
  11897. }
  11898. function transformer$2() {
  11899. var x0 = 0,
  11900. x1 = 1,
  11901. t0,
  11902. t1,
  11903. k10,
  11904. transform,
  11905. interpolator = identity$6,
  11906. clamp = false,
  11907. unknown;
  11908. function scale(x) {
  11909. return isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
  11910. }
  11911. scale.domain = function(_) {
  11912. return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
  11913. };
  11914. scale.clamp = function(_) {
  11915. return arguments.length ? (clamp = !!_, scale) : clamp;
  11916. };
  11917. scale.interpolator = function(_) {
  11918. return arguments.length ? (interpolator = _, scale) : interpolator;
  11919. };
  11920. scale.unknown = function(_) {
  11921. return arguments.length ? (unknown = _, scale) : unknown;
  11922. };
  11923. return function(t) {
  11924. transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
  11925. return scale;
  11926. };
  11927. }
  11928. function copy$1(source, target) {
  11929. return target
  11930. .domain(source.domain())
  11931. .interpolator(source.interpolator())
  11932. .clamp(source.clamp())
  11933. .unknown(source.unknown());
  11934. }
  11935. function sequential() {
  11936. var scale = linearish(transformer$2()(identity$6));
  11937. scale.copy = function() {
  11938. return copy$1(scale, sequential());
  11939. };
  11940. return initInterpolator.apply(scale, arguments);
  11941. }
  11942. function sequentialLog() {
  11943. var scale = loggish(transformer$2()).domain([1, 10]);
  11944. scale.copy = function() {
  11945. return copy$1(scale, sequentialLog()).base(scale.base());
  11946. };
  11947. return initInterpolator.apply(scale, arguments);
  11948. }
  11949. function sequentialSymlog() {
  11950. var scale = symlogish(transformer$2());
  11951. scale.copy = function() {
  11952. return copy$1(scale, sequentialSymlog()).constant(scale.constant());
  11953. };
  11954. return initInterpolator.apply(scale, arguments);
  11955. }
  11956. function sequentialPow() {
  11957. var scale = powish(transformer$2());
  11958. scale.copy = function() {
  11959. return copy$1(scale, sequentialPow()).exponent(scale.exponent());
  11960. };
  11961. return initInterpolator.apply(scale, arguments);
  11962. }
  11963. function sequentialSqrt() {
  11964. return sequentialPow.apply(null, arguments).exponent(0.5);
  11965. }
  11966. function sequentialQuantile() {
  11967. var domain = [],
  11968. interpolator = identity$6;
  11969. function scale(x) {
  11970. if (!isNaN(x = +x)) return interpolator((bisectRight(domain, x) - 1) / (domain.length - 1));
  11971. }
  11972. scale.domain = function(_) {
  11973. if (!arguments.length) return domain.slice();
  11974. domain = [];
  11975. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  11976. domain.sort(ascending);
  11977. return scale;
  11978. };
  11979. scale.interpolator = function(_) {
  11980. return arguments.length ? (interpolator = _, scale) : interpolator;
  11981. };
  11982. scale.copy = function() {
  11983. return sequentialQuantile(interpolator).domain(domain);
  11984. };
  11985. return initInterpolator.apply(scale, arguments);
  11986. }
  11987. function transformer$3() {
  11988. var x0 = 0,
  11989. x1 = 0.5,
  11990. x2 = 1,
  11991. t0,
  11992. t1,
  11993. t2,
  11994. k10,
  11995. k21,
  11996. interpolator = identity$6,
  11997. transform,
  11998. clamp = false,
  11999. unknown;
  12000. function scale(x) {
  12001. 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));
  12002. }
  12003. scale.domain = function(_) {
  12004. 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];
  12005. };
  12006. scale.clamp = function(_) {
  12007. return arguments.length ? (clamp = !!_, scale) : clamp;
  12008. };
  12009. scale.interpolator = function(_) {
  12010. return arguments.length ? (interpolator = _, scale) : interpolator;
  12011. };
  12012. scale.unknown = function(_) {
  12013. return arguments.length ? (unknown = _, scale) : unknown;
  12014. };
  12015. return function(t) {
  12016. 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);
  12017. return scale;
  12018. };
  12019. }
  12020. function diverging() {
  12021. var scale = linearish(transformer$3()(identity$6));
  12022. scale.copy = function() {
  12023. return copy$1(scale, diverging());
  12024. };
  12025. return initInterpolator.apply(scale, arguments);
  12026. }
  12027. function divergingLog() {
  12028. var scale = loggish(transformer$3()).domain([0.1, 1, 10]);
  12029. scale.copy = function() {
  12030. return copy$1(scale, divergingLog()).base(scale.base());
  12031. };
  12032. return initInterpolator.apply(scale, arguments);
  12033. }
  12034. function divergingSymlog() {
  12035. var scale = symlogish(transformer$3());
  12036. scale.copy = function() {
  12037. return copy$1(scale, divergingSymlog()).constant(scale.constant());
  12038. };
  12039. return initInterpolator.apply(scale, arguments);
  12040. }
  12041. function divergingPow() {
  12042. var scale = powish(transformer$3());
  12043. scale.copy = function() {
  12044. return copy$1(scale, divergingPow()).exponent(scale.exponent());
  12045. };
  12046. return initInterpolator.apply(scale, arguments);
  12047. }
  12048. function divergingSqrt() {
  12049. return divergingPow.apply(null, arguments).exponent(0.5);
  12050. }
  12051. function colors(specifier) {
  12052. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  12053. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  12054. return colors;
  12055. }
  12056. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  12057. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  12058. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  12059. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  12060. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  12061. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  12062. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  12063. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  12064. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  12065. var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
  12066. function ramp(scheme) {
  12067. return rgbBasis(scheme[scheme.length - 1]);
  12068. }
  12069. var scheme = new Array(3).concat(
  12070. "d8b365f5f5f55ab4ac",
  12071. "a6611adfc27d80cdc1018571",
  12072. "a6611adfc27df5f5f580cdc1018571",
  12073. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  12074. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  12075. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  12076. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  12077. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  12078. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  12079. ).map(colors);
  12080. var BrBG = ramp(scheme);
  12081. var scheme$1 = new Array(3).concat(
  12082. "af8dc3f7f7f77fbf7b",
  12083. "7b3294c2a5cfa6dba0008837",
  12084. "7b3294c2a5cff7f7f7a6dba0008837",
  12085. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  12086. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  12087. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  12088. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  12089. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  12090. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  12091. ).map(colors);
  12092. var PRGn = ramp(scheme$1);
  12093. var scheme$2 = new Array(3).concat(
  12094. "e9a3c9f7f7f7a1d76a",
  12095. "d01c8bf1b6dab8e1864dac26",
  12096. "d01c8bf1b6daf7f7f7b8e1864dac26",
  12097. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  12098. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  12099. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  12100. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  12101. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  12102. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  12103. ).map(colors);
  12104. var PiYG = ramp(scheme$2);
  12105. var scheme$3 = new Array(3).concat(
  12106. "998ec3f7f7f7f1a340",
  12107. "5e3c99b2abd2fdb863e66101",
  12108. "5e3c99b2abd2f7f7f7fdb863e66101",
  12109. "542788998ec3d8daebfee0b6f1a340b35806",
  12110. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  12111. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  12112. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  12113. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  12114. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  12115. ).map(colors);
  12116. var PuOr = ramp(scheme$3);
  12117. var scheme$4 = new Array(3).concat(
  12118. "ef8a62f7f7f767a9cf",
  12119. "ca0020f4a58292c5de0571b0",
  12120. "ca0020f4a582f7f7f792c5de0571b0",
  12121. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  12122. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  12123. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  12124. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  12125. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  12126. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  12127. ).map(colors);
  12128. var RdBu = ramp(scheme$4);
  12129. var scheme$5 = new Array(3).concat(
  12130. "ef8a62ffffff999999",
  12131. "ca0020f4a582bababa404040",
  12132. "ca0020f4a582ffffffbababa404040",
  12133. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  12134. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  12135. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  12136. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  12137. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  12138. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  12139. ).map(colors);
  12140. var RdGy = ramp(scheme$5);
  12141. var scheme$6 = new Array(3).concat(
  12142. "fc8d59ffffbf91bfdb",
  12143. "d7191cfdae61abd9e92c7bb6",
  12144. "d7191cfdae61ffffbfabd9e92c7bb6",
  12145. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  12146. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  12147. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  12148. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  12149. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  12150. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  12151. ).map(colors);
  12152. var RdYlBu = ramp(scheme$6);
  12153. var scheme$7 = new Array(3).concat(
  12154. "fc8d59ffffbf91cf60",
  12155. "d7191cfdae61a6d96a1a9641",
  12156. "d7191cfdae61ffffbfa6d96a1a9641",
  12157. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  12158. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  12159. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  12160. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  12161. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  12162. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  12163. ).map(colors);
  12164. var RdYlGn = ramp(scheme$7);
  12165. var scheme$8 = new Array(3).concat(
  12166. "fc8d59ffffbf99d594",
  12167. "d7191cfdae61abdda42b83ba",
  12168. "d7191cfdae61ffffbfabdda42b83ba",
  12169. "d53e4ffc8d59fee08be6f59899d5943288bd",
  12170. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  12171. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  12172. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  12173. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  12174. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  12175. ).map(colors);
  12176. var Spectral = ramp(scheme$8);
  12177. var scheme$9 = new Array(3).concat(
  12178. "e5f5f999d8c92ca25f",
  12179. "edf8fbb2e2e266c2a4238b45",
  12180. "edf8fbb2e2e266c2a42ca25f006d2c",
  12181. "edf8fbccece699d8c966c2a42ca25f006d2c",
  12182. "edf8fbccece699d8c966c2a441ae76238b45005824",
  12183. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  12184. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  12185. ).map(colors);
  12186. var BuGn = ramp(scheme$9);
  12187. var scheme$a = new Array(3).concat(
  12188. "e0ecf49ebcda8856a7",
  12189. "edf8fbb3cde38c96c688419d",
  12190. "edf8fbb3cde38c96c68856a7810f7c",
  12191. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  12192. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  12193. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  12194. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  12195. ).map(colors);
  12196. var BuPu = ramp(scheme$a);
  12197. var scheme$b = new Array(3).concat(
  12198. "e0f3dba8ddb543a2ca",
  12199. "f0f9e8bae4bc7bccc42b8cbe",
  12200. "f0f9e8bae4bc7bccc443a2ca0868ac",
  12201. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  12202. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  12203. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  12204. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  12205. ).map(colors);
  12206. var GnBu = ramp(scheme$b);
  12207. var scheme$c = new Array(3).concat(
  12208. "fee8c8fdbb84e34a33",
  12209. "fef0d9fdcc8afc8d59d7301f",
  12210. "fef0d9fdcc8afc8d59e34a33b30000",
  12211. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  12212. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  12213. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  12214. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  12215. ).map(colors);
  12216. var OrRd = ramp(scheme$c);
  12217. var scheme$d = new Array(3).concat(
  12218. "ece2f0a6bddb1c9099",
  12219. "f6eff7bdc9e167a9cf02818a",
  12220. "f6eff7bdc9e167a9cf1c9099016c59",
  12221. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  12222. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  12223. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  12224. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  12225. ).map(colors);
  12226. var PuBuGn = ramp(scheme$d);
  12227. var scheme$e = new Array(3).concat(
  12228. "ece7f2a6bddb2b8cbe",
  12229. "f1eef6bdc9e174a9cf0570b0",
  12230. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  12231. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  12232. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  12233. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  12234. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  12235. ).map(colors);
  12236. var PuBu = ramp(scheme$e);
  12237. var scheme$f = new Array(3).concat(
  12238. "e7e1efc994c7dd1c77",
  12239. "f1eef6d7b5d8df65b0ce1256",
  12240. "f1eef6d7b5d8df65b0dd1c77980043",
  12241. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  12242. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  12243. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  12244. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  12245. ).map(colors);
  12246. var PuRd = ramp(scheme$f);
  12247. var scheme$g = new Array(3).concat(
  12248. "fde0ddfa9fb5c51b8a",
  12249. "feebe2fbb4b9f768a1ae017e",
  12250. "feebe2fbb4b9f768a1c51b8a7a0177",
  12251. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  12252. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  12253. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  12254. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  12255. ).map(colors);
  12256. var RdPu = ramp(scheme$g);
  12257. var scheme$h = new Array(3).concat(
  12258. "edf8b17fcdbb2c7fb8",
  12259. "ffffcca1dab441b6c4225ea8",
  12260. "ffffcca1dab441b6c42c7fb8253494",
  12261. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  12262. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  12263. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  12264. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  12265. ).map(colors);
  12266. var YlGnBu = ramp(scheme$h);
  12267. var scheme$i = new Array(3).concat(
  12268. "f7fcb9addd8e31a354",
  12269. "ffffccc2e69978c679238443",
  12270. "ffffccc2e69978c67931a354006837",
  12271. "ffffccd9f0a3addd8e78c67931a354006837",
  12272. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  12273. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  12274. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  12275. ).map(colors);
  12276. var YlGn = ramp(scheme$i);
  12277. var scheme$j = new Array(3).concat(
  12278. "fff7bcfec44fd95f0e",
  12279. "ffffd4fed98efe9929cc4c02",
  12280. "ffffd4fed98efe9929d95f0e993404",
  12281. "ffffd4fee391fec44ffe9929d95f0e993404",
  12282. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  12283. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  12284. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  12285. ).map(colors);
  12286. var YlOrBr = ramp(scheme$j);
  12287. var scheme$k = new Array(3).concat(
  12288. "ffeda0feb24cf03b20",
  12289. "ffffb2fecc5cfd8d3ce31a1c",
  12290. "ffffb2fecc5cfd8d3cf03b20bd0026",
  12291. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  12292. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  12293. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  12294. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  12295. ).map(colors);
  12296. var YlOrRd = ramp(scheme$k);
  12297. var scheme$l = new Array(3).concat(
  12298. "deebf79ecae13182bd",
  12299. "eff3ffbdd7e76baed62171b5",
  12300. "eff3ffbdd7e76baed63182bd08519c",
  12301. "eff3ffc6dbef9ecae16baed63182bd08519c",
  12302. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  12303. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  12304. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  12305. ).map(colors);
  12306. var Blues = ramp(scheme$l);
  12307. var scheme$m = new Array(3).concat(
  12308. "e5f5e0a1d99b31a354",
  12309. "edf8e9bae4b374c476238b45",
  12310. "edf8e9bae4b374c47631a354006d2c",
  12311. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  12312. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  12313. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  12314. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  12315. ).map(colors);
  12316. var Greens = ramp(scheme$m);
  12317. var scheme$n = new Array(3).concat(
  12318. "f0f0f0bdbdbd636363",
  12319. "f7f7f7cccccc969696525252",
  12320. "f7f7f7cccccc969696636363252525",
  12321. "f7f7f7d9d9d9bdbdbd969696636363252525",
  12322. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  12323. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  12324. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  12325. ).map(colors);
  12326. var Greys = ramp(scheme$n);
  12327. var scheme$o = new Array(3).concat(
  12328. "efedf5bcbddc756bb1",
  12329. "f2f0f7cbc9e29e9ac86a51a3",
  12330. "f2f0f7cbc9e29e9ac8756bb154278f",
  12331. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  12332. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  12333. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  12334. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  12335. ).map(colors);
  12336. var Purples = ramp(scheme$o);
  12337. var scheme$p = new Array(3).concat(
  12338. "fee0d2fc9272de2d26",
  12339. "fee5d9fcae91fb6a4acb181d",
  12340. "fee5d9fcae91fb6a4ade2d26a50f15",
  12341. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  12342. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  12343. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  12344. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  12345. ).map(colors);
  12346. var Reds = ramp(scheme$p);
  12347. var scheme$q = new Array(3).concat(
  12348. "fee6cefdae6be6550d",
  12349. "feeddefdbe85fd8d3cd94701",
  12350. "feeddefdbe85fd8d3ce6550da63603",
  12351. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  12352. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  12353. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  12354. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  12355. ).map(colors);
  12356. var Oranges = ramp(scheme$q);
  12357. function cividis(t) {
  12358. t = Math.max(0, Math.min(1, t));
  12359. return "rgb("
  12360. + 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))))))) + ", "
  12361. + 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))))))) + ", "
  12362. + 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)))))))
  12363. + ")";
  12364. }
  12365. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  12366. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  12367. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  12368. var c = cubehelix();
  12369. function rainbow(t) {
  12370. if (t < 0 || t > 1) t -= Math.floor(t);
  12371. var ts = Math.abs(t - 0.5);
  12372. c.h = 360 * t - 100;
  12373. c.s = 1.5 - 1.5 * ts;
  12374. c.l = 0.8 - 0.9 * ts;
  12375. return c + "";
  12376. }
  12377. var c$1 = rgb(),
  12378. pi_1_3 = Math.PI / 3,
  12379. pi_2_3 = Math.PI * 2 / 3;
  12380. function sinebow(t) {
  12381. var x;
  12382. t = (0.5 - t) * Math.PI;
  12383. c$1.r = 255 * (x = Math.sin(t)) * x;
  12384. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  12385. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  12386. return c$1 + "";
  12387. }
  12388. function turbo(t) {
  12389. t = Math.max(0, Math.min(1, t));
  12390. return "rgb("
  12391. + 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))))))) + ", "
  12392. + 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))))))) + ", "
  12393. + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
  12394. + ")";
  12395. }
  12396. function ramp$1(range) {
  12397. var n = range.length;
  12398. return function(t) {
  12399. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  12400. };
  12401. }
  12402. var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  12403. var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  12404. var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  12405. var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  12406. function constant$b(x) {
  12407. return function constant() {
  12408. return x;
  12409. };
  12410. }
  12411. var abs$1 = Math.abs;
  12412. var atan2$1 = Math.atan2;
  12413. var cos$2 = Math.cos;
  12414. var max$2 = Math.max;
  12415. var min$1 = Math.min;
  12416. var sin$2 = Math.sin;
  12417. var sqrt$2 = Math.sqrt;
  12418. var epsilon$3 = 1e-12;
  12419. var pi$4 = Math.PI;
  12420. var halfPi$3 = pi$4 / 2;
  12421. var tau$4 = 2 * pi$4;
  12422. function acos$1(x) {
  12423. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  12424. }
  12425. function asin$1(x) {
  12426. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  12427. }
  12428. function arcInnerRadius(d) {
  12429. return d.innerRadius;
  12430. }
  12431. function arcOuterRadius(d) {
  12432. return d.outerRadius;
  12433. }
  12434. function arcStartAngle(d) {
  12435. return d.startAngle;
  12436. }
  12437. function arcEndAngle(d) {
  12438. return d.endAngle;
  12439. }
  12440. function arcPadAngle(d) {
  12441. return d && d.padAngle; // Note: optional!
  12442. }
  12443. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  12444. var x10 = x1 - x0, y10 = y1 - y0,
  12445. x32 = x3 - x2, y32 = y3 - y2,
  12446. t = y32 * x10 - x32 * y10;
  12447. if (t * t < epsilon$3) return;
  12448. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
  12449. return [x0 + t * x10, y0 + t * y10];
  12450. }
  12451. // Compute perpendicular offset line of length rc.
  12452. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  12453. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  12454. var x01 = x0 - x1,
  12455. y01 = y0 - y1,
  12456. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  12457. ox = lo * y01,
  12458. oy = -lo * x01,
  12459. x11 = x0 + ox,
  12460. y11 = y0 + oy,
  12461. x10 = x1 + ox,
  12462. y10 = y1 + oy,
  12463. x00 = (x11 + x10) / 2,
  12464. y00 = (y11 + y10) / 2,
  12465. dx = x10 - x11,
  12466. dy = y10 - y11,
  12467. d2 = dx * dx + dy * dy,
  12468. r = r1 - rc,
  12469. D = x11 * y10 - x10 * y11,
  12470. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  12471. cx0 = (D * dy - dx * d) / d2,
  12472. cy0 = (-D * dx - dy * d) / d2,
  12473. cx1 = (D * dy + dx * d) / d2,
  12474. cy1 = (-D * dx + dy * d) / d2,
  12475. dx0 = cx0 - x00,
  12476. dy0 = cy0 - y00,
  12477. dx1 = cx1 - x00,
  12478. dy1 = cy1 - y00;
  12479. // Pick the closer of the two intersection points.
  12480. // TODO Is there a faster way to determine which intersection to use?
  12481. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  12482. return {
  12483. cx: cx0,
  12484. cy: cy0,
  12485. x01: -ox,
  12486. y01: -oy,
  12487. x11: cx0 * (r1 / r - 1),
  12488. y11: cy0 * (r1 / r - 1)
  12489. };
  12490. }
  12491. function arc() {
  12492. var innerRadius = arcInnerRadius,
  12493. outerRadius = arcOuterRadius,
  12494. cornerRadius = constant$b(0),
  12495. padRadius = null,
  12496. startAngle = arcStartAngle,
  12497. endAngle = arcEndAngle,
  12498. padAngle = arcPadAngle,
  12499. context = null;
  12500. function arc() {
  12501. var buffer,
  12502. r,
  12503. r0 = +innerRadius.apply(this, arguments),
  12504. r1 = +outerRadius.apply(this, arguments),
  12505. a0 = startAngle.apply(this, arguments) - halfPi$3,
  12506. a1 = endAngle.apply(this, arguments) - halfPi$3,
  12507. da = abs$1(a1 - a0),
  12508. cw = a1 > a0;
  12509. if (!context) context = buffer = path();
  12510. // Ensure that the outer radius is always larger than the inner radius.
  12511. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  12512. // Is it a point?
  12513. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  12514. // Or is it a circle or annulus?
  12515. else if (da > tau$4 - epsilon$3) {
  12516. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  12517. context.arc(0, 0, r1, a0, a1, !cw);
  12518. if (r0 > epsilon$3) {
  12519. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  12520. context.arc(0, 0, r0, a1, a0, cw);
  12521. }
  12522. }
  12523. // Or is it a circular or annular sector?
  12524. else {
  12525. var a01 = a0,
  12526. a11 = a1,
  12527. a00 = a0,
  12528. a10 = a1,
  12529. da0 = da,
  12530. da1 = da,
  12531. ap = padAngle.apply(this, arguments) / 2,
  12532. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  12533. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  12534. rc0 = rc,
  12535. rc1 = rc,
  12536. t0,
  12537. t1;
  12538. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  12539. if (rp > epsilon$3) {
  12540. var p0 = asin$1(rp / r0 * sin$2(ap)),
  12541. p1 = asin$1(rp / r1 * sin$2(ap));
  12542. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  12543. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  12544. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  12545. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  12546. }
  12547. var x01 = r1 * cos$2(a01),
  12548. y01 = r1 * sin$2(a01),
  12549. x10 = r0 * cos$2(a10),
  12550. y10 = r0 * sin$2(a10);
  12551. // Apply rounded corners?
  12552. if (rc > epsilon$3) {
  12553. var x11 = r1 * cos$2(a11),
  12554. y11 = r1 * sin$2(a11),
  12555. x00 = r0 * cos$2(a00),
  12556. y00 = r0 * sin$2(a00),
  12557. oc;
  12558. // Restrict the corner radius according to the sector angle.
  12559. if (da < pi$4 && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
  12560. var ax = x01 - oc[0],
  12561. ay = y01 - oc[1],
  12562. bx = x11 - oc[0],
  12563. by = y11 - oc[1],
  12564. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  12565. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  12566. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  12567. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  12568. }
  12569. }
  12570. // Is the sector collapsed to a line?
  12571. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  12572. // Does the sector’s outer ring have rounded corners?
  12573. else if (rc1 > epsilon$3) {
  12574. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  12575. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  12576. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12577. // Have the corners merged?
  12578. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12579. // Otherwise, draw the two corners and the ring.
  12580. else {
  12581. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12582. 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);
  12583. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12584. }
  12585. }
  12586. // Or is the outer ring just a circular arc?
  12587. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  12588. // Is there no inner ring, and it’s a circular sector?
  12589. // Or perhaps it’s an annular sector collapsed due to padding?
  12590. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  12591. // Does the sector’s inner ring (or point) have rounded corners?
  12592. else if (rc0 > epsilon$3) {
  12593. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  12594. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  12595. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12596. // Have the corners merged?
  12597. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12598. // Otherwise, draw the two corners and the ring.
  12599. else {
  12600. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12601. 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);
  12602. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12603. }
  12604. }
  12605. // Or is the inner ring just a circular arc?
  12606. else context.arc(0, 0, r0, a10, a00, cw);
  12607. }
  12608. context.closePath();
  12609. if (buffer) return context = null, buffer + "" || null;
  12610. }
  12611. arc.centroid = function() {
  12612. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  12613. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  12614. return [cos$2(a) * r, sin$2(a) * r];
  12615. };
  12616. arc.innerRadius = function(_) {
  12617. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : innerRadius;
  12618. };
  12619. arc.outerRadius = function(_) {
  12620. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : outerRadius;
  12621. };
  12622. arc.cornerRadius = function(_) {
  12623. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : cornerRadius;
  12624. };
  12625. arc.padRadius = function(_) {
  12626. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), arc) : padRadius;
  12627. };
  12628. arc.startAngle = function(_) {
  12629. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : startAngle;
  12630. };
  12631. arc.endAngle = function(_) {
  12632. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : endAngle;
  12633. };
  12634. arc.padAngle = function(_) {
  12635. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : padAngle;
  12636. };
  12637. arc.context = function(_) {
  12638. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  12639. };
  12640. return arc;
  12641. }
  12642. function Linear(context) {
  12643. this._context = context;
  12644. }
  12645. Linear.prototype = {
  12646. areaStart: function() {
  12647. this._line = 0;
  12648. },
  12649. areaEnd: function() {
  12650. this._line = NaN;
  12651. },
  12652. lineStart: function() {
  12653. this._point = 0;
  12654. },
  12655. lineEnd: function() {
  12656. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12657. this._line = 1 - this._line;
  12658. },
  12659. point: function(x, y) {
  12660. x = +x, y = +y;
  12661. switch (this._point) {
  12662. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12663. case 1: this._point = 2; // proceed
  12664. default: this._context.lineTo(x, y); break;
  12665. }
  12666. }
  12667. };
  12668. function curveLinear(context) {
  12669. return new Linear(context);
  12670. }
  12671. function x$3(p) {
  12672. return p[0];
  12673. }
  12674. function y$3(p) {
  12675. return p[1];
  12676. }
  12677. function line() {
  12678. var x = x$3,
  12679. y = y$3,
  12680. defined = constant$b(true),
  12681. context = null,
  12682. curve = curveLinear,
  12683. output = null;
  12684. function line(data) {
  12685. var i,
  12686. n = data.length,
  12687. d,
  12688. defined0 = false,
  12689. buffer;
  12690. if (context == null) output = curve(buffer = path());
  12691. for (i = 0; i <= n; ++i) {
  12692. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12693. if (defined0 = !defined0) output.lineStart();
  12694. else output.lineEnd();
  12695. }
  12696. if (defined0) output.point(+x(d, i, data), +y(d, i, data));
  12697. }
  12698. if (buffer) return output = null, buffer + "" || null;
  12699. }
  12700. line.x = function(_) {
  12701. return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), line) : x;
  12702. };
  12703. line.y = function(_) {
  12704. return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), line) : y;
  12705. };
  12706. line.defined = function(_) {
  12707. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), line) : defined;
  12708. };
  12709. line.curve = function(_) {
  12710. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  12711. };
  12712. line.context = function(_) {
  12713. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  12714. };
  12715. return line;
  12716. }
  12717. function area$3() {
  12718. var x0 = x$3,
  12719. x1 = null,
  12720. y0 = constant$b(0),
  12721. y1 = y$3,
  12722. defined = constant$b(true),
  12723. context = null,
  12724. curve = curveLinear,
  12725. output = null;
  12726. function area(data) {
  12727. var i,
  12728. j,
  12729. k,
  12730. n = data.length,
  12731. d,
  12732. defined0 = false,
  12733. buffer,
  12734. x0z = new Array(n),
  12735. y0z = new Array(n);
  12736. if (context == null) output = curve(buffer = path());
  12737. for (i = 0; i <= n; ++i) {
  12738. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12739. if (defined0 = !defined0) {
  12740. j = i;
  12741. output.areaStart();
  12742. output.lineStart();
  12743. } else {
  12744. output.lineEnd();
  12745. output.lineStart();
  12746. for (k = i - 1; k >= j; --k) {
  12747. output.point(x0z[k], y0z[k]);
  12748. }
  12749. output.lineEnd();
  12750. output.areaEnd();
  12751. }
  12752. }
  12753. if (defined0) {
  12754. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  12755. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  12756. }
  12757. }
  12758. if (buffer) return output = null, buffer + "" || null;
  12759. }
  12760. function arealine() {
  12761. return line().defined(defined).curve(curve).context(context);
  12762. }
  12763. area.x = function(_) {
  12764. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), x1 = null, area) : x0;
  12765. };
  12766. area.x0 = function(_) {
  12767. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), area) : x0;
  12768. };
  12769. area.x1 = function(_) {
  12770. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : x1;
  12771. };
  12772. area.y = function(_) {
  12773. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), y1 = null, area) : y0;
  12774. };
  12775. area.y0 = function(_) {
  12776. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), area) : y0;
  12777. };
  12778. area.y1 = function(_) {
  12779. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : y1;
  12780. };
  12781. area.lineX0 =
  12782. area.lineY0 = function() {
  12783. return arealine().x(x0).y(y0);
  12784. };
  12785. area.lineY1 = function() {
  12786. return arealine().x(x0).y(y1);
  12787. };
  12788. area.lineX1 = function() {
  12789. return arealine().x(x1).y(y0);
  12790. };
  12791. area.defined = function(_) {
  12792. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), area) : defined;
  12793. };
  12794. area.curve = function(_) {
  12795. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  12796. };
  12797. area.context = function(_) {
  12798. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  12799. };
  12800. return area;
  12801. }
  12802. function descending$1(a, b) {
  12803. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  12804. }
  12805. function identity$8(d) {
  12806. return d;
  12807. }
  12808. function pie() {
  12809. var value = identity$8,
  12810. sortValues = descending$1,
  12811. sort = null,
  12812. startAngle = constant$b(0),
  12813. endAngle = constant$b(tau$4),
  12814. padAngle = constant$b(0);
  12815. function pie(data) {
  12816. var i,
  12817. n = data.length,
  12818. j,
  12819. k,
  12820. sum = 0,
  12821. index = new Array(n),
  12822. arcs = new Array(n),
  12823. a0 = +startAngle.apply(this, arguments),
  12824. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  12825. a1,
  12826. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  12827. pa = p * (da < 0 ? -1 : 1),
  12828. v;
  12829. for (i = 0; i < n; ++i) {
  12830. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  12831. sum += v;
  12832. }
  12833. }
  12834. // Optionally sort the arcs by previously-computed values or by data.
  12835. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  12836. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  12837. // Compute the arcs! They are stored in the original data's order.
  12838. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  12839. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  12840. data: data[j],
  12841. index: i,
  12842. value: v,
  12843. startAngle: a0,
  12844. endAngle: a1,
  12845. padAngle: p
  12846. };
  12847. }
  12848. return arcs;
  12849. }
  12850. pie.value = function(_) {
  12851. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), pie) : value;
  12852. };
  12853. pie.sortValues = function(_) {
  12854. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  12855. };
  12856. pie.sort = function(_) {
  12857. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  12858. };
  12859. pie.startAngle = function(_) {
  12860. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : startAngle;
  12861. };
  12862. pie.endAngle = function(_) {
  12863. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : endAngle;
  12864. };
  12865. pie.padAngle = function(_) {
  12866. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : padAngle;
  12867. };
  12868. return pie;
  12869. }
  12870. var curveRadialLinear = curveRadial(curveLinear);
  12871. function Radial(curve) {
  12872. this._curve = curve;
  12873. }
  12874. Radial.prototype = {
  12875. areaStart: function() {
  12876. this._curve.areaStart();
  12877. },
  12878. areaEnd: function() {
  12879. this._curve.areaEnd();
  12880. },
  12881. lineStart: function() {
  12882. this._curve.lineStart();
  12883. },
  12884. lineEnd: function() {
  12885. this._curve.lineEnd();
  12886. },
  12887. point: function(a, r) {
  12888. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  12889. }
  12890. };
  12891. function curveRadial(curve) {
  12892. function radial(context) {
  12893. return new Radial(curve(context));
  12894. }
  12895. radial._curve = curve;
  12896. return radial;
  12897. }
  12898. function lineRadial(l) {
  12899. var c = l.curve;
  12900. l.angle = l.x, delete l.x;
  12901. l.radius = l.y, delete l.y;
  12902. l.curve = function(_) {
  12903. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12904. };
  12905. return l;
  12906. }
  12907. function lineRadial$1() {
  12908. return lineRadial(line().curve(curveRadialLinear));
  12909. }
  12910. function areaRadial() {
  12911. var a = area$3().curve(curveRadialLinear),
  12912. c = a.curve,
  12913. x0 = a.lineX0,
  12914. x1 = a.lineX1,
  12915. y0 = a.lineY0,
  12916. y1 = a.lineY1;
  12917. a.angle = a.x, delete a.x;
  12918. a.startAngle = a.x0, delete a.x0;
  12919. a.endAngle = a.x1, delete a.x1;
  12920. a.radius = a.y, delete a.y;
  12921. a.innerRadius = a.y0, delete a.y0;
  12922. a.outerRadius = a.y1, delete a.y1;
  12923. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  12924. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  12925. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  12926. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  12927. a.curve = function(_) {
  12928. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12929. };
  12930. return a;
  12931. }
  12932. function pointRadial(x, y) {
  12933. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  12934. }
  12935. var slice$6 = Array.prototype.slice;
  12936. function linkSource(d) {
  12937. return d.source;
  12938. }
  12939. function linkTarget(d) {
  12940. return d.target;
  12941. }
  12942. function link$2(curve) {
  12943. var source = linkSource,
  12944. target = linkTarget,
  12945. x = x$3,
  12946. y = y$3,
  12947. context = null;
  12948. function link() {
  12949. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  12950. if (!context) context = buffer = path();
  12951. curve(context, +x.apply(this, (argv[0] = s, argv)), +y.apply(this, argv), +x.apply(this, (argv[0] = t, argv)), +y.apply(this, argv));
  12952. if (buffer) return context = null, buffer + "" || null;
  12953. }
  12954. link.source = function(_) {
  12955. return arguments.length ? (source = _, link) : source;
  12956. };
  12957. link.target = function(_) {
  12958. return arguments.length ? (target = _, link) : target;
  12959. };
  12960. link.x = function(_) {
  12961. return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), link) : x;
  12962. };
  12963. link.y = function(_) {
  12964. return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), link) : y;
  12965. };
  12966. link.context = function(_) {
  12967. return arguments.length ? ((context = _ == null ? null : _), link) : context;
  12968. };
  12969. return link;
  12970. }
  12971. function curveHorizontal(context, x0, y0, x1, y1) {
  12972. context.moveTo(x0, y0);
  12973. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  12974. }
  12975. function curveVertical(context, x0, y0, x1, y1) {
  12976. context.moveTo(x0, y0);
  12977. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  12978. }
  12979. function curveRadial$1(context, x0, y0, x1, y1) {
  12980. var p0 = pointRadial(x0, y0),
  12981. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  12982. p2 = pointRadial(x1, y0),
  12983. p3 = pointRadial(x1, y1);
  12984. context.moveTo(p0[0], p0[1]);
  12985. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  12986. }
  12987. function linkHorizontal() {
  12988. return link$2(curveHorizontal);
  12989. }
  12990. function linkVertical() {
  12991. return link$2(curveVertical);
  12992. }
  12993. function linkRadial() {
  12994. var l = link$2(curveRadial$1);
  12995. l.angle = l.x, delete l.x;
  12996. l.radius = l.y, delete l.y;
  12997. return l;
  12998. }
  12999. var circle$2 = {
  13000. draw: function(context, size) {
  13001. var r = Math.sqrt(size / pi$4);
  13002. context.moveTo(r, 0);
  13003. context.arc(0, 0, r, 0, tau$4);
  13004. }
  13005. };
  13006. var cross$2 = {
  13007. draw: function(context, size) {
  13008. var r = Math.sqrt(size / 5) / 2;
  13009. context.moveTo(-3 * r, -r);
  13010. context.lineTo(-r, -r);
  13011. context.lineTo(-r, -3 * r);
  13012. context.lineTo(r, -3 * r);
  13013. context.lineTo(r, -r);
  13014. context.lineTo(3 * r, -r);
  13015. context.lineTo(3 * r, r);
  13016. context.lineTo(r, r);
  13017. context.lineTo(r, 3 * r);
  13018. context.lineTo(-r, 3 * r);
  13019. context.lineTo(-r, r);
  13020. context.lineTo(-3 * r, r);
  13021. context.closePath();
  13022. }
  13023. };
  13024. var tan30 = Math.sqrt(1 / 3),
  13025. tan30_2 = tan30 * 2;
  13026. var diamond = {
  13027. draw: function(context, size) {
  13028. var y = Math.sqrt(size / tan30_2),
  13029. x = y * tan30;
  13030. context.moveTo(0, -y);
  13031. context.lineTo(x, 0);
  13032. context.lineTo(0, y);
  13033. context.lineTo(-x, 0);
  13034. context.closePath();
  13035. }
  13036. };
  13037. var ka = 0.89081309152928522810,
  13038. kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
  13039. kx = Math.sin(tau$4 / 10) * kr,
  13040. ky = -Math.cos(tau$4 / 10) * kr;
  13041. var star = {
  13042. draw: function(context, size) {
  13043. var r = Math.sqrt(size * ka),
  13044. x = kx * r,
  13045. y = ky * r;
  13046. context.moveTo(0, -r);
  13047. context.lineTo(x, y);
  13048. for (var i = 1; i < 5; ++i) {
  13049. var a = tau$4 * i / 5,
  13050. c = Math.cos(a),
  13051. s = Math.sin(a);
  13052. context.lineTo(s * r, -c * r);
  13053. context.lineTo(c * x - s * y, s * x + c * y);
  13054. }
  13055. context.closePath();
  13056. }
  13057. };
  13058. var square = {
  13059. draw: function(context, size) {
  13060. var w = Math.sqrt(size),
  13061. x = -w / 2;
  13062. context.rect(x, x, w, w);
  13063. }
  13064. };
  13065. var sqrt3 = Math.sqrt(3);
  13066. var triangle = {
  13067. draw: function(context, size) {
  13068. var y = -Math.sqrt(size / (sqrt3 * 3));
  13069. context.moveTo(0, y * 2);
  13070. context.lineTo(-sqrt3 * y, -y);
  13071. context.lineTo(sqrt3 * y, -y);
  13072. context.closePath();
  13073. }
  13074. };
  13075. var c$2 = -0.5,
  13076. s = Math.sqrt(3) / 2,
  13077. k = 1 / Math.sqrt(12),
  13078. a = (k / 2 + 1) * 3;
  13079. var wye = {
  13080. draw: function(context, size) {
  13081. var r = Math.sqrt(size / a),
  13082. x0 = r / 2,
  13083. y0 = r * k,
  13084. x1 = x0,
  13085. y1 = r * k + r,
  13086. x2 = -x1,
  13087. y2 = y1;
  13088. context.moveTo(x0, y0);
  13089. context.lineTo(x1, y1);
  13090. context.lineTo(x2, y2);
  13091. context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
  13092. context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
  13093. context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
  13094. context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
  13095. context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
  13096. context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
  13097. context.closePath();
  13098. }
  13099. };
  13100. var symbols = [
  13101. circle$2,
  13102. cross$2,
  13103. diamond,
  13104. square,
  13105. star,
  13106. triangle,
  13107. wye
  13108. ];
  13109. function symbol() {
  13110. var type = constant$b(circle$2),
  13111. size = constant$b(64),
  13112. context = null;
  13113. function symbol() {
  13114. var buffer;
  13115. if (!context) context = buffer = path();
  13116. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  13117. if (buffer) return context = null, buffer + "" || null;
  13118. }
  13119. symbol.type = function(_) {
  13120. return arguments.length ? (type = typeof _ === "function" ? _ : constant$b(_), symbol) : type;
  13121. };
  13122. symbol.size = function(_) {
  13123. return arguments.length ? (size = typeof _ === "function" ? _ : constant$b(+_), symbol) : size;
  13124. };
  13125. symbol.context = function(_) {
  13126. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  13127. };
  13128. return symbol;
  13129. }
  13130. function noop$3() {}
  13131. function point$2(that, x, y) {
  13132. that._context.bezierCurveTo(
  13133. (2 * that._x0 + that._x1) / 3,
  13134. (2 * that._y0 + that._y1) / 3,
  13135. (that._x0 + 2 * that._x1) / 3,
  13136. (that._y0 + 2 * that._y1) / 3,
  13137. (that._x0 + 4 * that._x1 + x) / 6,
  13138. (that._y0 + 4 * that._y1 + y) / 6
  13139. );
  13140. }
  13141. function Basis(context) {
  13142. this._context = context;
  13143. }
  13144. Basis.prototype = {
  13145. areaStart: function() {
  13146. this._line = 0;
  13147. },
  13148. areaEnd: function() {
  13149. this._line = NaN;
  13150. },
  13151. lineStart: function() {
  13152. this._x0 = this._x1 =
  13153. this._y0 = this._y1 = NaN;
  13154. this._point = 0;
  13155. },
  13156. lineEnd: function() {
  13157. switch (this._point) {
  13158. case 3: point$2(this, this._x1, this._y1); // proceed
  13159. case 2: this._context.lineTo(this._x1, this._y1); break;
  13160. }
  13161. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13162. this._line = 1 - this._line;
  13163. },
  13164. point: function(x, y) {
  13165. x = +x, y = +y;
  13166. switch (this._point) {
  13167. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13168. case 1: this._point = 2; break;
  13169. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  13170. default: point$2(this, x, y); break;
  13171. }
  13172. this._x0 = this._x1, this._x1 = x;
  13173. this._y0 = this._y1, this._y1 = y;
  13174. }
  13175. };
  13176. function basis$2(context) {
  13177. return new Basis(context);
  13178. }
  13179. function BasisClosed(context) {
  13180. this._context = context;
  13181. }
  13182. BasisClosed.prototype = {
  13183. areaStart: noop$3,
  13184. areaEnd: noop$3,
  13185. lineStart: function() {
  13186. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  13187. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  13188. this._point = 0;
  13189. },
  13190. lineEnd: function() {
  13191. switch (this._point) {
  13192. case 1: {
  13193. this._context.moveTo(this._x2, this._y2);
  13194. this._context.closePath();
  13195. break;
  13196. }
  13197. case 2: {
  13198. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  13199. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  13200. this._context.closePath();
  13201. break;
  13202. }
  13203. case 3: {
  13204. this.point(this._x2, this._y2);
  13205. this.point(this._x3, this._y3);
  13206. this.point(this._x4, this._y4);
  13207. break;
  13208. }
  13209. }
  13210. },
  13211. point: function(x, y) {
  13212. x = +x, y = +y;
  13213. switch (this._point) {
  13214. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  13215. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  13216. 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;
  13217. default: point$2(this, x, y); break;
  13218. }
  13219. this._x0 = this._x1, this._x1 = x;
  13220. this._y0 = this._y1, this._y1 = y;
  13221. }
  13222. };
  13223. function basisClosed$1(context) {
  13224. return new BasisClosed(context);
  13225. }
  13226. function BasisOpen(context) {
  13227. this._context = context;
  13228. }
  13229. BasisOpen.prototype = {
  13230. areaStart: function() {
  13231. this._line = 0;
  13232. },
  13233. areaEnd: function() {
  13234. this._line = NaN;
  13235. },
  13236. lineStart: function() {
  13237. this._x0 = this._x1 =
  13238. this._y0 = this._y1 = NaN;
  13239. this._point = 0;
  13240. },
  13241. lineEnd: function() {
  13242. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13243. this._line = 1 - this._line;
  13244. },
  13245. point: function(x, y) {
  13246. x = +x, y = +y;
  13247. switch (this._point) {
  13248. case 0: this._point = 1; break;
  13249. case 1: this._point = 2; break;
  13250. 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;
  13251. case 3: this._point = 4; // proceed
  13252. default: point$2(this, x, y); break;
  13253. }
  13254. this._x0 = this._x1, this._x1 = x;
  13255. this._y0 = this._y1, this._y1 = y;
  13256. }
  13257. };
  13258. function basisOpen(context) {
  13259. return new BasisOpen(context);
  13260. }
  13261. function Bundle(context, beta) {
  13262. this._basis = new Basis(context);
  13263. this._beta = beta;
  13264. }
  13265. Bundle.prototype = {
  13266. lineStart: function() {
  13267. this._x = [];
  13268. this._y = [];
  13269. this._basis.lineStart();
  13270. },
  13271. lineEnd: function() {
  13272. var x = this._x,
  13273. y = this._y,
  13274. j = x.length - 1;
  13275. if (j > 0) {
  13276. var x0 = x[0],
  13277. y0 = y[0],
  13278. dx = x[j] - x0,
  13279. dy = y[j] - y0,
  13280. i = -1,
  13281. t;
  13282. while (++i <= j) {
  13283. t = i / j;
  13284. this._basis.point(
  13285. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  13286. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  13287. );
  13288. }
  13289. }
  13290. this._x = this._y = null;
  13291. this._basis.lineEnd();
  13292. },
  13293. point: function(x, y) {
  13294. this._x.push(+x);
  13295. this._y.push(+y);
  13296. }
  13297. };
  13298. var bundle = (function custom(beta) {
  13299. function bundle(context) {
  13300. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  13301. }
  13302. bundle.beta = function(beta) {
  13303. return custom(+beta);
  13304. };
  13305. return bundle;
  13306. })(0.85);
  13307. function point$3(that, x, y) {
  13308. that._context.bezierCurveTo(
  13309. that._x1 + that._k * (that._x2 - that._x0),
  13310. that._y1 + that._k * (that._y2 - that._y0),
  13311. that._x2 + that._k * (that._x1 - x),
  13312. that._y2 + that._k * (that._y1 - y),
  13313. that._x2,
  13314. that._y2
  13315. );
  13316. }
  13317. function Cardinal(context, tension) {
  13318. this._context = context;
  13319. this._k = (1 - tension) / 6;
  13320. }
  13321. Cardinal.prototype = {
  13322. areaStart: function() {
  13323. this._line = 0;
  13324. },
  13325. areaEnd: function() {
  13326. this._line = NaN;
  13327. },
  13328. lineStart: function() {
  13329. this._x0 = this._x1 = this._x2 =
  13330. this._y0 = this._y1 = this._y2 = NaN;
  13331. this._point = 0;
  13332. },
  13333. lineEnd: function() {
  13334. switch (this._point) {
  13335. case 2: this._context.lineTo(this._x2, this._y2); break;
  13336. case 3: point$3(this, this._x1, this._y1); break;
  13337. }
  13338. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13339. this._line = 1 - this._line;
  13340. },
  13341. point: function(x, y) {
  13342. x = +x, y = +y;
  13343. switch (this._point) {
  13344. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13345. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  13346. case 2: this._point = 3; // proceed
  13347. default: point$3(this, x, y); break;
  13348. }
  13349. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13350. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13351. }
  13352. };
  13353. var cardinal = (function custom(tension) {
  13354. function cardinal(context) {
  13355. return new Cardinal(context, tension);
  13356. }
  13357. cardinal.tension = function(tension) {
  13358. return custom(+tension);
  13359. };
  13360. return cardinal;
  13361. })(0);
  13362. function CardinalClosed(context, tension) {
  13363. this._context = context;
  13364. this._k = (1 - tension) / 6;
  13365. }
  13366. CardinalClosed.prototype = {
  13367. areaStart: noop$3,
  13368. areaEnd: noop$3,
  13369. lineStart: function() {
  13370. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13371. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13372. this._point = 0;
  13373. },
  13374. lineEnd: function() {
  13375. switch (this._point) {
  13376. case 1: {
  13377. this._context.moveTo(this._x3, this._y3);
  13378. this._context.closePath();
  13379. break;
  13380. }
  13381. case 2: {
  13382. this._context.lineTo(this._x3, this._y3);
  13383. this._context.closePath();
  13384. break;
  13385. }
  13386. case 3: {
  13387. this.point(this._x3, this._y3);
  13388. this.point(this._x4, this._y4);
  13389. this.point(this._x5, this._y5);
  13390. break;
  13391. }
  13392. }
  13393. },
  13394. point: function(x, y) {
  13395. x = +x, y = +y;
  13396. switch (this._point) {
  13397. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13398. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13399. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13400. default: point$3(this, x, y); break;
  13401. }
  13402. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13403. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13404. }
  13405. };
  13406. var cardinalClosed = (function custom(tension) {
  13407. function cardinal(context) {
  13408. return new CardinalClosed(context, tension);
  13409. }
  13410. cardinal.tension = function(tension) {
  13411. return custom(+tension);
  13412. };
  13413. return cardinal;
  13414. })(0);
  13415. function CardinalOpen(context, tension) {
  13416. this._context = context;
  13417. this._k = (1 - tension) / 6;
  13418. }
  13419. CardinalOpen.prototype = {
  13420. areaStart: function() {
  13421. this._line = 0;
  13422. },
  13423. areaEnd: function() {
  13424. this._line = NaN;
  13425. },
  13426. lineStart: function() {
  13427. this._x0 = this._x1 = this._x2 =
  13428. this._y0 = this._y1 = this._y2 = NaN;
  13429. this._point = 0;
  13430. },
  13431. lineEnd: function() {
  13432. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13433. this._line = 1 - this._line;
  13434. },
  13435. point: function(x, y) {
  13436. x = +x, y = +y;
  13437. switch (this._point) {
  13438. case 0: this._point = 1; break;
  13439. case 1: this._point = 2; break;
  13440. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13441. case 3: this._point = 4; // proceed
  13442. default: point$3(this, x, y); break;
  13443. }
  13444. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13445. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13446. }
  13447. };
  13448. var cardinalOpen = (function custom(tension) {
  13449. function cardinal(context) {
  13450. return new CardinalOpen(context, tension);
  13451. }
  13452. cardinal.tension = function(tension) {
  13453. return custom(+tension);
  13454. };
  13455. return cardinal;
  13456. })(0);
  13457. function point$4(that, x, y) {
  13458. var x1 = that._x1,
  13459. y1 = that._y1,
  13460. x2 = that._x2,
  13461. y2 = that._y2;
  13462. if (that._l01_a > epsilon$3) {
  13463. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  13464. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  13465. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  13466. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  13467. }
  13468. if (that._l23_a > epsilon$3) {
  13469. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  13470. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  13471. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  13472. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  13473. }
  13474. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  13475. }
  13476. function CatmullRom(context, alpha) {
  13477. this._context = context;
  13478. this._alpha = alpha;
  13479. }
  13480. CatmullRom.prototype = {
  13481. areaStart: function() {
  13482. this._line = 0;
  13483. },
  13484. areaEnd: function() {
  13485. this._line = NaN;
  13486. },
  13487. lineStart: function() {
  13488. this._x0 = this._x1 = this._x2 =
  13489. this._y0 = this._y1 = this._y2 = NaN;
  13490. this._l01_a = this._l12_a = this._l23_a =
  13491. this._l01_2a = this._l12_2a = this._l23_2a =
  13492. this._point = 0;
  13493. },
  13494. lineEnd: function() {
  13495. switch (this._point) {
  13496. case 2: this._context.lineTo(this._x2, this._y2); break;
  13497. case 3: this.point(this._x2, this._y2); break;
  13498. }
  13499. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13500. this._line = 1 - this._line;
  13501. },
  13502. point: function(x, y) {
  13503. x = +x, y = +y;
  13504. if (this._point) {
  13505. var x23 = this._x2 - x,
  13506. y23 = this._y2 - y;
  13507. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13508. }
  13509. switch (this._point) {
  13510. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13511. case 1: this._point = 2; break;
  13512. case 2: this._point = 3; // proceed
  13513. default: point$4(this, x, y); break;
  13514. }
  13515. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13516. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13517. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13518. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13519. }
  13520. };
  13521. var catmullRom = (function custom(alpha) {
  13522. function catmullRom(context) {
  13523. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  13524. }
  13525. catmullRom.alpha = function(alpha) {
  13526. return custom(+alpha);
  13527. };
  13528. return catmullRom;
  13529. })(0.5);
  13530. function CatmullRomClosed(context, alpha) {
  13531. this._context = context;
  13532. this._alpha = alpha;
  13533. }
  13534. CatmullRomClosed.prototype = {
  13535. areaStart: noop$3,
  13536. areaEnd: noop$3,
  13537. lineStart: function() {
  13538. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13539. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13540. this._l01_a = this._l12_a = this._l23_a =
  13541. this._l01_2a = this._l12_2a = this._l23_2a =
  13542. this._point = 0;
  13543. },
  13544. lineEnd: function() {
  13545. switch (this._point) {
  13546. case 1: {
  13547. this._context.moveTo(this._x3, this._y3);
  13548. this._context.closePath();
  13549. break;
  13550. }
  13551. case 2: {
  13552. this._context.lineTo(this._x3, this._y3);
  13553. this._context.closePath();
  13554. break;
  13555. }
  13556. case 3: {
  13557. this.point(this._x3, this._y3);
  13558. this.point(this._x4, this._y4);
  13559. this.point(this._x5, this._y5);
  13560. break;
  13561. }
  13562. }
  13563. },
  13564. point: function(x, y) {
  13565. x = +x, y = +y;
  13566. if (this._point) {
  13567. var x23 = this._x2 - x,
  13568. y23 = this._y2 - y;
  13569. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13570. }
  13571. switch (this._point) {
  13572. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13573. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13574. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13575. default: point$4(this, x, y); break;
  13576. }
  13577. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13578. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13579. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13580. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13581. }
  13582. };
  13583. var catmullRomClosed = (function custom(alpha) {
  13584. function catmullRom(context) {
  13585. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  13586. }
  13587. catmullRom.alpha = function(alpha) {
  13588. return custom(+alpha);
  13589. };
  13590. return catmullRom;
  13591. })(0.5);
  13592. function CatmullRomOpen(context, alpha) {
  13593. this._context = context;
  13594. this._alpha = alpha;
  13595. }
  13596. CatmullRomOpen.prototype = {
  13597. areaStart: function() {
  13598. this._line = 0;
  13599. },
  13600. areaEnd: function() {
  13601. this._line = NaN;
  13602. },
  13603. lineStart: function() {
  13604. this._x0 = this._x1 = this._x2 =
  13605. this._y0 = this._y1 = this._y2 = NaN;
  13606. this._l01_a = this._l12_a = this._l23_a =
  13607. this._l01_2a = this._l12_2a = this._l23_2a =
  13608. this._point = 0;
  13609. },
  13610. lineEnd: function() {
  13611. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13612. this._line = 1 - this._line;
  13613. },
  13614. point: function(x, y) {
  13615. x = +x, y = +y;
  13616. if (this._point) {
  13617. var x23 = this._x2 - x,
  13618. y23 = this._y2 - y;
  13619. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13620. }
  13621. switch (this._point) {
  13622. case 0: this._point = 1; break;
  13623. case 1: this._point = 2; break;
  13624. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13625. case 3: this._point = 4; // proceed
  13626. default: point$4(this, x, y); break;
  13627. }
  13628. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13629. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13630. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13631. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13632. }
  13633. };
  13634. var catmullRomOpen = (function custom(alpha) {
  13635. function catmullRom(context) {
  13636. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  13637. }
  13638. catmullRom.alpha = function(alpha) {
  13639. return custom(+alpha);
  13640. };
  13641. return catmullRom;
  13642. })(0.5);
  13643. function LinearClosed(context) {
  13644. this._context = context;
  13645. }
  13646. LinearClosed.prototype = {
  13647. areaStart: noop$3,
  13648. areaEnd: noop$3,
  13649. lineStart: function() {
  13650. this._point = 0;
  13651. },
  13652. lineEnd: function() {
  13653. if (this._point) this._context.closePath();
  13654. },
  13655. point: function(x, y) {
  13656. x = +x, y = +y;
  13657. if (this._point) this._context.lineTo(x, y);
  13658. else this._point = 1, this._context.moveTo(x, y);
  13659. }
  13660. };
  13661. function linearClosed(context) {
  13662. return new LinearClosed(context);
  13663. }
  13664. function sign$1(x) {
  13665. return x < 0 ? -1 : 1;
  13666. }
  13667. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  13668. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  13669. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  13670. // NOV(II), P. 443, 1990.
  13671. function slope3(that, x2, y2) {
  13672. var h0 = that._x1 - that._x0,
  13673. h1 = x2 - that._x1,
  13674. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  13675. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  13676. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  13677. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  13678. }
  13679. // Calculate a one-sided slope.
  13680. function slope2(that, t) {
  13681. var h = that._x1 - that._x0;
  13682. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  13683. }
  13684. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  13685. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  13686. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  13687. function point$5(that, t0, t1) {
  13688. var x0 = that._x0,
  13689. y0 = that._y0,
  13690. x1 = that._x1,
  13691. y1 = that._y1,
  13692. dx = (x1 - x0) / 3;
  13693. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  13694. }
  13695. function MonotoneX(context) {
  13696. this._context = context;
  13697. }
  13698. MonotoneX.prototype = {
  13699. areaStart: function() {
  13700. this._line = 0;
  13701. },
  13702. areaEnd: function() {
  13703. this._line = NaN;
  13704. },
  13705. lineStart: function() {
  13706. this._x0 = this._x1 =
  13707. this._y0 = this._y1 =
  13708. this._t0 = NaN;
  13709. this._point = 0;
  13710. },
  13711. lineEnd: function() {
  13712. switch (this._point) {
  13713. case 2: this._context.lineTo(this._x1, this._y1); break;
  13714. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  13715. }
  13716. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13717. this._line = 1 - this._line;
  13718. },
  13719. point: function(x, y) {
  13720. var t1 = NaN;
  13721. x = +x, y = +y;
  13722. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  13723. switch (this._point) {
  13724. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13725. case 1: this._point = 2; break;
  13726. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  13727. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  13728. }
  13729. this._x0 = this._x1, this._x1 = x;
  13730. this._y0 = this._y1, this._y1 = y;
  13731. this._t0 = t1;
  13732. }
  13733. };
  13734. function MonotoneY(context) {
  13735. this._context = new ReflectContext(context);
  13736. }
  13737. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  13738. MonotoneX.prototype.point.call(this, y, x);
  13739. };
  13740. function ReflectContext(context) {
  13741. this._context = context;
  13742. }
  13743. ReflectContext.prototype = {
  13744. moveTo: function(x, y) { this._context.moveTo(y, x); },
  13745. closePath: function() { this._context.closePath(); },
  13746. lineTo: function(x, y) { this._context.lineTo(y, x); },
  13747. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  13748. };
  13749. function monotoneX(context) {
  13750. return new MonotoneX(context);
  13751. }
  13752. function monotoneY(context) {
  13753. return new MonotoneY(context);
  13754. }
  13755. function Natural(context) {
  13756. this._context = context;
  13757. }
  13758. Natural.prototype = {
  13759. areaStart: function() {
  13760. this._line = 0;
  13761. },
  13762. areaEnd: function() {
  13763. this._line = NaN;
  13764. },
  13765. lineStart: function() {
  13766. this._x = [];
  13767. this._y = [];
  13768. },
  13769. lineEnd: function() {
  13770. var x = this._x,
  13771. y = this._y,
  13772. n = x.length;
  13773. if (n) {
  13774. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  13775. if (n === 2) {
  13776. this._context.lineTo(x[1], y[1]);
  13777. } else {
  13778. var px = controlPoints(x),
  13779. py = controlPoints(y);
  13780. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  13781. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  13782. }
  13783. }
  13784. }
  13785. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  13786. this._line = 1 - this._line;
  13787. this._x = this._y = null;
  13788. },
  13789. point: function(x, y) {
  13790. this._x.push(+x);
  13791. this._y.push(+y);
  13792. }
  13793. };
  13794. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  13795. function controlPoints(x) {
  13796. var i,
  13797. n = x.length - 1,
  13798. m,
  13799. a = new Array(n),
  13800. b = new Array(n),
  13801. r = new Array(n);
  13802. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  13803. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  13804. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  13805. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  13806. a[n - 1] = r[n - 1] / b[n - 1];
  13807. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  13808. b[n - 1] = (x[n] + a[n - 1]) / 2;
  13809. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  13810. return [a, b];
  13811. }
  13812. function natural(context) {
  13813. return new Natural(context);
  13814. }
  13815. function Step(context, t) {
  13816. this._context = context;
  13817. this._t = t;
  13818. }
  13819. Step.prototype = {
  13820. areaStart: function() {
  13821. this._line = 0;
  13822. },
  13823. areaEnd: function() {
  13824. this._line = NaN;
  13825. },
  13826. lineStart: function() {
  13827. this._x = this._y = NaN;
  13828. this._point = 0;
  13829. },
  13830. lineEnd: function() {
  13831. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  13832. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13833. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  13834. },
  13835. point: function(x, y) {
  13836. x = +x, y = +y;
  13837. switch (this._point) {
  13838. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13839. case 1: this._point = 2; // proceed
  13840. default: {
  13841. if (this._t <= 0) {
  13842. this._context.lineTo(this._x, y);
  13843. this._context.lineTo(x, y);
  13844. } else {
  13845. var x1 = this._x * (1 - this._t) + x * this._t;
  13846. this._context.lineTo(x1, this._y);
  13847. this._context.lineTo(x1, y);
  13848. }
  13849. break;
  13850. }
  13851. }
  13852. this._x = x, this._y = y;
  13853. }
  13854. };
  13855. function step(context) {
  13856. return new Step(context, 0.5);
  13857. }
  13858. function stepBefore(context) {
  13859. return new Step(context, 0);
  13860. }
  13861. function stepAfter(context) {
  13862. return new Step(context, 1);
  13863. }
  13864. function none$1(series, order) {
  13865. if (!((n = series.length) > 1)) return;
  13866. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  13867. s0 = s1, s1 = series[order[i]];
  13868. for (j = 0; j < m; ++j) {
  13869. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  13870. }
  13871. }
  13872. }
  13873. function none$2(series) {
  13874. var n = series.length, o = new Array(n);
  13875. while (--n >= 0) o[n] = n;
  13876. return o;
  13877. }
  13878. function stackValue(d, key) {
  13879. return d[key];
  13880. }
  13881. function stack() {
  13882. var keys = constant$b([]),
  13883. order = none$2,
  13884. offset = none$1,
  13885. value = stackValue;
  13886. function stack(data) {
  13887. var kz = keys.apply(this, arguments),
  13888. i,
  13889. m = data.length,
  13890. n = kz.length,
  13891. sz = new Array(n),
  13892. oz;
  13893. for (i = 0; i < n; ++i) {
  13894. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  13895. si[j] = sij = [0, +value(data[j], ki, j, data)];
  13896. sij.data = data[j];
  13897. }
  13898. si.key = ki;
  13899. }
  13900. for (i = 0, oz = order(sz); i < n; ++i) {
  13901. sz[oz[i]].index = i;
  13902. }
  13903. offset(sz, oz);
  13904. return sz;
  13905. }
  13906. stack.keys = function(_) {
  13907. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : keys;
  13908. };
  13909. stack.value = function(_) {
  13910. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), stack) : value;
  13911. };
  13912. stack.order = function(_) {
  13913. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : order;
  13914. };
  13915. stack.offset = function(_) {
  13916. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  13917. };
  13918. return stack;
  13919. }
  13920. function expand(series, order) {
  13921. if (!((n = series.length) > 0)) return;
  13922. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  13923. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  13924. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  13925. }
  13926. none$1(series, order);
  13927. }
  13928. function diverging$1(series, order) {
  13929. if (!((n = series.length) > 0)) return;
  13930. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  13931. for (yp = yn = 0, i = 0; i < n; ++i) {
  13932. if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
  13933. d[0] = yp, d[1] = yp += dy;
  13934. } else if (dy < 0) {
  13935. d[1] = yn, d[0] = yn += dy;
  13936. } else {
  13937. d[0] = 0, d[1] = dy;
  13938. }
  13939. }
  13940. }
  13941. }
  13942. function silhouette(series, order) {
  13943. if (!((n = series.length) > 0)) return;
  13944. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  13945. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  13946. s0[j][1] += s0[j][0] = -y / 2;
  13947. }
  13948. none$1(series, order);
  13949. }
  13950. function wiggle(series, order) {
  13951. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  13952. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  13953. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  13954. var si = series[order[i]],
  13955. sij0 = si[j][1] || 0,
  13956. sij1 = si[j - 1][1] || 0,
  13957. s3 = (sij0 - sij1) / 2;
  13958. for (var k = 0; k < i; ++k) {
  13959. var sk = series[order[k]],
  13960. skj0 = sk[j][1] || 0,
  13961. skj1 = sk[j - 1][1] || 0;
  13962. s3 += skj0 - skj1;
  13963. }
  13964. s1 += sij0, s2 += s3 * sij0;
  13965. }
  13966. s0[j - 1][1] += s0[j - 1][0] = y;
  13967. if (s1) y -= s2 / s1;
  13968. }
  13969. s0[j - 1][1] += s0[j - 1][0] = y;
  13970. none$1(series, order);
  13971. }
  13972. function appearance(series) {
  13973. var peaks = series.map(peak);
  13974. return none$2(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
  13975. }
  13976. function peak(series) {
  13977. var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
  13978. while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
  13979. return j;
  13980. }
  13981. function ascending$3(series) {
  13982. var sums = series.map(sum$2);
  13983. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  13984. }
  13985. function sum$2(series) {
  13986. var s = 0, i = -1, n = series.length, v;
  13987. while (++i < n) if (v = +series[i][1]) s += v;
  13988. return s;
  13989. }
  13990. function descending$2(series) {
  13991. return ascending$3(series).reverse();
  13992. }
  13993. function insideOut(series) {
  13994. var n = series.length,
  13995. i,
  13996. j,
  13997. sums = series.map(sum$2),
  13998. order = appearance(series),
  13999. top = 0,
  14000. bottom = 0,
  14001. tops = [],
  14002. bottoms = [];
  14003. for (i = 0; i < n; ++i) {
  14004. j = order[i];
  14005. if (top < bottom) {
  14006. top += sums[j];
  14007. tops.push(j);
  14008. } else {
  14009. bottom += sums[j];
  14010. bottoms.push(j);
  14011. }
  14012. }
  14013. return bottoms.reverse().concat(tops);
  14014. }
  14015. function reverse(series) {
  14016. return none$2(series).reverse();
  14017. }
  14018. function constant$c(x) {
  14019. return function() {
  14020. return x;
  14021. };
  14022. }
  14023. function x$4(d) {
  14024. return d[0];
  14025. }
  14026. function y$4(d) {
  14027. return d[1];
  14028. }
  14029. function RedBlackTree() {
  14030. this._ = null; // root node
  14031. }
  14032. function RedBlackNode(node) {
  14033. node.U = // parent node
  14034. node.C = // color - true for red, false for black
  14035. node.L = // left node
  14036. node.R = // right node
  14037. node.P = // previous node
  14038. node.N = null; // next node
  14039. }
  14040. RedBlackTree.prototype = {
  14041. constructor: RedBlackTree,
  14042. insert: function(after, node) {
  14043. var parent, grandpa, uncle;
  14044. if (after) {
  14045. node.P = after;
  14046. node.N = after.N;
  14047. if (after.N) after.N.P = node;
  14048. after.N = node;
  14049. if (after.R) {
  14050. after = after.R;
  14051. while (after.L) after = after.L;
  14052. after.L = node;
  14053. } else {
  14054. after.R = node;
  14055. }
  14056. parent = after;
  14057. } else if (this._) {
  14058. after = RedBlackFirst(this._);
  14059. node.P = null;
  14060. node.N = after;
  14061. after.P = after.L = node;
  14062. parent = after;
  14063. } else {
  14064. node.P = node.N = null;
  14065. this._ = node;
  14066. parent = null;
  14067. }
  14068. node.L = node.R = null;
  14069. node.U = parent;
  14070. node.C = true;
  14071. after = node;
  14072. while (parent && parent.C) {
  14073. grandpa = parent.U;
  14074. if (parent === grandpa.L) {
  14075. uncle = grandpa.R;
  14076. if (uncle && uncle.C) {
  14077. parent.C = uncle.C = false;
  14078. grandpa.C = true;
  14079. after = grandpa;
  14080. } else {
  14081. if (after === parent.R) {
  14082. RedBlackRotateLeft(this, parent);
  14083. after = parent;
  14084. parent = after.U;
  14085. }
  14086. parent.C = false;
  14087. grandpa.C = true;
  14088. RedBlackRotateRight(this, grandpa);
  14089. }
  14090. } else {
  14091. uncle = grandpa.L;
  14092. if (uncle && uncle.C) {
  14093. parent.C = uncle.C = false;
  14094. grandpa.C = true;
  14095. after = grandpa;
  14096. } else {
  14097. if (after === parent.L) {
  14098. RedBlackRotateRight(this, parent);
  14099. after = parent;
  14100. parent = after.U;
  14101. }
  14102. parent.C = false;
  14103. grandpa.C = true;
  14104. RedBlackRotateLeft(this, grandpa);
  14105. }
  14106. }
  14107. parent = after.U;
  14108. }
  14109. this._.C = false;
  14110. },
  14111. remove: function(node) {
  14112. if (node.N) node.N.P = node.P;
  14113. if (node.P) node.P.N = node.N;
  14114. node.N = node.P = null;
  14115. var parent = node.U,
  14116. sibling,
  14117. left = node.L,
  14118. right = node.R,
  14119. next,
  14120. red;
  14121. if (!left) next = right;
  14122. else if (!right) next = left;
  14123. else next = RedBlackFirst(right);
  14124. if (parent) {
  14125. if (parent.L === node) parent.L = next;
  14126. else parent.R = next;
  14127. } else {
  14128. this._ = next;
  14129. }
  14130. if (left && right) {
  14131. red = next.C;
  14132. next.C = node.C;
  14133. next.L = left;
  14134. left.U = next;
  14135. if (next !== right) {
  14136. parent = next.U;
  14137. next.U = node.U;
  14138. node = next.R;
  14139. parent.L = node;
  14140. next.R = right;
  14141. right.U = next;
  14142. } else {
  14143. next.U = parent;
  14144. parent = next;
  14145. node = next.R;
  14146. }
  14147. } else {
  14148. red = node.C;
  14149. node = next;
  14150. }
  14151. if (node) node.U = parent;
  14152. if (red) return;
  14153. if (node && node.C) { node.C = false; return; }
  14154. do {
  14155. if (node === this._) break;
  14156. if (node === parent.L) {
  14157. sibling = parent.R;
  14158. if (sibling.C) {
  14159. sibling.C = false;
  14160. parent.C = true;
  14161. RedBlackRotateLeft(this, parent);
  14162. sibling = parent.R;
  14163. }
  14164. if ((sibling.L && sibling.L.C)
  14165. || (sibling.R && sibling.R.C)) {
  14166. if (!sibling.R || !sibling.R.C) {
  14167. sibling.L.C = false;
  14168. sibling.C = true;
  14169. RedBlackRotateRight(this, sibling);
  14170. sibling = parent.R;
  14171. }
  14172. sibling.C = parent.C;
  14173. parent.C = sibling.R.C = false;
  14174. RedBlackRotateLeft(this, parent);
  14175. node = this._;
  14176. break;
  14177. }
  14178. } else {
  14179. sibling = parent.L;
  14180. if (sibling.C) {
  14181. sibling.C = false;
  14182. parent.C = true;
  14183. RedBlackRotateRight(this, parent);
  14184. sibling = parent.L;
  14185. }
  14186. if ((sibling.L && sibling.L.C)
  14187. || (sibling.R && sibling.R.C)) {
  14188. if (!sibling.L || !sibling.L.C) {
  14189. sibling.R.C = false;
  14190. sibling.C = true;
  14191. RedBlackRotateLeft(this, sibling);
  14192. sibling = parent.L;
  14193. }
  14194. sibling.C = parent.C;
  14195. parent.C = sibling.L.C = false;
  14196. RedBlackRotateRight(this, parent);
  14197. node = this._;
  14198. break;
  14199. }
  14200. }
  14201. sibling.C = true;
  14202. node = parent;
  14203. parent = parent.U;
  14204. } while (!node.C);
  14205. if (node) node.C = false;
  14206. }
  14207. };
  14208. function RedBlackRotateLeft(tree, node) {
  14209. var p = node,
  14210. q = node.R,
  14211. parent = p.U;
  14212. if (parent) {
  14213. if (parent.L === p) parent.L = q;
  14214. else parent.R = q;
  14215. } else {
  14216. tree._ = q;
  14217. }
  14218. q.U = parent;
  14219. p.U = q;
  14220. p.R = q.L;
  14221. if (p.R) p.R.U = p;
  14222. q.L = p;
  14223. }
  14224. function RedBlackRotateRight(tree, node) {
  14225. var p = node,
  14226. q = node.L,
  14227. parent = p.U;
  14228. if (parent) {
  14229. if (parent.L === p) parent.L = q;
  14230. else parent.R = q;
  14231. } else {
  14232. tree._ = q;
  14233. }
  14234. q.U = parent;
  14235. p.U = q;
  14236. p.L = q.R;
  14237. if (p.L) p.L.U = p;
  14238. q.R = p;
  14239. }
  14240. function RedBlackFirst(node) {
  14241. while (node.L) node = node.L;
  14242. return node;
  14243. }
  14244. function createEdge(left, right, v0, v1) {
  14245. var edge = [null, null],
  14246. index = edges.push(edge) - 1;
  14247. edge.left = left;
  14248. edge.right = right;
  14249. if (v0) setEdgeEnd(edge, left, right, v0);
  14250. if (v1) setEdgeEnd(edge, right, left, v1);
  14251. cells[left.index].halfedges.push(index);
  14252. cells[right.index].halfedges.push(index);
  14253. return edge;
  14254. }
  14255. function createBorderEdge(left, v0, v1) {
  14256. var edge = [v0, v1];
  14257. edge.left = left;
  14258. return edge;
  14259. }
  14260. function setEdgeEnd(edge, left, right, vertex) {
  14261. if (!edge[0] && !edge[1]) {
  14262. edge[0] = vertex;
  14263. edge.left = left;
  14264. edge.right = right;
  14265. } else if (edge.left === right) {
  14266. edge[1] = vertex;
  14267. } else {
  14268. edge[0] = vertex;
  14269. }
  14270. }
  14271. // Liang–Barsky line clipping.
  14272. function clipEdge(edge, x0, y0, x1, y1) {
  14273. var a = edge[0],
  14274. b = edge[1],
  14275. ax = a[0],
  14276. ay = a[1],
  14277. bx = b[0],
  14278. by = b[1],
  14279. t0 = 0,
  14280. t1 = 1,
  14281. dx = bx - ax,
  14282. dy = by - ay,
  14283. r;
  14284. r = x0 - ax;
  14285. if (!dx && r > 0) return;
  14286. r /= dx;
  14287. if (dx < 0) {
  14288. if (r < t0) return;
  14289. if (r < t1) t1 = r;
  14290. } else if (dx > 0) {
  14291. if (r > t1) return;
  14292. if (r > t0) t0 = r;
  14293. }
  14294. r = x1 - ax;
  14295. if (!dx && r < 0) return;
  14296. r /= dx;
  14297. if (dx < 0) {
  14298. if (r > t1) return;
  14299. if (r > t0) t0 = r;
  14300. } else if (dx > 0) {
  14301. if (r < t0) return;
  14302. if (r < t1) t1 = r;
  14303. }
  14304. r = y0 - ay;
  14305. if (!dy && r > 0) return;
  14306. r /= dy;
  14307. if (dy < 0) {
  14308. if (r < t0) return;
  14309. if (r < t1) t1 = r;
  14310. } else if (dy > 0) {
  14311. if (r > t1) return;
  14312. if (r > t0) t0 = r;
  14313. }
  14314. r = y1 - ay;
  14315. if (!dy && r < 0) return;
  14316. r /= dy;
  14317. if (dy < 0) {
  14318. if (r > t1) return;
  14319. if (r > t0) t0 = r;
  14320. } else if (dy > 0) {
  14321. if (r < t0) return;
  14322. if (r < t1) t1 = r;
  14323. }
  14324. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  14325. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  14326. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  14327. return true;
  14328. }
  14329. function connectEdge(edge, x0, y0, x1, y1) {
  14330. var v1 = edge[1];
  14331. if (v1) return true;
  14332. var v0 = edge[0],
  14333. left = edge.left,
  14334. right = edge.right,
  14335. lx = left[0],
  14336. ly = left[1],
  14337. rx = right[0],
  14338. ry = right[1],
  14339. fx = (lx + rx) / 2,
  14340. fy = (ly + ry) / 2,
  14341. fm,
  14342. fb;
  14343. if (ry === ly) {
  14344. if (fx < x0 || fx >= x1) return;
  14345. if (lx > rx) {
  14346. if (!v0) v0 = [fx, y0];
  14347. else if (v0[1] >= y1) return;
  14348. v1 = [fx, y1];
  14349. } else {
  14350. if (!v0) v0 = [fx, y1];
  14351. else if (v0[1] < y0) return;
  14352. v1 = [fx, y0];
  14353. }
  14354. } else {
  14355. fm = (lx - rx) / (ry - ly);
  14356. fb = fy - fm * fx;
  14357. if (fm < -1 || fm > 1) {
  14358. if (lx > rx) {
  14359. if (!v0) v0 = [(y0 - fb) / fm, y0];
  14360. else if (v0[1] >= y1) return;
  14361. v1 = [(y1 - fb) / fm, y1];
  14362. } else {
  14363. if (!v0) v0 = [(y1 - fb) / fm, y1];
  14364. else if (v0[1] < y0) return;
  14365. v1 = [(y0 - fb) / fm, y0];
  14366. }
  14367. } else {
  14368. if (ly < ry) {
  14369. if (!v0) v0 = [x0, fm * x0 + fb];
  14370. else if (v0[0] >= x1) return;
  14371. v1 = [x1, fm * x1 + fb];
  14372. } else {
  14373. if (!v0) v0 = [x1, fm * x1 + fb];
  14374. else if (v0[0] < x0) return;
  14375. v1 = [x0, fm * x0 + fb];
  14376. }
  14377. }
  14378. }
  14379. edge[0] = v0;
  14380. edge[1] = v1;
  14381. return true;
  14382. }
  14383. function clipEdges(x0, y0, x1, y1) {
  14384. var i = edges.length,
  14385. edge;
  14386. while (i--) {
  14387. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  14388. || !clipEdge(edge, x0, y0, x1, y1)
  14389. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  14390. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  14391. delete edges[i];
  14392. }
  14393. }
  14394. }
  14395. function createCell(site) {
  14396. return cells[site.index] = {
  14397. site: site,
  14398. halfedges: []
  14399. };
  14400. }
  14401. function cellHalfedgeAngle(cell, edge) {
  14402. var site = cell.site,
  14403. va = edge.left,
  14404. vb = edge.right;
  14405. if (site === vb) vb = va, va = site;
  14406. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  14407. if (site === va) va = edge[1], vb = edge[0];
  14408. else va = edge[0], vb = edge[1];
  14409. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  14410. }
  14411. function cellHalfedgeStart(cell, edge) {
  14412. return edge[+(edge.left !== cell.site)];
  14413. }
  14414. function cellHalfedgeEnd(cell, edge) {
  14415. return edge[+(edge.left === cell.site)];
  14416. }
  14417. function sortCellHalfedges() {
  14418. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  14419. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  14420. var index = new Array(m),
  14421. array = new Array(m);
  14422. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  14423. index.sort(function(i, j) { return array[j] - array[i]; });
  14424. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  14425. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  14426. }
  14427. }
  14428. }
  14429. function clipCells(x0, y0, x1, y1) {
  14430. var nCells = cells.length,
  14431. iCell,
  14432. cell,
  14433. site,
  14434. iHalfedge,
  14435. halfedges,
  14436. nHalfedges,
  14437. start,
  14438. startX,
  14439. startY,
  14440. end,
  14441. endX,
  14442. endY,
  14443. cover = true;
  14444. for (iCell = 0; iCell < nCells; ++iCell) {
  14445. if (cell = cells[iCell]) {
  14446. site = cell.site;
  14447. halfedges = cell.halfedges;
  14448. iHalfedge = halfedges.length;
  14449. // Remove any dangling clipped edges.
  14450. while (iHalfedge--) {
  14451. if (!edges[halfedges[iHalfedge]]) {
  14452. halfedges.splice(iHalfedge, 1);
  14453. }
  14454. }
  14455. // Insert any border edges as necessary.
  14456. iHalfedge = 0, nHalfedges = halfedges.length;
  14457. while (iHalfedge < nHalfedges) {
  14458. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  14459. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  14460. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  14461. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  14462. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  14463. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  14464. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  14465. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  14466. : null)) - 1);
  14467. ++nHalfedges;
  14468. }
  14469. }
  14470. if (nHalfedges) cover = false;
  14471. }
  14472. }
  14473. // If there weren’t any edges, have the closest site cover the extent.
  14474. // It doesn’t matter which corner of the extent we measure!
  14475. if (cover) {
  14476. var dx, dy, d2, dc = Infinity;
  14477. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  14478. if (cell = cells[iCell]) {
  14479. site = cell.site;
  14480. dx = site[0] - x0;
  14481. dy = site[1] - y0;
  14482. d2 = dx * dx + dy * dy;
  14483. if (d2 < dc) dc = d2, cover = cell;
  14484. }
  14485. }
  14486. if (cover) {
  14487. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  14488. cover.halfedges.push(
  14489. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  14490. edges.push(createBorderEdge(site, v01, v11)) - 1,
  14491. edges.push(createBorderEdge(site, v11, v10)) - 1,
  14492. edges.push(createBorderEdge(site, v10, v00)) - 1
  14493. );
  14494. }
  14495. }
  14496. // Lastly delete any cells with no edges; these were entirely clipped.
  14497. for (iCell = 0; iCell < nCells; ++iCell) {
  14498. if (cell = cells[iCell]) {
  14499. if (!cell.halfedges.length) {
  14500. delete cells[iCell];
  14501. }
  14502. }
  14503. }
  14504. }
  14505. var circlePool = [];
  14506. var firstCircle;
  14507. function Circle() {
  14508. RedBlackNode(this);
  14509. this.x =
  14510. this.y =
  14511. this.arc =
  14512. this.site =
  14513. this.cy = null;
  14514. }
  14515. function attachCircle(arc) {
  14516. var lArc = arc.P,
  14517. rArc = arc.N;
  14518. if (!lArc || !rArc) return;
  14519. var lSite = lArc.site,
  14520. cSite = arc.site,
  14521. rSite = rArc.site;
  14522. if (lSite === rSite) return;
  14523. var bx = cSite[0],
  14524. by = cSite[1],
  14525. ax = lSite[0] - bx,
  14526. ay = lSite[1] - by,
  14527. cx = rSite[0] - bx,
  14528. cy = rSite[1] - by;
  14529. var d = 2 * (ax * cy - ay * cx);
  14530. if (d >= -epsilon2$2) return;
  14531. var ha = ax * ax + ay * ay,
  14532. hc = cx * cx + cy * cy,
  14533. x = (cy * ha - ay * hc) / d,
  14534. y = (ax * hc - cx * ha) / d;
  14535. var circle = circlePool.pop() || new Circle;
  14536. circle.arc = arc;
  14537. circle.site = cSite;
  14538. circle.x = x + bx;
  14539. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  14540. arc.circle = circle;
  14541. var before = null,
  14542. node = circles._;
  14543. while (node) {
  14544. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  14545. if (node.L) node = node.L;
  14546. else { before = node.P; break; }
  14547. } else {
  14548. if (node.R) node = node.R;
  14549. else { before = node; break; }
  14550. }
  14551. }
  14552. circles.insert(before, circle);
  14553. if (!before) firstCircle = circle;
  14554. }
  14555. function detachCircle(arc) {
  14556. var circle = arc.circle;
  14557. if (circle) {
  14558. if (!circle.P) firstCircle = circle.N;
  14559. circles.remove(circle);
  14560. circlePool.push(circle);
  14561. RedBlackNode(circle);
  14562. arc.circle = null;
  14563. }
  14564. }
  14565. var beachPool = [];
  14566. function Beach() {
  14567. RedBlackNode(this);
  14568. this.edge =
  14569. this.site =
  14570. this.circle = null;
  14571. }
  14572. function createBeach(site) {
  14573. var beach = beachPool.pop() || new Beach;
  14574. beach.site = site;
  14575. return beach;
  14576. }
  14577. function detachBeach(beach) {
  14578. detachCircle(beach);
  14579. beaches.remove(beach);
  14580. beachPool.push(beach);
  14581. RedBlackNode(beach);
  14582. }
  14583. function removeBeach(beach) {
  14584. var circle = beach.circle,
  14585. x = circle.x,
  14586. y = circle.cy,
  14587. vertex = [x, y],
  14588. previous = beach.P,
  14589. next = beach.N,
  14590. disappearing = [beach];
  14591. detachBeach(beach);
  14592. var lArc = previous;
  14593. while (lArc.circle
  14594. && Math.abs(x - lArc.circle.x) < epsilon$4
  14595. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  14596. previous = lArc.P;
  14597. disappearing.unshift(lArc);
  14598. detachBeach(lArc);
  14599. lArc = previous;
  14600. }
  14601. disappearing.unshift(lArc);
  14602. detachCircle(lArc);
  14603. var rArc = next;
  14604. while (rArc.circle
  14605. && Math.abs(x - rArc.circle.x) < epsilon$4
  14606. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  14607. next = rArc.N;
  14608. disappearing.push(rArc);
  14609. detachBeach(rArc);
  14610. rArc = next;
  14611. }
  14612. disappearing.push(rArc);
  14613. detachCircle(rArc);
  14614. var nArcs = disappearing.length,
  14615. iArc;
  14616. for (iArc = 1; iArc < nArcs; ++iArc) {
  14617. rArc = disappearing[iArc];
  14618. lArc = disappearing[iArc - 1];
  14619. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  14620. }
  14621. lArc = disappearing[0];
  14622. rArc = disappearing[nArcs - 1];
  14623. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  14624. attachCircle(lArc);
  14625. attachCircle(rArc);
  14626. }
  14627. function addBeach(site) {
  14628. var x = site[0],
  14629. directrix = site[1],
  14630. lArc,
  14631. rArc,
  14632. dxl,
  14633. dxr,
  14634. node = beaches._;
  14635. while (node) {
  14636. dxl = leftBreakPoint(node, directrix) - x;
  14637. if (dxl > epsilon$4) node = node.L; else {
  14638. dxr = x - rightBreakPoint(node, directrix);
  14639. if (dxr > epsilon$4) {
  14640. if (!node.R) {
  14641. lArc = node;
  14642. break;
  14643. }
  14644. node = node.R;
  14645. } else {
  14646. if (dxl > -epsilon$4) {
  14647. lArc = node.P;
  14648. rArc = node;
  14649. } else if (dxr > -epsilon$4) {
  14650. lArc = node;
  14651. rArc = node.N;
  14652. } else {
  14653. lArc = rArc = node;
  14654. }
  14655. break;
  14656. }
  14657. }
  14658. }
  14659. createCell(site);
  14660. var newArc = createBeach(site);
  14661. beaches.insert(lArc, newArc);
  14662. if (!lArc && !rArc) return;
  14663. if (lArc === rArc) {
  14664. detachCircle(lArc);
  14665. rArc = createBeach(lArc.site);
  14666. beaches.insert(newArc, rArc);
  14667. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  14668. attachCircle(lArc);
  14669. attachCircle(rArc);
  14670. return;
  14671. }
  14672. if (!rArc) { // && lArc
  14673. newArc.edge = createEdge(lArc.site, newArc.site);
  14674. return;
  14675. }
  14676. // else lArc !== rArc
  14677. detachCircle(lArc);
  14678. detachCircle(rArc);
  14679. var lSite = lArc.site,
  14680. ax = lSite[0],
  14681. ay = lSite[1],
  14682. bx = site[0] - ax,
  14683. by = site[1] - ay,
  14684. rSite = rArc.site,
  14685. cx = rSite[0] - ax,
  14686. cy = rSite[1] - ay,
  14687. d = 2 * (bx * cy - by * cx),
  14688. hb = bx * bx + by * by,
  14689. hc = cx * cx + cy * cy,
  14690. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  14691. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  14692. newArc.edge = createEdge(lSite, site, null, vertex);
  14693. rArc.edge = createEdge(site, rSite, null, vertex);
  14694. attachCircle(lArc);
  14695. attachCircle(rArc);
  14696. }
  14697. function leftBreakPoint(arc, directrix) {
  14698. var site = arc.site,
  14699. rfocx = site[0],
  14700. rfocy = site[1],
  14701. pby2 = rfocy - directrix;
  14702. if (!pby2) return rfocx;
  14703. var lArc = arc.P;
  14704. if (!lArc) return -Infinity;
  14705. site = lArc.site;
  14706. var lfocx = site[0],
  14707. lfocy = site[1],
  14708. plby2 = lfocy - directrix;
  14709. if (!plby2) return lfocx;
  14710. var hl = lfocx - rfocx,
  14711. aby2 = 1 / pby2 - 1 / plby2,
  14712. b = hl / plby2;
  14713. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  14714. return (rfocx + lfocx) / 2;
  14715. }
  14716. function rightBreakPoint(arc, directrix) {
  14717. var rArc = arc.N;
  14718. if (rArc) return leftBreakPoint(rArc, directrix);
  14719. var site = arc.site;
  14720. return site[1] === directrix ? site[0] : Infinity;
  14721. }
  14722. var epsilon$4 = 1e-6;
  14723. var epsilon2$2 = 1e-12;
  14724. var beaches;
  14725. var cells;
  14726. var circles;
  14727. var edges;
  14728. function triangleArea(a, b, c) {
  14729. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  14730. }
  14731. function lexicographic(a, b) {
  14732. return b[1] - a[1]
  14733. || b[0] - a[0];
  14734. }
  14735. function Diagram(sites, extent) {
  14736. var site = sites.sort(lexicographic).pop(),
  14737. x,
  14738. y,
  14739. circle;
  14740. edges = [];
  14741. cells = new Array(sites.length);
  14742. beaches = new RedBlackTree;
  14743. circles = new RedBlackTree;
  14744. while (true) {
  14745. circle = firstCircle;
  14746. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  14747. if (site[0] !== x || site[1] !== y) {
  14748. addBeach(site);
  14749. x = site[0], y = site[1];
  14750. }
  14751. site = sites.pop();
  14752. } else if (circle) {
  14753. removeBeach(circle.arc);
  14754. } else {
  14755. break;
  14756. }
  14757. }
  14758. sortCellHalfedges();
  14759. if (extent) {
  14760. var x0 = +extent[0][0],
  14761. y0 = +extent[0][1],
  14762. x1 = +extent[1][0],
  14763. y1 = +extent[1][1];
  14764. clipEdges(x0, y0, x1, y1);
  14765. clipCells(x0, y0, x1, y1);
  14766. }
  14767. this.edges = edges;
  14768. this.cells = cells;
  14769. beaches =
  14770. circles =
  14771. edges =
  14772. cells = null;
  14773. }
  14774. Diagram.prototype = {
  14775. constructor: Diagram,
  14776. polygons: function() {
  14777. var edges = this.edges;
  14778. return this.cells.map(function(cell) {
  14779. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  14780. polygon.data = cell.site.data;
  14781. return polygon;
  14782. });
  14783. },
  14784. triangles: function() {
  14785. var triangles = [],
  14786. edges = this.edges;
  14787. this.cells.forEach(function(cell, i) {
  14788. if (!(m = (halfedges = cell.halfedges).length)) return;
  14789. var site = cell.site,
  14790. halfedges,
  14791. j = -1,
  14792. m,
  14793. s0,
  14794. e1 = edges[halfedges[m - 1]],
  14795. s1 = e1.left === site ? e1.right : e1.left;
  14796. while (++j < m) {
  14797. s0 = s1;
  14798. e1 = edges[halfedges[j]];
  14799. s1 = e1.left === site ? e1.right : e1.left;
  14800. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  14801. triangles.push([site.data, s0.data, s1.data]);
  14802. }
  14803. }
  14804. });
  14805. return triangles;
  14806. },
  14807. links: function() {
  14808. return this.edges.filter(function(edge) {
  14809. return edge.right;
  14810. }).map(function(edge) {
  14811. return {
  14812. source: edge.left.data,
  14813. target: edge.right.data
  14814. };
  14815. });
  14816. },
  14817. find: function(x, y, radius) {
  14818. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  14819. // Use the previously-found cell, or start with an arbitrary one.
  14820. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  14821. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  14822. // Traverse the half-edges to find a closer cell, if any.
  14823. do {
  14824. cell = that.cells[i0 = i1], i1 = null;
  14825. cell.halfedges.forEach(function(e) {
  14826. var edge = that.edges[e], v = edge.left;
  14827. if ((v === cell.site || !v) && !(v = edge.right)) return;
  14828. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  14829. if (v2 < d2) d2 = v2, i1 = v.index;
  14830. });
  14831. } while (i1 !== null);
  14832. that._found = i0;
  14833. return radius == null || d2 <= radius * radius ? cell.site : null;
  14834. }
  14835. };
  14836. function voronoi() {
  14837. var x = x$4,
  14838. y = y$4,
  14839. extent = null;
  14840. function voronoi(data) {
  14841. return new Diagram(data.map(function(d, i) {
  14842. var s = [Math.round(x(d, i, data) / epsilon$4) * epsilon$4, Math.round(y(d, i, data) / epsilon$4) * epsilon$4];
  14843. s.index = i;
  14844. s.data = d;
  14845. return s;
  14846. }), extent);
  14847. }
  14848. voronoi.polygons = function(data) {
  14849. return voronoi(data).polygons();
  14850. };
  14851. voronoi.links = function(data) {
  14852. return voronoi(data).links();
  14853. };
  14854. voronoi.triangles = function(data) {
  14855. return voronoi(data).triangles();
  14856. };
  14857. voronoi.x = function(_) {
  14858. return arguments.length ? (x = typeof _ === "function" ? _ : constant$c(+_), voronoi) : x;
  14859. };
  14860. voronoi.y = function(_) {
  14861. return arguments.length ? (y = typeof _ === "function" ? _ : constant$c(+_), voronoi) : y;
  14862. };
  14863. voronoi.extent = function(_) {
  14864. 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]]];
  14865. };
  14866. voronoi.size = function(_) {
  14867. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  14868. };
  14869. return voronoi;
  14870. }
  14871. function constant$d(x) {
  14872. return function() {
  14873. return x;
  14874. };
  14875. }
  14876. function ZoomEvent(target, type, transform) {
  14877. this.target = target;
  14878. this.type = type;
  14879. this.transform = transform;
  14880. }
  14881. function Transform(k, x, y) {
  14882. this.k = k;
  14883. this.x = x;
  14884. this.y = y;
  14885. }
  14886. Transform.prototype = {
  14887. constructor: Transform,
  14888. scale: function(k) {
  14889. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  14890. },
  14891. translate: function(x, y) {
  14892. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  14893. },
  14894. apply: function(point) {
  14895. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  14896. },
  14897. applyX: function(x) {
  14898. return x * this.k + this.x;
  14899. },
  14900. applyY: function(y) {
  14901. return y * this.k + this.y;
  14902. },
  14903. invert: function(location) {
  14904. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  14905. },
  14906. invertX: function(x) {
  14907. return (x - this.x) / this.k;
  14908. },
  14909. invertY: function(y) {
  14910. return (y - this.y) / this.k;
  14911. },
  14912. rescaleX: function(x) {
  14913. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  14914. },
  14915. rescaleY: function(y) {
  14916. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  14917. },
  14918. toString: function() {
  14919. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  14920. }
  14921. };
  14922. var identity$9 = new Transform(1, 0, 0);
  14923. transform$1.prototype = Transform.prototype;
  14924. function transform$1(node) {
  14925. while (!node.__zoom) if (!(node = node.parentNode)) return identity$9;
  14926. return node.__zoom;
  14927. }
  14928. function nopropagation$2() {
  14929. exports.event.stopImmediatePropagation();
  14930. }
  14931. function noevent$2() {
  14932. exports.event.preventDefault();
  14933. exports.event.stopImmediatePropagation();
  14934. }
  14935. // Ignore right-click, since that should open the context menu.
  14936. function defaultFilter$2() {
  14937. return !exports.event.ctrlKey && !exports.event.button;
  14938. }
  14939. function defaultExtent$1() {
  14940. var e = this;
  14941. if (e instanceof SVGElement) {
  14942. e = e.ownerSVGElement || e;
  14943. if (e.hasAttribute("viewBox")) {
  14944. e = e.viewBox.baseVal;
  14945. return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
  14946. }
  14947. return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
  14948. }
  14949. return [[0, 0], [e.clientWidth, e.clientHeight]];
  14950. }
  14951. function defaultTransform() {
  14952. return this.__zoom || identity$9;
  14953. }
  14954. function defaultWheelDelta() {
  14955. return -exports.event.deltaY * (exports.event.deltaMode === 1 ? 0.05 : exports.event.deltaMode ? 1 : 0.002);
  14956. }
  14957. function defaultTouchable$2() {
  14958. return navigator.maxTouchPoints || ("ontouchstart" in this);
  14959. }
  14960. function defaultConstrain(transform, extent, translateExtent) {
  14961. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  14962. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  14963. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  14964. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  14965. return transform.translate(
  14966. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  14967. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  14968. );
  14969. }
  14970. function zoom() {
  14971. var filter = defaultFilter$2,
  14972. extent = defaultExtent$1,
  14973. constrain = defaultConstrain,
  14974. wheelDelta = defaultWheelDelta,
  14975. touchable = defaultTouchable$2,
  14976. scaleExtent = [0, Infinity],
  14977. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  14978. duration = 250,
  14979. interpolate = interpolateZoom,
  14980. listeners = dispatch("start", "zoom", "end"),
  14981. touchstarting,
  14982. touchending,
  14983. touchDelay = 500,
  14984. wheelDelay = 150,
  14985. clickDistance2 = 0;
  14986. function zoom(selection) {
  14987. selection
  14988. .property("__zoom", defaultTransform)
  14989. .on("wheel.zoom", wheeled)
  14990. .on("mousedown.zoom", mousedowned)
  14991. .on("dblclick.zoom", dblclicked)
  14992. .filter(touchable)
  14993. .on("touchstart.zoom", touchstarted)
  14994. .on("touchmove.zoom", touchmoved)
  14995. .on("touchend.zoom touchcancel.zoom", touchended)
  14996. .style("touch-action", "none")
  14997. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  14998. }
  14999. zoom.transform = function(collection, transform, point) {
  15000. var selection = collection.selection ? collection.selection() : collection;
  15001. selection.property("__zoom", defaultTransform);
  15002. if (collection !== selection) {
  15003. schedule(collection, transform, point);
  15004. } else {
  15005. selection.interrupt().each(function() {
  15006. gesture(this, arguments)
  15007. .start()
  15008. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  15009. .end();
  15010. });
  15011. }
  15012. };
  15013. zoom.scaleBy = function(selection, k, p) {
  15014. zoom.scaleTo(selection, function() {
  15015. var k0 = this.__zoom.k,
  15016. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  15017. return k0 * k1;
  15018. }, p);
  15019. };
  15020. zoom.scaleTo = function(selection, k, p) {
  15021. zoom.transform(selection, function() {
  15022. var e = extent.apply(this, arguments),
  15023. t0 = this.__zoom,
  15024. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
  15025. p1 = t0.invert(p0),
  15026. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  15027. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  15028. }, p);
  15029. };
  15030. zoom.translateBy = function(selection, x, y) {
  15031. zoom.transform(selection, function() {
  15032. return constrain(this.__zoom.translate(
  15033. typeof x === "function" ? x.apply(this, arguments) : x,
  15034. typeof y === "function" ? y.apply(this, arguments) : y
  15035. ), extent.apply(this, arguments), translateExtent);
  15036. });
  15037. };
  15038. zoom.translateTo = function(selection, x, y, p) {
  15039. zoom.transform(selection, function() {
  15040. var e = extent.apply(this, arguments),
  15041. t = this.__zoom,
  15042. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
  15043. return constrain(identity$9.translate(p0[0], p0[1]).scale(t.k).translate(
  15044. typeof x === "function" ? -x.apply(this, arguments) : -x,
  15045. typeof y === "function" ? -y.apply(this, arguments) : -y
  15046. ), e, translateExtent);
  15047. }, p);
  15048. };
  15049. function scale(transform, k) {
  15050. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  15051. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  15052. }
  15053. function translate(transform, p0, p1) {
  15054. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  15055. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  15056. }
  15057. function centroid(extent) {
  15058. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  15059. }
  15060. function schedule(transition, transform, point) {
  15061. transition
  15062. .on("start.zoom", function() { gesture(this, arguments).start(); })
  15063. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  15064. .tween("zoom", function() {
  15065. var that = this,
  15066. args = arguments,
  15067. g = gesture(that, args),
  15068. e = extent.apply(that, args),
  15069. p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
  15070. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  15071. a = that.__zoom,
  15072. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  15073. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  15074. return function(t) {
  15075. if (t === 1) t = b; // Avoid rounding error on end.
  15076. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  15077. g.zoom(null, t);
  15078. };
  15079. });
  15080. }
  15081. function gesture(that, args, clean) {
  15082. return (!clean && that.__zooming) || new Gesture(that, args);
  15083. }
  15084. function Gesture(that, args) {
  15085. this.that = that;
  15086. this.args = args;
  15087. this.active = 0;
  15088. this.extent = extent.apply(that, args);
  15089. this.taps = 0;
  15090. }
  15091. Gesture.prototype = {
  15092. start: function() {
  15093. if (++this.active === 1) {
  15094. this.that.__zooming = this;
  15095. this.emit("start");
  15096. }
  15097. return this;
  15098. },
  15099. zoom: function(key, transform) {
  15100. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  15101. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  15102. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  15103. this.that.__zoom = transform;
  15104. this.emit("zoom");
  15105. return this;
  15106. },
  15107. end: function() {
  15108. if (--this.active === 0) {
  15109. delete this.that.__zooming;
  15110. this.emit("end");
  15111. }
  15112. return this;
  15113. },
  15114. emit: function(type) {
  15115. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  15116. }
  15117. };
  15118. function wheeled() {
  15119. if (!filter.apply(this, arguments)) return;
  15120. var g = gesture(this, arguments),
  15121. t = this.__zoom,
  15122. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  15123. p = mouse(this);
  15124. // If the mouse is in the same location as before, reuse it.
  15125. // If there were recent wheel events, reset the wheel idle timeout.
  15126. if (g.wheel) {
  15127. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  15128. g.mouse[1] = t.invert(g.mouse[0] = p);
  15129. }
  15130. clearTimeout(g.wheel);
  15131. }
  15132. // If this wheel event won’t trigger a transform change, ignore it.
  15133. else if (t.k === k) return;
  15134. // Otherwise, capture the mouse point and location at the start.
  15135. else {
  15136. g.mouse = [p, t.invert(p)];
  15137. interrupt(this);
  15138. g.start();
  15139. }
  15140. noevent$2();
  15141. g.wheel = setTimeout(wheelidled, wheelDelay);
  15142. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  15143. function wheelidled() {
  15144. g.wheel = null;
  15145. g.end();
  15146. }
  15147. }
  15148. function mousedowned() {
  15149. if (touchending || !filter.apply(this, arguments)) return;
  15150. var g = gesture(this, arguments, true),
  15151. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  15152. p = mouse(this),
  15153. x0 = exports.event.clientX,
  15154. y0 = exports.event.clientY;
  15155. dragDisable(exports.event.view);
  15156. nopropagation$2();
  15157. g.mouse = [p, this.__zoom.invert(p)];
  15158. interrupt(this);
  15159. g.start();
  15160. function mousemoved() {
  15161. noevent$2();
  15162. if (!g.moved) {
  15163. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  15164. g.moved = dx * dx + dy * dy > clickDistance2;
  15165. }
  15166. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  15167. }
  15168. function mouseupped() {
  15169. v.on("mousemove.zoom mouseup.zoom", null);
  15170. yesdrag(exports.event.view, g.moved);
  15171. noevent$2();
  15172. g.end();
  15173. }
  15174. }
  15175. function dblclicked() {
  15176. if (!filter.apply(this, arguments)) return;
  15177. var t0 = this.__zoom,
  15178. p0 = mouse(this),
  15179. p1 = t0.invert(p0),
  15180. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  15181. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  15182. noevent$2();
  15183. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  15184. else select(this).call(zoom.transform, t1);
  15185. }
  15186. function touchstarted() {
  15187. if (!filter.apply(this, arguments)) return;
  15188. var touches = exports.event.touches,
  15189. n = touches.length,
  15190. g = gesture(this, arguments, exports.event.changedTouches.length === n),
  15191. started, i, t, p;
  15192. nopropagation$2();
  15193. for (i = 0; i < n; ++i) {
  15194. t = touches[i], p = touch(this, touches, t.identifier);
  15195. p = [p, this.__zoom.invert(p), t.identifier];
  15196. if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
  15197. else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
  15198. }
  15199. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  15200. if (started) {
  15201. if (g.taps < 2) touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  15202. interrupt(this);
  15203. g.start();
  15204. }
  15205. }
  15206. function touchmoved() {
  15207. if (!this.__zooming) return;
  15208. var g = gesture(this, arguments),
  15209. touches = exports.event.changedTouches,
  15210. n = touches.length, i, t, p, l;
  15211. noevent$2();
  15212. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  15213. g.taps = 0;
  15214. for (i = 0; i < n; ++i) {
  15215. t = touches[i], p = touch(this, touches, t.identifier);
  15216. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  15217. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  15218. }
  15219. t = g.that.__zoom;
  15220. if (g.touch1) {
  15221. var p0 = g.touch0[0], l0 = g.touch0[1],
  15222. p1 = g.touch1[0], l1 = g.touch1[1],
  15223. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  15224. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  15225. t = scale(t, Math.sqrt(dp / dl));
  15226. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  15227. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  15228. }
  15229. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  15230. else return;
  15231. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  15232. }
  15233. function touchended() {
  15234. if (!this.__zooming) return;
  15235. var g = gesture(this, arguments),
  15236. touches = exports.event.changedTouches,
  15237. n = touches.length, i, t;
  15238. nopropagation$2();
  15239. if (touchending) clearTimeout(touchending);
  15240. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  15241. for (i = 0; i < n; ++i) {
  15242. t = touches[i];
  15243. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  15244. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  15245. }
  15246. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  15247. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  15248. else {
  15249. g.end();
  15250. // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
  15251. if (g.taps === 2) {
  15252. var p = select(this).on("dblclick.zoom");
  15253. if (p) p.apply(this, arguments);
  15254. }
  15255. }
  15256. }
  15257. zoom.wheelDelta = function(_) {
  15258. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$d(+_), zoom) : wheelDelta;
  15259. };
  15260. zoom.filter = function(_) {
  15261. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$d(!!_), zoom) : filter;
  15262. };
  15263. zoom.touchable = function(_) {
  15264. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$d(!!_), zoom) : touchable;
  15265. };
  15266. zoom.extent = function(_) {
  15267. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$d([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  15268. };
  15269. zoom.scaleExtent = function(_) {
  15270. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  15271. };
  15272. zoom.translateExtent = function(_) {
  15273. 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]]];
  15274. };
  15275. zoom.constrain = function(_) {
  15276. return arguments.length ? (constrain = _, zoom) : constrain;
  15277. };
  15278. zoom.duration = function(_) {
  15279. return arguments.length ? (duration = +_, zoom) : duration;
  15280. };
  15281. zoom.interpolate = function(_) {
  15282. return arguments.length ? (interpolate = _, zoom) : interpolate;
  15283. };
  15284. zoom.on = function() {
  15285. var value = listeners.on.apply(listeners, arguments);
  15286. return value === listeners ? zoom : value;
  15287. };
  15288. zoom.clickDistance = function(_) {
  15289. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  15290. };
  15291. return zoom;
  15292. }
  15293. exports.FormatSpecifier = FormatSpecifier;
  15294. exports.active = active;
  15295. exports.arc = arc;
  15296. exports.area = area$3;
  15297. exports.areaRadial = areaRadial;
  15298. exports.ascending = ascending;
  15299. exports.autoType = autoType;
  15300. exports.axisBottom = axisBottom;
  15301. exports.axisLeft = axisLeft;
  15302. exports.axisRight = axisRight;
  15303. exports.axisTop = axisTop;
  15304. exports.bisect = bisectRight;
  15305. exports.bisectLeft = bisectLeft;
  15306. exports.bisectRight = bisectRight;
  15307. exports.bisector = bisector;
  15308. exports.blob = blob;
  15309. exports.brush = brush;
  15310. exports.brushSelection = brushSelection;
  15311. exports.brushX = brushX;
  15312. exports.brushY = brushY;
  15313. exports.buffer = buffer;
  15314. exports.chord = chord;
  15315. exports.clientPoint = point;
  15316. exports.cluster = cluster;
  15317. exports.color = color;
  15318. exports.contourDensity = density;
  15319. exports.contours = contours;
  15320. exports.create = create;
  15321. exports.creator = creator;
  15322. exports.cross = cross;
  15323. exports.csv = csv$1;
  15324. exports.csvFormat = csvFormat;
  15325. exports.csvFormatBody = csvFormatBody;
  15326. exports.csvFormatRow = csvFormatRow;
  15327. exports.csvFormatRows = csvFormatRows;
  15328. exports.csvFormatValue = csvFormatValue;
  15329. exports.csvParse = csvParse;
  15330. exports.csvParseRows = csvParseRows;
  15331. exports.cubehelix = cubehelix;
  15332. exports.curveBasis = basis$2;
  15333. exports.curveBasisClosed = basisClosed$1;
  15334. exports.curveBasisOpen = basisOpen;
  15335. exports.curveBundle = bundle;
  15336. exports.curveCardinal = cardinal;
  15337. exports.curveCardinalClosed = cardinalClosed;
  15338. exports.curveCardinalOpen = cardinalOpen;
  15339. exports.curveCatmullRom = catmullRom;
  15340. exports.curveCatmullRomClosed = catmullRomClosed;
  15341. exports.curveCatmullRomOpen = catmullRomOpen;
  15342. exports.curveLinear = curveLinear;
  15343. exports.curveLinearClosed = linearClosed;
  15344. exports.curveMonotoneX = monotoneX;
  15345. exports.curveMonotoneY = monotoneY;
  15346. exports.curveNatural = natural;
  15347. exports.curveStep = step;
  15348. exports.curveStepAfter = stepAfter;
  15349. exports.curveStepBefore = stepBefore;
  15350. exports.customEvent = customEvent;
  15351. exports.descending = descending;
  15352. exports.deviation = deviation;
  15353. exports.dispatch = dispatch;
  15354. exports.drag = drag;
  15355. exports.dragDisable = dragDisable;
  15356. exports.dragEnable = yesdrag;
  15357. exports.dsv = dsv;
  15358. exports.dsvFormat = dsvFormat;
  15359. exports.easeBack = backInOut;
  15360. exports.easeBackIn = backIn;
  15361. exports.easeBackInOut = backInOut;
  15362. exports.easeBackOut = backOut;
  15363. exports.easeBounce = bounceOut;
  15364. exports.easeBounceIn = bounceIn;
  15365. exports.easeBounceInOut = bounceInOut;
  15366. exports.easeBounceOut = bounceOut;
  15367. exports.easeCircle = circleInOut;
  15368. exports.easeCircleIn = circleIn;
  15369. exports.easeCircleInOut = circleInOut;
  15370. exports.easeCircleOut = circleOut;
  15371. exports.easeCubic = cubicInOut;
  15372. exports.easeCubicIn = cubicIn;
  15373. exports.easeCubicInOut = cubicInOut;
  15374. exports.easeCubicOut = cubicOut;
  15375. exports.easeElastic = elasticOut;
  15376. exports.easeElasticIn = elasticIn;
  15377. exports.easeElasticInOut = elasticInOut;
  15378. exports.easeElasticOut = elasticOut;
  15379. exports.easeExp = expInOut;
  15380. exports.easeExpIn = expIn;
  15381. exports.easeExpInOut = expInOut;
  15382. exports.easeExpOut = expOut;
  15383. exports.easeLinear = linear$1;
  15384. exports.easePoly = polyInOut;
  15385. exports.easePolyIn = polyIn;
  15386. exports.easePolyInOut = polyInOut;
  15387. exports.easePolyOut = polyOut;
  15388. exports.easeQuad = quadInOut;
  15389. exports.easeQuadIn = quadIn;
  15390. exports.easeQuadInOut = quadInOut;
  15391. exports.easeQuadOut = quadOut;
  15392. exports.easeSin = sinInOut;
  15393. exports.easeSinIn = sinIn;
  15394. exports.easeSinInOut = sinInOut;
  15395. exports.easeSinOut = sinOut;
  15396. exports.entries = entries;
  15397. exports.extent = extent;
  15398. exports.forceCenter = center$1;
  15399. exports.forceCollide = collide;
  15400. exports.forceLink = link;
  15401. exports.forceManyBody = manyBody;
  15402. exports.forceRadial = radial;
  15403. exports.forceSimulation = simulation;
  15404. exports.forceX = x$2;
  15405. exports.forceY = y$2;
  15406. exports.formatDefaultLocale = defaultLocale;
  15407. exports.formatLocale = formatLocale;
  15408. exports.formatSpecifier = formatSpecifier;
  15409. exports.geoAlbers = albers;
  15410. exports.geoAlbersUsa = albersUsa;
  15411. exports.geoArea = area$1;
  15412. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  15413. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  15414. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  15415. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  15416. exports.geoBounds = bounds;
  15417. exports.geoCentroid = centroid;
  15418. exports.geoCircle = circle;
  15419. exports.geoClipAntimeridian = clipAntimeridian;
  15420. exports.geoClipCircle = clipCircle;
  15421. exports.geoClipExtent = extent$1;
  15422. exports.geoClipRectangle = clipRectangle;
  15423. exports.geoConicConformal = conicConformal;
  15424. exports.geoConicConformalRaw = conicConformalRaw;
  15425. exports.geoConicEqualArea = conicEqualArea;
  15426. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  15427. exports.geoConicEquidistant = conicEquidistant;
  15428. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  15429. exports.geoContains = contains$1;
  15430. exports.geoDistance = distance;
  15431. exports.geoEqualEarth = equalEarth;
  15432. exports.geoEqualEarthRaw = equalEarthRaw;
  15433. exports.geoEquirectangular = equirectangular;
  15434. exports.geoEquirectangularRaw = equirectangularRaw;
  15435. exports.geoGnomonic = gnomonic;
  15436. exports.geoGnomonicRaw = gnomonicRaw;
  15437. exports.geoGraticule = graticule;
  15438. exports.geoGraticule10 = graticule10;
  15439. exports.geoIdentity = identity$5;
  15440. exports.geoInterpolate = interpolate$1;
  15441. exports.geoLength = length$1;
  15442. exports.geoMercator = mercator;
  15443. exports.geoMercatorRaw = mercatorRaw;
  15444. exports.geoNaturalEarth1 = naturalEarth1;
  15445. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  15446. exports.geoOrthographic = orthographic;
  15447. exports.geoOrthographicRaw = orthographicRaw;
  15448. exports.geoPath = index$1;
  15449. exports.geoProjection = projection;
  15450. exports.geoProjectionMutator = projectionMutator;
  15451. exports.geoRotation = rotation;
  15452. exports.geoStereographic = stereographic;
  15453. exports.geoStereographicRaw = stereographicRaw;
  15454. exports.geoStream = geoStream;
  15455. exports.geoTransform = transform;
  15456. exports.geoTransverseMercator = transverseMercator;
  15457. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  15458. exports.gray = gray;
  15459. exports.hcl = hcl;
  15460. exports.hierarchy = hierarchy;
  15461. exports.histogram = histogram;
  15462. exports.hsl = hsl;
  15463. exports.html = html;
  15464. exports.image = image;
  15465. exports.interpolate = interpolateValue;
  15466. exports.interpolateArray = array$1;
  15467. exports.interpolateBasis = basis$1;
  15468. exports.interpolateBasisClosed = basisClosed;
  15469. exports.interpolateBlues = Blues;
  15470. exports.interpolateBrBG = BrBG;
  15471. exports.interpolateBuGn = BuGn;
  15472. exports.interpolateBuPu = BuPu;
  15473. exports.interpolateCividis = cividis;
  15474. exports.interpolateCool = cool;
  15475. exports.interpolateCubehelix = cubehelix$2;
  15476. exports.interpolateCubehelixDefault = cubehelix$3;
  15477. exports.interpolateCubehelixLong = cubehelixLong;
  15478. exports.interpolateDate = date;
  15479. exports.interpolateDiscrete = discrete;
  15480. exports.interpolateGnBu = GnBu;
  15481. exports.interpolateGreens = Greens;
  15482. exports.interpolateGreys = Greys;
  15483. exports.interpolateHcl = hcl$2;
  15484. exports.interpolateHclLong = hclLong;
  15485. exports.interpolateHsl = hsl$2;
  15486. exports.interpolateHslLong = hslLong;
  15487. exports.interpolateHue = hue$1;
  15488. exports.interpolateInferno = inferno;
  15489. exports.interpolateLab = lab$1;
  15490. exports.interpolateMagma = magma;
  15491. exports.interpolateNumber = interpolateNumber;
  15492. exports.interpolateObject = object;
  15493. exports.interpolateOrRd = OrRd;
  15494. exports.interpolateOranges = Oranges;
  15495. exports.interpolatePRGn = PRGn;
  15496. exports.interpolatePiYG = PiYG;
  15497. exports.interpolatePlasma = plasma;
  15498. exports.interpolatePuBu = PuBu;
  15499. exports.interpolatePuBuGn = PuBuGn;
  15500. exports.interpolatePuOr = PuOr;
  15501. exports.interpolatePuRd = PuRd;
  15502. exports.interpolatePurples = Purples;
  15503. exports.interpolateRainbow = rainbow;
  15504. exports.interpolateRdBu = RdBu;
  15505. exports.interpolateRdGy = RdGy;
  15506. exports.interpolateRdPu = RdPu;
  15507. exports.interpolateRdYlBu = RdYlBu;
  15508. exports.interpolateRdYlGn = RdYlGn;
  15509. exports.interpolateReds = Reds;
  15510. exports.interpolateRgb = interpolateRgb;
  15511. exports.interpolateRgbBasis = rgbBasis;
  15512. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  15513. exports.interpolateRound = interpolateRound;
  15514. exports.interpolateSinebow = sinebow;
  15515. exports.interpolateSpectral = Spectral;
  15516. exports.interpolateString = interpolateString;
  15517. exports.interpolateTransformCss = interpolateTransformCss;
  15518. exports.interpolateTransformSvg = interpolateTransformSvg;
  15519. exports.interpolateTurbo = turbo;
  15520. exports.interpolateViridis = viridis;
  15521. exports.interpolateWarm = warm;
  15522. exports.interpolateYlGn = YlGn;
  15523. exports.interpolateYlGnBu = YlGnBu;
  15524. exports.interpolateYlOrBr = YlOrBr;
  15525. exports.interpolateYlOrRd = YlOrRd;
  15526. exports.interpolateZoom = interpolateZoom;
  15527. exports.interrupt = interrupt;
  15528. exports.interval = interval$1;
  15529. exports.isoFormat = formatIso;
  15530. exports.isoParse = parseIso;
  15531. exports.json = json;
  15532. exports.keys = keys;
  15533. exports.lab = lab;
  15534. exports.lch = lch;
  15535. exports.line = line;
  15536. exports.lineRadial = lineRadial$1;
  15537. exports.linkHorizontal = linkHorizontal;
  15538. exports.linkRadial = linkRadial;
  15539. exports.linkVertical = linkVertical;
  15540. exports.local = local;
  15541. exports.map = map$1;
  15542. exports.matcher = matcher;
  15543. exports.max = max;
  15544. exports.mean = mean;
  15545. exports.median = median;
  15546. exports.merge = merge;
  15547. exports.min = min;
  15548. exports.mouse = mouse;
  15549. exports.namespace = namespace;
  15550. exports.namespaces = namespaces;
  15551. exports.nest = nest;
  15552. exports.now = now;
  15553. exports.pack = index$2;
  15554. exports.packEnclose = enclose;
  15555. exports.packSiblings = siblings;
  15556. exports.pairs = pairs;
  15557. exports.partition = partition;
  15558. exports.path = path;
  15559. exports.permute = permute;
  15560. exports.pie = pie;
  15561. exports.piecewise = piecewise;
  15562. exports.pointRadial = pointRadial;
  15563. exports.polygonArea = area$2;
  15564. exports.polygonCentroid = centroid$1;
  15565. exports.polygonContains = contains$2;
  15566. exports.polygonHull = hull;
  15567. exports.polygonLength = length$2;
  15568. exports.precisionFixed = precisionFixed;
  15569. exports.precisionPrefix = precisionPrefix;
  15570. exports.precisionRound = precisionRound;
  15571. exports.quadtree = quadtree;
  15572. exports.quantile = threshold;
  15573. exports.quantize = quantize;
  15574. exports.radialArea = areaRadial;
  15575. exports.radialLine = lineRadial$1;
  15576. exports.randomBates = bates;
  15577. exports.randomExponential = exponential$1;
  15578. exports.randomIrwinHall = irwinHall;
  15579. exports.randomLogNormal = logNormal;
  15580. exports.randomNormal = normal;
  15581. exports.randomUniform = uniform;
  15582. exports.range = sequence;
  15583. exports.rgb = rgb;
  15584. exports.ribbon = ribbon;
  15585. exports.scaleBand = band;
  15586. exports.scaleDiverging = diverging;
  15587. exports.scaleDivergingLog = divergingLog;
  15588. exports.scaleDivergingPow = divergingPow;
  15589. exports.scaleDivergingSqrt = divergingSqrt;
  15590. exports.scaleDivergingSymlog = divergingSymlog;
  15591. exports.scaleIdentity = identity$7;
  15592. exports.scaleImplicit = implicit;
  15593. exports.scaleLinear = linear$2;
  15594. exports.scaleLog = log$1;
  15595. exports.scaleOrdinal = ordinal;
  15596. exports.scalePoint = point$1;
  15597. exports.scalePow = pow$1;
  15598. exports.scaleQuantile = quantile;
  15599. exports.scaleQuantize = quantize$1;
  15600. exports.scaleSequential = sequential;
  15601. exports.scaleSequentialLog = sequentialLog;
  15602. exports.scaleSequentialPow = sequentialPow;
  15603. exports.scaleSequentialQuantile = sequentialQuantile;
  15604. exports.scaleSequentialSqrt = sequentialSqrt;
  15605. exports.scaleSequentialSymlog = sequentialSymlog;
  15606. exports.scaleSqrt = sqrt$1;
  15607. exports.scaleSymlog = symlog;
  15608. exports.scaleThreshold = threshold$1;
  15609. exports.scaleTime = time;
  15610. exports.scaleUtc = utcTime;
  15611. exports.scan = scan;
  15612. exports.schemeAccent = Accent;
  15613. exports.schemeBlues = scheme$l;
  15614. exports.schemeBrBG = scheme;
  15615. exports.schemeBuGn = scheme$9;
  15616. exports.schemeBuPu = scheme$a;
  15617. exports.schemeCategory10 = category10;
  15618. exports.schemeDark2 = Dark2;
  15619. exports.schemeGnBu = scheme$b;
  15620. exports.schemeGreens = scheme$m;
  15621. exports.schemeGreys = scheme$n;
  15622. exports.schemeOrRd = scheme$c;
  15623. exports.schemeOranges = scheme$q;
  15624. exports.schemePRGn = scheme$1;
  15625. exports.schemePaired = Paired;
  15626. exports.schemePastel1 = Pastel1;
  15627. exports.schemePastel2 = Pastel2;
  15628. exports.schemePiYG = scheme$2;
  15629. exports.schemePuBu = scheme$e;
  15630. exports.schemePuBuGn = scheme$d;
  15631. exports.schemePuOr = scheme$3;
  15632. exports.schemePuRd = scheme$f;
  15633. exports.schemePurples = scheme$o;
  15634. exports.schemeRdBu = scheme$4;
  15635. exports.schemeRdGy = scheme$5;
  15636. exports.schemeRdPu = scheme$g;
  15637. exports.schemeRdYlBu = scheme$6;
  15638. exports.schemeRdYlGn = scheme$7;
  15639. exports.schemeReds = scheme$p;
  15640. exports.schemeSet1 = Set1;
  15641. exports.schemeSet2 = Set2;
  15642. exports.schemeSet3 = Set3;
  15643. exports.schemeSpectral = scheme$8;
  15644. exports.schemeTableau10 = Tableau10;
  15645. exports.schemeYlGn = scheme$i;
  15646. exports.schemeYlGnBu = scheme$h;
  15647. exports.schemeYlOrBr = scheme$j;
  15648. exports.schemeYlOrRd = scheme$k;
  15649. exports.select = select;
  15650. exports.selectAll = selectAll;
  15651. exports.selection = selection;
  15652. exports.selector = selector;
  15653. exports.selectorAll = selectorAll;
  15654. exports.set = set$2;
  15655. exports.shuffle = shuffle;
  15656. exports.stack = stack;
  15657. exports.stackOffsetDiverging = diverging$1;
  15658. exports.stackOffsetExpand = expand;
  15659. exports.stackOffsetNone = none$1;
  15660. exports.stackOffsetSilhouette = silhouette;
  15661. exports.stackOffsetWiggle = wiggle;
  15662. exports.stackOrderAppearance = appearance;
  15663. exports.stackOrderAscending = ascending$3;
  15664. exports.stackOrderDescending = descending$2;
  15665. exports.stackOrderInsideOut = insideOut;
  15666. exports.stackOrderNone = none$2;
  15667. exports.stackOrderReverse = reverse;
  15668. exports.stratify = stratify;
  15669. exports.style = styleValue;
  15670. exports.sum = sum;
  15671. exports.svg = svg;
  15672. exports.symbol = symbol;
  15673. exports.symbolCircle = circle$2;
  15674. exports.symbolCross = cross$2;
  15675. exports.symbolDiamond = diamond;
  15676. exports.symbolSquare = square;
  15677. exports.symbolStar = star;
  15678. exports.symbolTriangle = triangle;
  15679. exports.symbolWye = wye;
  15680. exports.symbols = symbols;
  15681. exports.text = text;
  15682. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  15683. exports.thresholdScott = scott;
  15684. exports.thresholdSturges = thresholdSturges;
  15685. exports.tickFormat = tickFormat;
  15686. exports.tickIncrement = tickIncrement;
  15687. exports.tickStep = tickStep;
  15688. exports.ticks = ticks;
  15689. exports.timeDay = day;
  15690. exports.timeDays = days;
  15691. exports.timeFormatDefaultLocale = defaultLocale$1;
  15692. exports.timeFormatLocale = formatLocale$1;
  15693. exports.timeFriday = friday;
  15694. exports.timeFridays = fridays;
  15695. exports.timeHour = hour;
  15696. exports.timeHours = hours;
  15697. exports.timeInterval = newInterval;
  15698. exports.timeMillisecond = millisecond;
  15699. exports.timeMilliseconds = milliseconds;
  15700. exports.timeMinute = minute;
  15701. exports.timeMinutes = minutes;
  15702. exports.timeMonday = monday;
  15703. exports.timeMondays = mondays;
  15704. exports.timeMonth = month;
  15705. exports.timeMonths = months;
  15706. exports.timeSaturday = saturday;
  15707. exports.timeSaturdays = saturdays;
  15708. exports.timeSecond = second;
  15709. exports.timeSeconds = seconds;
  15710. exports.timeSunday = sunday;
  15711. exports.timeSundays = sundays;
  15712. exports.timeThursday = thursday;
  15713. exports.timeThursdays = thursdays;
  15714. exports.timeTuesday = tuesday;
  15715. exports.timeTuesdays = tuesdays;
  15716. exports.timeWednesday = wednesday;
  15717. exports.timeWednesdays = wednesdays;
  15718. exports.timeWeek = sunday;
  15719. exports.timeWeeks = sundays;
  15720. exports.timeYear = year;
  15721. exports.timeYears = years;
  15722. exports.timeout = timeout$1;
  15723. exports.timer = timer;
  15724. exports.timerFlush = timerFlush;
  15725. exports.touch = touch;
  15726. exports.touches = touches;
  15727. exports.transition = transition;
  15728. exports.transpose = transpose;
  15729. exports.tree = tree;
  15730. exports.treemap = index$3;
  15731. exports.treemapBinary = binary;
  15732. exports.treemapDice = treemapDice;
  15733. exports.treemapResquarify = resquarify;
  15734. exports.treemapSlice = treemapSlice;
  15735. exports.treemapSliceDice = sliceDice;
  15736. exports.treemapSquarify = squarify;
  15737. exports.tsv = tsv$1;
  15738. exports.tsvFormat = tsvFormat;
  15739. exports.tsvFormatBody = tsvFormatBody;
  15740. exports.tsvFormatRow = tsvFormatRow;
  15741. exports.tsvFormatRows = tsvFormatRows;
  15742. exports.tsvFormatValue = tsvFormatValue;
  15743. exports.tsvParse = tsvParse;
  15744. exports.tsvParseRows = tsvParseRows;
  15745. exports.utcDay = utcDay;
  15746. exports.utcDays = utcDays;
  15747. exports.utcFriday = utcFriday;
  15748. exports.utcFridays = utcFridays;
  15749. exports.utcHour = utcHour;
  15750. exports.utcHours = utcHours;
  15751. exports.utcMillisecond = millisecond;
  15752. exports.utcMilliseconds = milliseconds;
  15753. exports.utcMinute = utcMinute;
  15754. exports.utcMinutes = utcMinutes;
  15755. exports.utcMonday = utcMonday;
  15756. exports.utcMondays = utcMondays;
  15757. exports.utcMonth = utcMonth;
  15758. exports.utcMonths = utcMonths;
  15759. exports.utcSaturday = utcSaturday;
  15760. exports.utcSaturdays = utcSaturdays;
  15761. exports.utcSecond = second;
  15762. exports.utcSeconds = seconds;
  15763. exports.utcSunday = utcSunday;
  15764. exports.utcSundays = utcSundays;
  15765. exports.utcThursday = utcThursday;
  15766. exports.utcThursdays = utcThursdays;
  15767. exports.utcTuesday = utcTuesday;
  15768. exports.utcTuesdays = utcTuesdays;
  15769. exports.utcWednesday = utcWednesday;
  15770. exports.utcWednesdays = utcWednesdays;
  15771. exports.utcWeek = utcSunday;
  15772. exports.utcWeeks = utcSundays;
  15773. exports.utcYear = utcYear;
  15774. exports.utcYears = utcYears;
  15775. exports.values = values;
  15776. exports.variance = variance;
  15777. exports.version = version;
  15778. exports.voronoi = voronoi;
  15779. exports.window = defaultView;
  15780. exports.xml = xml;
  15781. exports.zip = zip;
  15782. exports.zoom = zoom;
  15783. exports.zoomIdentity = identity$9;
  15784. exports.zoomTransform = transform$1;
  15785. Object.defineProperty(exports, '__esModule', { value: true });
  15786. }));