d3.js 457 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020
  1. // https://d3js.org Version 4.11.0. Copyright 2017 Mike Bostock.
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (factory((global.d3 = global.d3 || {})));
  6. }(this, (function (exports) { 'use strict';
  7. var version = "4.11.0";
  8. var ascending = function(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. };
  11. var bisector = function(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. var pairs = function(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. var cross = function(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. var descending = function(a, b) {
  70. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  71. };
  72. var number = function(x) {
  73. return x === null ? NaN : +x;
  74. };
  75. var variance = function(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. var deviation = function(array, f) {
  104. var v = variance(array, f);
  105. return v ? Math.sqrt(v) : v;
  106. };
  107. var extent = function(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. var constant = function(x) {
  145. return function() {
  146. return x;
  147. };
  148. };
  149. var identity = function(x) {
  150. return x;
  151. };
  152. var sequence = function(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. var e5 = Math.sqrt(10);
  164. var e2 = Math.sqrt(2);
  165. var ticks = function(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. var sturges = function(values) {
  207. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  208. };
  209. var histogram = function() {
  210. var value = identity,
  211. domain = extent,
  212. threshold = sturges;
  213. function histogram(data) {
  214. var i,
  215. n = data.length,
  216. x,
  217. values = new Array(n);
  218. for (i = 0; i < n; ++i) {
  219. values[i] = value(data[i], i, data);
  220. }
  221. var xz = domain(values),
  222. x0 = xz[0],
  223. x1 = xz[1],
  224. tz = threshold(values, x0, x1);
  225. // Convert number of thresholds into uniform thresholds.
  226. if (!Array.isArray(tz)) {
  227. tz = tickStep(x0, x1, tz);
  228. tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
  229. }
  230. // Remove any thresholds outside the domain.
  231. var m = tz.length;
  232. while (tz[0] <= x0) tz.shift(), --m;
  233. while (tz[m - 1] > x1) tz.pop(), --m;
  234. var bins = new Array(m + 1),
  235. bin;
  236. // Initialize bins.
  237. for (i = 0; i <= m; ++i) {
  238. bin = bins[i] = [];
  239. bin.x0 = i > 0 ? tz[i - 1] : x0;
  240. bin.x1 = i < m ? tz[i] : x1;
  241. }
  242. // Assign data to bins by value, ignoring any outside the domain.
  243. for (i = 0; i < n; ++i) {
  244. x = values[i];
  245. if (x0 <= x && x <= x1) {
  246. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  247. }
  248. }
  249. return bins;
  250. }
  251. histogram.value = function(_) {
  252. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  253. };
  254. histogram.domain = function(_) {
  255. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  256. };
  257. histogram.thresholds = function(_) {
  258. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  259. };
  260. return histogram;
  261. };
  262. var threshold = function(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. var freedmanDiaconis = function(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. var scott = function(values, min, max) {
  279. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  280. };
  281. var max = function(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. var mean = function(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. var median = function(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. var merge = function(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. var min = function(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. var permute = function(array, indexes) {
  403. var i = indexes.length, permutes = new Array(i);
  404. while (i--) permutes[i] = array[indexes[i]];
  405. return permutes;
  406. };
  407. var scan = function(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. var shuffle = function(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. var sum = function(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. var transpose = function(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. var zip = function() {
  464. return transpose(arguments);
  465. };
  466. var slice$1 = Array.prototype.slice;
  467. var identity$1 = function(x) {
  468. return x;
  469. };
  470. var top = 1;
  471. var right = 2;
  472. var bottom = 3;
  473. var left = 4;
  474. var epsilon = 1e-6;
  475. function translateX(x) {
  476. return "translate(" + (x + 0.5) + ",0)";
  477. }
  478. function translateY(y) {
  479. return "translate(0," + (y + 0.5) + ")";
  480. }
  481. function number$1(scale) {
  482. return function(d) {
  483. return +scale(d);
  484. };
  485. }
  486. function center(scale) {
  487. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  488. if (scale.round()) offset = Math.round(offset);
  489. return function(d) {
  490. return +scale(d) + offset;
  491. };
  492. }
  493. function entering() {
  494. return !this.__axis;
  495. }
  496. function axis(orient, scale) {
  497. var tickArguments = [],
  498. tickValues = null,
  499. tickFormat = null,
  500. tickSizeInner = 6,
  501. tickSizeOuter = 6,
  502. tickPadding = 3,
  503. k = orient === top || orient === left ? -1 : 1,
  504. x = orient === left || orient === right ? "x" : "y",
  505. transform = orient === top || orient === bottom ? translateX : translateY;
  506. function axis(context) {
  507. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  508. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  509. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  510. range = scale.range(),
  511. range0 = +range[0] + 0.5,
  512. range1 = +range[range.length - 1] + 0.5,
  513. position = (scale.bandwidth ? center : number$1)(scale.copy()),
  514. selection = context.selection ? context.selection() : context,
  515. path = selection.selectAll(".domain").data([null]),
  516. tick = selection.selectAll(".tick").data(values, scale).order(),
  517. tickExit = tick.exit(),
  518. tickEnter = tick.enter().append("g").attr("class", "tick"),
  519. line = tick.select("line"),
  520. text = tick.select("text");
  521. path = path.merge(path.enter().insert("path", ".tick")
  522. .attr("class", "domain")
  523. .attr("stroke", "#000"));
  524. tick = tick.merge(tickEnter);
  525. line = line.merge(tickEnter.append("line")
  526. .attr("stroke", "#000")
  527. .attr(x + "2", k * tickSizeInner));
  528. text = text.merge(tickEnter.append("text")
  529. .attr("fill", "#000")
  530. .attr(x, k * spacing)
  531. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  532. if (context !== selection) {
  533. path = path.transition(context);
  534. tick = tick.transition(context);
  535. line = line.transition(context);
  536. text = text.transition(context);
  537. tickExit = tickExit.transition(context)
  538. .attr("opacity", epsilon)
  539. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  540. tickEnter
  541. .attr("opacity", epsilon)
  542. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  543. }
  544. tickExit.remove();
  545. path
  546. .attr("d", orient === left || orient == right
  547. ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
  548. : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
  549. tick
  550. .attr("opacity", 1)
  551. .attr("transform", function(d) { return transform(position(d)); });
  552. line
  553. .attr(x + "2", k * tickSizeInner);
  554. text
  555. .attr(x, k * spacing)
  556. .text(format);
  557. selection.filter(entering)
  558. .attr("fill", "none")
  559. .attr("font-size", 10)
  560. .attr("font-family", "sans-serif")
  561. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  562. selection
  563. .each(function() { this.__axis = position; });
  564. }
  565. axis.scale = function(_) {
  566. return arguments.length ? (scale = _, axis) : scale;
  567. };
  568. axis.ticks = function() {
  569. return tickArguments = slice$1.call(arguments), axis;
  570. };
  571. axis.tickArguments = function(_) {
  572. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  573. };
  574. axis.tickValues = function(_) {
  575. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  576. };
  577. axis.tickFormat = function(_) {
  578. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  579. };
  580. axis.tickSize = function(_) {
  581. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  582. };
  583. axis.tickSizeInner = function(_) {
  584. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  585. };
  586. axis.tickSizeOuter = function(_) {
  587. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  588. };
  589. axis.tickPadding = function(_) {
  590. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  591. };
  592. return axis;
  593. }
  594. function axisTop(scale) {
  595. return axis(top, scale);
  596. }
  597. function axisRight(scale) {
  598. return axis(right, scale);
  599. }
  600. function axisBottom(scale) {
  601. return axis(bottom, scale);
  602. }
  603. function axisLeft(scale) {
  604. return axis(left, scale);
  605. }
  606. var noop = {value: function() {}};
  607. function dispatch() {
  608. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  609. if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
  610. _[t] = [];
  611. }
  612. return new Dispatch(_);
  613. }
  614. function Dispatch(_) {
  615. this._ = _;
  616. }
  617. function parseTypenames(typenames, types) {
  618. return typenames.trim().split(/^|\s+/).map(function(t) {
  619. var name = "", i = t.indexOf(".");
  620. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  621. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  622. return {type: t, name: name};
  623. });
  624. }
  625. Dispatch.prototype = dispatch.prototype = {
  626. constructor: Dispatch,
  627. on: function(typename, callback) {
  628. var _ = this._,
  629. T = parseTypenames(typename + "", _),
  630. t,
  631. i = -1,
  632. n = T.length;
  633. // If no callback was specified, return the callback of the given type and name.
  634. if (arguments.length < 2) {
  635. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  636. return;
  637. }
  638. // If a type was specified, set the callback for the given type and name.
  639. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  640. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  641. while (++i < n) {
  642. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  643. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  644. }
  645. return this;
  646. },
  647. copy: function() {
  648. var copy = {}, _ = this._;
  649. for (var t in _) copy[t] = _[t].slice();
  650. return new Dispatch(copy);
  651. },
  652. call: function(type, that) {
  653. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  654. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  655. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  656. },
  657. apply: function(type, that, args) {
  658. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  659. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  660. }
  661. };
  662. function get(type, name) {
  663. for (var i = 0, n = type.length, c; i < n; ++i) {
  664. if ((c = type[i]).name === name) {
  665. return c.value;
  666. }
  667. }
  668. }
  669. function set(type, name, callback) {
  670. for (var i = 0, n = type.length; i < n; ++i) {
  671. if (type[i].name === name) {
  672. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  673. break;
  674. }
  675. }
  676. if (callback != null) type.push({name: name, value: callback});
  677. return type;
  678. }
  679. var xhtml = "http://www.w3.org/1999/xhtml";
  680. var namespaces = {
  681. svg: "http://www.w3.org/2000/svg",
  682. xhtml: xhtml,
  683. xlink: "http://www.w3.org/1999/xlink",
  684. xml: "http://www.w3.org/XML/1998/namespace",
  685. xmlns: "http://www.w3.org/2000/xmlns/"
  686. };
  687. var namespace = function(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. var creator = function(name) {
  707. var fullname = namespace(name);
  708. return (fullname.local
  709. ? creatorFixed
  710. : creatorInherit)(fullname);
  711. };
  712. var nextId = 0;
  713. function local$1() {
  714. return new Local;
  715. }
  716. function Local() {
  717. this._ = "@" + (++nextId).toString(36);
  718. }
  719. Local.prototype = local$1.prototype = {
  720. constructor: Local,
  721. get: function(node) {
  722. var id = this._;
  723. while (!(id in node)) if (!(node = node.parentNode)) return;
  724. return node[id];
  725. },
  726. set: function(node, value) {
  727. return node[this._] = value;
  728. },
  729. remove: function(node) {
  730. return this._ in node && delete node[this._];
  731. },
  732. toString: function() {
  733. return this._;
  734. }
  735. };
  736. var matcher = function(selector) {
  737. return function() {
  738. return this.matches(selector);
  739. };
  740. };
  741. if (typeof document !== "undefined") {
  742. var element = document.documentElement;
  743. if (!element.matches) {
  744. var vendorMatches = element.webkitMatchesSelector
  745. || element.msMatchesSelector
  746. || element.mozMatchesSelector
  747. || element.oMatchesSelector;
  748. matcher = function(selector) {
  749. return function() {
  750. return vendorMatches.call(this, selector);
  751. };
  752. };
  753. }
  754. }
  755. var matcher$1 = matcher;
  756. var filterEvents = {};
  757. exports.event = null;
  758. if (typeof document !== "undefined") {
  759. var element$1 = document.documentElement;
  760. if (!("onmouseenter" in element$1)) {
  761. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  762. }
  763. }
  764. function filterContextListener(listener, index, group) {
  765. listener = contextListener(listener, index, group);
  766. return function(event) {
  767. var related = event.relatedTarget;
  768. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  769. listener.call(this, event);
  770. }
  771. };
  772. }
  773. function contextListener(listener, index, group) {
  774. return function(event1) {
  775. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  776. exports.event = event1;
  777. try {
  778. listener.call(this, this.__data__, index, group);
  779. } finally {
  780. exports.event = event0;
  781. }
  782. };
  783. }
  784. function parseTypenames$1(typenames) {
  785. return typenames.trim().split(/^|\s+/).map(function(t) {
  786. var name = "", i = t.indexOf(".");
  787. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  788. return {type: t, name: name};
  789. });
  790. }
  791. function onRemove(typename) {
  792. return function() {
  793. var on = this.__on;
  794. if (!on) return;
  795. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  796. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  797. this.removeEventListener(o.type, o.listener, o.capture);
  798. } else {
  799. on[++i] = o;
  800. }
  801. }
  802. if (++i) on.length = i;
  803. else delete this.__on;
  804. };
  805. }
  806. function onAdd(typename, value, capture) {
  807. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  808. return function(d, i, group) {
  809. var on = this.__on, o, listener = wrap(value, i, group);
  810. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  811. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  812. this.removeEventListener(o.type, o.listener, o.capture);
  813. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  814. o.value = value;
  815. return;
  816. }
  817. }
  818. this.addEventListener(typename.type, listener, capture);
  819. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  820. if (!on) this.__on = [o];
  821. else on.push(o);
  822. };
  823. }
  824. var selection_on = function(typename, value, capture) {
  825. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  826. if (arguments.length < 2) {
  827. var on = this.node().__on;
  828. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  829. for (i = 0, o = on[j]; i < n; ++i) {
  830. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  831. return o.value;
  832. }
  833. }
  834. }
  835. return;
  836. }
  837. on = value ? onAdd : onRemove;
  838. if (capture == null) capture = false;
  839. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  840. return this;
  841. };
  842. function customEvent(event1, listener, that, args) {
  843. var event0 = exports.event;
  844. event1.sourceEvent = exports.event;
  845. exports.event = event1;
  846. try {
  847. return listener.apply(that, args);
  848. } finally {
  849. exports.event = event0;
  850. }
  851. }
  852. var sourceEvent = function() {
  853. var current = exports.event, source;
  854. while (source = current.sourceEvent) current = source;
  855. return current;
  856. };
  857. var point = function(node, event) {
  858. var svg = node.ownerSVGElement || node;
  859. if (svg.createSVGPoint) {
  860. var point = svg.createSVGPoint();
  861. point.x = event.clientX, point.y = event.clientY;
  862. point = point.matrixTransform(node.getScreenCTM().inverse());
  863. return [point.x, point.y];
  864. }
  865. var rect = node.getBoundingClientRect();
  866. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  867. };
  868. var mouse = function(node) {
  869. var event = sourceEvent();
  870. if (event.changedTouches) event = event.changedTouches[0];
  871. return point(node, event);
  872. };
  873. function none() {}
  874. var selector = function(selector) {
  875. return selector == null ? none : function() {
  876. return this.querySelector(selector);
  877. };
  878. };
  879. var selection_select = function(select) {
  880. if (typeof select !== "function") select = selector(select);
  881. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  882. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  883. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  884. if ("__data__" in node) subnode.__data__ = node.__data__;
  885. subgroup[i] = subnode;
  886. }
  887. }
  888. }
  889. return new Selection(subgroups, this._parents);
  890. };
  891. function empty$1() {
  892. return [];
  893. }
  894. var selectorAll = function(selector) {
  895. return selector == null ? empty$1 : function() {
  896. return this.querySelectorAll(selector);
  897. };
  898. };
  899. var selection_selectAll = function(select) {
  900. if (typeof select !== "function") select = selectorAll(select);
  901. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  902. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  903. if (node = group[i]) {
  904. subgroups.push(select.call(node, node.__data__, i, group));
  905. parents.push(node);
  906. }
  907. }
  908. }
  909. return new Selection(subgroups, parents);
  910. };
  911. var selection_filter = function(match) {
  912. if (typeof match !== "function") match = matcher$1(match);
  913. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  914. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  915. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  916. subgroup.push(node);
  917. }
  918. }
  919. }
  920. return new Selection(subgroups, this._parents);
  921. };
  922. var sparse = function(update) {
  923. return new Array(update.length);
  924. };
  925. var selection_enter = function() {
  926. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  927. };
  928. function EnterNode(parent, datum) {
  929. this.ownerDocument = parent.ownerDocument;
  930. this.namespaceURI = parent.namespaceURI;
  931. this._next = null;
  932. this._parent = parent;
  933. this.__data__ = datum;
  934. }
  935. EnterNode.prototype = {
  936. constructor: EnterNode,
  937. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  938. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  939. querySelector: function(selector) { return this._parent.querySelector(selector); },
  940. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  941. };
  942. var constant$1 = function(x) {
  943. return function() {
  944. return x;
  945. };
  946. };
  947. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  948. function bindIndex(parent, group, enter, update, exit, data) {
  949. var i = 0,
  950. node,
  951. groupLength = group.length,
  952. dataLength = data.length;
  953. // Put any non-null nodes that fit into update.
  954. // Put any null nodes into enter.
  955. // Put any remaining data into enter.
  956. for (; i < dataLength; ++i) {
  957. if (node = group[i]) {
  958. node.__data__ = data[i];
  959. update[i] = node;
  960. } else {
  961. enter[i] = new EnterNode(parent, data[i]);
  962. }
  963. }
  964. // Put any non-null nodes that don’t fit into exit.
  965. for (; i < groupLength; ++i) {
  966. if (node = group[i]) {
  967. exit[i] = node;
  968. }
  969. }
  970. }
  971. function bindKey(parent, group, enter, update, exit, data, key) {
  972. var i,
  973. node,
  974. nodeByKeyValue = {},
  975. groupLength = group.length,
  976. dataLength = data.length,
  977. keyValues = new Array(groupLength),
  978. keyValue;
  979. // Compute the key for each node.
  980. // If multiple nodes have the same key, the duplicates are added to exit.
  981. for (i = 0; i < groupLength; ++i) {
  982. if (node = group[i]) {
  983. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  984. if (keyValue in nodeByKeyValue) {
  985. exit[i] = node;
  986. } else {
  987. nodeByKeyValue[keyValue] = node;
  988. }
  989. }
  990. }
  991. // Compute the key for each datum.
  992. // If there a node associated with this key, join and add it to update.
  993. // If there is not (or the key is a duplicate), add it to enter.
  994. for (i = 0; i < dataLength; ++i) {
  995. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  996. if (node = nodeByKeyValue[keyValue]) {
  997. update[i] = node;
  998. node.__data__ = data[i];
  999. nodeByKeyValue[keyValue] = null;
  1000. } else {
  1001. enter[i] = new EnterNode(parent, data[i]);
  1002. }
  1003. }
  1004. // Add any remaining nodes that were not bound to data to exit.
  1005. for (i = 0; i < groupLength; ++i) {
  1006. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  1007. exit[i] = node;
  1008. }
  1009. }
  1010. }
  1011. var selection_data = function(value, key) {
  1012. if (!value) {
  1013. data = new Array(this.size()), j = -1;
  1014. this.each(function(d) { data[++j] = d; });
  1015. return data;
  1016. }
  1017. var bind = key ? bindKey : bindIndex,
  1018. parents = this._parents,
  1019. groups = this._groups;
  1020. if (typeof value !== "function") value = constant$1(value);
  1021. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  1022. var parent = parents[j],
  1023. group = groups[j],
  1024. groupLength = group.length,
  1025. data = value.call(parent, parent && parent.__data__, j, parents),
  1026. dataLength = data.length,
  1027. enterGroup = enter[j] = new Array(dataLength),
  1028. updateGroup = update[j] = new Array(dataLength),
  1029. exitGroup = exit[j] = new Array(groupLength);
  1030. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  1031. // Now connect the enter nodes to their following update node, such that
  1032. // appendChild can insert the materialized enter node before this node,
  1033. // rather than at the end of the parent node.
  1034. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  1035. if (previous = enterGroup[i0]) {
  1036. if (i0 >= i1) i1 = i0 + 1;
  1037. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  1038. previous._next = next || null;
  1039. }
  1040. }
  1041. }
  1042. update = new Selection(update, parents);
  1043. update._enter = enter;
  1044. update._exit = exit;
  1045. return update;
  1046. };
  1047. var selection_exit = function() {
  1048. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  1049. };
  1050. var selection_merge = function(selection$$1) {
  1051. for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  1052. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  1053. if (node = group0[i] || group1[i]) {
  1054. merge[i] = node;
  1055. }
  1056. }
  1057. }
  1058. for (; j < m0; ++j) {
  1059. merges[j] = groups0[j];
  1060. }
  1061. return new Selection(merges, this._parents);
  1062. };
  1063. var selection_order = function() {
  1064. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  1065. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  1066. if (node = group[i]) {
  1067. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  1068. next = node;
  1069. }
  1070. }
  1071. }
  1072. return this;
  1073. };
  1074. var selection_sort = function(compare) {
  1075. if (!compare) compare = ascending$1;
  1076. function compareNode(a, b) {
  1077. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  1078. }
  1079. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  1080. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  1081. if (node = group[i]) {
  1082. sortgroup[i] = node;
  1083. }
  1084. }
  1085. sortgroup.sort(compareNode);
  1086. }
  1087. return new Selection(sortgroups, this._parents).order();
  1088. };
  1089. function ascending$1(a, b) {
  1090. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  1091. }
  1092. var selection_call = function() {
  1093. var callback = arguments[0];
  1094. arguments[0] = this;
  1095. callback.apply(null, arguments);
  1096. return this;
  1097. };
  1098. var selection_nodes = function() {
  1099. var nodes = new Array(this.size()), i = -1;
  1100. this.each(function() { nodes[++i] = this; });
  1101. return nodes;
  1102. };
  1103. var selection_node = function() {
  1104. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1105. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  1106. var node = group[i];
  1107. if (node) return node;
  1108. }
  1109. }
  1110. return null;
  1111. };
  1112. var selection_size = function() {
  1113. var size = 0;
  1114. this.each(function() { ++size; });
  1115. return size;
  1116. };
  1117. var selection_empty = function() {
  1118. return !this.node();
  1119. };
  1120. var selection_each = function(callback) {
  1121. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  1122. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  1123. if (node = group[i]) callback.call(node, node.__data__, i, group);
  1124. }
  1125. }
  1126. return this;
  1127. };
  1128. function attrRemove(name) {
  1129. return function() {
  1130. this.removeAttribute(name);
  1131. };
  1132. }
  1133. function attrRemoveNS(fullname) {
  1134. return function() {
  1135. this.removeAttributeNS(fullname.space, fullname.local);
  1136. };
  1137. }
  1138. function attrConstant(name, value) {
  1139. return function() {
  1140. this.setAttribute(name, value);
  1141. };
  1142. }
  1143. function attrConstantNS(fullname, value) {
  1144. return function() {
  1145. this.setAttributeNS(fullname.space, fullname.local, value);
  1146. };
  1147. }
  1148. function attrFunction(name, value) {
  1149. return function() {
  1150. var v = value.apply(this, arguments);
  1151. if (v == null) this.removeAttribute(name);
  1152. else this.setAttribute(name, v);
  1153. };
  1154. }
  1155. function attrFunctionNS(fullname, value) {
  1156. return function() {
  1157. var v = value.apply(this, arguments);
  1158. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1159. else this.setAttributeNS(fullname.space, fullname.local, v);
  1160. };
  1161. }
  1162. var selection_attr = function(name, value) {
  1163. var fullname = namespace(name);
  1164. if (arguments.length < 2) {
  1165. var node = this.node();
  1166. return fullname.local
  1167. ? node.getAttributeNS(fullname.space, fullname.local)
  1168. : node.getAttribute(fullname);
  1169. }
  1170. return this.each((value == null
  1171. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1172. ? (fullname.local ? attrFunctionNS : attrFunction)
  1173. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1174. };
  1175. var defaultView = function(node) {
  1176. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1177. || (node.document && node) // node is a Window
  1178. || node.defaultView; // node is a Document
  1179. };
  1180. function styleRemove(name) {
  1181. return function() {
  1182. this.style.removeProperty(name);
  1183. };
  1184. }
  1185. function styleConstant(name, value, priority) {
  1186. return function() {
  1187. this.style.setProperty(name, value, priority);
  1188. };
  1189. }
  1190. function styleFunction(name, value, priority) {
  1191. return function() {
  1192. var v = value.apply(this, arguments);
  1193. if (v == null) this.style.removeProperty(name);
  1194. else this.style.setProperty(name, v, priority);
  1195. };
  1196. }
  1197. var selection_style = function(name, value, priority) {
  1198. return arguments.length > 1
  1199. ? this.each((value == null
  1200. ? styleRemove : typeof value === "function"
  1201. ? styleFunction
  1202. : styleConstant)(name, value, priority == null ? "" : priority))
  1203. : styleValue(this.node(), name);
  1204. };
  1205. function styleValue(node, name) {
  1206. return node.style.getPropertyValue(name)
  1207. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1208. }
  1209. function propertyRemove(name) {
  1210. return function() {
  1211. delete this[name];
  1212. };
  1213. }
  1214. function propertyConstant(name, value) {
  1215. return function() {
  1216. this[name] = value;
  1217. };
  1218. }
  1219. function propertyFunction(name, value) {
  1220. return function() {
  1221. var v = value.apply(this, arguments);
  1222. if (v == null) delete this[name];
  1223. else this[name] = v;
  1224. };
  1225. }
  1226. var selection_property = function(name, value) {
  1227. return arguments.length > 1
  1228. ? this.each((value == null
  1229. ? propertyRemove : typeof value === "function"
  1230. ? propertyFunction
  1231. : propertyConstant)(name, value))
  1232. : this.node()[name];
  1233. };
  1234. function classArray(string) {
  1235. return string.trim().split(/^|\s+/);
  1236. }
  1237. function classList(node) {
  1238. return node.classList || new ClassList(node);
  1239. }
  1240. function ClassList(node) {
  1241. this._node = node;
  1242. this._names = classArray(node.getAttribute("class") || "");
  1243. }
  1244. ClassList.prototype = {
  1245. add: function(name) {
  1246. var i = this._names.indexOf(name);
  1247. if (i < 0) {
  1248. this._names.push(name);
  1249. this._node.setAttribute("class", this._names.join(" "));
  1250. }
  1251. },
  1252. remove: function(name) {
  1253. var i = this._names.indexOf(name);
  1254. if (i >= 0) {
  1255. this._names.splice(i, 1);
  1256. this._node.setAttribute("class", this._names.join(" "));
  1257. }
  1258. },
  1259. contains: function(name) {
  1260. return this._names.indexOf(name) >= 0;
  1261. }
  1262. };
  1263. function classedAdd(node, names) {
  1264. var list = classList(node), i = -1, n = names.length;
  1265. while (++i < n) list.add(names[i]);
  1266. }
  1267. function classedRemove(node, names) {
  1268. var list = classList(node), i = -1, n = names.length;
  1269. while (++i < n) list.remove(names[i]);
  1270. }
  1271. function classedTrue(names) {
  1272. return function() {
  1273. classedAdd(this, names);
  1274. };
  1275. }
  1276. function classedFalse(names) {
  1277. return function() {
  1278. classedRemove(this, names);
  1279. };
  1280. }
  1281. function classedFunction(names, value) {
  1282. return function() {
  1283. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1284. };
  1285. }
  1286. var selection_classed = function(name, value) {
  1287. var names = classArray(name + "");
  1288. if (arguments.length < 2) {
  1289. var list = classList(this.node()), i = -1, n = names.length;
  1290. while (++i < n) if (!list.contains(names[i])) return false;
  1291. return true;
  1292. }
  1293. return this.each((typeof value === "function"
  1294. ? classedFunction : value
  1295. ? classedTrue
  1296. : classedFalse)(names, value));
  1297. };
  1298. function textRemove() {
  1299. this.textContent = "";
  1300. }
  1301. function textConstant(value) {
  1302. return function() {
  1303. this.textContent = value;
  1304. };
  1305. }
  1306. function textFunction(value) {
  1307. return function() {
  1308. var v = value.apply(this, arguments);
  1309. this.textContent = v == null ? "" : v;
  1310. };
  1311. }
  1312. var selection_text = function(value) {
  1313. return arguments.length
  1314. ? this.each(value == null
  1315. ? textRemove : (typeof value === "function"
  1316. ? textFunction
  1317. : textConstant)(value))
  1318. : this.node().textContent;
  1319. };
  1320. function htmlRemove() {
  1321. this.innerHTML = "";
  1322. }
  1323. function htmlConstant(value) {
  1324. return function() {
  1325. this.innerHTML = value;
  1326. };
  1327. }
  1328. function htmlFunction(value) {
  1329. return function() {
  1330. var v = value.apply(this, arguments);
  1331. this.innerHTML = v == null ? "" : v;
  1332. };
  1333. }
  1334. var selection_html = function(value) {
  1335. return arguments.length
  1336. ? this.each(value == null
  1337. ? htmlRemove : (typeof value === "function"
  1338. ? htmlFunction
  1339. : htmlConstant)(value))
  1340. : this.node().innerHTML;
  1341. };
  1342. function raise() {
  1343. if (this.nextSibling) this.parentNode.appendChild(this);
  1344. }
  1345. var selection_raise = function() {
  1346. return this.each(raise);
  1347. };
  1348. function lower() {
  1349. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1350. }
  1351. var selection_lower = function() {
  1352. return this.each(lower);
  1353. };
  1354. var selection_append = function(name) {
  1355. var create = typeof name === "function" ? name : creator(name);
  1356. return this.select(function() {
  1357. return this.appendChild(create.apply(this, arguments));
  1358. });
  1359. };
  1360. function constantNull() {
  1361. return null;
  1362. }
  1363. var selection_insert = function(name, before) {
  1364. var create = typeof name === "function" ? name : creator(name),
  1365. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1366. return this.select(function() {
  1367. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1368. });
  1369. };
  1370. function remove() {
  1371. var parent = this.parentNode;
  1372. if (parent) parent.removeChild(this);
  1373. }
  1374. var selection_remove = function() {
  1375. return this.each(remove);
  1376. };
  1377. var selection_datum = function(value) {
  1378. return arguments.length
  1379. ? this.property("__data__", value)
  1380. : this.node().__data__;
  1381. };
  1382. function dispatchEvent(node, type, params) {
  1383. var window = defaultView(node),
  1384. event = window.CustomEvent;
  1385. if (typeof event === "function") {
  1386. event = new event(type, params);
  1387. } else {
  1388. event = window.document.createEvent("Event");
  1389. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1390. else event.initEvent(type, false, false);
  1391. }
  1392. node.dispatchEvent(event);
  1393. }
  1394. function dispatchConstant(type, params) {
  1395. return function() {
  1396. return dispatchEvent(this, type, params);
  1397. };
  1398. }
  1399. function dispatchFunction(type, params) {
  1400. return function() {
  1401. return dispatchEvent(this, type, params.apply(this, arguments));
  1402. };
  1403. }
  1404. var selection_dispatch = function(type, params) {
  1405. return this.each((typeof params === "function"
  1406. ? dispatchFunction
  1407. : dispatchConstant)(type, params));
  1408. };
  1409. var root = [null];
  1410. function Selection(groups, parents) {
  1411. this._groups = groups;
  1412. this._parents = parents;
  1413. }
  1414. function selection() {
  1415. return new Selection([[document.documentElement]], root);
  1416. }
  1417. Selection.prototype = selection.prototype = {
  1418. constructor: Selection,
  1419. select: selection_select,
  1420. selectAll: selection_selectAll,
  1421. filter: selection_filter,
  1422. data: selection_data,
  1423. enter: selection_enter,
  1424. exit: selection_exit,
  1425. merge: selection_merge,
  1426. order: selection_order,
  1427. sort: selection_sort,
  1428. call: selection_call,
  1429. nodes: selection_nodes,
  1430. node: selection_node,
  1431. size: selection_size,
  1432. empty: selection_empty,
  1433. each: selection_each,
  1434. attr: selection_attr,
  1435. style: selection_style,
  1436. property: selection_property,
  1437. classed: selection_classed,
  1438. text: selection_text,
  1439. html: selection_html,
  1440. raise: selection_raise,
  1441. lower: selection_lower,
  1442. append: selection_append,
  1443. insert: selection_insert,
  1444. remove: selection_remove,
  1445. datum: selection_datum,
  1446. on: selection_on,
  1447. dispatch: selection_dispatch
  1448. };
  1449. var select = function(selector) {
  1450. return typeof selector === "string"
  1451. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1452. : new Selection([[selector]], root);
  1453. };
  1454. var selectAll = function(selector) {
  1455. return typeof selector === "string"
  1456. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1457. : new Selection([selector == null ? [] : selector], root);
  1458. };
  1459. var touch = function(node, touches, identifier) {
  1460. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1461. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1462. if ((touch = touches[i]).identifier === identifier) {
  1463. return point(node, touch);
  1464. }
  1465. }
  1466. return null;
  1467. };
  1468. var touches = function(node, touches) {
  1469. if (touches == null) touches = sourceEvent().touches;
  1470. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1471. points[i] = point(node, touches[i]);
  1472. }
  1473. return points;
  1474. };
  1475. function nopropagation() {
  1476. exports.event.stopImmediatePropagation();
  1477. }
  1478. var noevent = function() {
  1479. exports.event.preventDefault();
  1480. exports.event.stopImmediatePropagation();
  1481. };
  1482. var dragDisable = function(view) {
  1483. var root = view.document.documentElement,
  1484. selection = select(view).on("dragstart.drag", noevent, true);
  1485. if ("onselectstart" in root) {
  1486. selection.on("selectstart.drag", noevent, true);
  1487. } else {
  1488. root.__noselect = root.style.MozUserSelect;
  1489. root.style.MozUserSelect = "none";
  1490. }
  1491. };
  1492. function yesdrag(view, noclick) {
  1493. var root = view.document.documentElement,
  1494. selection = select(view).on("dragstart.drag", null);
  1495. if (noclick) {
  1496. selection.on("click.drag", noevent, true);
  1497. setTimeout(function() { selection.on("click.drag", null); }, 0);
  1498. }
  1499. if ("onselectstart" in root) {
  1500. selection.on("selectstart.drag", null);
  1501. } else {
  1502. root.style.MozUserSelect = root.__noselect;
  1503. delete root.__noselect;
  1504. }
  1505. }
  1506. var constant$2 = function(x) {
  1507. return function() {
  1508. return x;
  1509. };
  1510. };
  1511. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1512. this.target = target;
  1513. this.type = type;
  1514. this.subject = subject;
  1515. this.identifier = id;
  1516. this.active = active;
  1517. this.x = x;
  1518. this.y = y;
  1519. this.dx = dx;
  1520. this.dy = dy;
  1521. this._ = dispatch;
  1522. }
  1523. DragEvent.prototype.on = function() {
  1524. var value = this._.on.apply(this._, arguments);
  1525. return value === this._ ? this : value;
  1526. };
  1527. // Ignore right-click, since that should open the context menu.
  1528. function defaultFilter$1() {
  1529. return !exports.event.button;
  1530. }
  1531. function defaultContainer() {
  1532. return this.parentNode;
  1533. }
  1534. function defaultSubject(d) {
  1535. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1536. }
  1537. function defaultTouchable() {
  1538. return "ontouchstart" in this;
  1539. }
  1540. var drag = function() {
  1541. var filter = defaultFilter$1,
  1542. container = defaultContainer,
  1543. subject = defaultSubject,
  1544. touchable = defaultTouchable,
  1545. gestures = {},
  1546. listeners = dispatch("start", "drag", "end"),
  1547. active = 0,
  1548. mousedownx,
  1549. mousedowny,
  1550. mousemoving,
  1551. touchending,
  1552. clickDistance2 = 0;
  1553. function drag(selection) {
  1554. selection
  1555. .on("mousedown.drag", mousedowned)
  1556. .filter(touchable)
  1557. .on("touchstart.drag", touchstarted)
  1558. .on("touchmove.drag", touchmoved)
  1559. .on("touchend.drag touchcancel.drag", touchended)
  1560. .style("touch-action", "none")
  1561. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1562. }
  1563. function mousedowned() {
  1564. if (touchending || !filter.apply(this, arguments)) return;
  1565. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1566. if (!gesture) return;
  1567. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1568. dragDisable(exports.event.view);
  1569. nopropagation();
  1570. mousemoving = false;
  1571. mousedownx = exports.event.clientX;
  1572. mousedowny = exports.event.clientY;
  1573. gesture("start");
  1574. }
  1575. function mousemoved() {
  1576. noevent();
  1577. if (!mousemoving) {
  1578. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1579. mousemoving = dx * dx + dy * dy > clickDistance2;
  1580. }
  1581. gestures.mouse("drag");
  1582. }
  1583. function mouseupped() {
  1584. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1585. yesdrag(exports.event.view, mousemoving);
  1586. noevent();
  1587. gestures.mouse("end");
  1588. }
  1589. function touchstarted() {
  1590. if (!filter.apply(this, arguments)) return;
  1591. var touches = exports.event.changedTouches,
  1592. c = container.apply(this, arguments),
  1593. n = touches.length, i, gesture;
  1594. for (i = 0; i < n; ++i) {
  1595. if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
  1596. nopropagation();
  1597. gesture("start");
  1598. }
  1599. }
  1600. }
  1601. function touchmoved() {
  1602. var touches = exports.event.changedTouches,
  1603. n = touches.length, i, gesture;
  1604. for (i = 0; i < n; ++i) {
  1605. if (gesture = gestures[touches[i].identifier]) {
  1606. noevent();
  1607. gesture("drag");
  1608. }
  1609. }
  1610. }
  1611. function touchended() {
  1612. var touches = exports.event.changedTouches,
  1613. n = touches.length, i, gesture;
  1614. if (touchending) clearTimeout(touchending);
  1615. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1616. for (i = 0; i < n; ++i) {
  1617. if (gesture = gestures[touches[i].identifier]) {
  1618. nopropagation();
  1619. gesture("end");
  1620. }
  1621. }
  1622. }
  1623. function beforestart(id, container, point, that, args) {
  1624. var p = point(container, id), s, dx, dy,
  1625. sublisteners = listeners.copy();
  1626. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1627. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1628. dx = s.x - p[0] || 0;
  1629. dy = s.y - p[1] || 0;
  1630. return true;
  1631. })) return;
  1632. return function gesture(type) {
  1633. var p0 = p, n;
  1634. switch (type) {
  1635. case "start": gestures[id] = gesture, n = active++; break;
  1636. case "end": delete gestures[id], --active; // nobreak
  1637. case "drag": p = point(container, id), n = active; break;
  1638. }
  1639. 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]);
  1640. };
  1641. }
  1642. drag.filter = function(_) {
  1643. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1644. };
  1645. drag.container = function(_) {
  1646. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1647. };
  1648. drag.subject = function(_) {
  1649. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1650. };
  1651. drag.touchable = function(_) {
  1652. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
  1653. };
  1654. drag.on = function() {
  1655. var value = listeners.on.apply(listeners, arguments);
  1656. return value === listeners ? drag : value;
  1657. };
  1658. drag.clickDistance = function(_) {
  1659. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1660. };
  1661. return drag;
  1662. };
  1663. var define = function(constructor, factory, prototype) {
  1664. constructor.prototype = factory.prototype = prototype;
  1665. prototype.constructor = constructor;
  1666. };
  1667. function extend(parent, definition) {
  1668. var prototype = Object.create(parent.prototype);
  1669. for (var key in definition) prototype[key] = definition[key];
  1670. return prototype;
  1671. }
  1672. function Color() {}
  1673. var darker = 0.7;
  1674. var brighter = 1 / darker;
  1675. var reI = "\\s*([+-]?\\d+)\\s*";
  1676. var reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*";
  1677. var reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*";
  1678. var reHex3 = /^#([0-9a-f]{3})$/;
  1679. var reHex6 = /^#([0-9a-f]{6})$/;
  1680. var reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$");
  1681. var reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$");
  1682. var reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$");
  1683. var reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$");
  1684. var reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$");
  1685. var reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1686. var named = {
  1687. aliceblue: 0xf0f8ff,
  1688. antiquewhite: 0xfaebd7,
  1689. aqua: 0x00ffff,
  1690. aquamarine: 0x7fffd4,
  1691. azure: 0xf0ffff,
  1692. beige: 0xf5f5dc,
  1693. bisque: 0xffe4c4,
  1694. black: 0x000000,
  1695. blanchedalmond: 0xffebcd,
  1696. blue: 0x0000ff,
  1697. blueviolet: 0x8a2be2,
  1698. brown: 0xa52a2a,
  1699. burlywood: 0xdeb887,
  1700. cadetblue: 0x5f9ea0,
  1701. chartreuse: 0x7fff00,
  1702. chocolate: 0xd2691e,
  1703. coral: 0xff7f50,
  1704. cornflowerblue: 0x6495ed,
  1705. cornsilk: 0xfff8dc,
  1706. crimson: 0xdc143c,
  1707. cyan: 0x00ffff,
  1708. darkblue: 0x00008b,
  1709. darkcyan: 0x008b8b,
  1710. darkgoldenrod: 0xb8860b,
  1711. darkgray: 0xa9a9a9,
  1712. darkgreen: 0x006400,
  1713. darkgrey: 0xa9a9a9,
  1714. darkkhaki: 0xbdb76b,
  1715. darkmagenta: 0x8b008b,
  1716. darkolivegreen: 0x556b2f,
  1717. darkorange: 0xff8c00,
  1718. darkorchid: 0x9932cc,
  1719. darkred: 0x8b0000,
  1720. darksalmon: 0xe9967a,
  1721. darkseagreen: 0x8fbc8f,
  1722. darkslateblue: 0x483d8b,
  1723. darkslategray: 0x2f4f4f,
  1724. darkslategrey: 0x2f4f4f,
  1725. darkturquoise: 0x00ced1,
  1726. darkviolet: 0x9400d3,
  1727. deeppink: 0xff1493,
  1728. deepskyblue: 0x00bfff,
  1729. dimgray: 0x696969,
  1730. dimgrey: 0x696969,
  1731. dodgerblue: 0x1e90ff,
  1732. firebrick: 0xb22222,
  1733. floralwhite: 0xfffaf0,
  1734. forestgreen: 0x228b22,
  1735. fuchsia: 0xff00ff,
  1736. gainsboro: 0xdcdcdc,
  1737. ghostwhite: 0xf8f8ff,
  1738. gold: 0xffd700,
  1739. goldenrod: 0xdaa520,
  1740. gray: 0x808080,
  1741. green: 0x008000,
  1742. greenyellow: 0xadff2f,
  1743. grey: 0x808080,
  1744. honeydew: 0xf0fff0,
  1745. hotpink: 0xff69b4,
  1746. indianred: 0xcd5c5c,
  1747. indigo: 0x4b0082,
  1748. ivory: 0xfffff0,
  1749. khaki: 0xf0e68c,
  1750. lavender: 0xe6e6fa,
  1751. lavenderblush: 0xfff0f5,
  1752. lawngreen: 0x7cfc00,
  1753. lemonchiffon: 0xfffacd,
  1754. lightblue: 0xadd8e6,
  1755. lightcoral: 0xf08080,
  1756. lightcyan: 0xe0ffff,
  1757. lightgoldenrodyellow: 0xfafad2,
  1758. lightgray: 0xd3d3d3,
  1759. lightgreen: 0x90ee90,
  1760. lightgrey: 0xd3d3d3,
  1761. lightpink: 0xffb6c1,
  1762. lightsalmon: 0xffa07a,
  1763. lightseagreen: 0x20b2aa,
  1764. lightskyblue: 0x87cefa,
  1765. lightslategray: 0x778899,
  1766. lightslategrey: 0x778899,
  1767. lightsteelblue: 0xb0c4de,
  1768. lightyellow: 0xffffe0,
  1769. lime: 0x00ff00,
  1770. limegreen: 0x32cd32,
  1771. linen: 0xfaf0e6,
  1772. magenta: 0xff00ff,
  1773. maroon: 0x800000,
  1774. mediumaquamarine: 0x66cdaa,
  1775. mediumblue: 0x0000cd,
  1776. mediumorchid: 0xba55d3,
  1777. mediumpurple: 0x9370db,
  1778. mediumseagreen: 0x3cb371,
  1779. mediumslateblue: 0x7b68ee,
  1780. mediumspringgreen: 0x00fa9a,
  1781. mediumturquoise: 0x48d1cc,
  1782. mediumvioletred: 0xc71585,
  1783. midnightblue: 0x191970,
  1784. mintcream: 0xf5fffa,
  1785. mistyrose: 0xffe4e1,
  1786. moccasin: 0xffe4b5,
  1787. navajowhite: 0xffdead,
  1788. navy: 0x000080,
  1789. oldlace: 0xfdf5e6,
  1790. olive: 0x808000,
  1791. olivedrab: 0x6b8e23,
  1792. orange: 0xffa500,
  1793. orangered: 0xff4500,
  1794. orchid: 0xda70d6,
  1795. palegoldenrod: 0xeee8aa,
  1796. palegreen: 0x98fb98,
  1797. paleturquoise: 0xafeeee,
  1798. palevioletred: 0xdb7093,
  1799. papayawhip: 0xffefd5,
  1800. peachpuff: 0xffdab9,
  1801. peru: 0xcd853f,
  1802. pink: 0xffc0cb,
  1803. plum: 0xdda0dd,
  1804. powderblue: 0xb0e0e6,
  1805. purple: 0x800080,
  1806. rebeccapurple: 0x663399,
  1807. red: 0xff0000,
  1808. rosybrown: 0xbc8f8f,
  1809. royalblue: 0x4169e1,
  1810. saddlebrown: 0x8b4513,
  1811. salmon: 0xfa8072,
  1812. sandybrown: 0xf4a460,
  1813. seagreen: 0x2e8b57,
  1814. seashell: 0xfff5ee,
  1815. sienna: 0xa0522d,
  1816. silver: 0xc0c0c0,
  1817. skyblue: 0x87ceeb,
  1818. slateblue: 0x6a5acd,
  1819. slategray: 0x708090,
  1820. slategrey: 0x708090,
  1821. snow: 0xfffafa,
  1822. springgreen: 0x00ff7f,
  1823. steelblue: 0x4682b4,
  1824. tan: 0xd2b48c,
  1825. teal: 0x008080,
  1826. thistle: 0xd8bfd8,
  1827. tomato: 0xff6347,
  1828. turquoise: 0x40e0d0,
  1829. violet: 0xee82ee,
  1830. wheat: 0xf5deb3,
  1831. white: 0xffffff,
  1832. whitesmoke: 0xf5f5f5,
  1833. yellow: 0xffff00,
  1834. yellowgreen: 0x9acd32
  1835. };
  1836. define(Color, color, {
  1837. displayable: function() {
  1838. return this.rgb().displayable();
  1839. },
  1840. toString: function() {
  1841. return this.rgb() + "";
  1842. }
  1843. });
  1844. function color(format) {
  1845. var m;
  1846. format = (format + "").trim().toLowerCase();
  1847. return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
  1848. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  1849. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1850. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1851. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1852. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1853. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1854. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1855. : named.hasOwnProperty(format) ? rgbn(named[format])
  1856. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1857. : null;
  1858. }
  1859. function rgbn(n) {
  1860. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1861. }
  1862. function rgba(r, g, b, a) {
  1863. if (a <= 0) r = g = b = NaN;
  1864. return new Rgb(r, g, b, a);
  1865. }
  1866. function rgbConvert(o) {
  1867. if (!(o instanceof Color)) o = color(o);
  1868. if (!o) return new Rgb;
  1869. o = o.rgb();
  1870. return new Rgb(o.r, o.g, o.b, o.opacity);
  1871. }
  1872. function rgb(r, g, b, opacity) {
  1873. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1874. }
  1875. function Rgb(r, g, b, opacity) {
  1876. this.r = +r;
  1877. this.g = +g;
  1878. this.b = +b;
  1879. this.opacity = +opacity;
  1880. }
  1881. define(Rgb, rgb, extend(Color, {
  1882. brighter: function(k) {
  1883. k = k == null ? brighter : Math.pow(brighter, k);
  1884. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1885. },
  1886. darker: function(k) {
  1887. k = k == null ? darker : Math.pow(darker, k);
  1888. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1889. },
  1890. rgb: function() {
  1891. return this;
  1892. },
  1893. displayable: function() {
  1894. return (0 <= this.r && this.r <= 255)
  1895. && (0 <= this.g && this.g <= 255)
  1896. && (0 <= this.b && this.b <= 255)
  1897. && (0 <= this.opacity && this.opacity <= 1);
  1898. },
  1899. toString: function() {
  1900. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1901. return (a === 1 ? "rgb(" : "rgba(")
  1902. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1903. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1904. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1905. + (a === 1 ? ")" : ", " + a + ")");
  1906. }
  1907. }));
  1908. function hsla(h, s, l, a) {
  1909. if (a <= 0) h = s = l = NaN;
  1910. else if (l <= 0 || l >= 1) h = s = NaN;
  1911. else if (s <= 0) h = NaN;
  1912. return new Hsl(h, s, l, a);
  1913. }
  1914. function hslConvert(o) {
  1915. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1916. if (!(o instanceof Color)) o = color(o);
  1917. if (!o) return new Hsl;
  1918. if (o instanceof Hsl) return o;
  1919. o = o.rgb();
  1920. var r = o.r / 255,
  1921. g = o.g / 255,
  1922. b = o.b / 255,
  1923. min = Math.min(r, g, b),
  1924. max = Math.max(r, g, b),
  1925. h = NaN,
  1926. s = max - min,
  1927. l = (max + min) / 2;
  1928. if (s) {
  1929. if (r === max) h = (g - b) / s + (g < b) * 6;
  1930. else if (g === max) h = (b - r) / s + 2;
  1931. else h = (r - g) / s + 4;
  1932. s /= l < 0.5 ? max + min : 2 - max - min;
  1933. h *= 60;
  1934. } else {
  1935. s = l > 0 && l < 1 ? 0 : h;
  1936. }
  1937. return new Hsl(h, s, l, o.opacity);
  1938. }
  1939. function hsl(h, s, l, opacity) {
  1940. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1941. }
  1942. function Hsl(h, s, l, opacity) {
  1943. this.h = +h;
  1944. this.s = +s;
  1945. this.l = +l;
  1946. this.opacity = +opacity;
  1947. }
  1948. define(Hsl, hsl, extend(Color, {
  1949. brighter: function(k) {
  1950. k = k == null ? brighter : Math.pow(brighter, k);
  1951. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1952. },
  1953. darker: function(k) {
  1954. k = k == null ? darker : Math.pow(darker, k);
  1955. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1956. },
  1957. rgb: function() {
  1958. var h = this.h % 360 + (this.h < 0) * 360,
  1959. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1960. l = this.l,
  1961. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1962. m1 = 2 * l - m2;
  1963. return new Rgb(
  1964. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  1965. hsl2rgb(h, m1, m2),
  1966. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  1967. this.opacity
  1968. );
  1969. },
  1970. displayable: function() {
  1971. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  1972. && (0 <= this.l && this.l <= 1)
  1973. && (0 <= this.opacity && this.opacity <= 1);
  1974. }
  1975. }));
  1976. /* From FvD 13.37, CSS Color Module Level 3 */
  1977. function hsl2rgb(h, m1, m2) {
  1978. return (h < 60 ? m1 + (m2 - m1) * h / 60
  1979. : h < 180 ? m2
  1980. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  1981. : m1) * 255;
  1982. }
  1983. var deg2rad = Math.PI / 180;
  1984. var rad2deg = 180 / Math.PI;
  1985. var Kn = 18;
  1986. var Xn = 0.950470;
  1987. var Yn = 1;
  1988. var Zn = 1.088830;
  1989. var t0 = 4 / 29;
  1990. var t1 = 6 / 29;
  1991. var t2 = 3 * t1 * t1;
  1992. var t3 = t1 * t1 * t1;
  1993. function labConvert(o) {
  1994. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  1995. if (o instanceof Hcl) {
  1996. var h = o.h * deg2rad;
  1997. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  1998. }
  1999. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2000. var b = rgb2xyz(o.r),
  2001. a = rgb2xyz(o.g),
  2002. l = rgb2xyz(o.b),
  2003. x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
  2004. y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
  2005. z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
  2006. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2007. }
  2008. function lab(l, a, b, opacity) {
  2009. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2010. }
  2011. function Lab(l, a, b, opacity) {
  2012. this.l = +l;
  2013. this.a = +a;
  2014. this.b = +b;
  2015. this.opacity = +opacity;
  2016. }
  2017. define(Lab, lab, extend(Color, {
  2018. brighter: function(k) {
  2019. return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2020. },
  2021. darker: function(k) {
  2022. return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2023. },
  2024. rgb: function() {
  2025. var y = (this.l + 16) / 116,
  2026. x = isNaN(this.a) ? y : y + this.a / 500,
  2027. z = isNaN(this.b) ? y : y - this.b / 200;
  2028. y = Yn * lab2xyz(y);
  2029. x = Xn * lab2xyz(x);
  2030. z = Zn * lab2xyz(z);
  2031. return new Rgb(
  2032. xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
  2033. xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
  2034. xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
  2035. this.opacity
  2036. );
  2037. }
  2038. }));
  2039. function xyz2lab(t) {
  2040. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2041. }
  2042. function lab2xyz(t) {
  2043. return t > t1 ? t * t * t : t2 * (t - t0);
  2044. }
  2045. function xyz2rgb(x) {
  2046. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2047. }
  2048. function rgb2xyz(x) {
  2049. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2050. }
  2051. function hclConvert(o) {
  2052. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2053. if (!(o instanceof Lab)) o = labConvert(o);
  2054. var h = Math.atan2(o.b, o.a) * rad2deg;
  2055. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2056. }
  2057. function hcl(h, c, l, opacity) {
  2058. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2059. }
  2060. function Hcl(h, c, l, opacity) {
  2061. this.h = +h;
  2062. this.c = +c;
  2063. this.l = +l;
  2064. this.opacity = +opacity;
  2065. }
  2066. define(Hcl, hcl, extend(Color, {
  2067. brighter: function(k) {
  2068. return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
  2069. },
  2070. darker: function(k) {
  2071. return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
  2072. },
  2073. rgb: function() {
  2074. return labConvert(this).rgb();
  2075. }
  2076. }));
  2077. var A = -0.14861;
  2078. var B = +1.78277;
  2079. var C = -0.29227;
  2080. var D = -0.90649;
  2081. var E = +1.97294;
  2082. var ED = E * D;
  2083. var EB = E * B;
  2084. var BC_DA = B * C - D * A;
  2085. function cubehelixConvert(o) {
  2086. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2087. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2088. var r = o.r / 255,
  2089. g = o.g / 255,
  2090. b = o.b / 255,
  2091. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2092. bl = b - l,
  2093. k = (E * (g - l) - C * bl) / D,
  2094. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2095. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2096. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2097. }
  2098. function cubehelix(h, s, l, opacity) {
  2099. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2100. }
  2101. function Cubehelix(h, s, l, opacity) {
  2102. this.h = +h;
  2103. this.s = +s;
  2104. this.l = +l;
  2105. this.opacity = +opacity;
  2106. }
  2107. define(Cubehelix, cubehelix, extend(Color, {
  2108. brighter: function(k) {
  2109. k = k == null ? brighter : Math.pow(brighter, k);
  2110. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2111. },
  2112. darker: function(k) {
  2113. k = k == null ? darker : Math.pow(darker, k);
  2114. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2115. },
  2116. rgb: function() {
  2117. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2118. l = +this.l,
  2119. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2120. cosh = Math.cos(h),
  2121. sinh = Math.sin(h);
  2122. return new Rgb(
  2123. 255 * (l + a * (A * cosh + B * sinh)),
  2124. 255 * (l + a * (C * cosh + D * sinh)),
  2125. 255 * (l + a * (E * cosh)),
  2126. this.opacity
  2127. );
  2128. }
  2129. }));
  2130. function basis(t1, v0, v1, v2, v3) {
  2131. var t2 = t1 * t1, t3 = t2 * t1;
  2132. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2133. + (4 - 6 * t2 + 3 * t3) * v1
  2134. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2135. + t3 * v3) / 6;
  2136. }
  2137. var basis$1 = function(values) {
  2138. var n = values.length - 1;
  2139. return function(t) {
  2140. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2141. v1 = values[i],
  2142. v2 = values[i + 1],
  2143. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2144. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2145. return basis((t - i / n) * n, v0, v1, v2, v3);
  2146. };
  2147. };
  2148. var basisClosed = function(values) {
  2149. var n = values.length;
  2150. return function(t) {
  2151. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2152. v0 = values[(i + n - 1) % n],
  2153. v1 = values[i % n],
  2154. v2 = values[(i + 1) % n],
  2155. v3 = values[(i + 2) % n];
  2156. return basis((t - i / n) * n, v0, v1, v2, v3);
  2157. };
  2158. };
  2159. var constant$3 = function(x) {
  2160. return function() {
  2161. return x;
  2162. };
  2163. };
  2164. function linear(a, d) {
  2165. return function(t) {
  2166. return a + t * d;
  2167. };
  2168. }
  2169. function exponential(a, b, y) {
  2170. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2171. return Math.pow(a + t * b, y);
  2172. };
  2173. }
  2174. function hue(a, b) {
  2175. var d = b - a;
  2176. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2177. }
  2178. function gamma(y) {
  2179. return (y = +y) === 1 ? nogamma : function(a, b) {
  2180. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2181. };
  2182. }
  2183. function nogamma(a, b) {
  2184. var d = b - a;
  2185. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2186. }
  2187. var interpolateRgb = (function rgbGamma(y) {
  2188. var color$$1 = gamma(y);
  2189. function rgb$$1(start, end) {
  2190. var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
  2191. g = color$$1(start.g, end.g),
  2192. b = color$$1(start.b, end.b),
  2193. opacity = nogamma(start.opacity, end.opacity);
  2194. return function(t) {
  2195. start.r = r(t);
  2196. start.g = g(t);
  2197. start.b = b(t);
  2198. start.opacity = opacity(t);
  2199. return start + "";
  2200. };
  2201. }
  2202. rgb$$1.gamma = rgbGamma;
  2203. return rgb$$1;
  2204. })(1);
  2205. function rgbSpline(spline) {
  2206. return function(colors) {
  2207. var n = colors.length,
  2208. r = new Array(n),
  2209. g = new Array(n),
  2210. b = new Array(n),
  2211. i, color$$1;
  2212. for (i = 0; i < n; ++i) {
  2213. color$$1 = rgb(colors[i]);
  2214. r[i] = color$$1.r || 0;
  2215. g[i] = color$$1.g || 0;
  2216. b[i] = color$$1.b || 0;
  2217. }
  2218. r = spline(r);
  2219. g = spline(g);
  2220. b = spline(b);
  2221. color$$1.opacity = 1;
  2222. return function(t) {
  2223. color$$1.r = r(t);
  2224. color$$1.g = g(t);
  2225. color$$1.b = b(t);
  2226. return color$$1 + "";
  2227. };
  2228. };
  2229. }
  2230. var rgbBasis = rgbSpline(basis$1);
  2231. var rgbBasisClosed = rgbSpline(basisClosed);
  2232. var array$1 = function(a, b) {
  2233. var nb = b ? b.length : 0,
  2234. na = a ? Math.min(nb, a.length) : 0,
  2235. x = new Array(nb),
  2236. c = new Array(nb),
  2237. i;
  2238. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2239. for (; i < nb; ++i) c[i] = b[i];
  2240. return function(t) {
  2241. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2242. return c;
  2243. };
  2244. };
  2245. var date = function(a, b) {
  2246. var d = new Date;
  2247. return a = +a, b -= a, function(t) {
  2248. return d.setTime(a + b * t), d;
  2249. };
  2250. };
  2251. var reinterpolate = function(a, b) {
  2252. return a = +a, b -= a, function(t) {
  2253. return a + b * t;
  2254. };
  2255. };
  2256. var object = function(a, b) {
  2257. var i = {},
  2258. c = {},
  2259. k;
  2260. if (a === null || typeof a !== "object") a = {};
  2261. if (b === null || typeof b !== "object") b = {};
  2262. for (k in b) {
  2263. if (k in a) {
  2264. i[k] = interpolateValue(a[k], b[k]);
  2265. } else {
  2266. c[k] = b[k];
  2267. }
  2268. }
  2269. return function(t) {
  2270. for (k in i) c[k] = i[k](t);
  2271. return c;
  2272. };
  2273. };
  2274. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
  2275. var reB = new RegExp(reA.source, "g");
  2276. function zero(b) {
  2277. return function() {
  2278. return b;
  2279. };
  2280. }
  2281. function one(b) {
  2282. return function(t) {
  2283. return b(t) + "";
  2284. };
  2285. }
  2286. var interpolateString = function(a, b) {
  2287. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2288. am, // current match in a
  2289. bm, // current match in b
  2290. bs, // string preceding current number in b, if any
  2291. i = -1, // index in s
  2292. s = [], // string constants and placeholders
  2293. q = []; // number interpolators
  2294. // Coerce inputs to strings.
  2295. a = a + "", b = b + "";
  2296. // Interpolate pairs of numbers in a & b.
  2297. while ((am = reA.exec(a))
  2298. && (bm = reB.exec(b))) {
  2299. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2300. bs = b.slice(bi, bs);
  2301. if (s[i]) s[i] += bs; // coalesce with previous string
  2302. else s[++i] = bs;
  2303. }
  2304. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2305. if (s[i]) s[i] += bm; // coalesce with previous string
  2306. else s[++i] = bm;
  2307. } else { // interpolate non-matching numbers
  2308. s[++i] = null;
  2309. q.push({i: i, x: reinterpolate(am, bm)});
  2310. }
  2311. bi = reB.lastIndex;
  2312. }
  2313. // Add remains of b.
  2314. if (bi < b.length) {
  2315. bs = b.slice(bi);
  2316. if (s[i]) s[i] += bs; // coalesce with previous string
  2317. else s[++i] = bs;
  2318. }
  2319. // Special optimization for only a single match.
  2320. // Otherwise, interpolate each of the numbers and rejoin the string.
  2321. return s.length < 2 ? (q[0]
  2322. ? one(q[0].x)
  2323. : zero(b))
  2324. : (b = q.length, function(t) {
  2325. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2326. return s.join("");
  2327. });
  2328. };
  2329. var interpolateValue = function(a, b) {
  2330. var t = typeof b, c;
  2331. return b == null || t === "boolean" ? constant$3(b)
  2332. : (t === "number" ? reinterpolate
  2333. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2334. : b instanceof color ? interpolateRgb
  2335. : b instanceof Date ? date
  2336. : Array.isArray(b) ? array$1
  2337. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2338. : reinterpolate)(a, b);
  2339. };
  2340. var interpolateRound = function(a, b) {
  2341. return a = +a, b -= a, function(t) {
  2342. return Math.round(a + b * t);
  2343. };
  2344. };
  2345. var degrees = 180 / Math.PI;
  2346. var identity$2 = {
  2347. translateX: 0,
  2348. translateY: 0,
  2349. rotate: 0,
  2350. skewX: 0,
  2351. scaleX: 1,
  2352. scaleY: 1
  2353. };
  2354. var decompose = function(a, b, c, d, e, f) {
  2355. var scaleX, scaleY, skewX;
  2356. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2357. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2358. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2359. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2360. return {
  2361. translateX: e,
  2362. translateY: f,
  2363. rotate: Math.atan2(b, a) * degrees,
  2364. skewX: Math.atan(skewX) * degrees,
  2365. scaleX: scaleX,
  2366. scaleY: scaleY
  2367. };
  2368. };
  2369. var cssNode;
  2370. var cssRoot;
  2371. var cssView;
  2372. var svgNode;
  2373. function parseCss(value) {
  2374. if (value === "none") return identity$2;
  2375. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2376. cssNode.style.transform = value;
  2377. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2378. cssRoot.removeChild(cssNode);
  2379. value = value.slice(7, -1).split(",");
  2380. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2381. }
  2382. function parseSvg(value) {
  2383. if (value == null) return identity$2;
  2384. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2385. svgNode.setAttribute("transform", value);
  2386. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2387. value = value.matrix;
  2388. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2389. }
  2390. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2391. function pop(s) {
  2392. return s.length ? s.pop() + " " : "";
  2393. }
  2394. function translate(xa, ya, xb, yb, s, q) {
  2395. if (xa !== xb || ya !== yb) {
  2396. var i = s.push("translate(", null, pxComma, null, pxParen);
  2397. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2398. } else if (xb || yb) {
  2399. s.push("translate(" + xb + pxComma + yb + pxParen);
  2400. }
  2401. }
  2402. function rotate(a, b, s, q) {
  2403. if (a !== b) {
  2404. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2405. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
  2406. } else if (b) {
  2407. s.push(pop(s) + "rotate(" + b + degParen);
  2408. }
  2409. }
  2410. function skewX(a, b, s, q) {
  2411. if (a !== b) {
  2412. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
  2413. } else if (b) {
  2414. s.push(pop(s) + "skewX(" + b + degParen);
  2415. }
  2416. }
  2417. function scale(xa, ya, xb, yb, s, q) {
  2418. if (xa !== xb || ya !== yb) {
  2419. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2420. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2421. } else if (xb !== 1 || yb !== 1) {
  2422. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2423. }
  2424. }
  2425. return function(a, b) {
  2426. var s = [], // string constants and placeholders
  2427. q = []; // number interpolators
  2428. a = parse(a), b = parse(b);
  2429. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2430. rotate(a.rotate, b.rotate, s, q);
  2431. skewX(a.skewX, b.skewX, s, q);
  2432. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2433. a = b = null; // gc
  2434. return function(t) {
  2435. var i = -1, n = q.length, o;
  2436. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2437. return s.join("");
  2438. };
  2439. };
  2440. }
  2441. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2442. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2443. var rho = Math.SQRT2;
  2444. var rho2 = 2;
  2445. var rho4 = 4;
  2446. var epsilon2 = 1e-12;
  2447. function cosh(x) {
  2448. return ((x = Math.exp(x)) + 1 / x) / 2;
  2449. }
  2450. function sinh(x) {
  2451. return ((x = Math.exp(x)) - 1 / x) / 2;
  2452. }
  2453. function tanh(x) {
  2454. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2455. }
  2456. // p0 = [ux0, uy0, w0]
  2457. // p1 = [ux1, uy1, w1]
  2458. var interpolateZoom = function(p0, p1) {
  2459. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2460. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2461. dx = ux1 - ux0,
  2462. dy = uy1 - uy0,
  2463. d2 = dx * dx + dy * dy,
  2464. i,
  2465. S;
  2466. // Special case for u0 ≅ u1.
  2467. if (d2 < epsilon2) {
  2468. S = Math.log(w1 / w0) / rho;
  2469. i = function(t) {
  2470. return [
  2471. ux0 + t * dx,
  2472. uy0 + t * dy,
  2473. w0 * Math.exp(rho * t * S)
  2474. ];
  2475. };
  2476. }
  2477. // General case.
  2478. else {
  2479. var d1 = Math.sqrt(d2),
  2480. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2481. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2482. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2483. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2484. S = (r1 - r0) / rho;
  2485. i = function(t) {
  2486. var s = t * S,
  2487. coshr0 = cosh(r0),
  2488. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2489. return [
  2490. ux0 + u * dx,
  2491. uy0 + u * dy,
  2492. w0 * coshr0 / cosh(rho * s + r0)
  2493. ];
  2494. };
  2495. }
  2496. i.duration = S * 1000;
  2497. return i;
  2498. };
  2499. function hsl$1(hue$$1) {
  2500. return function(start, end) {
  2501. var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
  2502. s = nogamma(start.s, end.s),
  2503. l = nogamma(start.l, end.l),
  2504. opacity = nogamma(start.opacity, end.opacity);
  2505. return function(t) {
  2506. start.h = h(t);
  2507. start.s = s(t);
  2508. start.l = l(t);
  2509. start.opacity = opacity(t);
  2510. return start + "";
  2511. };
  2512. }
  2513. }
  2514. var hsl$2 = hsl$1(hue);
  2515. var hslLong = hsl$1(nogamma);
  2516. function lab$1(start, end) {
  2517. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2518. a = nogamma(start.a, end.a),
  2519. b = nogamma(start.b, end.b),
  2520. opacity = nogamma(start.opacity, end.opacity);
  2521. return function(t) {
  2522. start.l = l(t);
  2523. start.a = a(t);
  2524. start.b = b(t);
  2525. start.opacity = opacity(t);
  2526. return start + "";
  2527. };
  2528. }
  2529. function hcl$1(hue$$1) {
  2530. return function(start, end) {
  2531. var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
  2532. c = nogamma(start.c, end.c),
  2533. l = nogamma(start.l, end.l),
  2534. opacity = nogamma(start.opacity, end.opacity);
  2535. return function(t) {
  2536. start.h = h(t);
  2537. start.c = c(t);
  2538. start.l = l(t);
  2539. start.opacity = opacity(t);
  2540. return start + "";
  2541. };
  2542. }
  2543. }
  2544. var hcl$2 = hcl$1(hue);
  2545. var hclLong = hcl$1(nogamma);
  2546. function cubehelix$1(hue$$1) {
  2547. return (function cubehelixGamma(y) {
  2548. y = +y;
  2549. function cubehelix$$1(start, end) {
  2550. var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2551. s = nogamma(start.s, end.s),
  2552. l = nogamma(start.l, end.l),
  2553. opacity = nogamma(start.opacity, end.opacity);
  2554. return function(t) {
  2555. start.h = h(t);
  2556. start.s = s(t);
  2557. start.l = l(Math.pow(t, y));
  2558. start.opacity = opacity(t);
  2559. return start + "";
  2560. };
  2561. }
  2562. cubehelix$$1.gamma = cubehelixGamma;
  2563. return cubehelix$$1;
  2564. })(1);
  2565. }
  2566. var cubehelix$2 = cubehelix$1(hue);
  2567. var cubehelixLong = cubehelix$1(nogamma);
  2568. var quantize = function(interpolator, n) {
  2569. var samples = new Array(n);
  2570. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2571. return samples;
  2572. };
  2573. var frame = 0;
  2574. var timeout = 0;
  2575. var interval = 0;
  2576. var pokeDelay = 1000;
  2577. var taskHead;
  2578. var taskTail;
  2579. var clockLast = 0;
  2580. var clockNow = 0;
  2581. var clockSkew = 0;
  2582. var clock = typeof performance === "object" && performance.now ? performance : Date;
  2583. var setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2584. function now() {
  2585. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2586. }
  2587. function clearNow() {
  2588. clockNow = 0;
  2589. }
  2590. function Timer() {
  2591. this._call =
  2592. this._time =
  2593. this._next = null;
  2594. }
  2595. Timer.prototype = timer.prototype = {
  2596. constructor: Timer,
  2597. restart: function(callback, delay, time) {
  2598. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2599. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2600. if (!this._next && taskTail !== this) {
  2601. if (taskTail) taskTail._next = this;
  2602. else taskHead = this;
  2603. taskTail = this;
  2604. }
  2605. this._call = callback;
  2606. this._time = time;
  2607. sleep();
  2608. },
  2609. stop: function() {
  2610. if (this._call) {
  2611. this._call = null;
  2612. this._time = Infinity;
  2613. sleep();
  2614. }
  2615. }
  2616. };
  2617. function timer(callback, delay, time) {
  2618. var t = new Timer;
  2619. t.restart(callback, delay, time);
  2620. return t;
  2621. }
  2622. function timerFlush() {
  2623. now(); // Get the current time, if not already set.
  2624. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2625. var t = taskHead, e;
  2626. while (t) {
  2627. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2628. t = t._next;
  2629. }
  2630. --frame;
  2631. }
  2632. function wake() {
  2633. clockNow = (clockLast = clock.now()) + clockSkew;
  2634. frame = timeout = 0;
  2635. try {
  2636. timerFlush();
  2637. } finally {
  2638. frame = 0;
  2639. nap();
  2640. clockNow = 0;
  2641. }
  2642. }
  2643. function poke() {
  2644. var now = clock.now(), delay = now - clockLast;
  2645. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2646. }
  2647. function nap() {
  2648. var t0, t1 = taskHead, t2, time = Infinity;
  2649. while (t1) {
  2650. if (t1._call) {
  2651. if (time > t1._time) time = t1._time;
  2652. t0 = t1, t1 = t1._next;
  2653. } else {
  2654. t2 = t1._next, t1._next = null;
  2655. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2656. }
  2657. }
  2658. taskTail = t0;
  2659. sleep(time);
  2660. }
  2661. function sleep(time) {
  2662. if (frame) return; // Soonest alarm already set, or will be.
  2663. if (timeout) timeout = clearTimeout(timeout);
  2664. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2665. if (delay > 24) {
  2666. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2667. if (interval) interval = clearInterval(interval);
  2668. } else {
  2669. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2670. frame = 1, setFrame(wake);
  2671. }
  2672. }
  2673. var timeout$1 = function(callback, delay, time) {
  2674. var t = new Timer;
  2675. delay = delay == null ? 0 : +delay;
  2676. t.restart(function(elapsed) {
  2677. t.stop();
  2678. callback(elapsed + delay);
  2679. }, delay, time);
  2680. return t;
  2681. };
  2682. var interval$1 = function(callback, delay, time) {
  2683. var t = new Timer, total = delay;
  2684. if (delay == null) return t.restart(callback, delay, time), t;
  2685. delay = +delay, time = time == null ? now() : +time;
  2686. t.restart(function tick(elapsed) {
  2687. elapsed += total;
  2688. t.restart(tick, total += delay, time);
  2689. callback(elapsed);
  2690. }, delay, time);
  2691. return t;
  2692. };
  2693. var emptyOn = dispatch("start", "end", "interrupt");
  2694. var emptyTween = [];
  2695. var CREATED = 0;
  2696. var SCHEDULED = 1;
  2697. var STARTING = 2;
  2698. var STARTED = 3;
  2699. var RUNNING = 4;
  2700. var ENDING = 5;
  2701. var ENDED = 6;
  2702. var schedule = function(node, name, id, index, group, timing) {
  2703. var schedules = node.__transition;
  2704. if (!schedules) node.__transition = {};
  2705. else if (id in schedules) return;
  2706. create(node, id, {
  2707. name: name,
  2708. index: index, // For context during callback.
  2709. group: group, // For context during callback.
  2710. on: emptyOn,
  2711. tween: emptyTween,
  2712. time: timing.time,
  2713. delay: timing.delay,
  2714. duration: timing.duration,
  2715. ease: timing.ease,
  2716. timer: null,
  2717. state: CREATED
  2718. });
  2719. };
  2720. function init(node, id) {
  2721. var schedule = node.__transition;
  2722. if (!schedule || !(schedule = schedule[id]) || schedule.state > CREATED) throw new Error("too late");
  2723. return schedule;
  2724. }
  2725. function set$1(node, id) {
  2726. var schedule = node.__transition;
  2727. if (!schedule || !(schedule = schedule[id]) || schedule.state > STARTING) throw new Error("too late");
  2728. return schedule;
  2729. }
  2730. function get$1(node, id) {
  2731. var schedule = node.__transition;
  2732. if (!schedule || !(schedule = schedule[id])) throw new Error("too late");
  2733. return schedule;
  2734. }
  2735. function create(node, id, self) {
  2736. var schedules = node.__transition,
  2737. tween;
  2738. // Initialize the self timer when the transition is created.
  2739. // Note the actual delay is not known until the first callback!
  2740. schedules[id] = self;
  2741. self.timer = timer(schedule, 0, self.time);
  2742. function schedule(elapsed) {
  2743. self.state = SCHEDULED;
  2744. self.timer.restart(start, self.delay, self.time);
  2745. // If the elapsed delay is less than our first sleep, start immediately.
  2746. if (self.delay <= elapsed) start(elapsed - self.delay);
  2747. }
  2748. function start(elapsed) {
  2749. var i, j, n, o;
  2750. // If the state is not SCHEDULED, then we previously errored on start.
  2751. if (self.state !== SCHEDULED) return stop();
  2752. for (i in schedules) {
  2753. o = schedules[i];
  2754. if (o.name !== self.name) continue;
  2755. // While this element already has a starting transition during this frame,
  2756. // defer starting an interrupting transition until that transition has a
  2757. // chance to tick (and possibly end); see d3/d3-transition#54!
  2758. if (o.state === STARTED) return timeout$1(start);
  2759. // Interrupt the active transition, if any.
  2760. // Dispatch the interrupt event.
  2761. if (o.state === RUNNING) {
  2762. o.state = ENDED;
  2763. o.timer.stop();
  2764. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2765. delete schedules[i];
  2766. }
  2767. // Cancel any pre-empted transitions. No interrupt event is dispatched
  2768. // because the cancelled transitions never started. Note that this also
  2769. // removes this transition from the pending list!
  2770. else if (+i < id) {
  2771. o.state = ENDED;
  2772. o.timer.stop();
  2773. delete schedules[i];
  2774. }
  2775. }
  2776. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2777. // Note the transition may be canceled after start and before the first tick!
  2778. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2779. // Assuming this is successful, subsequent callbacks go straight to tick.
  2780. timeout$1(function() {
  2781. if (self.state === STARTED) {
  2782. self.state = RUNNING;
  2783. self.timer.restart(tick, self.delay, self.time);
  2784. tick(elapsed);
  2785. }
  2786. });
  2787. // Dispatch the start event.
  2788. // Note this must be done before the tween are initialized.
  2789. self.state = STARTING;
  2790. self.on.call("start", node, node.__data__, self.index, self.group);
  2791. if (self.state !== STARTING) return; // interrupted
  2792. self.state = STARTED;
  2793. // Initialize the tween, deleting null tween.
  2794. tween = new Array(n = self.tween.length);
  2795. for (i = 0, j = -1; i < n; ++i) {
  2796. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2797. tween[++j] = o;
  2798. }
  2799. }
  2800. tween.length = j + 1;
  2801. }
  2802. function tick(elapsed) {
  2803. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2804. i = -1,
  2805. n = tween.length;
  2806. while (++i < n) {
  2807. tween[i].call(null, t);
  2808. }
  2809. // Dispatch the end event.
  2810. if (self.state === ENDING) {
  2811. self.on.call("end", node, node.__data__, self.index, self.group);
  2812. stop();
  2813. }
  2814. }
  2815. function stop() {
  2816. self.state = ENDED;
  2817. self.timer.stop();
  2818. delete schedules[id];
  2819. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2820. delete node.__transition;
  2821. }
  2822. }
  2823. var interrupt = function(node, name) {
  2824. var schedules = node.__transition,
  2825. schedule$$1,
  2826. active,
  2827. empty = true,
  2828. i;
  2829. if (!schedules) return;
  2830. name = name == null ? null : name + "";
  2831. for (i in schedules) {
  2832. if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
  2833. active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
  2834. schedule$$1.state = ENDED;
  2835. schedule$$1.timer.stop();
  2836. if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
  2837. delete schedules[i];
  2838. }
  2839. if (empty) delete node.__transition;
  2840. };
  2841. var selection_interrupt = function(name) {
  2842. return this.each(function() {
  2843. interrupt(this, name);
  2844. });
  2845. };
  2846. function tweenRemove(id, name) {
  2847. var tween0, tween1;
  2848. return function() {
  2849. var schedule$$1 = set$1(this, id),
  2850. tween = schedule$$1.tween;
  2851. // If this node shared tween with the previous node,
  2852. // just assign the updated shared tween and we’re done!
  2853. // Otherwise, copy-on-write.
  2854. if (tween !== tween0) {
  2855. tween1 = tween0 = tween;
  2856. for (var i = 0, n = tween1.length; i < n; ++i) {
  2857. if (tween1[i].name === name) {
  2858. tween1 = tween1.slice();
  2859. tween1.splice(i, 1);
  2860. break;
  2861. }
  2862. }
  2863. }
  2864. schedule$$1.tween = tween1;
  2865. };
  2866. }
  2867. function tweenFunction(id, name, value) {
  2868. var tween0, tween1;
  2869. if (typeof value !== "function") throw new Error;
  2870. return function() {
  2871. var schedule$$1 = set$1(this, id),
  2872. tween = schedule$$1.tween;
  2873. // If this node shared tween with the previous node,
  2874. // just assign the updated shared tween and we’re done!
  2875. // Otherwise, copy-on-write.
  2876. if (tween !== tween0) {
  2877. tween1 = (tween0 = tween).slice();
  2878. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2879. if (tween1[i].name === name) {
  2880. tween1[i] = t;
  2881. break;
  2882. }
  2883. }
  2884. if (i === n) tween1.push(t);
  2885. }
  2886. schedule$$1.tween = tween1;
  2887. };
  2888. }
  2889. var transition_tween = function(name, value) {
  2890. var id = this._id;
  2891. name += "";
  2892. if (arguments.length < 2) {
  2893. var tween = get$1(this.node(), id).tween;
  2894. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2895. if ((t = tween[i]).name === name) {
  2896. return t.value;
  2897. }
  2898. }
  2899. return null;
  2900. }
  2901. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2902. };
  2903. function tweenValue(transition, name, value) {
  2904. var id = transition._id;
  2905. transition.each(function() {
  2906. var schedule$$1 = set$1(this, id);
  2907. (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
  2908. });
  2909. return function(node) {
  2910. return get$1(node, id).value[name];
  2911. };
  2912. }
  2913. var interpolate = function(a, b) {
  2914. var c;
  2915. return (typeof b === "number" ? reinterpolate
  2916. : b instanceof color ? interpolateRgb
  2917. : (c = color(b)) ? (b = c, interpolateRgb)
  2918. : interpolateString)(a, b);
  2919. };
  2920. function attrRemove$1(name) {
  2921. return function() {
  2922. this.removeAttribute(name);
  2923. };
  2924. }
  2925. function attrRemoveNS$1(fullname) {
  2926. return function() {
  2927. this.removeAttributeNS(fullname.space, fullname.local);
  2928. };
  2929. }
  2930. function attrConstant$1(name, interpolate$$1, value1) {
  2931. var value00,
  2932. interpolate0;
  2933. return function() {
  2934. var value0 = this.getAttribute(name);
  2935. return value0 === value1 ? null
  2936. : value0 === value00 ? interpolate0
  2937. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2938. };
  2939. }
  2940. function attrConstantNS$1(fullname, interpolate$$1, value1) {
  2941. var value00,
  2942. interpolate0;
  2943. return function() {
  2944. var value0 = this.getAttributeNS(fullname.space, fullname.local);
  2945. return value0 === value1 ? null
  2946. : value0 === value00 ? interpolate0
  2947. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2948. };
  2949. }
  2950. function attrFunction$1(name, interpolate$$1, value) {
  2951. var value00,
  2952. value10,
  2953. interpolate0;
  2954. return function() {
  2955. var value0, value1 = value(this);
  2956. if (value1 == null) return void this.removeAttribute(name);
  2957. value0 = this.getAttribute(name);
  2958. return value0 === value1 ? null
  2959. : value0 === value00 && value1 === value10 ? interpolate0
  2960. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  2961. };
  2962. }
  2963. function attrFunctionNS$1(fullname, interpolate$$1, value) {
  2964. var value00,
  2965. value10,
  2966. interpolate0;
  2967. return function() {
  2968. var value0, value1 = value(this);
  2969. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  2970. value0 = this.getAttributeNS(fullname.space, fullname.local);
  2971. return value0 === value1 ? null
  2972. : value0 === value00 && value1 === value10 ? interpolate0
  2973. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  2974. };
  2975. }
  2976. var transition_attr = function(name, value) {
  2977. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  2978. return this.attrTween(name, typeof value === "function"
  2979. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  2980. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  2981. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
  2982. };
  2983. function attrTweenNS(fullname, value) {
  2984. function tween() {
  2985. var node = this, i = value.apply(node, arguments);
  2986. return i && function(t) {
  2987. node.setAttributeNS(fullname.space, fullname.local, i(t));
  2988. };
  2989. }
  2990. tween._value = value;
  2991. return tween;
  2992. }
  2993. function attrTween(name, value) {
  2994. function tween() {
  2995. var node = this, i = value.apply(node, arguments);
  2996. return i && function(t) {
  2997. node.setAttribute(name, i(t));
  2998. };
  2999. }
  3000. tween._value = value;
  3001. return tween;
  3002. }
  3003. var transition_attrTween = function(name, value) {
  3004. var key = "attr." + name;
  3005. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3006. if (value == null) return this.tween(key, null);
  3007. if (typeof value !== "function") throw new Error;
  3008. var fullname = namespace(name);
  3009. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3010. };
  3011. function delayFunction(id, value) {
  3012. return function() {
  3013. init(this, id).delay = +value.apply(this, arguments);
  3014. };
  3015. }
  3016. function delayConstant(id, value) {
  3017. return value = +value, function() {
  3018. init(this, id).delay = value;
  3019. };
  3020. }
  3021. var transition_delay = function(value) {
  3022. var id = this._id;
  3023. return arguments.length
  3024. ? this.each((typeof value === "function"
  3025. ? delayFunction
  3026. : delayConstant)(id, value))
  3027. : get$1(this.node(), id).delay;
  3028. };
  3029. function durationFunction(id, value) {
  3030. return function() {
  3031. set$1(this, id).duration = +value.apply(this, arguments);
  3032. };
  3033. }
  3034. function durationConstant(id, value) {
  3035. return value = +value, function() {
  3036. set$1(this, id).duration = value;
  3037. };
  3038. }
  3039. var transition_duration = function(value) {
  3040. var id = this._id;
  3041. return arguments.length
  3042. ? this.each((typeof value === "function"
  3043. ? durationFunction
  3044. : durationConstant)(id, value))
  3045. : get$1(this.node(), id).duration;
  3046. };
  3047. function easeConstant(id, value) {
  3048. if (typeof value !== "function") throw new Error;
  3049. return function() {
  3050. set$1(this, id).ease = value;
  3051. };
  3052. }
  3053. var transition_ease = function(value) {
  3054. var id = this._id;
  3055. return arguments.length
  3056. ? this.each(easeConstant(id, value))
  3057. : get$1(this.node(), id).ease;
  3058. };
  3059. var transition_filter = function(match) {
  3060. if (typeof match !== "function") match = matcher$1(match);
  3061. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3062. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3063. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3064. subgroup.push(node);
  3065. }
  3066. }
  3067. }
  3068. return new Transition(subgroups, this._parents, this._name, this._id);
  3069. };
  3070. var transition_merge = function(transition$$1) {
  3071. if (transition$$1._id !== this._id) throw new Error;
  3072. for (var groups0 = this._groups, groups1 = transition$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  3073. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3074. if (node = group0[i] || group1[i]) {
  3075. merge[i] = node;
  3076. }
  3077. }
  3078. }
  3079. for (; j < m0; ++j) {
  3080. merges[j] = groups0[j];
  3081. }
  3082. return new Transition(merges, this._parents, this._name, this._id);
  3083. };
  3084. function start(name) {
  3085. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3086. var i = t.indexOf(".");
  3087. if (i >= 0) t = t.slice(0, i);
  3088. return !t || t === "start";
  3089. });
  3090. }
  3091. function onFunction(id, name, listener) {
  3092. var on0, on1, sit = start(name) ? init : set$1;
  3093. return function() {
  3094. var schedule$$1 = sit(this, id),
  3095. on = schedule$$1.on;
  3096. // If this node shared a dispatch with the previous node,
  3097. // just assign the updated shared dispatch and we’re done!
  3098. // Otherwise, copy-on-write.
  3099. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3100. schedule$$1.on = on1;
  3101. };
  3102. }
  3103. var transition_on = function(name, listener) {
  3104. var id = this._id;
  3105. return arguments.length < 2
  3106. ? get$1(this.node(), id).on.on(name)
  3107. : this.each(onFunction(id, name, listener));
  3108. };
  3109. function removeFunction(id) {
  3110. return function() {
  3111. var parent = this.parentNode;
  3112. for (var i in this.__transition) if (+i !== id) return;
  3113. if (parent) parent.removeChild(this);
  3114. };
  3115. }
  3116. var transition_remove = function() {
  3117. return this.on("end.remove", removeFunction(this._id));
  3118. };
  3119. var transition_select = function(select) {
  3120. var name = this._name,
  3121. id = this._id;
  3122. if (typeof select !== "function") select = selector(select);
  3123. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3124. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3125. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  3126. if ("__data__" in node) subnode.__data__ = node.__data__;
  3127. subgroup[i] = subnode;
  3128. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3129. }
  3130. }
  3131. }
  3132. return new Transition(subgroups, this._parents, name, id);
  3133. };
  3134. var transition_selectAll = function(select) {
  3135. var name = this._name,
  3136. id = this._id;
  3137. if (typeof select !== "function") select = selectorAll(select);
  3138. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3139. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3140. if (node = group[i]) {
  3141. for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3142. if (child = children[k]) {
  3143. schedule(child, name, id, k, children, inherit);
  3144. }
  3145. }
  3146. subgroups.push(children);
  3147. parents.push(node);
  3148. }
  3149. }
  3150. }
  3151. return new Transition(subgroups, parents, name, id);
  3152. };
  3153. var Selection$1 = selection.prototype.constructor;
  3154. var transition_selection = function() {
  3155. return new Selection$1(this._groups, this._parents);
  3156. };
  3157. function styleRemove$1(name, interpolate$$1) {
  3158. var value00,
  3159. value10,
  3160. interpolate0;
  3161. return function() {
  3162. var value0 = styleValue(this, name),
  3163. value1 = (this.style.removeProperty(name), styleValue(this, name));
  3164. return value0 === value1 ? null
  3165. : value0 === value00 && value1 === value10 ? interpolate0
  3166. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3167. };
  3168. }
  3169. function styleRemoveEnd(name) {
  3170. return function() {
  3171. this.style.removeProperty(name);
  3172. };
  3173. }
  3174. function styleConstant$1(name, interpolate$$1, value1) {
  3175. var value00,
  3176. interpolate0;
  3177. return function() {
  3178. var value0 = styleValue(this, name);
  3179. return value0 === value1 ? null
  3180. : value0 === value00 ? interpolate0
  3181. : interpolate0 = interpolate$$1(value00 = value0, value1);
  3182. };
  3183. }
  3184. function styleFunction$1(name, interpolate$$1, value) {
  3185. var value00,
  3186. value10,
  3187. interpolate0;
  3188. return function() {
  3189. var value0 = styleValue(this, name),
  3190. value1 = value(this);
  3191. if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
  3192. return value0 === value1 ? null
  3193. : value0 === value00 && value1 === value10 ? interpolate0
  3194. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3195. };
  3196. }
  3197. var transition_style = function(name, value, priority) {
  3198. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3199. return value == null ? this
  3200. .styleTween(name, styleRemove$1(name, i))
  3201. .on("end.style." + name, styleRemoveEnd(name))
  3202. : this.styleTween(name, typeof value === "function"
  3203. ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
  3204. : styleConstant$1(name, i, value + ""), priority);
  3205. };
  3206. function styleTween(name, value, priority) {
  3207. function tween() {
  3208. var node = this, i = value.apply(node, arguments);
  3209. return i && function(t) {
  3210. node.style.setProperty(name, i(t), priority);
  3211. };
  3212. }
  3213. tween._value = value;
  3214. return tween;
  3215. }
  3216. var transition_styleTween = function(name, value, priority) {
  3217. var key = "style." + (name += "");
  3218. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3219. if (value == null) return this.tween(key, null);
  3220. if (typeof value !== "function") throw new Error;
  3221. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3222. };
  3223. function textConstant$1(value) {
  3224. return function() {
  3225. this.textContent = value;
  3226. };
  3227. }
  3228. function textFunction$1(value) {
  3229. return function() {
  3230. var value1 = value(this);
  3231. this.textContent = value1 == null ? "" : value1;
  3232. };
  3233. }
  3234. var transition_text = function(value) {
  3235. return this.tween("text", typeof value === "function"
  3236. ? textFunction$1(tweenValue(this, "text", value))
  3237. : textConstant$1(value == null ? "" : value + ""));
  3238. };
  3239. var transition_transition = function() {
  3240. var name = this._name,
  3241. id0 = this._id,
  3242. id1 = newId();
  3243. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3244. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3245. if (node = group[i]) {
  3246. var inherit = get$1(node, id0);
  3247. schedule(node, name, id1, i, group, {
  3248. time: inherit.time + inherit.delay + inherit.duration,
  3249. delay: 0,
  3250. duration: inherit.duration,
  3251. ease: inherit.ease
  3252. });
  3253. }
  3254. }
  3255. }
  3256. return new Transition(groups, this._parents, name, id1);
  3257. };
  3258. var id = 0;
  3259. function Transition(groups, parents, name, id) {
  3260. this._groups = groups;
  3261. this._parents = parents;
  3262. this._name = name;
  3263. this._id = id;
  3264. }
  3265. function transition(name) {
  3266. return selection().transition(name);
  3267. }
  3268. function newId() {
  3269. return ++id;
  3270. }
  3271. var selection_prototype = selection.prototype;
  3272. Transition.prototype = transition.prototype = {
  3273. constructor: Transition,
  3274. select: transition_select,
  3275. selectAll: transition_selectAll,
  3276. filter: transition_filter,
  3277. merge: transition_merge,
  3278. selection: transition_selection,
  3279. transition: transition_transition,
  3280. call: selection_prototype.call,
  3281. nodes: selection_prototype.nodes,
  3282. node: selection_prototype.node,
  3283. size: selection_prototype.size,
  3284. empty: selection_prototype.empty,
  3285. each: selection_prototype.each,
  3286. on: transition_on,
  3287. attr: transition_attr,
  3288. attrTween: transition_attrTween,
  3289. style: transition_style,
  3290. styleTween: transition_styleTween,
  3291. text: transition_text,
  3292. remove: transition_remove,
  3293. tween: transition_tween,
  3294. delay: transition_delay,
  3295. duration: transition_duration,
  3296. ease: transition_ease
  3297. };
  3298. function linear$1(t) {
  3299. return +t;
  3300. }
  3301. function quadIn(t) {
  3302. return t * t;
  3303. }
  3304. function quadOut(t) {
  3305. return t * (2 - t);
  3306. }
  3307. function quadInOut(t) {
  3308. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3309. }
  3310. function cubicIn(t) {
  3311. return t * t * t;
  3312. }
  3313. function cubicOut(t) {
  3314. return --t * t * t + 1;
  3315. }
  3316. function cubicInOut(t) {
  3317. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3318. }
  3319. var exponent = 3;
  3320. var polyIn = (function custom(e) {
  3321. e = +e;
  3322. function polyIn(t) {
  3323. return Math.pow(t, e);
  3324. }
  3325. polyIn.exponent = custom;
  3326. return polyIn;
  3327. })(exponent);
  3328. var polyOut = (function custom(e) {
  3329. e = +e;
  3330. function polyOut(t) {
  3331. return 1 - Math.pow(1 - t, e);
  3332. }
  3333. polyOut.exponent = custom;
  3334. return polyOut;
  3335. })(exponent);
  3336. var polyInOut = (function custom(e) {
  3337. e = +e;
  3338. function polyInOut(t) {
  3339. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3340. }
  3341. polyInOut.exponent = custom;
  3342. return polyInOut;
  3343. })(exponent);
  3344. var pi = Math.PI;
  3345. var halfPi = pi / 2;
  3346. function sinIn(t) {
  3347. return 1 - Math.cos(t * halfPi);
  3348. }
  3349. function sinOut(t) {
  3350. return Math.sin(t * halfPi);
  3351. }
  3352. function sinInOut(t) {
  3353. return (1 - Math.cos(pi * t)) / 2;
  3354. }
  3355. function expIn(t) {
  3356. return Math.pow(2, 10 * t - 10);
  3357. }
  3358. function expOut(t) {
  3359. return 1 - Math.pow(2, -10 * t);
  3360. }
  3361. function expInOut(t) {
  3362. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3363. }
  3364. function circleIn(t) {
  3365. return 1 - Math.sqrt(1 - t * t);
  3366. }
  3367. function circleOut(t) {
  3368. return Math.sqrt(1 - --t * t);
  3369. }
  3370. function circleInOut(t) {
  3371. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3372. }
  3373. var b1 = 4 / 11;
  3374. var b2 = 6 / 11;
  3375. var b3 = 8 / 11;
  3376. var b4 = 3 / 4;
  3377. var b5 = 9 / 11;
  3378. var b6 = 10 / 11;
  3379. var b7 = 15 / 16;
  3380. var b8 = 21 / 22;
  3381. var b9 = 63 / 64;
  3382. var b0 = 1 / b1 / b1;
  3383. function bounceIn(t) {
  3384. return 1 - bounceOut(1 - t);
  3385. }
  3386. function bounceOut(t) {
  3387. 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;
  3388. }
  3389. function bounceInOut(t) {
  3390. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3391. }
  3392. var overshoot = 1.70158;
  3393. var backIn = (function custom(s) {
  3394. s = +s;
  3395. function backIn(t) {
  3396. return t * t * ((s + 1) * t - s);
  3397. }
  3398. backIn.overshoot = custom;
  3399. return backIn;
  3400. })(overshoot);
  3401. var backOut = (function custom(s) {
  3402. s = +s;
  3403. function backOut(t) {
  3404. return --t * t * ((s + 1) * t + s) + 1;
  3405. }
  3406. backOut.overshoot = custom;
  3407. return backOut;
  3408. })(overshoot);
  3409. var backInOut = (function custom(s) {
  3410. s = +s;
  3411. function backInOut(t) {
  3412. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3413. }
  3414. backInOut.overshoot = custom;
  3415. return backInOut;
  3416. })(overshoot);
  3417. var tau = 2 * Math.PI;
  3418. var amplitude = 1;
  3419. var period = 0.3;
  3420. var elasticIn = (function custom(a, p) {
  3421. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3422. function elasticIn(t) {
  3423. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3424. }
  3425. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3426. elasticIn.period = function(p) { return custom(a, p); };
  3427. return elasticIn;
  3428. })(amplitude, period);
  3429. var elasticOut = (function custom(a, p) {
  3430. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3431. function elasticOut(t) {
  3432. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3433. }
  3434. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3435. elasticOut.period = function(p) { return custom(a, p); };
  3436. return elasticOut;
  3437. })(amplitude, period);
  3438. var elasticInOut = (function custom(a, p) {
  3439. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3440. function elasticInOut(t) {
  3441. return ((t = t * 2 - 1) < 0
  3442. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3443. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3444. }
  3445. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3446. elasticInOut.period = function(p) { return custom(a, p); };
  3447. return elasticInOut;
  3448. })(amplitude, period);
  3449. var defaultTiming = {
  3450. time: null, // Set on use.
  3451. delay: 0,
  3452. duration: 250,
  3453. ease: cubicInOut
  3454. };
  3455. function inherit(node, id) {
  3456. var timing;
  3457. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3458. if (!(node = node.parentNode)) {
  3459. return defaultTiming.time = now(), defaultTiming;
  3460. }
  3461. }
  3462. return timing;
  3463. }
  3464. var selection_transition = function(name) {
  3465. var id,
  3466. timing;
  3467. if (name instanceof Transition) {
  3468. id = name._id, name = name._name;
  3469. } else {
  3470. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3471. }
  3472. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3473. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3474. if (node = group[i]) {
  3475. schedule(node, name, id, i, group, timing || inherit(node, id));
  3476. }
  3477. }
  3478. }
  3479. return new Transition(groups, this._parents, name, id);
  3480. };
  3481. selection.prototype.interrupt = selection_interrupt;
  3482. selection.prototype.transition = selection_transition;
  3483. var root$1 = [null];
  3484. var active = function(node, name) {
  3485. var schedules = node.__transition,
  3486. schedule$$1,
  3487. i;
  3488. if (schedules) {
  3489. name = name == null ? null : name + "";
  3490. for (i in schedules) {
  3491. if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
  3492. return new Transition([[node]], root$1, name, +i);
  3493. }
  3494. }
  3495. }
  3496. return null;
  3497. };
  3498. var constant$4 = function(x) {
  3499. return function() {
  3500. return x;
  3501. };
  3502. };
  3503. var BrushEvent = function(target, type, selection) {
  3504. this.target = target;
  3505. this.type = type;
  3506. this.selection = selection;
  3507. };
  3508. function nopropagation$1() {
  3509. exports.event.stopImmediatePropagation();
  3510. }
  3511. var noevent$1 = function() {
  3512. exports.event.preventDefault();
  3513. exports.event.stopImmediatePropagation();
  3514. };
  3515. var MODE_DRAG = {name: "drag"};
  3516. var MODE_SPACE = {name: "space"};
  3517. var MODE_HANDLE = {name: "handle"};
  3518. var MODE_CENTER = {name: "center"};
  3519. var X = {
  3520. name: "x",
  3521. handles: ["e", "w"].map(type),
  3522. input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
  3523. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3524. };
  3525. var Y = {
  3526. name: "y",
  3527. handles: ["n", "s"].map(type),
  3528. input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
  3529. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3530. };
  3531. var XY = {
  3532. name: "xy",
  3533. handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
  3534. input: function(xy) { return xy; },
  3535. output: function(xy) { return xy; }
  3536. };
  3537. var cursors = {
  3538. overlay: "crosshair",
  3539. selection: "move",
  3540. n: "ns-resize",
  3541. e: "ew-resize",
  3542. s: "ns-resize",
  3543. w: "ew-resize",
  3544. nw: "nwse-resize",
  3545. ne: "nesw-resize",
  3546. se: "nwse-resize",
  3547. sw: "nesw-resize"
  3548. };
  3549. var flipX = {
  3550. e: "w",
  3551. w: "e",
  3552. nw: "ne",
  3553. ne: "nw",
  3554. se: "sw",
  3555. sw: "se"
  3556. };
  3557. var flipY = {
  3558. n: "s",
  3559. s: "n",
  3560. nw: "sw",
  3561. ne: "se",
  3562. se: "ne",
  3563. sw: "nw"
  3564. };
  3565. var signsX = {
  3566. overlay: +1,
  3567. selection: +1,
  3568. n: null,
  3569. e: +1,
  3570. s: null,
  3571. w: -1,
  3572. nw: -1,
  3573. ne: +1,
  3574. se: +1,
  3575. sw: -1
  3576. };
  3577. var signsY = {
  3578. overlay: +1,
  3579. selection: +1,
  3580. n: -1,
  3581. e: null,
  3582. s: +1,
  3583. w: null,
  3584. nw: -1,
  3585. ne: -1,
  3586. se: +1,
  3587. sw: +1
  3588. };
  3589. function type(t) {
  3590. return {type: t};
  3591. }
  3592. // Ignore right-click, since that should open the context menu.
  3593. function defaultFilter() {
  3594. return !exports.event.button;
  3595. }
  3596. function defaultExtent() {
  3597. var svg = this.ownerSVGElement || this;
  3598. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3599. }
  3600. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3601. function local(node) {
  3602. while (!node.__brush) if (!(node = node.parentNode)) return;
  3603. return node.__brush;
  3604. }
  3605. function empty(extent) {
  3606. return extent[0][0] === extent[1][0]
  3607. || extent[0][1] === extent[1][1];
  3608. }
  3609. function brushSelection(node) {
  3610. var state = node.__brush;
  3611. return state ? state.dim.output(state.selection) : null;
  3612. }
  3613. function brushX() {
  3614. return brush$1(X);
  3615. }
  3616. function brushY() {
  3617. return brush$1(Y);
  3618. }
  3619. var brush = function() {
  3620. return brush$1(XY);
  3621. };
  3622. function brush$1(dim) {
  3623. var extent = defaultExtent,
  3624. filter = defaultFilter,
  3625. listeners = dispatch(brush, "start", "brush", "end"),
  3626. handleSize = 6,
  3627. touchending;
  3628. function brush(group) {
  3629. var overlay = group
  3630. .property("__brush", initialize)
  3631. .selectAll(".overlay")
  3632. .data([type("overlay")]);
  3633. overlay.enter().append("rect")
  3634. .attr("class", "overlay")
  3635. .attr("pointer-events", "all")
  3636. .attr("cursor", cursors.overlay)
  3637. .merge(overlay)
  3638. .each(function() {
  3639. var extent = local(this).extent;
  3640. select(this)
  3641. .attr("x", extent[0][0])
  3642. .attr("y", extent[0][1])
  3643. .attr("width", extent[1][0] - extent[0][0])
  3644. .attr("height", extent[1][1] - extent[0][1]);
  3645. });
  3646. group.selectAll(".selection")
  3647. .data([type("selection")])
  3648. .enter().append("rect")
  3649. .attr("class", "selection")
  3650. .attr("cursor", cursors.selection)
  3651. .attr("fill", "#777")
  3652. .attr("fill-opacity", 0.3)
  3653. .attr("stroke", "#fff")
  3654. .attr("shape-rendering", "crispEdges");
  3655. var handle = group.selectAll(".handle")
  3656. .data(dim.handles, function(d) { return d.type; });
  3657. handle.exit().remove();
  3658. handle.enter().append("rect")
  3659. .attr("class", function(d) { return "handle handle--" + d.type; })
  3660. .attr("cursor", function(d) { return cursors[d.type]; });
  3661. group
  3662. .each(redraw)
  3663. .attr("fill", "none")
  3664. .attr("pointer-events", "all")
  3665. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  3666. .on("mousedown.brush touchstart.brush", started);
  3667. }
  3668. brush.move = function(group, selection) {
  3669. if (group.selection) {
  3670. group
  3671. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3672. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3673. .tween("brush", function() {
  3674. var that = this,
  3675. state = that.__brush,
  3676. emit = emitter(that, arguments),
  3677. selection0 = state.selection,
  3678. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  3679. i = interpolateValue(selection0, selection1);
  3680. function tween(t) {
  3681. state.selection = t === 1 && empty(selection1) ? null : i(t);
  3682. redraw.call(that);
  3683. emit.brush();
  3684. }
  3685. return selection0 && selection1 ? tween : tween(1);
  3686. });
  3687. } else {
  3688. group
  3689. .each(function() {
  3690. var that = this,
  3691. args = arguments,
  3692. state = that.__brush,
  3693. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  3694. emit = emitter(that, args).beforestart();
  3695. interrupt(that);
  3696. state.selection = selection1 == null || empty(selection1) ? null : selection1;
  3697. redraw.call(that);
  3698. emit.start().brush().end();
  3699. });
  3700. }
  3701. };
  3702. function redraw() {
  3703. var group = select(this),
  3704. selection = local(this).selection;
  3705. if (selection) {
  3706. group.selectAll(".selection")
  3707. .style("display", null)
  3708. .attr("x", selection[0][0])
  3709. .attr("y", selection[0][1])
  3710. .attr("width", selection[1][0] - selection[0][0])
  3711. .attr("height", selection[1][1] - selection[0][1]);
  3712. group.selectAll(".handle")
  3713. .style("display", null)
  3714. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  3715. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  3716. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  3717. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  3718. }
  3719. else {
  3720. group.selectAll(".selection,.handle")
  3721. .style("display", "none")
  3722. .attr("x", null)
  3723. .attr("y", null)
  3724. .attr("width", null)
  3725. .attr("height", null);
  3726. }
  3727. }
  3728. function emitter(that, args) {
  3729. return that.__brush.emitter || new Emitter(that, args);
  3730. }
  3731. function Emitter(that, args) {
  3732. this.that = that;
  3733. this.args = args;
  3734. this.state = that.__brush;
  3735. this.active = 0;
  3736. }
  3737. Emitter.prototype = {
  3738. beforestart: function() {
  3739. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3740. return this;
  3741. },
  3742. start: function() {
  3743. if (this.starting) this.starting = false, this.emit("start");
  3744. return this;
  3745. },
  3746. brush: function() {
  3747. this.emit("brush");
  3748. return this;
  3749. },
  3750. end: function() {
  3751. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3752. return this;
  3753. },
  3754. emit: function(type) {
  3755. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3756. }
  3757. };
  3758. function started() {
  3759. if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
  3760. else if (touchending) return;
  3761. if (!filter.apply(this, arguments)) return;
  3762. var that = this,
  3763. type = exports.event.target.__data__.type,
  3764. mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3765. signX = dim === Y ? null : signsX[type],
  3766. signY = dim === X ? null : signsY[type],
  3767. state = local(that),
  3768. extent = state.extent,
  3769. selection = state.selection,
  3770. W = extent[0][0], w0, w1,
  3771. N = extent[0][1], n0, n1,
  3772. E = extent[1][0], e0, e1,
  3773. S = extent[1][1], s0, s1,
  3774. dx,
  3775. dy,
  3776. moving,
  3777. shifting = signX && signY && exports.event.shiftKey,
  3778. lockX,
  3779. lockY,
  3780. point0 = mouse(that),
  3781. point = point0,
  3782. emit = emitter(that, arguments).beforestart();
  3783. if (type === "overlay") {
  3784. state.selection = selection = [
  3785. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3786. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3787. ];
  3788. } else {
  3789. w0 = selection[0][0];
  3790. n0 = selection[0][1];
  3791. e0 = selection[1][0];
  3792. s0 = selection[1][1];
  3793. }
  3794. w1 = w0;
  3795. n1 = n0;
  3796. e1 = e0;
  3797. s1 = s0;
  3798. var group = select(that)
  3799. .attr("pointer-events", "none");
  3800. var overlay = group.selectAll(".overlay")
  3801. .attr("cursor", cursors[type]);
  3802. if (exports.event.touches) {
  3803. group
  3804. .on("touchmove.brush", moved, true)
  3805. .on("touchend.brush touchcancel.brush", ended, true);
  3806. } else {
  3807. var view = select(exports.event.view)
  3808. .on("keydown.brush", keydowned, true)
  3809. .on("keyup.brush", keyupped, true)
  3810. .on("mousemove.brush", moved, true)
  3811. .on("mouseup.brush", ended, true);
  3812. dragDisable(exports.event.view);
  3813. }
  3814. nopropagation$1();
  3815. interrupt(that);
  3816. redraw.call(that);
  3817. emit.start();
  3818. function moved() {
  3819. var point1 = mouse(that);
  3820. if (shifting && !lockX && !lockY) {
  3821. if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
  3822. else lockX = true;
  3823. }
  3824. point = point1;
  3825. moving = true;
  3826. noevent$1();
  3827. move();
  3828. }
  3829. function move() {
  3830. var t;
  3831. dx = point[0] - point0[0];
  3832. dy = point[1] - point0[1];
  3833. switch (mode) {
  3834. case MODE_SPACE:
  3835. case MODE_DRAG: {
  3836. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  3837. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  3838. break;
  3839. }
  3840. case MODE_HANDLE: {
  3841. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  3842. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  3843. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  3844. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  3845. break;
  3846. }
  3847. case MODE_CENTER: {
  3848. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  3849. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  3850. break;
  3851. }
  3852. }
  3853. if (e1 < w1) {
  3854. signX *= -1;
  3855. t = w0, w0 = e0, e0 = t;
  3856. t = w1, w1 = e1, e1 = t;
  3857. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  3858. }
  3859. if (s1 < n1) {
  3860. signY *= -1;
  3861. t = n0, n0 = s0, s0 = t;
  3862. t = n1, n1 = s1, s1 = t;
  3863. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  3864. }
  3865. if (state.selection) selection = state.selection; // May be set by brush.move!
  3866. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  3867. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  3868. if (selection[0][0] !== w1
  3869. || selection[0][1] !== n1
  3870. || selection[1][0] !== e1
  3871. || selection[1][1] !== s1) {
  3872. state.selection = [[w1, n1], [e1, s1]];
  3873. redraw.call(that);
  3874. emit.brush();
  3875. }
  3876. }
  3877. function ended() {
  3878. nopropagation$1();
  3879. if (exports.event.touches) {
  3880. if (exports.event.touches.length) return;
  3881. if (touchending) clearTimeout(touchending);
  3882. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  3883. group.on("touchmove.brush touchend.brush touchcancel.brush", null);
  3884. } else {
  3885. yesdrag(exports.event.view, moving);
  3886. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  3887. }
  3888. group.attr("pointer-events", "all");
  3889. overlay.attr("cursor", cursors.overlay);
  3890. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  3891. if (empty(selection)) state.selection = null, redraw.call(that);
  3892. emit.end();
  3893. }
  3894. function keydowned() {
  3895. switch (exports.event.keyCode) {
  3896. case 16: { // SHIFT
  3897. shifting = signX && signY;
  3898. break;
  3899. }
  3900. case 18: { // ALT
  3901. if (mode === MODE_HANDLE) {
  3902. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3903. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3904. mode = MODE_CENTER;
  3905. move();
  3906. }
  3907. break;
  3908. }
  3909. case 32: { // SPACE; takes priority over ALT
  3910. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  3911. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  3912. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  3913. mode = MODE_SPACE;
  3914. overlay.attr("cursor", cursors.selection);
  3915. move();
  3916. }
  3917. break;
  3918. }
  3919. default: return;
  3920. }
  3921. noevent$1();
  3922. }
  3923. function keyupped() {
  3924. switch (exports.event.keyCode) {
  3925. case 16: { // SHIFT
  3926. if (shifting) {
  3927. lockX = lockY = shifting = false;
  3928. move();
  3929. }
  3930. break;
  3931. }
  3932. case 18: { // ALT
  3933. if (mode === MODE_CENTER) {
  3934. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3935. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3936. mode = MODE_HANDLE;
  3937. move();
  3938. }
  3939. break;
  3940. }
  3941. case 32: { // SPACE
  3942. if (mode === MODE_SPACE) {
  3943. if (exports.event.altKey) {
  3944. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3945. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3946. mode = MODE_CENTER;
  3947. } else {
  3948. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3949. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3950. mode = MODE_HANDLE;
  3951. }
  3952. overlay.attr("cursor", cursors[type]);
  3953. move();
  3954. }
  3955. break;
  3956. }
  3957. default: return;
  3958. }
  3959. noevent$1();
  3960. }
  3961. }
  3962. function initialize() {
  3963. var state = this.__brush || {selection: null};
  3964. state.extent = extent.apply(this, arguments);
  3965. state.dim = dim;
  3966. return state;
  3967. }
  3968. brush.extent = function(_) {
  3969. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
  3970. };
  3971. brush.filter = function(_) {
  3972. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  3973. };
  3974. brush.handleSize = function(_) {
  3975. return arguments.length ? (handleSize = +_, brush) : handleSize;
  3976. };
  3977. brush.on = function() {
  3978. var value = listeners.on.apply(listeners, arguments);
  3979. return value === listeners ? brush : value;
  3980. };
  3981. return brush;
  3982. }
  3983. var cos = Math.cos;
  3984. var sin = Math.sin;
  3985. var pi$1 = Math.PI;
  3986. var halfPi$1 = pi$1 / 2;
  3987. var tau$1 = pi$1 * 2;
  3988. var max$1 = Math.max;
  3989. function compareValue(compare) {
  3990. return function(a, b) {
  3991. return compare(
  3992. a.source.value + a.target.value,
  3993. b.source.value + b.target.value
  3994. );
  3995. };
  3996. }
  3997. var chord = function() {
  3998. var padAngle = 0,
  3999. sortGroups = null,
  4000. sortSubgroups = null,
  4001. sortChords = null;
  4002. function chord(matrix) {
  4003. var n = matrix.length,
  4004. groupSums = [],
  4005. groupIndex = sequence(n),
  4006. subgroupIndex = [],
  4007. chords = [],
  4008. groups = chords.groups = new Array(n),
  4009. subgroups = new Array(n * n),
  4010. k,
  4011. x,
  4012. x0,
  4013. dx,
  4014. i,
  4015. j;
  4016. // Compute the sum.
  4017. k = 0, i = -1; while (++i < n) {
  4018. x = 0, j = -1; while (++j < n) {
  4019. x += matrix[i][j];
  4020. }
  4021. groupSums.push(x);
  4022. subgroupIndex.push(sequence(n));
  4023. k += x;
  4024. }
  4025. // Sort groups…
  4026. if (sortGroups) groupIndex.sort(function(a, b) {
  4027. return sortGroups(groupSums[a], groupSums[b]);
  4028. });
  4029. // Sort subgroups…
  4030. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4031. d.sort(function(a, b) {
  4032. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4033. });
  4034. });
  4035. // Convert the sum to scaling factor for [0, 2pi].
  4036. // TODO Allow start and end angle to be specified?
  4037. // TODO Allow padding to be specified as percentage?
  4038. k = max$1(0, tau$1 - padAngle * n) / k;
  4039. dx = k ? padAngle : tau$1 / n;
  4040. // Compute the start and end angle for each group and subgroup.
  4041. // Note: Opera has a bug reordering object literal properties!
  4042. x = 0, i = -1; while (++i < n) {
  4043. x0 = x, j = -1; while (++j < n) {
  4044. var di = groupIndex[i],
  4045. dj = subgroupIndex[di][j],
  4046. v = matrix[di][dj],
  4047. a0 = x,
  4048. a1 = x += v * k;
  4049. subgroups[dj * n + di] = {
  4050. index: di,
  4051. subindex: dj,
  4052. startAngle: a0,
  4053. endAngle: a1,
  4054. value: v
  4055. };
  4056. }
  4057. groups[di] = {
  4058. index: di,
  4059. startAngle: x0,
  4060. endAngle: x,
  4061. value: groupSums[di]
  4062. };
  4063. x += dx;
  4064. }
  4065. // Generate chords for each (non-empty) subgroup-subgroup link.
  4066. i = -1; while (++i < n) {
  4067. j = i - 1; while (++j < n) {
  4068. var source = subgroups[j * n + i],
  4069. target = subgroups[i * n + j];
  4070. if (source.value || target.value) {
  4071. chords.push(source.value < target.value
  4072. ? {source: target, target: source}
  4073. : {source: source, target: target});
  4074. }
  4075. }
  4076. }
  4077. return sortChords ? chords.sort(sortChords) : chords;
  4078. }
  4079. chord.padAngle = function(_) {
  4080. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4081. };
  4082. chord.sortGroups = function(_) {
  4083. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4084. };
  4085. chord.sortSubgroups = function(_) {
  4086. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4087. };
  4088. chord.sortChords = function(_) {
  4089. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4090. };
  4091. return chord;
  4092. };
  4093. var slice$2 = Array.prototype.slice;
  4094. var constant$5 = function(x) {
  4095. return function() {
  4096. return x;
  4097. };
  4098. };
  4099. var pi$2 = Math.PI;
  4100. var tau$2 = 2 * pi$2;
  4101. var epsilon$1 = 1e-6;
  4102. var tauEpsilon = tau$2 - epsilon$1;
  4103. function Path() {
  4104. this._x0 = this._y0 = // start of current subpath
  4105. this._x1 = this._y1 = null; // end of current subpath
  4106. this._ = "";
  4107. }
  4108. function path() {
  4109. return new Path;
  4110. }
  4111. Path.prototype = path.prototype = {
  4112. constructor: Path,
  4113. moveTo: function(x, y) {
  4114. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4115. },
  4116. closePath: function() {
  4117. if (this._x1 !== null) {
  4118. this._x1 = this._x0, this._y1 = this._y0;
  4119. this._ += "Z";
  4120. }
  4121. },
  4122. lineTo: function(x, y) {
  4123. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4124. },
  4125. quadraticCurveTo: function(x1, y1, x, y) {
  4126. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4127. },
  4128. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4129. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4130. },
  4131. arcTo: function(x1, y1, x2, y2, r) {
  4132. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4133. var x0 = this._x1,
  4134. y0 = this._y1,
  4135. x21 = x2 - x1,
  4136. y21 = y2 - y1,
  4137. x01 = x0 - x1,
  4138. y01 = y0 - y1,
  4139. l01_2 = x01 * x01 + y01 * y01;
  4140. // Is the radius negative? Error.
  4141. if (r < 0) throw new Error("negative radius: " + r);
  4142. // Is this path empty? Move to (x1,y1).
  4143. if (this._x1 === null) {
  4144. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4145. }
  4146. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4147. else if (!(l01_2 > epsilon$1)) {}
  4148. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4149. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4150. // Or, is the radius zero? Line to (x1,y1).
  4151. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4152. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4153. }
  4154. // Otherwise, draw an arc!
  4155. else {
  4156. var x20 = x2 - x0,
  4157. y20 = y2 - y0,
  4158. l21_2 = x21 * x21 + y21 * y21,
  4159. l20_2 = x20 * x20 + y20 * y20,
  4160. l21 = Math.sqrt(l21_2),
  4161. l01 = Math.sqrt(l01_2),
  4162. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4163. t01 = l / l01,
  4164. t21 = l / l21;
  4165. // If the start tangent is not coincident with (x0,y0), line to.
  4166. if (Math.abs(t01 - 1) > epsilon$1) {
  4167. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4168. }
  4169. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4170. }
  4171. },
  4172. arc: function(x, y, r, a0, a1, ccw) {
  4173. x = +x, y = +y, r = +r;
  4174. var dx = r * Math.cos(a0),
  4175. dy = r * Math.sin(a0),
  4176. x0 = x + dx,
  4177. y0 = y + dy,
  4178. cw = 1 ^ ccw,
  4179. da = ccw ? a0 - a1 : a1 - a0;
  4180. // Is the radius negative? Error.
  4181. if (r < 0) throw new Error("negative radius: " + r);
  4182. // Is this path empty? Move to (x0,y0).
  4183. if (this._x1 === null) {
  4184. this._ += "M" + x0 + "," + y0;
  4185. }
  4186. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4187. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4188. this._ += "L" + x0 + "," + y0;
  4189. }
  4190. // Is this arc empty? We’re done.
  4191. if (!r) return;
  4192. // Does the angle go the wrong way? Flip the direction.
  4193. if (da < 0) da = da % tau$2 + tau$2;
  4194. // Is this a complete circle? Draw two arcs to complete the circle.
  4195. if (da > tauEpsilon) {
  4196. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4197. }
  4198. // Is this arc non-empty? Draw an arc!
  4199. else if (da > epsilon$1) {
  4200. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4201. }
  4202. },
  4203. rect: function(x, y, w, h) {
  4204. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4205. },
  4206. toString: function() {
  4207. return this._;
  4208. }
  4209. };
  4210. function defaultSource(d) {
  4211. return d.source;
  4212. }
  4213. function defaultTarget(d) {
  4214. return d.target;
  4215. }
  4216. function defaultRadius(d) {
  4217. return d.radius;
  4218. }
  4219. function defaultStartAngle(d) {
  4220. return d.startAngle;
  4221. }
  4222. function defaultEndAngle(d) {
  4223. return d.endAngle;
  4224. }
  4225. var ribbon = function() {
  4226. var source = defaultSource,
  4227. target = defaultTarget,
  4228. radius = defaultRadius,
  4229. startAngle = defaultStartAngle,
  4230. endAngle = defaultEndAngle,
  4231. context = null;
  4232. function ribbon() {
  4233. var buffer,
  4234. argv = slice$2.call(arguments),
  4235. s = source.apply(this, argv),
  4236. t = target.apply(this, argv),
  4237. sr = +radius.apply(this, (argv[0] = s, argv)),
  4238. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4239. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4240. sx0 = sr * cos(sa0),
  4241. sy0 = sr * sin(sa0),
  4242. tr = +radius.apply(this, (argv[0] = t, argv)),
  4243. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4244. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4245. if (!context) context = buffer = path();
  4246. context.moveTo(sx0, sy0);
  4247. context.arc(0, 0, sr, sa0, sa1);
  4248. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4249. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4250. context.arc(0, 0, tr, ta0, ta1);
  4251. }
  4252. context.quadraticCurveTo(0, 0, sx0, sy0);
  4253. context.closePath();
  4254. if (buffer) return context = null, buffer + "" || null;
  4255. }
  4256. ribbon.radius = function(_) {
  4257. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4258. };
  4259. ribbon.startAngle = function(_) {
  4260. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4261. };
  4262. ribbon.endAngle = function(_) {
  4263. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4264. };
  4265. ribbon.source = function(_) {
  4266. return arguments.length ? (source = _, ribbon) : source;
  4267. };
  4268. ribbon.target = function(_) {
  4269. return arguments.length ? (target = _, ribbon) : target;
  4270. };
  4271. ribbon.context = function(_) {
  4272. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  4273. };
  4274. return ribbon;
  4275. };
  4276. var prefix = "$";
  4277. function Map() {}
  4278. Map.prototype = map$1.prototype = {
  4279. constructor: Map,
  4280. has: function(key) {
  4281. return (prefix + key) in this;
  4282. },
  4283. get: function(key) {
  4284. return this[prefix + key];
  4285. },
  4286. set: function(key, value) {
  4287. this[prefix + key] = value;
  4288. return this;
  4289. },
  4290. remove: function(key) {
  4291. var property = prefix + key;
  4292. return property in this && delete this[property];
  4293. },
  4294. clear: function() {
  4295. for (var property in this) if (property[0] === prefix) delete this[property];
  4296. },
  4297. keys: function() {
  4298. var keys = [];
  4299. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4300. return keys;
  4301. },
  4302. values: function() {
  4303. var values = [];
  4304. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4305. return values;
  4306. },
  4307. entries: function() {
  4308. var entries = [];
  4309. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4310. return entries;
  4311. },
  4312. size: function() {
  4313. var size = 0;
  4314. for (var property in this) if (property[0] === prefix) ++size;
  4315. return size;
  4316. },
  4317. empty: function() {
  4318. for (var property in this) if (property[0] === prefix) return false;
  4319. return true;
  4320. },
  4321. each: function(f) {
  4322. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4323. }
  4324. };
  4325. function map$1(object, f) {
  4326. var map = new Map;
  4327. // Copy constructor.
  4328. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4329. // Index array by numeric index or specified key function.
  4330. else if (Array.isArray(object)) {
  4331. var i = -1,
  4332. n = object.length,
  4333. o;
  4334. if (f == null) while (++i < n) map.set(i, object[i]);
  4335. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4336. }
  4337. // Convert object to map.
  4338. else if (object) for (var key in object) map.set(key, object[key]);
  4339. return map;
  4340. }
  4341. var nest = function() {
  4342. var keys = [],
  4343. sortKeys = [],
  4344. sortValues,
  4345. rollup,
  4346. nest;
  4347. function apply(array, depth, createResult, setResult) {
  4348. if (depth >= keys.length) {
  4349. if (sortValues != null) array.sort(sortValues);
  4350. return rollup != null ? rollup(array) : array;
  4351. }
  4352. var i = -1,
  4353. n = array.length,
  4354. key = keys[depth++],
  4355. keyValue,
  4356. value,
  4357. valuesByKey = map$1(),
  4358. values,
  4359. result = createResult();
  4360. while (++i < n) {
  4361. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4362. values.push(value);
  4363. } else {
  4364. valuesByKey.set(keyValue, [value]);
  4365. }
  4366. }
  4367. valuesByKey.each(function(values, key) {
  4368. setResult(result, key, apply(values, depth, createResult, setResult));
  4369. });
  4370. return result;
  4371. }
  4372. function entries(map, depth) {
  4373. if (++depth > keys.length) return map;
  4374. var array, sortKey = sortKeys[depth - 1];
  4375. if (rollup != null && depth >= keys.length) array = map.entries();
  4376. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4377. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4378. }
  4379. return nest = {
  4380. object: function(array) { return apply(array, 0, createObject, setObject); },
  4381. map: function(array) { return apply(array, 0, createMap, setMap); },
  4382. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4383. key: function(d) { keys.push(d); return nest; },
  4384. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4385. sortValues: function(order) { sortValues = order; return nest; },
  4386. rollup: function(f) { rollup = f; return nest; }
  4387. };
  4388. };
  4389. function createObject() {
  4390. return {};
  4391. }
  4392. function setObject(object, key, value) {
  4393. object[key] = value;
  4394. }
  4395. function createMap() {
  4396. return map$1();
  4397. }
  4398. function setMap(map, key, value) {
  4399. map.set(key, value);
  4400. }
  4401. function Set() {}
  4402. var proto = map$1.prototype;
  4403. Set.prototype = set$2.prototype = {
  4404. constructor: Set,
  4405. has: proto.has,
  4406. add: function(value) {
  4407. value += "";
  4408. this[prefix + value] = value;
  4409. return this;
  4410. },
  4411. remove: proto.remove,
  4412. clear: proto.clear,
  4413. values: proto.keys,
  4414. size: proto.size,
  4415. empty: proto.empty,
  4416. each: proto.each
  4417. };
  4418. function set$2(object, f) {
  4419. var set = new Set;
  4420. // Copy constructor.
  4421. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4422. // Otherwise, assume it’s an array.
  4423. else if (object) {
  4424. var i = -1, n = object.length;
  4425. if (f == null) while (++i < n) set.add(object[i]);
  4426. else while (++i < n) set.add(f(object[i], i, object));
  4427. }
  4428. return set;
  4429. }
  4430. var keys = function(map) {
  4431. var keys = [];
  4432. for (var key in map) keys.push(key);
  4433. return keys;
  4434. };
  4435. var values = function(map) {
  4436. var values = [];
  4437. for (var key in map) values.push(map[key]);
  4438. return values;
  4439. };
  4440. var entries = function(map) {
  4441. var entries = [];
  4442. for (var key in map) entries.push({key: key, value: map[key]});
  4443. return entries;
  4444. };
  4445. var EOL = {};
  4446. var EOF = {};
  4447. var QUOTE = 34;
  4448. var NEWLINE = 10;
  4449. var RETURN = 13;
  4450. function objectConverter(columns) {
  4451. return new Function("d", "return {" + columns.map(function(name, i) {
  4452. return JSON.stringify(name) + ": d[" + i + "]";
  4453. }).join(",") + "}");
  4454. }
  4455. function customConverter(columns, f) {
  4456. var object = objectConverter(columns);
  4457. return function(row, i) {
  4458. return f(object(row), i, columns);
  4459. };
  4460. }
  4461. // Compute unique columns in order of discovery.
  4462. function inferColumns(rows) {
  4463. var columnSet = Object.create(null),
  4464. columns = [];
  4465. rows.forEach(function(row) {
  4466. for (var column in row) {
  4467. if (!(column in columnSet)) {
  4468. columns.push(columnSet[column] = column);
  4469. }
  4470. }
  4471. });
  4472. return columns;
  4473. }
  4474. var dsv = function(delimiter) {
  4475. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  4476. DELIMITER = delimiter.charCodeAt(0);
  4477. function parse(text, f) {
  4478. var convert, columns, rows = parseRows(text, function(row, i) {
  4479. if (convert) return convert(row, i - 1);
  4480. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  4481. });
  4482. rows.columns = columns;
  4483. return rows;
  4484. }
  4485. function parseRows(text, f) {
  4486. var rows = [], // output rows
  4487. N = text.length,
  4488. I = 0, // current character index
  4489. n = 0, // current line number
  4490. t, // current token
  4491. eof = N <= 0, // current token followed by EOF?
  4492. eol = false; // current token followed by EOL?
  4493. // Strip the trailing newline.
  4494. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  4495. if (text.charCodeAt(N - 1) === RETURN) --N;
  4496. function token() {
  4497. if (eof) return EOF;
  4498. if (eol) return eol = false, EOL;
  4499. // Unescape quotes.
  4500. var i, j = I, c;
  4501. if (text.charCodeAt(j) === QUOTE) {
  4502. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  4503. if ((i = I) >= N) eof = true;
  4504. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  4505. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4506. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  4507. }
  4508. // Find next delimiter or newline.
  4509. while (I < N) {
  4510. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  4511. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4512. else if (c !== DELIMITER) continue;
  4513. return text.slice(j, i);
  4514. }
  4515. // Return last token before EOF.
  4516. return eof = true, text.slice(j, N);
  4517. }
  4518. while ((t = token()) !== EOF) {
  4519. var row = [];
  4520. while (t !== EOL && t !== EOF) row.push(t), t = token();
  4521. if (f && (row = f(row, n++)) == null) continue;
  4522. rows.push(row);
  4523. }
  4524. return rows;
  4525. }
  4526. function format(rows, columns) {
  4527. if (columns == null) columns = inferColumns(rows);
  4528. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  4529. return columns.map(function(column) {
  4530. return formatValue(row[column]);
  4531. }).join(delimiter);
  4532. })).join("\n");
  4533. }
  4534. function formatRows(rows) {
  4535. return rows.map(formatRow).join("\n");
  4536. }
  4537. function formatRow(row) {
  4538. return row.map(formatValue).join(delimiter);
  4539. }
  4540. function formatValue(text) {
  4541. return text == null ? ""
  4542. : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
  4543. : text;
  4544. }
  4545. return {
  4546. parse: parse,
  4547. parseRows: parseRows,
  4548. format: format,
  4549. formatRows: formatRows
  4550. };
  4551. };
  4552. var csv = dsv(",");
  4553. var csvParse = csv.parse;
  4554. var csvParseRows = csv.parseRows;
  4555. var csvFormat = csv.format;
  4556. var csvFormatRows = csv.formatRows;
  4557. var tsv = dsv("\t");
  4558. var tsvParse = tsv.parse;
  4559. var tsvParseRows = tsv.parseRows;
  4560. var tsvFormat = tsv.format;
  4561. var tsvFormatRows = tsv.formatRows;
  4562. var center$1 = function(x, y) {
  4563. var nodes;
  4564. if (x == null) x = 0;
  4565. if (y == null) y = 0;
  4566. function force() {
  4567. var i,
  4568. n = nodes.length,
  4569. node,
  4570. sx = 0,
  4571. sy = 0;
  4572. for (i = 0; i < n; ++i) {
  4573. node = nodes[i], sx += node.x, sy += node.y;
  4574. }
  4575. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  4576. node = nodes[i], node.x -= sx, node.y -= sy;
  4577. }
  4578. }
  4579. force.initialize = function(_) {
  4580. nodes = _;
  4581. };
  4582. force.x = function(_) {
  4583. return arguments.length ? (x = +_, force) : x;
  4584. };
  4585. force.y = function(_) {
  4586. return arguments.length ? (y = +_, force) : y;
  4587. };
  4588. return force;
  4589. };
  4590. var constant$6 = function(x) {
  4591. return function() {
  4592. return x;
  4593. };
  4594. };
  4595. var jiggle = function() {
  4596. return (Math.random() - 0.5) * 1e-6;
  4597. };
  4598. var tree_add = function(d) {
  4599. var x = +this._x.call(null, d),
  4600. y = +this._y.call(null, d);
  4601. return add(this.cover(x, y), x, y, d);
  4602. };
  4603. function add(tree, x, y, d) {
  4604. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  4605. var parent,
  4606. node = tree._root,
  4607. leaf = {data: d},
  4608. x0 = tree._x0,
  4609. y0 = tree._y0,
  4610. x1 = tree._x1,
  4611. y1 = tree._y1,
  4612. xm,
  4613. ym,
  4614. xp,
  4615. yp,
  4616. right,
  4617. bottom,
  4618. i,
  4619. j;
  4620. // If the tree is empty, initialize the root as a leaf.
  4621. if (!node) return tree._root = leaf, tree;
  4622. // Find the existing leaf for the new point, or add it.
  4623. while (node.length) {
  4624. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4625. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4626. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  4627. }
  4628. // Is the new point is exactly coincident with the existing point?
  4629. xp = +tree._x.call(null, node.data);
  4630. yp = +tree._y.call(null, node.data);
  4631. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  4632. // Otherwise, split the leaf node until the old and new point are separated.
  4633. do {
  4634. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  4635. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4636. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4637. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  4638. return parent[j] = node, parent[i] = leaf, tree;
  4639. }
  4640. function addAll(data) {
  4641. var d, i, n = data.length,
  4642. x,
  4643. y,
  4644. xz = new Array(n),
  4645. yz = new Array(n),
  4646. x0 = Infinity,
  4647. y0 = Infinity,
  4648. x1 = -Infinity,
  4649. y1 = -Infinity;
  4650. // Compute the points and their extent.
  4651. for (i = 0; i < n; ++i) {
  4652. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  4653. xz[i] = x;
  4654. yz[i] = y;
  4655. if (x < x0) x0 = x;
  4656. if (x > x1) x1 = x;
  4657. if (y < y0) y0 = y;
  4658. if (y > y1) y1 = y;
  4659. }
  4660. // If there were no (valid) points, inherit the existing extent.
  4661. if (x1 < x0) x0 = this._x0, x1 = this._x1;
  4662. if (y1 < y0) y0 = this._y0, y1 = this._y1;
  4663. // Expand the tree to cover the new points.
  4664. this.cover(x0, y0).cover(x1, y1);
  4665. // Add the new points.
  4666. for (i = 0; i < n; ++i) {
  4667. add(this, xz[i], yz[i], data[i]);
  4668. }
  4669. return this;
  4670. }
  4671. var tree_cover = function(x, y) {
  4672. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  4673. var x0 = this._x0,
  4674. y0 = this._y0,
  4675. x1 = this._x1,
  4676. y1 = this._y1;
  4677. // If the quadtree has no extent, initialize them.
  4678. // Integer extent are necessary so that if we later double the extent,
  4679. // the existing quadrant boundaries don’t change due to floating point error!
  4680. if (isNaN(x0)) {
  4681. x1 = (x0 = Math.floor(x)) + 1;
  4682. y1 = (y0 = Math.floor(y)) + 1;
  4683. }
  4684. // Otherwise, double repeatedly to cover.
  4685. else if (x0 > x || x > x1 || y0 > y || y > y1) {
  4686. var z = x1 - x0,
  4687. node = this._root,
  4688. parent,
  4689. i;
  4690. switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
  4691. case 0: {
  4692. do parent = new Array(4), parent[i] = node, node = parent;
  4693. while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
  4694. break;
  4695. }
  4696. case 1: {
  4697. do parent = new Array(4), parent[i] = node, node = parent;
  4698. while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
  4699. break;
  4700. }
  4701. case 2: {
  4702. do parent = new Array(4), parent[i] = node, node = parent;
  4703. while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
  4704. break;
  4705. }
  4706. case 3: {
  4707. do parent = new Array(4), parent[i] = node, node = parent;
  4708. while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
  4709. break;
  4710. }
  4711. }
  4712. if (this._root && this._root.length) this._root = node;
  4713. }
  4714. // If the quadtree covers the point already, just return.
  4715. else return this;
  4716. this._x0 = x0;
  4717. this._y0 = y0;
  4718. this._x1 = x1;
  4719. this._y1 = y1;
  4720. return this;
  4721. };
  4722. var tree_data = function() {
  4723. var data = [];
  4724. this.visit(function(node) {
  4725. if (!node.length) do data.push(node.data); while (node = node.next)
  4726. });
  4727. return data;
  4728. };
  4729. var tree_extent = function(_) {
  4730. return arguments.length
  4731. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  4732. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  4733. };
  4734. var Quad = function(node, x0, y0, x1, y1) {
  4735. this.node = node;
  4736. this.x0 = x0;
  4737. this.y0 = y0;
  4738. this.x1 = x1;
  4739. this.y1 = y1;
  4740. };
  4741. var tree_find = function(x, y, radius) {
  4742. var data,
  4743. x0 = this._x0,
  4744. y0 = this._y0,
  4745. x1,
  4746. y1,
  4747. x2,
  4748. y2,
  4749. x3 = this._x1,
  4750. y3 = this._y1,
  4751. quads = [],
  4752. node = this._root,
  4753. q,
  4754. i;
  4755. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  4756. if (radius == null) radius = Infinity;
  4757. else {
  4758. x0 = x - radius, y0 = y - radius;
  4759. x3 = x + radius, y3 = y + radius;
  4760. radius *= radius;
  4761. }
  4762. while (q = quads.pop()) {
  4763. // Stop searching if this quadrant can’t contain a closer node.
  4764. if (!(node = q.node)
  4765. || (x1 = q.x0) > x3
  4766. || (y1 = q.y0) > y3
  4767. || (x2 = q.x1) < x0
  4768. || (y2 = q.y1) < y0) continue;
  4769. // Bisect the current quadrant.
  4770. if (node.length) {
  4771. var xm = (x1 + x2) / 2,
  4772. ym = (y1 + y2) / 2;
  4773. quads.push(
  4774. new Quad(node[3], xm, ym, x2, y2),
  4775. new Quad(node[2], x1, ym, xm, y2),
  4776. new Quad(node[1], xm, y1, x2, ym),
  4777. new Quad(node[0], x1, y1, xm, ym)
  4778. );
  4779. // Visit the closest quadrant first.
  4780. if (i = (y >= ym) << 1 | (x >= xm)) {
  4781. q = quads[quads.length - 1];
  4782. quads[quads.length - 1] = quads[quads.length - 1 - i];
  4783. quads[quads.length - 1 - i] = q;
  4784. }
  4785. }
  4786. // Visit this point. (Visiting coincident points isn’t necessary!)
  4787. else {
  4788. var dx = x - +this._x.call(null, node.data),
  4789. dy = y - +this._y.call(null, node.data),
  4790. d2 = dx * dx + dy * dy;
  4791. if (d2 < radius) {
  4792. var d = Math.sqrt(radius = d2);
  4793. x0 = x - d, y0 = y - d;
  4794. x3 = x + d, y3 = y + d;
  4795. data = node.data;
  4796. }
  4797. }
  4798. }
  4799. return data;
  4800. };
  4801. var tree_remove = function(d) {
  4802. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  4803. var parent,
  4804. node = this._root,
  4805. retainer,
  4806. previous,
  4807. next,
  4808. x0 = this._x0,
  4809. y0 = this._y0,
  4810. x1 = this._x1,
  4811. y1 = this._y1,
  4812. x,
  4813. y,
  4814. xm,
  4815. ym,
  4816. right,
  4817. bottom,
  4818. i,
  4819. j;
  4820. // If the tree is empty, initialize the root as a leaf.
  4821. if (!node) return this;
  4822. // Find the leaf node for the point.
  4823. // While descending, also retain the deepest parent with a non-removed sibling.
  4824. if (node.length) while (true) {
  4825. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4826. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4827. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  4828. if (!node.length) break;
  4829. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  4830. }
  4831. // Find the point to remove.
  4832. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  4833. if (next = node.next) delete node.next;
  4834. // If there are multiple coincident points, remove just the point.
  4835. if (previous) return (next ? previous.next = next : delete previous.next), this;
  4836. // If this is the root point, remove it.
  4837. if (!parent) return this._root = next, this;
  4838. // Remove this leaf.
  4839. next ? parent[i] = next : delete parent[i];
  4840. // If the parent now contains exactly one leaf, collapse superfluous parents.
  4841. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  4842. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  4843. && !node.length) {
  4844. if (retainer) retainer[j] = node;
  4845. else this._root = node;
  4846. }
  4847. return this;
  4848. };
  4849. function removeAll(data) {
  4850. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  4851. return this;
  4852. }
  4853. var tree_root = function() {
  4854. return this._root;
  4855. };
  4856. var tree_size = function() {
  4857. var size = 0;
  4858. this.visit(function(node) {
  4859. if (!node.length) do ++size; while (node = node.next)
  4860. });
  4861. return size;
  4862. };
  4863. var tree_visit = function(callback) {
  4864. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  4865. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  4866. while (q = quads.pop()) {
  4867. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  4868. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  4869. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  4870. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  4871. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  4872. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  4873. }
  4874. }
  4875. return this;
  4876. };
  4877. var tree_visitAfter = function(callback) {
  4878. var quads = [], next = [], q;
  4879. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  4880. while (q = quads.pop()) {
  4881. var node = q.node;
  4882. if (node.length) {
  4883. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  4884. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  4885. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  4886. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  4887. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  4888. }
  4889. next.push(q);
  4890. }
  4891. while (q = next.pop()) {
  4892. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  4893. }
  4894. return this;
  4895. };
  4896. function defaultX(d) {
  4897. return d[0];
  4898. }
  4899. var tree_x = function(_) {
  4900. return arguments.length ? (this._x = _, this) : this._x;
  4901. };
  4902. function defaultY(d) {
  4903. return d[1];
  4904. }
  4905. var tree_y = function(_) {
  4906. return arguments.length ? (this._y = _, this) : this._y;
  4907. };
  4908. function quadtree(nodes, x, y) {
  4909. var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
  4910. return nodes == null ? tree : tree.addAll(nodes);
  4911. }
  4912. function Quadtree(x, y, x0, y0, x1, y1) {
  4913. this._x = x;
  4914. this._y = y;
  4915. this._x0 = x0;
  4916. this._y0 = y0;
  4917. this._x1 = x1;
  4918. this._y1 = y1;
  4919. this._root = undefined;
  4920. }
  4921. function leaf_copy(leaf) {
  4922. var copy = {data: leaf.data}, next = copy;
  4923. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  4924. return copy;
  4925. }
  4926. var treeProto = quadtree.prototype = Quadtree.prototype;
  4927. treeProto.copy = function() {
  4928. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  4929. node = this._root,
  4930. nodes,
  4931. child;
  4932. if (!node) return copy;
  4933. if (!node.length) return copy._root = leaf_copy(node), copy;
  4934. nodes = [{source: node, target: copy._root = new Array(4)}];
  4935. while (node = nodes.pop()) {
  4936. for (var i = 0; i < 4; ++i) {
  4937. if (child = node.source[i]) {
  4938. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  4939. else node.target[i] = leaf_copy(child);
  4940. }
  4941. }
  4942. }
  4943. return copy;
  4944. };
  4945. treeProto.add = tree_add;
  4946. treeProto.addAll = addAll;
  4947. treeProto.cover = tree_cover;
  4948. treeProto.data = tree_data;
  4949. treeProto.extent = tree_extent;
  4950. treeProto.find = tree_find;
  4951. treeProto.remove = tree_remove;
  4952. treeProto.removeAll = removeAll;
  4953. treeProto.root = tree_root;
  4954. treeProto.size = tree_size;
  4955. treeProto.visit = tree_visit;
  4956. treeProto.visitAfter = tree_visitAfter;
  4957. treeProto.x = tree_x;
  4958. treeProto.y = tree_y;
  4959. function x(d) {
  4960. return d.x + d.vx;
  4961. }
  4962. function y(d) {
  4963. return d.y + d.vy;
  4964. }
  4965. var collide = function(radius) {
  4966. var nodes,
  4967. radii,
  4968. strength = 1,
  4969. iterations = 1;
  4970. if (typeof radius !== "function") radius = constant$6(radius == null ? 1 : +radius);
  4971. function force() {
  4972. var i, n = nodes.length,
  4973. tree,
  4974. node,
  4975. xi,
  4976. yi,
  4977. ri,
  4978. ri2;
  4979. for (var k = 0; k < iterations; ++k) {
  4980. tree = quadtree(nodes, x, y).visitAfter(prepare);
  4981. for (i = 0; i < n; ++i) {
  4982. node = nodes[i];
  4983. ri = radii[node.index], ri2 = ri * ri;
  4984. xi = node.x + node.vx;
  4985. yi = node.y + node.vy;
  4986. tree.visit(apply);
  4987. }
  4988. }
  4989. function apply(quad, x0, y0, x1, y1) {
  4990. var data = quad.data, rj = quad.r, r = ri + rj;
  4991. if (data) {
  4992. if (data.index > node.index) {
  4993. var x = xi - data.x - data.vx,
  4994. y = yi - data.y - data.vy,
  4995. l = x * x + y * y;
  4996. if (l < r * r) {
  4997. if (x === 0) x = jiggle(), l += x * x;
  4998. if (y === 0) y = jiggle(), l += y * y;
  4999. l = (r - (l = Math.sqrt(l))) / l * strength;
  5000. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5001. node.vy += (y *= l) * r;
  5002. data.vx -= x * (r = 1 - r);
  5003. data.vy -= y * r;
  5004. }
  5005. }
  5006. return;
  5007. }
  5008. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5009. }
  5010. }
  5011. function prepare(quad) {
  5012. if (quad.data) return quad.r = radii[quad.data.index];
  5013. for (var i = quad.r = 0; i < 4; ++i) {
  5014. if (quad[i] && quad[i].r > quad.r) {
  5015. quad.r = quad[i].r;
  5016. }
  5017. }
  5018. }
  5019. function initialize() {
  5020. if (!nodes) return;
  5021. var i, n = nodes.length, node;
  5022. radii = new Array(n);
  5023. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5024. }
  5025. force.initialize = function(_) {
  5026. nodes = _;
  5027. initialize();
  5028. };
  5029. force.iterations = function(_) {
  5030. return arguments.length ? (iterations = +_, force) : iterations;
  5031. };
  5032. force.strength = function(_) {
  5033. return arguments.length ? (strength = +_, force) : strength;
  5034. };
  5035. force.radius = function(_) {
  5036. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
  5037. };
  5038. return force;
  5039. };
  5040. function index(d) {
  5041. return d.index;
  5042. }
  5043. function find(nodeById, nodeId) {
  5044. var node = nodeById.get(nodeId);
  5045. if (!node) throw new Error("missing: " + nodeId);
  5046. return node;
  5047. }
  5048. var link = function(links) {
  5049. var id = index,
  5050. strength = defaultStrength,
  5051. strengths,
  5052. distance = constant$6(30),
  5053. distances,
  5054. nodes,
  5055. count,
  5056. bias,
  5057. iterations = 1;
  5058. if (links == null) links = [];
  5059. function defaultStrength(link) {
  5060. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5061. }
  5062. function force(alpha) {
  5063. for (var k = 0, n = links.length; k < iterations; ++k) {
  5064. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5065. link = links[i], source = link.source, target = link.target;
  5066. x = target.x + target.vx - source.x - source.vx || jiggle();
  5067. y = target.y + target.vy - source.y - source.vy || jiggle();
  5068. l = Math.sqrt(x * x + y * y);
  5069. l = (l - distances[i]) / l * alpha * strengths[i];
  5070. x *= l, y *= l;
  5071. target.vx -= x * (b = bias[i]);
  5072. target.vy -= y * b;
  5073. source.vx += x * (b = 1 - b);
  5074. source.vy += y * b;
  5075. }
  5076. }
  5077. }
  5078. function initialize() {
  5079. if (!nodes) return;
  5080. var i,
  5081. n = nodes.length,
  5082. m = links.length,
  5083. nodeById = map$1(nodes, id),
  5084. link;
  5085. for (i = 0, count = new Array(n); i < m; ++i) {
  5086. link = links[i], link.index = i;
  5087. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5088. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5089. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5090. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5091. }
  5092. for (i = 0, bias = new Array(m); i < m; ++i) {
  5093. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5094. }
  5095. strengths = new Array(m), initializeStrength();
  5096. distances = new Array(m), initializeDistance();
  5097. }
  5098. function initializeStrength() {
  5099. if (!nodes) return;
  5100. for (var i = 0, n = links.length; i < n; ++i) {
  5101. strengths[i] = +strength(links[i], i, links);
  5102. }
  5103. }
  5104. function initializeDistance() {
  5105. if (!nodes) return;
  5106. for (var i = 0, n = links.length; i < n; ++i) {
  5107. distances[i] = +distance(links[i], i, links);
  5108. }
  5109. }
  5110. force.initialize = function(_) {
  5111. nodes = _;
  5112. initialize();
  5113. };
  5114. force.links = function(_) {
  5115. return arguments.length ? (links = _, initialize(), force) : links;
  5116. };
  5117. force.id = function(_) {
  5118. return arguments.length ? (id = _, force) : id;
  5119. };
  5120. force.iterations = function(_) {
  5121. return arguments.length ? (iterations = +_, force) : iterations;
  5122. };
  5123. force.strength = function(_) {
  5124. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initializeStrength(), force) : strength;
  5125. };
  5126. force.distance = function(_) {
  5127. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$6(+_), initializeDistance(), force) : distance;
  5128. };
  5129. return force;
  5130. };
  5131. function x$1(d) {
  5132. return d.x;
  5133. }
  5134. function y$1(d) {
  5135. return d.y;
  5136. }
  5137. var initialRadius = 10;
  5138. var initialAngle = Math.PI * (3 - Math.sqrt(5));
  5139. var simulation = function(nodes) {
  5140. var simulation,
  5141. alpha = 1,
  5142. alphaMin = 0.001,
  5143. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5144. alphaTarget = 0,
  5145. velocityDecay = 0.6,
  5146. forces = map$1(),
  5147. stepper = timer(step),
  5148. event = dispatch("tick", "end");
  5149. if (nodes == null) nodes = [];
  5150. function step() {
  5151. tick();
  5152. event.call("tick", simulation);
  5153. if (alpha < alphaMin) {
  5154. stepper.stop();
  5155. event.call("end", simulation);
  5156. }
  5157. }
  5158. function tick() {
  5159. var i, n = nodes.length, node;
  5160. alpha += (alphaTarget - alpha) * alphaDecay;
  5161. forces.each(function(force) {
  5162. force(alpha);
  5163. });
  5164. for (i = 0; i < n; ++i) {
  5165. node = nodes[i];
  5166. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5167. else node.x = node.fx, node.vx = 0;
  5168. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5169. else node.y = node.fy, node.vy = 0;
  5170. }
  5171. }
  5172. function initializeNodes() {
  5173. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5174. node = nodes[i], node.index = i;
  5175. if (isNaN(node.x) || isNaN(node.y)) {
  5176. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5177. node.x = radius * Math.cos(angle);
  5178. node.y = radius * Math.sin(angle);
  5179. }
  5180. if (isNaN(node.vx) || isNaN(node.vy)) {
  5181. node.vx = node.vy = 0;
  5182. }
  5183. }
  5184. }
  5185. function initializeForce(force) {
  5186. if (force.initialize) force.initialize(nodes);
  5187. return force;
  5188. }
  5189. initializeNodes();
  5190. return simulation = {
  5191. tick: tick,
  5192. restart: function() {
  5193. return stepper.restart(step), simulation;
  5194. },
  5195. stop: function() {
  5196. return stepper.stop(), simulation;
  5197. },
  5198. nodes: function(_) {
  5199. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5200. },
  5201. alpha: function(_) {
  5202. return arguments.length ? (alpha = +_, simulation) : alpha;
  5203. },
  5204. alphaMin: function(_) {
  5205. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5206. },
  5207. alphaDecay: function(_) {
  5208. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5209. },
  5210. alphaTarget: function(_) {
  5211. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5212. },
  5213. velocityDecay: function(_) {
  5214. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5215. },
  5216. force: function(name, _) {
  5217. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  5218. },
  5219. find: function(x, y, radius) {
  5220. var i = 0,
  5221. n = nodes.length,
  5222. dx,
  5223. dy,
  5224. d2,
  5225. node,
  5226. closest;
  5227. if (radius == null) radius = Infinity;
  5228. else radius *= radius;
  5229. for (i = 0; i < n; ++i) {
  5230. node = nodes[i];
  5231. dx = x - node.x;
  5232. dy = y - node.y;
  5233. d2 = dx * dx + dy * dy;
  5234. if (d2 < radius) closest = node, radius = d2;
  5235. }
  5236. return closest;
  5237. },
  5238. on: function(name, _) {
  5239. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5240. }
  5241. };
  5242. };
  5243. var manyBody = function() {
  5244. var nodes,
  5245. node,
  5246. alpha,
  5247. strength = constant$6(-30),
  5248. strengths,
  5249. distanceMin2 = 1,
  5250. distanceMax2 = Infinity,
  5251. theta2 = 0.81;
  5252. function force(_) {
  5253. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5254. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5255. }
  5256. function initialize() {
  5257. if (!nodes) return;
  5258. var i, n = nodes.length, node;
  5259. strengths = new Array(n);
  5260. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5261. }
  5262. function accumulate(quad) {
  5263. var strength = 0, q, c, weight = 0, x, y, i;
  5264. // For internal nodes, accumulate forces from child quadrants.
  5265. if (quad.length) {
  5266. for (x = y = i = 0; i < 4; ++i) {
  5267. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5268. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5269. }
  5270. }
  5271. quad.x = x / weight;
  5272. quad.y = y / weight;
  5273. }
  5274. // For leaf nodes, accumulate forces from coincident quadrants.
  5275. else {
  5276. q = quad;
  5277. q.x = q.data.x;
  5278. q.y = q.data.y;
  5279. do strength += strengths[q.data.index];
  5280. while (q = q.next);
  5281. }
  5282. quad.value = strength;
  5283. }
  5284. function apply(quad, x1, _, x2) {
  5285. if (!quad.value) return true;
  5286. var x = quad.x - node.x,
  5287. y = quad.y - node.y,
  5288. w = x2 - x1,
  5289. l = x * x + y * y;
  5290. // Apply the Barnes-Hut approximation if possible.
  5291. // Limit forces for very close nodes; randomize direction if coincident.
  5292. if (w * w / theta2 < l) {
  5293. if (l < distanceMax2) {
  5294. if (x === 0) x = jiggle(), l += x * x;
  5295. if (y === 0) y = jiggle(), l += y * y;
  5296. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5297. node.vx += x * quad.value * alpha / l;
  5298. node.vy += y * quad.value * alpha / l;
  5299. }
  5300. return true;
  5301. }
  5302. // Otherwise, process points directly.
  5303. else if (quad.length || l >= distanceMax2) return;
  5304. // Limit forces for very close nodes; randomize direction if coincident.
  5305. if (quad.data !== node || quad.next) {
  5306. if (x === 0) x = jiggle(), l += x * x;
  5307. if (y === 0) y = jiggle(), l += y * y;
  5308. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5309. }
  5310. do if (quad.data !== node) {
  5311. w = strengths[quad.data.index] * alpha / l;
  5312. node.vx += x * w;
  5313. node.vy += y * w;
  5314. } while (quad = quad.next);
  5315. }
  5316. force.initialize = function(_) {
  5317. nodes = _;
  5318. initialize();
  5319. };
  5320. force.strength = function(_) {
  5321. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5322. };
  5323. force.distanceMin = function(_) {
  5324. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5325. };
  5326. force.distanceMax = function(_) {
  5327. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5328. };
  5329. force.theta = function(_) {
  5330. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  5331. };
  5332. return force;
  5333. };
  5334. var radial = function(radius, x, y) {
  5335. var nodes,
  5336. strength = constant$6(0.1),
  5337. strengths,
  5338. radiuses;
  5339. if (typeof radius !== "function") radius = constant$6(+radius);
  5340. if (x == null) x = 0;
  5341. if (y == null) y = 0;
  5342. function force(alpha) {
  5343. for (var i = 0, n = nodes.length; i < n; ++i) {
  5344. var node = nodes[i],
  5345. dx = node.x - x || 1e-6,
  5346. dy = node.y - y || 1e-6,
  5347. r = Math.sqrt(dx * dx + dy * dy),
  5348. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  5349. node.vx += dx * k;
  5350. node.vy += dy * k;
  5351. }
  5352. }
  5353. function initialize() {
  5354. if (!nodes) return;
  5355. var i, n = nodes.length;
  5356. strengths = new Array(n);
  5357. radiuses = new Array(n);
  5358. for (i = 0; i < n; ++i) {
  5359. radiuses[i] = +radius(nodes[i], i, nodes);
  5360. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  5361. }
  5362. }
  5363. force.initialize = function(_) {
  5364. nodes = _, initialize();
  5365. };
  5366. force.strength = function(_) {
  5367. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5368. };
  5369. force.radius = function(_) {
  5370. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
  5371. };
  5372. force.x = function(_) {
  5373. return arguments.length ? (x = +_, force) : x;
  5374. };
  5375. force.y = function(_) {
  5376. return arguments.length ? (y = +_, force) : y;
  5377. };
  5378. return force;
  5379. };
  5380. var x$2 = function(x) {
  5381. var strength = constant$6(0.1),
  5382. nodes,
  5383. strengths,
  5384. xz;
  5385. if (typeof x !== "function") x = constant$6(x == null ? 0 : +x);
  5386. function force(alpha) {
  5387. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5388. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  5389. }
  5390. }
  5391. function initialize() {
  5392. if (!nodes) return;
  5393. var i, n = nodes.length;
  5394. strengths = new Array(n);
  5395. xz = new Array(n);
  5396. for (i = 0; i < n; ++i) {
  5397. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5398. }
  5399. }
  5400. force.initialize = function(_) {
  5401. nodes = _;
  5402. initialize();
  5403. };
  5404. force.strength = function(_) {
  5405. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5406. };
  5407. force.x = function(_) {
  5408. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : x;
  5409. };
  5410. return force;
  5411. };
  5412. var y$2 = function(y) {
  5413. var strength = constant$6(0.1),
  5414. nodes,
  5415. strengths,
  5416. yz;
  5417. if (typeof y !== "function") y = constant$6(y == null ? 0 : +y);
  5418. function force(alpha) {
  5419. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5420. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  5421. }
  5422. }
  5423. function initialize() {
  5424. if (!nodes) return;
  5425. var i, n = nodes.length;
  5426. strengths = new Array(n);
  5427. yz = new Array(n);
  5428. for (i = 0; i < n; ++i) {
  5429. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5430. }
  5431. }
  5432. force.initialize = function(_) {
  5433. nodes = _;
  5434. initialize();
  5435. };
  5436. force.strength = function(_) {
  5437. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5438. };
  5439. force.y = function(_) {
  5440. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : y;
  5441. };
  5442. return force;
  5443. };
  5444. // Computes the decimal coefficient and exponent of the specified number x with
  5445. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  5446. // For example, formatDecimal(1.23) returns ["123", 0].
  5447. var formatDecimal = function(x, p) {
  5448. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  5449. var i, coefficient = x.slice(0, i);
  5450. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  5451. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  5452. return [
  5453. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  5454. +x.slice(i + 1)
  5455. ];
  5456. };
  5457. var exponent$1 = function(x) {
  5458. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  5459. };
  5460. var formatGroup = function(grouping, thousands) {
  5461. return function(value, width) {
  5462. var i = value.length,
  5463. t = [],
  5464. j = 0,
  5465. g = grouping[0],
  5466. length = 0;
  5467. while (i > 0 && g > 0) {
  5468. if (length + g + 1 > width) g = Math.max(1, width - length);
  5469. t.push(value.substring(i -= g, i + g));
  5470. if ((length += g + 1) > width) break;
  5471. g = grouping[j = (j + 1) % grouping.length];
  5472. }
  5473. return t.reverse().join(thousands);
  5474. };
  5475. };
  5476. var formatNumerals = function(numerals) {
  5477. return function(value) {
  5478. return value.replace(/[0-9]/g, function(i) {
  5479. return numerals[+i];
  5480. });
  5481. };
  5482. };
  5483. var formatDefault = function(x, p) {
  5484. x = x.toPrecision(p);
  5485. out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
  5486. switch (x[i]) {
  5487. case ".": i0 = i1 = i; break;
  5488. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  5489. case "e": break out;
  5490. default: if (i0 > 0) i0 = 0; break;
  5491. }
  5492. }
  5493. return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
  5494. };
  5495. var prefixExponent;
  5496. var formatPrefixAuto = function(x, p) {
  5497. var d = formatDecimal(x, p);
  5498. if (!d) return x + "";
  5499. var coefficient = d[0],
  5500. exponent = d[1],
  5501. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  5502. n = coefficient.length;
  5503. return i === n ? coefficient
  5504. : i > n ? coefficient + new Array(i - n + 1).join("0")
  5505. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  5506. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  5507. };
  5508. var formatRounded = function(x, p) {
  5509. var d = formatDecimal(x, p);
  5510. if (!d) return x + "";
  5511. var coefficient = d[0],
  5512. exponent = d[1];
  5513. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  5514. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  5515. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  5516. };
  5517. var formatTypes = {
  5518. "": formatDefault,
  5519. "%": function(x, p) { return (x * 100).toFixed(p); },
  5520. "b": function(x) { return Math.round(x).toString(2); },
  5521. "c": function(x) { return x + ""; },
  5522. "d": function(x) { return Math.round(x).toString(10); },
  5523. "e": function(x, p) { return x.toExponential(p); },
  5524. "f": function(x, p) { return x.toFixed(p); },
  5525. "g": function(x, p) { return x.toPrecision(p); },
  5526. "o": function(x) { return Math.round(x).toString(8); },
  5527. "p": function(x, p) { return formatRounded(x * 100, p); },
  5528. "r": formatRounded,
  5529. "s": formatPrefixAuto,
  5530. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  5531. "x": function(x) { return Math.round(x).toString(16); }
  5532. };
  5533. // [[fill]align][sign][symbol][0][width][,][.precision][type]
  5534. var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
  5535. function formatSpecifier(specifier) {
  5536. return new FormatSpecifier(specifier);
  5537. }
  5538. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  5539. function FormatSpecifier(specifier) {
  5540. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  5541. var match,
  5542. fill = match[1] || " ",
  5543. align = match[2] || ">",
  5544. sign = match[3] || "-",
  5545. symbol = match[4] || "",
  5546. zero = !!match[5],
  5547. width = match[6] && +match[6],
  5548. comma = !!match[7],
  5549. precision = match[8] && +match[8].slice(1),
  5550. type = match[9] || "";
  5551. // The "n" type is an alias for ",g".
  5552. if (type === "n") comma = true, type = "g";
  5553. // Map invalid types to the default format.
  5554. else if (!formatTypes[type]) type = "";
  5555. // If zero fill is specified, padding goes after sign and before digits.
  5556. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  5557. this.fill = fill;
  5558. this.align = align;
  5559. this.sign = sign;
  5560. this.symbol = symbol;
  5561. this.zero = zero;
  5562. this.width = width;
  5563. this.comma = comma;
  5564. this.precision = precision;
  5565. this.type = type;
  5566. }
  5567. FormatSpecifier.prototype.toString = function() {
  5568. return this.fill
  5569. + this.align
  5570. + this.sign
  5571. + this.symbol
  5572. + (this.zero ? "0" : "")
  5573. + (this.width == null ? "" : Math.max(1, this.width | 0))
  5574. + (this.comma ? "," : "")
  5575. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  5576. + this.type;
  5577. };
  5578. var identity$3 = function(x) {
  5579. return x;
  5580. };
  5581. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  5582. var formatLocale = function(locale) {
  5583. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  5584. currency = locale.currency,
  5585. decimal = locale.decimal,
  5586. numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
  5587. percent = locale.percent || "%";
  5588. function newFormat(specifier) {
  5589. specifier = formatSpecifier(specifier);
  5590. var fill = specifier.fill,
  5591. align = specifier.align,
  5592. sign = specifier.sign,
  5593. symbol = specifier.symbol,
  5594. zero = specifier.zero,
  5595. width = specifier.width,
  5596. comma = specifier.comma,
  5597. precision = specifier.precision,
  5598. type = specifier.type;
  5599. // Compute the prefix and suffix.
  5600. // For SI-prefix, the suffix is lazily computed.
  5601. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  5602. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
  5603. // What format function should we use?
  5604. // Is this an integer type?
  5605. // Can this type generate exponential notation?
  5606. var formatType = formatTypes[type],
  5607. maybeSuffix = !type || /[defgprs%]/.test(type);
  5608. // Set the default precision if not specified,
  5609. // or clamp the specified precision to the supported range.
  5610. // For significant precision, it must be in [1, 21].
  5611. // For fixed precision, it must be in [0, 20].
  5612. precision = precision == null ? (type ? 6 : 12)
  5613. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  5614. : Math.max(0, Math.min(20, precision));
  5615. function format(value) {
  5616. var valuePrefix = prefix,
  5617. valueSuffix = suffix,
  5618. i, n, c;
  5619. if (type === "c") {
  5620. valueSuffix = formatType(value) + valueSuffix;
  5621. value = "";
  5622. } else {
  5623. value = +value;
  5624. // Perform the initial formatting.
  5625. var valueNegative = value < 0;
  5626. value = formatType(Math.abs(value), precision);
  5627. // If a negative value rounds to zero during formatting, treat as positive.
  5628. if (valueNegative && +value === 0) valueNegative = false;
  5629. // Compute the prefix and suffix.
  5630. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  5631. valueSuffix = valueSuffix + (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + (valueNegative && sign === "(" ? ")" : "");
  5632. // Break the formatted value into the integer “value” part that can be
  5633. // grouped, and fractional or exponential “suffix” part that is not.
  5634. if (maybeSuffix) {
  5635. i = -1, n = value.length;
  5636. while (++i < n) {
  5637. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  5638. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  5639. value = value.slice(0, i);
  5640. break;
  5641. }
  5642. }
  5643. }
  5644. }
  5645. // If the fill character is not "0", grouping is applied before padding.
  5646. if (comma && !zero) value = group(value, Infinity);
  5647. // Compute the padding.
  5648. var length = valuePrefix.length + value.length + valueSuffix.length,
  5649. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  5650. // If the fill character is "0", grouping is applied after padding.
  5651. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  5652. // Reconstruct the final output based on the desired alignment.
  5653. switch (align) {
  5654. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  5655. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  5656. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  5657. default: value = padding + valuePrefix + value + valueSuffix; break;
  5658. }
  5659. return numerals(value);
  5660. }
  5661. format.toString = function() {
  5662. return specifier + "";
  5663. };
  5664. return format;
  5665. }
  5666. function formatPrefix(specifier, value) {
  5667. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  5668. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  5669. k = Math.pow(10, -e),
  5670. prefix = prefixes[8 + e / 3];
  5671. return function(value) {
  5672. return f(k * value) + prefix;
  5673. };
  5674. }
  5675. return {
  5676. format: newFormat,
  5677. formatPrefix: formatPrefix
  5678. };
  5679. };
  5680. var locale;
  5681. defaultLocale({
  5682. decimal: ".",
  5683. thousands: ",",
  5684. grouping: [3],
  5685. currency: ["$", ""]
  5686. });
  5687. function defaultLocale(definition) {
  5688. locale = formatLocale(definition);
  5689. exports.format = locale.format;
  5690. exports.formatPrefix = locale.formatPrefix;
  5691. return locale;
  5692. }
  5693. var precisionFixed = function(step) {
  5694. return Math.max(0, -exponent$1(Math.abs(step)));
  5695. };
  5696. var precisionPrefix = function(step, value) {
  5697. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  5698. };
  5699. var precisionRound = function(step, max) {
  5700. step = Math.abs(step), max = Math.abs(max) - step;
  5701. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  5702. };
  5703. // Adds floating point numbers with twice the normal precision.
  5704. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  5705. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  5706. // 305–363 (1997).
  5707. // Code adapted from GeographicLib by Charles F. F. Karney,
  5708. // http://geographiclib.sourceforge.net/
  5709. var adder = function() {
  5710. return new Adder;
  5711. };
  5712. function Adder() {
  5713. this.reset();
  5714. }
  5715. Adder.prototype = {
  5716. constructor: Adder,
  5717. reset: function() {
  5718. this.s = // rounded value
  5719. this.t = 0; // exact error
  5720. },
  5721. add: function(y) {
  5722. add$1(temp, y, this.t);
  5723. add$1(this, temp.s, this.s);
  5724. if (this.s) this.t += temp.t;
  5725. else this.s = temp.t;
  5726. },
  5727. valueOf: function() {
  5728. return this.s;
  5729. }
  5730. };
  5731. var temp = new Adder;
  5732. function add$1(adder, a, b) {
  5733. var x = adder.s = a + b,
  5734. bv = x - a,
  5735. av = x - bv;
  5736. adder.t = (a - av) + (b - bv);
  5737. }
  5738. var epsilon$2 = 1e-6;
  5739. var epsilon2$1 = 1e-12;
  5740. var pi$3 = Math.PI;
  5741. var halfPi$2 = pi$3 / 2;
  5742. var quarterPi = pi$3 / 4;
  5743. var tau$3 = pi$3 * 2;
  5744. var degrees$1 = 180 / pi$3;
  5745. var radians = pi$3 / 180;
  5746. var abs = Math.abs;
  5747. var atan = Math.atan;
  5748. var atan2 = Math.atan2;
  5749. var cos$1 = Math.cos;
  5750. var ceil = Math.ceil;
  5751. var exp = Math.exp;
  5752. var log = Math.log;
  5753. var pow = Math.pow;
  5754. var sin$1 = Math.sin;
  5755. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  5756. var sqrt = Math.sqrt;
  5757. var tan = Math.tan;
  5758. function acos(x) {
  5759. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  5760. }
  5761. function asin(x) {
  5762. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  5763. }
  5764. function haversin(x) {
  5765. return (x = sin$1(x / 2)) * x;
  5766. }
  5767. function noop$1() {}
  5768. function streamGeometry(geometry, stream) {
  5769. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  5770. streamGeometryType[geometry.type](geometry, stream);
  5771. }
  5772. }
  5773. var streamObjectType = {
  5774. Feature: function(object, stream) {
  5775. streamGeometry(object.geometry, stream);
  5776. },
  5777. FeatureCollection: function(object, stream) {
  5778. var features = object.features, i = -1, n = features.length;
  5779. while (++i < n) streamGeometry(features[i].geometry, stream);
  5780. }
  5781. };
  5782. var streamGeometryType = {
  5783. Sphere: function(object, stream) {
  5784. stream.sphere();
  5785. },
  5786. Point: function(object, stream) {
  5787. object = object.coordinates;
  5788. stream.point(object[0], object[1], object[2]);
  5789. },
  5790. MultiPoint: function(object, stream) {
  5791. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5792. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  5793. },
  5794. LineString: function(object, stream) {
  5795. streamLine(object.coordinates, stream, 0);
  5796. },
  5797. MultiLineString: function(object, stream) {
  5798. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5799. while (++i < n) streamLine(coordinates[i], stream, 0);
  5800. },
  5801. Polygon: function(object, stream) {
  5802. streamPolygon(object.coordinates, stream);
  5803. },
  5804. MultiPolygon: function(object, stream) {
  5805. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5806. while (++i < n) streamPolygon(coordinates[i], stream);
  5807. },
  5808. GeometryCollection: function(object, stream) {
  5809. var geometries = object.geometries, i = -1, n = geometries.length;
  5810. while (++i < n) streamGeometry(geometries[i], stream);
  5811. }
  5812. };
  5813. function streamLine(coordinates, stream, closed) {
  5814. var i = -1, n = coordinates.length - closed, coordinate;
  5815. stream.lineStart();
  5816. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  5817. stream.lineEnd();
  5818. }
  5819. function streamPolygon(coordinates, stream) {
  5820. var i = -1, n = coordinates.length;
  5821. stream.polygonStart();
  5822. while (++i < n) streamLine(coordinates[i], stream, 1);
  5823. stream.polygonEnd();
  5824. }
  5825. var geoStream = function(object, stream) {
  5826. if (object && streamObjectType.hasOwnProperty(object.type)) {
  5827. streamObjectType[object.type](object, stream);
  5828. } else {
  5829. streamGeometry(object, stream);
  5830. }
  5831. };
  5832. var areaRingSum = adder();
  5833. var areaSum = adder();
  5834. var lambda00;
  5835. var phi00;
  5836. var lambda0;
  5837. var cosPhi0;
  5838. var sinPhi0;
  5839. var areaStream = {
  5840. point: noop$1,
  5841. lineStart: noop$1,
  5842. lineEnd: noop$1,
  5843. polygonStart: function() {
  5844. areaRingSum.reset();
  5845. areaStream.lineStart = areaRingStart;
  5846. areaStream.lineEnd = areaRingEnd;
  5847. },
  5848. polygonEnd: function() {
  5849. var areaRing = +areaRingSum;
  5850. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  5851. this.lineStart = this.lineEnd = this.point = noop$1;
  5852. },
  5853. sphere: function() {
  5854. areaSum.add(tau$3);
  5855. }
  5856. };
  5857. function areaRingStart() {
  5858. areaStream.point = areaPointFirst;
  5859. }
  5860. function areaRingEnd() {
  5861. areaPoint(lambda00, phi00);
  5862. }
  5863. function areaPointFirst(lambda, phi) {
  5864. areaStream.point = areaPoint;
  5865. lambda00 = lambda, phi00 = phi;
  5866. lambda *= radians, phi *= radians;
  5867. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  5868. }
  5869. function areaPoint(lambda, phi) {
  5870. lambda *= radians, phi *= radians;
  5871. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  5872. // Spherical excess E for a spherical triangle with vertices: south pole,
  5873. // previous point, current point. Uses a formula derived from Cagnoli’s
  5874. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  5875. var dLambda = lambda - lambda0,
  5876. sdLambda = dLambda >= 0 ? 1 : -1,
  5877. adLambda = sdLambda * dLambda,
  5878. cosPhi = cos$1(phi),
  5879. sinPhi = sin$1(phi),
  5880. k = sinPhi0 * sinPhi,
  5881. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  5882. v = k * sdLambda * sin$1(adLambda);
  5883. areaRingSum.add(atan2(v, u));
  5884. // Advance the previous points.
  5885. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  5886. }
  5887. var area = function(object) {
  5888. areaSum.reset();
  5889. geoStream(object, areaStream);
  5890. return areaSum * 2;
  5891. };
  5892. function spherical(cartesian) {
  5893. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  5894. }
  5895. function cartesian(spherical) {
  5896. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  5897. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  5898. }
  5899. function cartesianDot(a, b) {
  5900. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  5901. }
  5902. function cartesianCross(a, b) {
  5903. 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]];
  5904. }
  5905. // TODO return a
  5906. function cartesianAddInPlace(a, b) {
  5907. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  5908. }
  5909. function cartesianScale(vector, k) {
  5910. return [vector[0] * k, vector[1] * k, vector[2] * k];
  5911. }
  5912. // TODO return d
  5913. function cartesianNormalizeInPlace(d) {
  5914. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  5915. d[0] /= l, d[1] /= l, d[2] /= l;
  5916. }
  5917. var lambda0$1;
  5918. var phi0;
  5919. var lambda1;
  5920. var phi1;
  5921. var lambda2;
  5922. var lambda00$1;
  5923. var phi00$1;
  5924. var p0;
  5925. var deltaSum = adder();
  5926. var ranges;
  5927. var range;
  5928. var boundsStream = {
  5929. point: boundsPoint,
  5930. lineStart: boundsLineStart,
  5931. lineEnd: boundsLineEnd,
  5932. polygonStart: function() {
  5933. boundsStream.point = boundsRingPoint;
  5934. boundsStream.lineStart = boundsRingStart;
  5935. boundsStream.lineEnd = boundsRingEnd;
  5936. deltaSum.reset();
  5937. areaStream.polygonStart();
  5938. },
  5939. polygonEnd: function() {
  5940. areaStream.polygonEnd();
  5941. boundsStream.point = boundsPoint;
  5942. boundsStream.lineStart = boundsLineStart;
  5943. boundsStream.lineEnd = boundsLineEnd;
  5944. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  5945. else if (deltaSum > epsilon$2) phi1 = 90;
  5946. else if (deltaSum < -epsilon$2) phi0 = -90;
  5947. range[0] = lambda0$1, range[1] = lambda1;
  5948. }
  5949. };
  5950. function boundsPoint(lambda, phi) {
  5951. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  5952. if (phi < phi0) phi0 = phi;
  5953. if (phi > phi1) phi1 = phi;
  5954. }
  5955. function linePoint(lambda, phi) {
  5956. var p = cartesian([lambda * radians, phi * radians]);
  5957. if (p0) {
  5958. var normal = cartesianCross(p0, p),
  5959. equatorial = [normal[1], -normal[0], 0],
  5960. inflection = cartesianCross(equatorial, normal);
  5961. cartesianNormalizeInPlace(inflection);
  5962. inflection = spherical(inflection);
  5963. var delta = lambda - lambda2,
  5964. sign$$1 = delta > 0 ? 1 : -1,
  5965. lambdai = inflection[0] * degrees$1 * sign$$1,
  5966. phii,
  5967. antimeridian = abs(delta) > 180;
  5968. if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  5969. phii = inflection[1] * degrees$1;
  5970. if (phii > phi1) phi1 = phii;
  5971. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  5972. phii = -inflection[1] * degrees$1;
  5973. if (phii < phi0) phi0 = phii;
  5974. } else {
  5975. if (phi < phi0) phi0 = phi;
  5976. if (phi > phi1) phi1 = phi;
  5977. }
  5978. if (antimeridian) {
  5979. if (lambda < lambda2) {
  5980. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  5981. } else {
  5982. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  5983. }
  5984. } else {
  5985. if (lambda1 >= lambda0$1) {
  5986. if (lambda < lambda0$1) lambda0$1 = lambda;
  5987. if (lambda > lambda1) lambda1 = lambda;
  5988. } else {
  5989. if (lambda > lambda2) {
  5990. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  5991. } else {
  5992. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  5993. }
  5994. }
  5995. }
  5996. } else {
  5997. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  5998. }
  5999. if (phi < phi0) phi0 = phi;
  6000. if (phi > phi1) phi1 = phi;
  6001. p0 = p, lambda2 = lambda;
  6002. }
  6003. function boundsLineStart() {
  6004. boundsStream.point = linePoint;
  6005. }
  6006. function boundsLineEnd() {
  6007. range[0] = lambda0$1, range[1] = lambda1;
  6008. boundsStream.point = boundsPoint;
  6009. p0 = null;
  6010. }
  6011. function boundsRingPoint(lambda, phi) {
  6012. if (p0) {
  6013. var delta = lambda - lambda2;
  6014. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6015. } else {
  6016. lambda00$1 = lambda, phi00$1 = phi;
  6017. }
  6018. areaStream.point(lambda, phi);
  6019. linePoint(lambda, phi);
  6020. }
  6021. function boundsRingStart() {
  6022. areaStream.lineStart();
  6023. }
  6024. function boundsRingEnd() {
  6025. boundsRingPoint(lambda00$1, phi00$1);
  6026. areaStream.lineEnd();
  6027. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6028. range[0] = lambda0$1, range[1] = lambda1;
  6029. p0 = null;
  6030. }
  6031. // Finds the left-right distance between two longitudes.
  6032. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6033. // the distance between ±180° to be 360°.
  6034. function angle(lambda0, lambda1) {
  6035. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6036. }
  6037. function rangeCompare(a, b) {
  6038. return a[0] - b[0];
  6039. }
  6040. function rangeContains(range, x) {
  6041. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6042. }
  6043. var bounds = function(feature) {
  6044. var i, n, a, b, merged, deltaMax, delta;
  6045. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6046. ranges = [];
  6047. geoStream(feature, boundsStream);
  6048. // First, sort ranges by their minimum longitudes.
  6049. if (n = ranges.length) {
  6050. ranges.sort(rangeCompare);
  6051. // Then, merge any ranges that overlap.
  6052. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6053. b = ranges[i];
  6054. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6055. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6056. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6057. } else {
  6058. merged.push(a = b);
  6059. }
  6060. }
  6061. // Finally, find the largest gap between the merged ranges.
  6062. // The final bounding box will be the inverse of this gap.
  6063. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6064. b = merged[i];
  6065. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6066. }
  6067. }
  6068. ranges = range = null;
  6069. return lambda0$1 === Infinity || phi0 === Infinity
  6070. ? [[NaN, NaN], [NaN, NaN]]
  6071. : [[lambda0$1, phi0], [lambda1, phi1]];
  6072. };
  6073. var W0;
  6074. var W1;
  6075. var X0;
  6076. var Y0;
  6077. var Z0;
  6078. var X1;
  6079. var Y1;
  6080. var Z1;
  6081. var X2;
  6082. var Y2;
  6083. var Z2;
  6084. var lambda00$2;
  6085. var phi00$2;
  6086. var x0;
  6087. var y0;
  6088. var z0; // previous point
  6089. var centroidStream = {
  6090. sphere: noop$1,
  6091. point: centroidPoint,
  6092. lineStart: centroidLineStart,
  6093. lineEnd: centroidLineEnd,
  6094. polygonStart: function() {
  6095. centroidStream.lineStart = centroidRingStart;
  6096. centroidStream.lineEnd = centroidRingEnd;
  6097. },
  6098. polygonEnd: function() {
  6099. centroidStream.lineStart = centroidLineStart;
  6100. centroidStream.lineEnd = centroidLineEnd;
  6101. }
  6102. };
  6103. // Arithmetic mean of Cartesian vectors.
  6104. function centroidPoint(lambda, phi) {
  6105. lambda *= radians, phi *= radians;
  6106. var cosPhi = cos$1(phi);
  6107. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6108. }
  6109. function centroidPointCartesian(x, y, z) {
  6110. ++W0;
  6111. X0 += (x - X0) / W0;
  6112. Y0 += (y - Y0) / W0;
  6113. Z0 += (z - Z0) / W0;
  6114. }
  6115. function centroidLineStart() {
  6116. centroidStream.point = centroidLinePointFirst;
  6117. }
  6118. function centroidLinePointFirst(lambda, phi) {
  6119. lambda *= radians, phi *= radians;
  6120. var cosPhi = cos$1(phi);
  6121. x0 = cosPhi * cos$1(lambda);
  6122. y0 = cosPhi * sin$1(lambda);
  6123. z0 = sin$1(phi);
  6124. centroidStream.point = centroidLinePoint;
  6125. centroidPointCartesian(x0, y0, z0);
  6126. }
  6127. function centroidLinePoint(lambda, phi) {
  6128. lambda *= radians, phi *= radians;
  6129. var cosPhi = cos$1(phi),
  6130. x = cosPhi * cos$1(lambda),
  6131. y = cosPhi * sin$1(lambda),
  6132. z = sin$1(phi),
  6133. 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);
  6134. W1 += w;
  6135. X1 += w * (x0 + (x0 = x));
  6136. Y1 += w * (y0 + (y0 = y));
  6137. Z1 += w * (z0 + (z0 = z));
  6138. centroidPointCartesian(x0, y0, z0);
  6139. }
  6140. function centroidLineEnd() {
  6141. centroidStream.point = centroidPoint;
  6142. }
  6143. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6144. // J. Applied Mechanics 42, 239 (1975).
  6145. function centroidRingStart() {
  6146. centroidStream.point = centroidRingPointFirst;
  6147. }
  6148. function centroidRingEnd() {
  6149. centroidRingPoint(lambda00$2, phi00$2);
  6150. centroidStream.point = centroidPoint;
  6151. }
  6152. function centroidRingPointFirst(lambda, phi) {
  6153. lambda00$2 = lambda, phi00$2 = phi;
  6154. lambda *= radians, phi *= radians;
  6155. centroidStream.point = centroidRingPoint;
  6156. var cosPhi = cos$1(phi);
  6157. x0 = cosPhi * cos$1(lambda);
  6158. y0 = cosPhi * sin$1(lambda);
  6159. z0 = sin$1(phi);
  6160. centroidPointCartesian(x0, y0, z0);
  6161. }
  6162. function centroidRingPoint(lambda, phi) {
  6163. lambda *= radians, phi *= radians;
  6164. var cosPhi = cos$1(phi),
  6165. x = cosPhi * cos$1(lambda),
  6166. y = cosPhi * sin$1(lambda),
  6167. z = sin$1(phi),
  6168. cx = y0 * z - z0 * y,
  6169. cy = z0 * x - x0 * z,
  6170. cz = x0 * y - y0 * x,
  6171. m = sqrt(cx * cx + cy * cy + cz * cz),
  6172. w = asin(m), // line weight = angle
  6173. v = m && -w / m; // area weight multiplier
  6174. X2 += v * cx;
  6175. Y2 += v * cy;
  6176. Z2 += v * cz;
  6177. W1 += w;
  6178. X1 += w * (x0 + (x0 = x));
  6179. Y1 += w * (y0 + (y0 = y));
  6180. Z1 += w * (z0 + (z0 = z));
  6181. centroidPointCartesian(x0, y0, z0);
  6182. }
  6183. var centroid = function(object) {
  6184. W0 = W1 =
  6185. X0 = Y0 = Z0 =
  6186. X1 = Y1 = Z1 =
  6187. X2 = Y2 = Z2 = 0;
  6188. geoStream(object, centroidStream);
  6189. var x = X2,
  6190. y = Y2,
  6191. z = Z2,
  6192. m = x * x + y * y + z * z;
  6193. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6194. if (m < epsilon2$1) {
  6195. x = X1, y = Y1, z = Z1;
  6196. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6197. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6198. m = x * x + y * y + z * z;
  6199. // If the feature still has an undefined ccentroid, then return.
  6200. if (m < epsilon2$1) return [NaN, NaN];
  6201. }
  6202. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6203. };
  6204. var constant$7 = function(x) {
  6205. return function() {
  6206. return x;
  6207. };
  6208. };
  6209. var compose = function(a, b) {
  6210. function compose(x, y) {
  6211. return x = a(x, y), b(x[0], x[1]);
  6212. }
  6213. if (a.invert && b.invert) compose.invert = function(x, y) {
  6214. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6215. };
  6216. return compose;
  6217. };
  6218. function rotationIdentity(lambda, phi) {
  6219. return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6220. }
  6221. rotationIdentity.invert = rotationIdentity;
  6222. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6223. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6224. : rotationLambda(deltaLambda))
  6225. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6226. : rotationIdentity);
  6227. }
  6228. function forwardRotationLambda(deltaLambda) {
  6229. return function(lambda, phi) {
  6230. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6231. };
  6232. }
  6233. function rotationLambda(deltaLambda) {
  6234. var rotation = forwardRotationLambda(deltaLambda);
  6235. rotation.invert = forwardRotationLambda(-deltaLambda);
  6236. return rotation;
  6237. }
  6238. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6239. var cosDeltaPhi = cos$1(deltaPhi),
  6240. sinDeltaPhi = sin$1(deltaPhi),
  6241. cosDeltaGamma = cos$1(deltaGamma),
  6242. sinDeltaGamma = sin$1(deltaGamma);
  6243. function rotation(lambda, phi) {
  6244. var cosPhi = cos$1(phi),
  6245. x = cos$1(lambda) * cosPhi,
  6246. y = sin$1(lambda) * cosPhi,
  6247. z = sin$1(phi),
  6248. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6249. return [
  6250. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6251. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6252. ];
  6253. }
  6254. rotation.invert = function(lambda, phi) {
  6255. var cosPhi = cos$1(phi),
  6256. x = cos$1(lambda) * cosPhi,
  6257. y = sin$1(lambda) * cosPhi,
  6258. z = sin$1(phi),
  6259. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6260. return [
  6261. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6262. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6263. ];
  6264. };
  6265. return rotation;
  6266. }
  6267. var rotation = function(rotate) {
  6268. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6269. function forward(coordinates) {
  6270. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6271. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6272. }
  6273. forward.invert = function(coordinates) {
  6274. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6275. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6276. };
  6277. return forward;
  6278. };
  6279. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6280. function circleStream(stream, radius, delta, direction, t0, t1) {
  6281. if (!delta) return;
  6282. var cosRadius = cos$1(radius),
  6283. sinRadius = sin$1(radius),
  6284. step = direction * delta;
  6285. if (t0 == null) {
  6286. t0 = radius + direction * tau$3;
  6287. t1 = radius - step / 2;
  6288. } else {
  6289. t0 = circleRadius(cosRadius, t0);
  6290. t1 = circleRadius(cosRadius, t1);
  6291. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6292. }
  6293. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6294. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6295. stream.point(point[0], point[1]);
  6296. }
  6297. }
  6298. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6299. function circleRadius(cosRadius, point) {
  6300. point = cartesian(point), point[0] -= cosRadius;
  6301. cartesianNormalizeInPlace(point);
  6302. var radius = acos(-point[1]);
  6303. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6304. }
  6305. var circle = function() {
  6306. var center = constant$7([0, 0]),
  6307. radius = constant$7(90),
  6308. precision = constant$7(6),
  6309. ring,
  6310. rotate,
  6311. stream = {point: point};
  6312. function point(x, y) {
  6313. ring.push(x = rotate(x, y));
  6314. x[0] *= degrees$1, x[1] *= degrees$1;
  6315. }
  6316. function circle() {
  6317. var c = center.apply(this, arguments),
  6318. r = radius.apply(this, arguments) * radians,
  6319. p = precision.apply(this, arguments) * radians;
  6320. ring = [];
  6321. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6322. circleStream(stream, r, p, 1);
  6323. c = {type: "Polygon", coordinates: [ring]};
  6324. ring = rotate = null;
  6325. return c;
  6326. }
  6327. circle.center = function(_) {
  6328. return arguments.length ? (center = typeof _ === "function" ? _ : constant$7([+_[0], +_[1]]), circle) : center;
  6329. };
  6330. circle.radius = function(_) {
  6331. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), circle) : radius;
  6332. };
  6333. circle.precision = function(_) {
  6334. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$7(+_), circle) : precision;
  6335. };
  6336. return circle;
  6337. };
  6338. var clipBuffer = function() {
  6339. var lines = [],
  6340. line;
  6341. return {
  6342. point: function(x, y) {
  6343. line.push([x, y]);
  6344. },
  6345. lineStart: function() {
  6346. lines.push(line = []);
  6347. },
  6348. lineEnd: noop$1,
  6349. rejoin: function() {
  6350. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  6351. },
  6352. result: function() {
  6353. var result = lines;
  6354. lines = [];
  6355. line = null;
  6356. return result;
  6357. }
  6358. };
  6359. };
  6360. var pointEqual = function(a, b) {
  6361. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  6362. };
  6363. function Intersection(point, points, other, entry) {
  6364. this.x = point;
  6365. this.z = points;
  6366. this.o = other; // another intersection
  6367. this.e = entry; // is an entry?
  6368. this.v = false; // visited
  6369. this.n = this.p = null; // next & previous
  6370. }
  6371. // A generalized polygon clipping algorithm: given a polygon that has been cut
  6372. // into its visible line segments, and rejoins the segments by interpolating
  6373. // along the clip edge.
  6374. var clipRejoin = function(segments, compareIntersection, startInside, interpolate, stream) {
  6375. var subject = [],
  6376. clip = [],
  6377. i,
  6378. n;
  6379. segments.forEach(function(segment) {
  6380. if ((n = segment.length - 1) <= 0) return;
  6381. var n, p0 = segment[0], p1 = segment[n], x;
  6382. // If the first and last points of a segment are coincident, then treat as a
  6383. // closed ring. TODO if all rings are closed, then the winding order of the
  6384. // exterior ring should be checked.
  6385. if (pointEqual(p0, p1)) {
  6386. stream.lineStart();
  6387. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  6388. stream.lineEnd();
  6389. return;
  6390. }
  6391. subject.push(x = new Intersection(p0, segment, null, true));
  6392. clip.push(x.o = new Intersection(p0, null, x, false));
  6393. subject.push(x = new Intersection(p1, segment, null, false));
  6394. clip.push(x.o = new Intersection(p1, null, x, true));
  6395. });
  6396. if (!subject.length) return;
  6397. clip.sort(compareIntersection);
  6398. link$1(subject);
  6399. link$1(clip);
  6400. for (i = 0, n = clip.length; i < n; ++i) {
  6401. clip[i].e = startInside = !startInside;
  6402. }
  6403. var start = subject[0],
  6404. points,
  6405. point;
  6406. while (1) {
  6407. // Find first unvisited intersection.
  6408. var current = start,
  6409. isSubject = true;
  6410. while (current.v) if ((current = current.n) === start) return;
  6411. points = current.z;
  6412. stream.lineStart();
  6413. do {
  6414. current.v = current.o.v = true;
  6415. if (current.e) {
  6416. if (isSubject) {
  6417. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  6418. } else {
  6419. interpolate(current.x, current.n.x, 1, stream);
  6420. }
  6421. current = current.n;
  6422. } else {
  6423. if (isSubject) {
  6424. points = current.p.z;
  6425. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  6426. } else {
  6427. interpolate(current.x, current.p.x, -1, stream);
  6428. }
  6429. current = current.p;
  6430. }
  6431. current = current.o;
  6432. points = current.z;
  6433. isSubject = !isSubject;
  6434. } while (!current.v);
  6435. stream.lineEnd();
  6436. }
  6437. };
  6438. function link$1(array) {
  6439. if (!(n = array.length)) return;
  6440. var n,
  6441. i = 0,
  6442. a = array[0],
  6443. b;
  6444. while (++i < n) {
  6445. a.n = b = array[i];
  6446. b.p = a;
  6447. a = b;
  6448. }
  6449. a.n = b = array[0];
  6450. b.p = a;
  6451. }
  6452. var sum$1 = adder();
  6453. var polygonContains = function(polygon, point) {
  6454. var lambda = point[0],
  6455. phi = point[1],
  6456. normal = [sin$1(lambda), -cos$1(lambda), 0],
  6457. angle = 0,
  6458. winding = 0;
  6459. sum$1.reset();
  6460. for (var i = 0, n = polygon.length; i < n; ++i) {
  6461. if (!(m = (ring = polygon[i]).length)) continue;
  6462. var ring,
  6463. m,
  6464. point0 = ring[m - 1],
  6465. lambda0 = point0[0],
  6466. phi0 = point0[1] / 2 + quarterPi,
  6467. sinPhi0 = sin$1(phi0),
  6468. cosPhi0 = cos$1(phi0);
  6469. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  6470. var point1 = ring[j],
  6471. lambda1 = point1[0],
  6472. phi1 = point1[1] / 2 + quarterPi,
  6473. sinPhi1 = sin$1(phi1),
  6474. cosPhi1 = cos$1(phi1),
  6475. delta = lambda1 - lambda0,
  6476. sign$$1 = delta >= 0 ? 1 : -1,
  6477. absDelta = sign$$1 * delta,
  6478. antimeridian = absDelta > pi$3,
  6479. k = sinPhi0 * sinPhi1;
  6480. sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  6481. angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
  6482. // Are the longitudes either side of the point’s meridian (lambda),
  6483. // and are the latitudes smaller than the parallel (phi)?
  6484. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  6485. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  6486. cartesianNormalizeInPlace(arc);
  6487. var intersection = cartesianCross(normal, arc);
  6488. cartesianNormalizeInPlace(intersection);
  6489. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  6490. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  6491. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  6492. }
  6493. }
  6494. }
  6495. }
  6496. // First, determine whether the South pole is inside or outside:
  6497. //
  6498. // It is inside if:
  6499. // * the polygon winds around it in a clockwise direction.
  6500. // * the polygon does not (cumulatively) wind around it, but has a negative
  6501. // (counter-clockwise) area.
  6502. //
  6503. // Second, count the (signed) number of times a segment crosses a lambda
  6504. // from the point to the South pole. If it is zero, then the point is the
  6505. // same side as the South pole.
  6506. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  6507. };
  6508. var clip = function(pointVisible, clipLine, interpolate, start) {
  6509. return function(sink) {
  6510. var line = clipLine(sink),
  6511. ringBuffer = clipBuffer(),
  6512. ringSink = clipLine(ringBuffer),
  6513. polygonStarted = false,
  6514. polygon,
  6515. segments,
  6516. ring;
  6517. var clip = {
  6518. point: point,
  6519. lineStart: lineStart,
  6520. lineEnd: lineEnd,
  6521. polygonStart: function() {
  6522. clip.point = pointRing;
  6523. clip.lineStart = ringStart;
  6524. clip.lineEnd = ringEnd;
  6525. segments = [];
  6526. polygon = [];
  6527. },
  6528. polygonEnd: function() {
  6529. clip.point = point;
  6530. clip.lineStart = lineStart;
  6531. clip.lineEnd = lineEnd;
  6532. segments = merge(segments);
  6533. var startInside = polygonContains(polygon, start);
  6534. if (segments.length) {
  6535. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6536. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  6537. } else if (startInside) {
  6538. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6539. sink.lineStart();
  6540. interpolate(null, null, 1, sink);
  6541. sink.lineEnd();
  6542. }
  6543. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  6544. segments = polygon = null;
  6545. },
  6546. sphere: function() {
  6547. sink.polygonStart();
  6548. sink.lineStart();
  6549. interpolate(null, null, 1, sink);
  6550. sink.lineEnd();
  6551. sink.polygonEnd();
  6552. }
  6553. };
  6554. function point(lambda, phi) {
  6555. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  6556. }
  6557. function pointLine(lambda, phi) {
  6558. line.point(lambda, phi);
  6559. }
  6560. function lineStart() {
  6561. clip.point = pointLine;
  6562. line.lineStart();
  6563. }
  6564. function lineEnd() {
  6565. clip.point = point;
  6566. line.lineEnd();
  6567. }
  6568. function pointRing(lambda, phi) {
  6569. ring.push([lambda, phi]);
  6570. ringSink.point(lambda, phi);
  6571. }
  6572. function ringStart() {
  6573. ringSink.lineStart();
  6574. ring = [];
  6575. }
  6576. function ringEnd() {
  6577. pointRing(ring[0][0], ring[0][1]);
  6578. ringSink.lineEnd();
  6579. var clean = ringSink.clean(),
  6580. ringSegments = ringBuffer.result(),
  6581. i, n = ringSegments.length, m,
  6582. segment,
  6583. point;
  6584. ring.pop();
  6585. polygon.push(ring);
  6586. ring = null;
  6587. if (!n) return;
  6588. // No intersections.
  6589. if (clean & 1) {
  6590. segment = ringSegments[0];
  6591. if ((m = segment.length - 1) > 0) {
  6592. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6593. sink.lineStart();
  6594. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  6595. sink.lineEnd();
  6596. }
  6597. return;
  6598. }
  6599. // Rejoin connected segments.
  6600. // TODO reuse ringBuffer.rejoin()?
  6601. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  6602. segments.push(ringSegments.filter(validSegment));
  6603. }
  6604. return clip;
  6605. };
  6606. };
  6607. function validSegment(segment) {
  6608. return segment.length > 1;
  6609. }
  6610. // Intersections are sorted along the clip edge. For both antimeridian cutting
  6611. // and circle clipping, the same comparison is used.
  6612. function compareIntersection(a, b) {
  6613. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  6614. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  6615. }
  6616. var clipAntimeridian = clip(
  6617. function() { return true; },
  6618. clipAntimeridianLine,
  6619. clipAntimeridianInterpolate,
  6620. [-pi$3, -halfPi$2]
  6621. );
  6622. // Takes a line and cuts into visible segments. Return values: 0 - there were
  6623. // intersections or the line was empty; 1 - no intersections; 2 - there were
  6624. // intersections, and the first and last segments should be rejoined.
  6625. function clipAntimeridianLine(stream) {
  6626. var lambda0 = NaN,
  6627. phi0 = NaN,
  6628. sign0 = NaN,
  6629. clean; // no intersections
  6630. return {
  6631. lineStart: function() {
  6632. stream.lineStart();
  6633. clean = 1;
  6634. },
  6635. point: function(lambda1, phi1) {
  6636. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  6637. delta = abs(lambda1 - lambda0);
  6638. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  6639. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  6640. stream.point(sign0, phi0);
  6641. stream.lineEnd();
  6642. stream.lineStart();
  6643. stream.point(sign1, phi0);
  6644. stream.point(lambda1, phi0);
  6645. clean = 0;
  6646. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  6647. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  6648. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  6649. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  6650. stream.point(sign0, phi0);
  6651. stream.lineEnd();
  6652. stream.lineStart();
  6653. stream.point(sign1, phi0);
  6654. clean = 0;
  6655. }
  6656. stream.point(lambda0 = lambda1, phi0 = phi1);
  6657. sign0 = sign1;
  6658. },
  6659. lineEnd: function() {
  6660. stream.lineEnd();
  6661. lambda0 = phi0 = NaN;
  6662. },
  6663. clean: function() {
  6664. return 2 - clean; // if intersections, rejoin first and last segments
  6665. }
  6666. };
  6667. }
  6668. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  6669. var cosPhi0,
  6670. cosPhi1,
  6671. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  6672. return abs(sinLambda0Lambda1) > epsilon$2
  6673. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  6674. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  6675. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  6676. : (phi0 + phi1) / 2;
  6677. }
  6678. function clipAntimeridianInterpolate(from, to, direction, stream) {
  6679. var phi;
  6680. if (from == null) {
  6681. phi = direction * halfPi$2;
  6682. stream.point(-pi$3, phi);
  6683. stream.point(0, phi);
  6684. stream.point(pi$3, phi);
  6685. stream.point(pi$3, 0);
  6686. stream.point(pi$3, -phi);
  6687. stream.point(0, -phi);
  6688. stream.point(-pi$3, -phi);
  6689. stream.point(-pi$3, 0);
  6690. stream.point(-pi$3, phi);
  6691. } else if (abs(from[0] - to[0]) > epsilon$2) {
  6692. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  6693. phi = direction * lambda / 2;
  6694. stream.point(-lambda, phi);
  6695. stream.point(0, phi);
  6696. stream.point(lambda, phi);
  6697. } else {
  6698. stream.point(to[0], to[1]);
  6699. }
  6700. }
  6701. var clipCircle = function(radius) {
  6702. var cr = cos$1(radius),
  6703. delta = 6 * radians,
  6704. smallRadius = cr > 0,
  6705. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  6706. function interpolate(from, to, direction, stream) {
  6707. circleStream(stream, radius, delta, direction, from, to);
  6708. }
  6709. function visible(lambda, phi) {
  6710. return cos$1(lambda) * cos$1(phi) > cr;
  6711. }
  6712. // Takes a line and cuts into visible segments. Return values used for polygon
  6713. // clipping: 0 - there were intersections or the line was empty; 1 - no
  6714. // intersections 2 - there were intersections, and the first and last segments
  6715. // should be rejoined.
  6716. function clipLine(stream) {
  6717. var point0, // previous point
  6718. c0, // code for previous point
  6719. v0, // visibility of previous point
  6720. v00, // visibility of first point
  6721. clean; // no intersections
  6722. return {
  6723. lineStart: function() {
  6724. v00 = v0 = false;
  6725. clean = 1;
  6726. },
  6727. point: function(lambda, phi) {
  6728. var point1 = [lambda, phi],
  6729. point2,
  6730. v = visible(lambda, phi),
  6731. c = smallRadius
  6732. ? v ? 0 : code(lambda, phi)
  6733. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  6734. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  6735. // Handle degeneracies.
  6736. // TODO ignore if not clipping polygons.
  6737. if (v !== v0) {
  6738. point2 = intersect(point0, point1);
  6739. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  6740. point1[0] += epsilon$2;
  6741. point1[1] += epsilon$2;
  6742. v = visible(point1[0], point1[1]);
  6743. }
  6744. }
  6745. if (v !== v0) {
  6746. clean = 0;
  6747. if (v) {
  6748. // outside going in
  6749. stream.lineStart();
  6750. point2 = intersect(point1, point0);
  6751. stream.point(point2[0], point2[1]);
  6752. } else {
  6753. // inside going out
  6754. point2 = intersect(point0, point1);
  6755. stream.point(point2[0], point2[1]);
  6756. stream.lineEnd();
  6757. }
  6758. point0 = point2;
  6759. } else if (notHemisphere && point0 && smallRadius ^ v) {
  6760. var t;
  6761. // If the codes for two points are different, or are both zero,
  6762. // and there this segment intersects with the small circle.
  6763. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  6764. clean = 0;
  6765. if (smallRadius) {
  6766. stream.lineStart();
  6767. stream.point(t[0][0], t[0][1]);
  6768. stream.point(t[1][0], t[1][1]);
  6769. stream.lineEnd();
  6770. } else {
  6771. stream.point(t[1][0], t[1][1]);
  6772. stream.lineEnd();
  6773. stream.lineStart();
  6774. stream.point(t[0][0], t[0][1]);
  6775. }
  6776. }
  6777. }
  6778. if (v && (!point0 || !pointEqual(point0, point1))) {
  6779. stream.point(point1[0], point1[1]);
  6780. }
  6781. point0 = point1, v0 = v, c0 = c;
  6782. },
  6783. lineEnd: function() {
  6784. if (v0) stream.lineEnd();
  6785. point0 = null;
  6786. },
  6787. // Rejoin first and last segments if there were intersections and the first
  6788. // and last points were visible.
  6789. clean: function() {
  6790. return clean | ((v00 && v0) << 1);
  6791. }
  6792. };
  6793. }
  6794. // Intersects the great circle between a and b with the clip circle.
  6795. function intersect(a, b, two) {
  6796. var pa = cartesian(a),
  6797. pb = cartesian(b);
  6798. // We have two planes, n1.p = d1 and n2.p = d2.
  6799. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  6800. var n1 = [1, 0, 0], // normal
  6801. n2 = cartesianCross(pa, pb),
  6802. n2n2 = cartesianDot(n2, n2),
  6803. n1n2 = n2[0], // cartesianDot(n1, n2),
  6804. determinant = n2n2 - n1n2 * n1n2;
  6805. // Two polar points.
  6806. if (!determinant) return !two && a;
  6807. var c1 = cr * n2n2 / determinant,
  6808. c2 = -cr * n1n2 / determinant,
  6809. n1xn2 = cartesianCross(n1, n2),
  6810. A = cartesianScale(n1, c1),
  6811. B = cartesianScale(n2, c2);
  6812. cartesianAddInPlace(A, B);
  6813. // Solve |p(t)|^2 = 1.
  6814. var u = n1xn2,
  6815. w = cartesianDot(A, u),
  6816. uu = cartesianDot(u, u),
  6817. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  6818. if (t2 < 0) return;
  6819. var t = sqrt(t2),
  6820. q = cartesianScale(u, (-w - t) / uu);
  6821. cartesianAddInPlace(q, A);
  6822. q = spherical(q);
  6823. if (!two) return q;
  6824. // Two intersection points.
  6825. var lambda0 = a[0],
  6826. lambda1 = b[0],
  6827. phi0 = a[1],
  6828. phi1 = b[1],
  6829. z;
  6830. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  6831. var delta = lambda1 - lambda0,
  6832. polar = abs(delta - pi$3) < epsilon$2,
  6833. meridian = polar || delta < epsilon$2;
  6834. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  6835. // Check that the first point is between a and b.
  6836. if (meridian
  6837. ? polar
  6838. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  6839. : phi0 <= q[1] && q[1] <= phi1
  6840. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  6841. var q1 = cartesianScale(u, (-w + t) / uu);
  6842. cartesianAddInPlace(q1, A);
  6843. return [q, spherical(q1)];
  6844. }
  6845. }
  6846. // Generates a 4-bit vector representing the location of a point relative to
  6847. // the small circle's bounding box.
  6848. function code(lambda, phi) {
  6849. var r = smallRadius ? radius : pi$3 - radius,
  6850. code = 0;
  6851. if (lambda < -r) code |= 1; // left
  6852. else if (lambda > r) code |= 2; // right
  6853. if (phi < -r) code |= 4; // below
  6854. else if (phi > r) code |= 8; // above
  6855. return code;
  6856. }
  6857. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  6858. };
  6859. var clipLine = function(a, b, x0, y0, x1, y1) {
  6860. var ax = a[0],
  6861. ay = a[1],
  6862. bx = b[0],
  6863. by = b[1],
  6864. t0 = 0,
  6865. t1 = 1,
  6866. dx = bx - ax,
  6867. dy = by - ay,
  6868. r;
  6869. r = x0 - ax;
  6870. if (!dx && r > 0) return;
  6871. r /= dx;
  6872. if (dx < 0) {
  6873. if (r < t0) return;
  6874. if (r < t1) t1 = r;
  6875. } else if (dx > 0) {
  6876. if (r > t1) return;
  6877. if (r > t0) t0 = r;
  6878. }
  6879. r = x1 - ax;
  6880. if (!dx && r < 0) return;
  6881. r /= dx;
  6882. if (dx < 0) {
  6883. if (r > t1) return;
  6884. if (r > t0) t0 = r;
  6885. } else if (dx > 0) {
  6886. if (r < t0) return;
  6887. if (r < t1) t1 = r;
  6888. }
  6889. r = y0 - ay;
  6890. if (!dy && r > 0) return;
  6891. r /= dy;
  6892. if (dy < 0) {
  6893. if (r < t0) return;
  6894. if (r < t1) t1 = r;
  6895. } else if (dy > 0) {
  6896. if (r > t1) return;
  6897. if (r > t0) t0 = r;
  6898. }
  6899. r = y1 - ay;
  6900. if (!dy && r < 0) return;
  6901. r /= dy;
  6902. if (dy < 0) {
  6903. if (r > t1) return;
  6904. if (r > t0) t0 = r;
  6905. } else if (dy > 0) {
  6906. if (r < t0) return;
  6907. if (r < t1) t1 = r;
  6908. }
  6909. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  6910. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  6911. return true;
  6912. };
  6913. var clipMax = 1e9;
  6914. var clipMin = -clipMax;
  6915. // TODO Use d3-polygon’s polygonContains here for the ring check?
  6916. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  6917. function clipRectangle(x0, y0, x1, y1) {
  6918. function visible(x, y) {
  6919. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  6920. }
  6921. function interpolate(from, to, direction, stream) {
  6922. var a = 0, a1 = 0;
  6923. if (from == null
  6924. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  6925. || comparePoint(from, to) < 0 ^ direction > 0) {
  6926. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  6927. while ((a = (a + direction + 4) % 4) !== a1);
  6928. } else {
  6929. stream.point(to[0], to[1]);
  6930. }
  6931. }
  6932. function corner(p, direction) {
  6933. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  6934. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  6935. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  6936. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  6937. }
  6938. function compareIntersection(a, b) {
  6939. return comparePoint(a.x, b.x);
  6940. }
  6941. function comparePoint(a, b) {
  6942. var ca = corner(a, 1),
  6943. cb = corner(b, 1);
  6944. return ca !== cb ? ca - cb
  6945. : ca === 0 ? b[1] - a[1]
  6946. : ca === 1 ? a[0] - b[0]
  6947. : ca === 2 ? a[1] - b[1]
  6948. : b[0] - a[0];
  6949. }
  6950. return function(stream) {
  6951. var activeStream = stream,
  6952. bufferStream = clipBuffer(),
  6953. segments,
  6954. polygon,
  6955. ring,
  6956. x__, y__, v__, // first point
  6957. x_, y_, v_, // previous point
  6958. first,
  6959. clean;
  6960. var clipStream = {
  6961. point: point,
  6962. lineStart: lineStart,
  6963. lineEnd: lineEnd,
  6964. polygonStart: polygonStart,
  6965. polygonEnd: polygonEnd
  6966. };
  6967. function point(x, y) {
  6968. if (visible(x, y)) activeStream.point(x, y);
  6969. }
  6970. function polygonInside() {
  6971. var winding = 0;
  6972. for (var i = 0, n = polygon.length; i < n; ++i) {
  6973. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  6974. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  6975. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  6976. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  6977. }
  6978. }
  6979. return winding;
  6980. }
  6981. // Buffer geometry within a polygon and then clip it en masse.
  6982. function polygonStart() {
  6983. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  6984. }
  6985. function polygonEnd() {
  6986. var startInside = polygonInside(),
  6987. cleanInside = clean && startInside,
  6988. visible = (segments = merge(segments)).length;
  6989. if (cleanInside || visible) {
  6990. stream.polygonStart();
  6991. if (cleanInside) {
  6992. stream.lineStart();
  6993. interpolate(null, null, 1, stream);
  6994. stream.lineEnd();
  6995. }
  6996. if (visible) {
  6997. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  6998. }
  6999. stream.polygonEnd();
  7000. }
  7001. activeStream = stream, segments = polygon = ring = null;
  7002. }
  7003. function lineStart() {
  7004. clipStream.point = linePoint;
  7005. if (polygon) polygon.push(ring = []);
  7006. first = true;
  7007. v_ = false;
  7008. x_ = y_ = NaN;
  7009. }
  7010. // TODO rather than special-case polygons, simply handle them separately.
  7011. // Ideally, coincident intersection points should be jittered to avoid
  7012. // clipping issues.
  7013. function lineEnd() {
  7014. if (segments) {
  7015. linePoint(x__, y__);
  7016. if (v__ && v_) bufferStream.rejoin();
  7017. segments.push(bufferStream.result());
  7018. }
  7019. clipStream.point = point;
  7020. if (v_) activeStream.lineEnd();
  7021. }
  7022. function linePoint(x, y) {
  7023. var v = visible(x, y);
  7024. if (polygon) ring.push([x, y]);
  7025. if (first) {
  7026. x__ = x, y__ = y, v__ = v;
  7027. first = false;
  7028. if (v) {
  7029. activeStream.lineStart();
  7030. activeStream.point(x, y);
  7031. }
  7032. } else {
  7033. if (v && v_) activeStream.point(x, y);
  7034. else {
  7035. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7036. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7037. if (clipLine(a, b, x0, y0, x1, y1)) {
  7038. if (!v_) {
  7039. activeStream.lineStart();
  7040. activeStream.point(a[0], a[1]);
  7041. }
  7042. activeStream.point(b[0], b[1]);
  7043. if (!v) activeStream.lineEnd();
  7044. clean = false;
  7045. } else if (v) {
  7046. activeStream.lineStart();
  7047. activeStream.point(x, y);
  7048. clean = false;
  7049. }
  7050. }
  7051. }
  7052. x_ = x, y_ = y, v_ = v;
  7053. }
  7054. return clipStream;
  7055. };
  7056. }
  7057. var extent$1 = function() {
  7058. var x0 = 0,
  7059. y0 = 0,
  7060. x1 = 960,
  7061. y1 = 500,
  7062. cache,
  7063. cacheStream,
  7064. clip;
  7065. return clip = {
  7066. stream: function(stream) {
  7067. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7068. },
  7069. extent: function(_) {
  7070. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7071. }
  7072. };
  7073. };
  7074. var lengthSum = adder();
  7075. var lambda0$2;
  7076. var sinPhi0$1;
  7077. var cosPhi0$1;
  7078. var lengthStream = {
  7079. sphere: noop$1,
  7080. point: noop$1,
  7081. lineStart: lengthLineStart,
  7082. lineEnd: noop$1,
  7083. polygonStart: noop$1,
  7084. polygonEnd: noop$1
  7085. };
  7086. function lengthLineStart() {
  7087. lengthStream.point = lengthPointFirst;
  7088. lengthStream.lineEnd = lengthLineEnd;
  7089. }
  7090. function lengthLineEnd() {
  7091. lengthStream.point = lengthStream.lineEnd = noop$1;
  7092. }
  7093. function lengthPointFirst(lambda, phi) {
  7094. lambda *= radians, phi *= radians;
  7095. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7096. lengthStream.point = lengthPoint;
  7097. }
  7098. function lengthPoint(lambda, phi) {
  7099. lambda *= radians, phi *= radians;
  7100. var sinPhi = sin$1(phi),
  7101. cosPhi = cos$1(phi),
  7102. delta = abs(lambda - lambda0$2),
  7103. cosDelta = cos$1(delta),
  7104. sinDelta = sin$1(delta),
  7105. x = cosPhi * sinDelta,
  7106. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7107. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7108. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7109. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7110. }
  7111. var length$1 = function(object) {
  7112. lengthSum.reset();
  7113. geoStream(object, lengthStream);
  7114. return +lengthSum;
  7115. };
  7116. var coordinates = [null, null];
  7117. var object$1 = {type: "LineString", coordinates: coordinates};
  7118. var distance = function(a, b) {
  7119. coordinates[0] = a;
  7120. coordinates[1] = b;
  7121. return length$1(object$1);
  7122. };
  7123. var containsObjectType = {
  7124. Feature: function(object, point) {
  7125. return containsGeometry(object.geometry, point);
  7126. },
  7127. FeatureCollection: function(object, point) {
  7128. var features = object.features, i = -1, n = features.length;
  7129. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7130. return false;
  7131. }
  7132. };
  7133. var containsGeometryType = {
  7134. Sphere: function() {
  7135. return true;
  7136. },
  7137. Point: function(object, point) {
  7138. return containsPoint(object.coordinates, point);
  7139. },
  7140. MultiPoint: function(object, point) {
  7141. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7142. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7143. return false;
  7144. },
  7145. LineString: function(object, point) {
  7146. return containsLine(object.coordinates, point);
  7147. },
  7148. MultiLineString: function(object, point) {
  7149. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7150. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7151. return false;
  7152. },
  7153. Polygon: function(object, point) {
  7154. return containsPolygon(object.coordinates, point);
  7155. },
  7156. MultiPolygon: function(object, point) {
  7157. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7158. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7159. return false;
  7160. },
  7161. GeometryCollection: function(object, point) {
  7162. var geometries = object.geometries, i = -1, n = geometries.length;
  7163. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7164. return false;
  7165. }
  7166. };
  7167. function containsGeometry(geometry, point) {
  7168. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7169. ? containsGeometryType[geometry.type](geometry, point)
  7170. : false;
  7171. }
  7172. function containsPoint(coordinates, point) {
  7173. return distance(coordinates, point) === 0;
  7174. }
  7175. function containsLine(coordinates, point) {
  7176. var ab = distance(coordinates[0], coordinates[1]),
  7177. ao = distance(coordinates[0], point),
  7178. ob = distance(point, coordinates[1]);
  7179. return ao + ob <= ab + epsilon$2;
  7180. }
  7181. function containsPolygon(coordinates, point) {
  7182. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7183. }
  7184. function ringRadians(ring) {
  7185. return ring = ring.map(pointRadians), ring.pop(), ring;
  7186. }
  7187. function pointRadians(point) {
  7188. return [point[0] * radians, point[1] * radians];
  7189. }
  7190. var contains = function(object, point) {
  7191. return (object && containsObjectType.hasOwnProperty(object.type)
  7192. ? containsObjectType[object.type]
  7193. : containsGeometry)(object, point);
  7194. };
  7195. function graticuleX(y0, y1, dy) {
  7196. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7197. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7198. }
  7199. function graticuleY(x0, x1, dx) {
  7200. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7201. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7202. }
  7203. function graticule() {
  7204. var x1, x0, X1, X0,
  7205. y1, y0, Y1, Y0,
  7206. dx = 10, dy = dx, DX = 90, DY = 360,
  7207. x, y, X, Y,
  7208. precision = 2.5;
  7209. function graticule() {
  7210. return {type: "MultiLineString", coordinates: lines()};
  7211. }
  7212. function lines() {
  7213. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7214. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7215. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7216. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7217. }
  7218. graticule.lines = function() {
  7219. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7220. };
  7221. graticule.outline = function() {
  7222. return {
  7223. type: "Polygon",
  7224. coordinates: [
  7225. X(X0).concat(
  7226. Y(Y1).slice(1),
  7227. X(X1).reverse().slice(1),
  7228. Y(Y0).reverse().slice(1))
  7229. ]
  7230. };
  7231. };
  7232. graticule.extent = function(_) {
  7233. if (!arguments.length) return graticule.extentMinor();
  7234. return graticule.extentMajor(_).extentMinor(_);
  7235. };
  7236. graticule.extentMajor = function(_) {
  7237. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7238. X0 = +_[0][0], X1 = +_[1][0];
  7239. Y0 = +_[0][1], Y1 = +_[1][1];
  7240. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7241. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7242. return graticule.precision(precision);
  7243. };
  7244. graticule.extentMinor = function(_) {
  7245. if (!arguments.length) return [[x0, y0], [x1, y1]];
  7246. x0 = +_[0][0], x1 = +_[1][0];
  7247. y0 = +_[0][1], y1 = +_[1][1];
  7248. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  7249. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  7250. return graticule.precision(precision);
  7251. };
  7252. graticule.step = function(_) {
  7253. if (!arguments.length) return graticule.stepMinor();
  7254. return graticule.stepMajor(_).stepMinor(_);
  7255. };
  7256. graticule.stepMajor = function(_) {
  7257. if (!arguments.length) return [DX, DY];
  7258. DX = +_[0], DY = +_[1];
  7259. return graticule;
  7260. };
  7261. graticule.stepMinor = function(_) {
  7262. if (!arguments.length) return [dx, dy];
  7263. dx = +_[0], dy = +_[1];
  7264. return graticule;
  7265. };
  7266. graticule.precision = function(_) {
  7267. if (!arguments.length) return precision;
  7268. precision = +_;
  7269. x = graticuleX(y0, y1, 90);
  7270. y = graticuleY(x0, x1, precision);
  7271. X = graticuleX(Y0, Y1, 90);
  7272. Y = graticuleY(X0, X1, precision);
  7273. return graticule;
  7274. };
  7275. return graticule
  7276. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7277. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7278. }
  7279. function graticule10() {
  7280. return graticule()();
  7281. }
  7282. var interpolate$1 = function(a, b) {
  7283. var x0 = a[0] * radians,
  7284. y0 = a[1] * radians,
  7285. x1 = b[0] * radians,
  7286. y1 = b[1] * radians,
  7287. cy0 = cos$1(y0),
  7288. sy0 = sin$1(y0),
  7289. cy1 = cos$1(y1),
  7290. sy1 = sin$1(y1),
  7291. kx0 = cy0 * cos$1(x0),
  7292. ky0 = cy0 * sin$1(x0),
  7293. kx1 = cy1 * cos$1(x1),
  7294. ky1 = cy1 * sin$1(x1),
  7295. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  7296. k = sin$1(d);
  7297. var interpolate = d ? function(t) {
  7298. var B = sin$1(t *= d) / k,
  7299. A = sin$1(d - t) / k,
  7300. x = A * kx0 + B * kx1,
  7301. y = A * ky0 + B * ky1,
  7302. z = A * sy0 + B * sy1;
  7303. return [
  7304. atan2(y, x) * degrees$1,
  7305. atan2(z, sqrt(x * x + y * y)) * degrees$1
  7306. ];
  7307. } : function() {
  7308. return [x0 * degrees$1, y0 * degrees$1];
  7309. };
  7310. interpolate.distance = d;
  7311. return interpolate;
  7312. };
  7313. var identity$4 = function(x) {
  7314. return x;
  7315. };
  7316. var areaSum$1 = adder();
  7317. var areaRingSum$1 = adder();
  7318. var x00;
  7319. var y00;
  7320. var x0$1;
  7321. var y0$1;
  7322. var areaStream$1 = {
  7323. point: noop$1,
  7324. lineStart: noop$1,
  7325. lineEnd: noop$1,
  7326. polygonStart: function() {
  7327. areaStream$1.lineStart = areaRingStart$1;
  7328. areaStream$1.lineEnd = areaRingEnd$1;
  7329. },
  7330. polygonEnd: function() {
  7331. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$1;
  7332. areaSum$1.add(abs(areaRingSum$1));
  7333. areaRingSum$1.reset();
  7334. },
  7335. result: function() {
  7336. var area = areaSum$1 / 2;
  7337. areaSum$1.reset();
  7338. return area;
  7339. }
  7340. };
  7341. function areaRingStart$1() {
  7342. areaStream$1.point = areaPointFirst$1;
  7343. }
  7344. function areaPointFirst$1(x, y) {
  7345. areaStream$1.point = areaPoint$1;
  7346. x00 = x0$1 = x, y00 = y0$1 = y;
  7347. }
  7348. function areaPoint$1(x, y) {
  7349. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  7350. x0$1 = x, y0$1 = y;
  7351. }
  7352. function areaRingEnd$1() {
  7353. areaPoint$1(x00, y00);
  7354. }
  7355. var x0$2 = Infinity;
  7356. var y0$2 = x0$2;
  7357. var x1 = -x0$2;
  7358. var y1 = x1;
  7359. var boundsStream$1 = {
  7360. point: boundsPoint$1,
  7361. lineStart: noop$1,
  7362. lineEnd: noop$1,
  7363. polygonStart: noop$1,
  7364. polygonEnd: noop$1,
  7365. result: function() {
  7366. var bounds = [[x0$2, y0$2], [x1, y1]];
  7367. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  7368. return bounds;
  7369. }
  7370. };
  7371. function boundsPoint$1(x, y) {
  7372. if (x < x0$2) x0$2 = x;
  7373. if (x > x1) x1 = x;
  7374. if (y < y0$2) y0$2 = y;
  7375. if (y > y1) y1 = y;
  7376. }
  7377. // TODO Enforce positive area for exterior, negative area for interior?
  7378. var X0$1 = 0;
  7379. var Y0$1 = 0;
  7380. var Z0$1 = 0;
  7381. var X1$1 = 0;
  7382. var Y1$1 = 0;
  7383. var Z1$1 = 0;
  7384. var X2$1 = 0;
  7385. var Y2$1 = 0;
  7386. var Z2$1 = 0;
  7387. var x00$1;
  7388. var y00$1;
  7389. var x0$3;
  7390. var y0$3;
  7391. var centroidStream$1 = {
  7392. point: centroidPoint$1,
  7393. lineStart: centroidLineStart$1,
  7394. lineEnd: centroidLineEnd$1,
  7395. polygonStart: function() {
  7396. centroidStream$1.lineStart = centroidRingStart$1;
  7397. centroidStream$1.lineEnd = centroidRingEnd$1;
  7398. },
  7399. polygonEnd: function() {
  7400. centroidStream$1.point = centroidPoint$1;
  7401. centroidStream$1.lineStart = centroidLineStart$1;
  7402. centroidStream$1.lineEnd = centroidLineEnd$1;
  7403. },
  7404. result: function() {
  7405. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  7406. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  7407. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  7408. : [NaN, NaN];
  7409. X0$1 = Y0$1 = Z0$1 =
  7410. X1$1 = Y1$1 = Z1$1 =
  7411. X2$1 = Y2$1 = Z2$1 = 0;
  7412. return centroid;
  7413. }
  7414. };
  7415. function centroidPoint$1(x, y) {
  7416. X0$1 += x;
  7417. Y0$1 += y;
  7418. ++Z0$1;
  7419. }
  7420. function centroidLineStart$1() {
  7421. centroidStream$1.point = centroidPointFirstLine;
  7422. }
  7423. function centroidPointFirstLine(x, y) {
  7424. centroidStream$1.point = centroidPointLine;
  7425. centroidPoint$1(x0$3 = x, y0$3 = y);
  7426. }
  7427. function centroidPointLine(x, y) {
  7428. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  7429. X1$1 += z * (x0$3 + x) / 2;
  7430. Y1$1 += z * (y0$3 + y) / 2;
  7431. Z1$1 += z;
  7432. centroidPoint$1(x0$3 = x, y0$3 = y);
  7433. }
  7434. function centroidLineEnd$1() {
  7435. centroidStream$1.point = centroidPoint$1;
  7436. }
  7437. function centroidRingStart$1() {
  7438. centroidStream$1.point = centroidPointFirstRing;
  7439. }
  7440. function centroidRingEnd$1() {
  7441. centroidPointRing(x00$1, y00$1);
  7442. }
  7443. function centroidPointFirstRing(x, y) {
  7444. centroidStream$1.point = centroidPointRing;
  7445. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  7446. }
  7447. function centroidPointRing(x, y) {
  7448. var dx = x - x0$3,
  7449. dy = y - y0$3,
  7450. z = sqrt(dx * dx + dy * dy);
  7451. X1$1 += z * (x0$3 + x) / 2;
  7452. Y1$1 += z * (y0$3 + y) / 2;
  7453. Z1$1 += z;
  7454. z = y0$3 * x - x0$3 * y;
  7455. X2$1 += z * (x0$3 + x);
  7456. Y2$1 += z * (y0$3 + y);
  7457. Z2$1 += z * 3;
  7458. centroidPoint$1(x0$3 = x, y0$3 = y);
  7459. }
  7460. function PathContext(context) {
  7461. this._context = context;
  7462. }
  7463. PathContext.prototype = {
  7464. _radius: 4.5,
  7465. pointRadius: function(_) {
  7466. return this._radius = _, this;
  7467. },
  7468. polygonStart: function() {
  7469. this._line = 0;
  7470. },
  7471. polygonEnd: function() {
  7472. this._line = NaN;
  7473. },
  7474. lineStart: function() {
  7475. this._point = 0;
  7476. },
  7477. lineEnd: function() {
  7478. if (this._line === 0) this._context.closePath();
  7479. this._point = NaN;
  7480. },
  7481. point: function(x, y) {
  7482. switch (this._point) {
  7483. case 0: {
  7484. this._context.moveTo(x, y);
  7485. this._point = 1;
  7486. break;
  7487. }
  7488. case 1: {
  7489. this._context.lineTo(x, y);
  7490. break;
  7491. }
  7492. default: {
  7493. this._context.moveTo(x + this._radius, y);
  7494. this._context.arc(x, y, this._radius, 0, tau$3);
  7495. break;
  7496. }
  7497. }
  7498. },
  7499. result: noop$1
  7500. };
  7501. var lengthSum$1 = adder();
  7502. var lengthRing;
  7503. var x00$2;
  7504. var y00$2;
  7505. var x0$4;
  7506. var y0$4;
  7507. var lengthStream$1 = {
  7508. point: noop$1,
  7509. lineStart: function() {
  7510. lengthStream$1.point = lengthPointFirst$1;
  7511. },
  7512. lineEnd: function() {
  7513. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  7514. lengthStream$1.point = noop$1;
  7515. },
  7516. polygonStart: function() {
  7517. lengthRing = true;
  7518. },
  7519. polygonEnd: function() {
  7520. lengthRing = null;
  7521. },
  7522. result: function() {
  7523. var length = +lengthSum$1;
  7524. lengthSum$1.reset();
  7525. return length;
  7526. }
  7527. };
  7528. function lengthPointFirst$1(x, y) {
  7529. lengthStream$1.point = lengthPoint$1;
  7530. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  7531. }
  7532. function lengthPoint$1(x, y) {
  7533. x0$4 -= x, y0$4 -= y;
  7534. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  7535. x0$4 = x, y0$4 = y;
  7536. }
  7537. function PathString() {
  7538. this._string = [];
  7539. }
  7540. PathString.prototype = {
  7541. _radius: 4.5,
  7542. _circle: circle$1(4.5),
  7543. pointRadius: function(_) {
  7544. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  7545. return this;
  7546. },
  7547. polygonStart: function() {
  7548. this._line = 0;
  7549. },
  7550. polygonEnd: function() {
  7551. this._line = NaN;
  7552. },
  7553. lineStart: function() {
  7554. this._point = 0;
  7555. },
  7556. lineEnd: function() {
  7557. if (this._line === 0) this._string.push("Z");
  7558. this._point = NaN;
  7559. },
  7560. point: function(x, y) {
  7561. switch (this._point) {
  7562. case 0: {
  7563. this._string.push("M", x, ",", y);
  7564. this._point = 1;
  7565. break;
  7566. }
  7567. case 1: {
  7568. this._string.push("L", x, ",", y);
  7569. break;
  7570. }
  7571. default: {
  7572. if (this._circle == null) this._circle = circle$1(this._radius);
  7573. this._string.push("M", x, ",", y, this._circle);
  7574. break;
  7575. }
  7576. }
  7577. },
  7578. result: function() {
  7579. if (this._string.length) {
  7580. var result = this._string.join("");
  7581. this._string = [];
  7582. return result;
  7583. } else {
  7584. return null;
  7585. }
  7586. }
  7587. };
  7588. function circle$1(radius) {
  7589. return "m0," + radius
  7590. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  7591. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  7592. + "z";
  7593. }
  7594. var index$1 = function(projection, context) {
  7595. var pointRadius = 4.5,
  7596. projectionStream,
  7597. contextStream;
  7598. function path(object) {
  7599. if (object) {
  7600. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  7601. geoStream(object, projectionStream(contextStream));
  7602. }
  7603. return contextStream.result();
  7604. }
  7605. path.area = function(object) {
  7606. geoStream(object, projectionStream(areaStream$1));
  7607. return areaStream$1.result();
  7608. };
  7609. path.measure = function(object) {
  7610. geoStream(object, projectionStream(lengthStream$1));
  7611. return lengthStream$1.result();
  7612. };
  7613. path.bounds = function(object) {
  7614. geoStream(object, projectionStream(boundsStream$1));
  7615. return boundsStream$1.result();
  7616. };
  7617. path.centroid = function(object) {
  7618. geoStream(object, projectionStream(centroidStream$1));
  7619. return centroidStream$1.result();
  7620. };
  7621. path.projection = function(_) {
  7622. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  7623. };
  7624. path.context = function(_) {
  7625. if (!arguments.length) return context;
  7626. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  7627. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  7628. return path;
  7629. };
  7630. path.pointRadius = function(_) {
  7631. if (!arguments.length) return pointRadius;
  7632. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  7633. return path;
  7634. };
  7635. return path.projection(projection).context(context);
  7636. };
  7637. var transform = function(methods) {
  7638. return {
  7639. stream: transformer(methods)
  7640. };
  7641. };
  7642. function transformer(methods) {
  7643. return function(stream) {
  7644. var s = new TransformStream;
  7645. for (var key in methods) s[key] = methods[key];
  7646. s.stream = stream;
  7647. return s;
  7648. };
  7649. }
  7650. function TransformStream() {}
  7651. TransformStream.prototype = {
  7652. constructor: TransformStream,
  7653. point: function(x, y) { this.stream.point(x, y); },
  7654. sphere: function() { this.stream.sphere(); },
  7655. lineStart: function() { this.stream.lineStart(); },
  7656. lineEnd: function() { this.stream.lineEnd(); },
  7657. polygonStart: function() { this.stream.polygonStart(); },
  7658. polygonEnd: function() { this.stream.polygonEnd(); }
  7659. };
  7660. function fitExtent(projection, extent, object) {
  7661. var w = extent[1][0] - extent[0][0],
  7662. h = extent[1][1] - extent[0][1],
  7663. clip = projection.clipExtent && projection.clipExtent();
  7664. projection
  7665. .scale(150)
  7666. .translate([0, 0]);
  7667. if (clip != null) projection.clipExtent(null);
  7668. geoStream(object, projection.stream(boundsStream$1));
  7669. var b = boundsStream$1.result(),
  7670. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  7671. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  7672. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  7673. if (clip != null) projection.clipExtent(clip);
  7674. return projection
  7675. .scale(k * 150)
  7676. .translate([x, y]);
  7677. }
  7678. function fitSize(projection, size, object) {
  7679. return fitExtent(projection, [[0, 0], size], object);
  7680. }
  7681. var maxDepth = 16;
  7682. var cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  7683. var resample = function(project, delta2) {
  7684. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  7685. };
  7686. function resampleNone(project) {
  7687. return transformer({
  7688. point: function(x, y) {
  7689. x = project(x, y);
  7690. this.stream.point(x[0], x[1]);
  7691. }
  7692. });
  7693. }
  7694. function resample$1(project, delta2) {
  7695. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  7696. var dx = x1 - x0,
  7697. dy = y1 - y0,
  7698. d2 = dx * dx + dy * dy;
  7699. if (d2 > 4 * delta2 && depth--) {
  7700. var a = a0 + a1,
  7701. b = b0 + b1,
  7702. c = c0 + c1,
  7703. m = sqrt(a * a + b * b + c * c),
  7704. phi2 = asin(c /= m),
  7705. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  7706. p = project(lambda2, phi2),
  7707. x2 = p[0],
  7708. y2 = p[1],
  7709. dx2 = x2 - x0,
  7710. dy2 = y2 - y0,
  7711. dz = dy * dx2 - dx * dy2;
  7712. if (dz * dz / d2 > delta2 // perpendicular projected distance
  7713. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  7714. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  7715. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  7716. stream.point(x2, y2);
  7717. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  7718. }
  7719. }
  7720. }
  7721. return function(stream) {
  7722. var lambda00, x00, y00, a00, b00, c00, // first point
  7723. lambda0, x0, y0, a0, b0, c0; // previous point
  7724. var resampleStream = {
  7725. point: point,
  7726. lineStart: lineStart,
  7727. lineEnd: lineEnd,
  7728. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  7729. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  7730. };
  7731. function point(x, y) {
  7732. x = project(x, y);
  7733. stream.point(x[0], x[1]);
  7734. }
  7735. function lineStart() {
  7736. x0 = NaN;
  7737. resampleStream.point = linePoint;
  7738. stream.lineStart();
  7739. }
  7740. function linePoint(lambda, phi) {
  7741. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  7742. 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);
  7743. stream.point(x0, y0);
  7744. }
  7745. function lineEnd() {
  7746. resampleStream.point = point;
  7747. stream.lineEnd();
  7748. }
  7749. function ringStart() {
  7750. lineStart();
  7751. resampleStream.point = ringPoint;
  7752. resampleStream.lineEnd = ringEnd;
  7753. }
  7754. function ringPoint(lambda, phi) {
  7755. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  7756. resampleStream.point = linePoint;
  7757. }
  7758. function ringEnd() {
  7759. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  7760. resampleStream.lineEnd = lineEnd;
  7761. lineEnd();
  7762. }
  7763. return resampleStream;
  7764. };
  7765. }
  7766. var transformRadians = transformer({
  7767. point: function(x, y) {
  7768. this.stream.point(x * radians, y * radians);
  7769. }
  7770. });
  7771. function transformRotate(rotate) {
  7772. return transformer({
  7773. point: function(x, y) {
  7774. var r = rotate(x, y);
  7775. return this.stream.point(r[0], r[1]);
  7776. }
  7777. });
  7778. }
  7779. function projection(project) {
  7780. return projectionMutator(function() { return project; })();
  7781. }
  7782. function projectionMutator(projectAt) {
  7783. var project,
  7784. k = 150, // scale
  7785. x = 480, y = 250, // translate
  7786. dx, dy, lambda = 0, phi = 0, // center
  7787. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
  7788. theta = null, preclip = clipAntimeridian, // clip angle
  7789. x0 = null, y0, x1, y1, postclip = identity$4, // clip extent
  7790. delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
  7791. cache,
  7792. cacheStream;
  7793. function projection(point) {
  7794. point = projectRotate(point[0] * radians, point[1] * radians);
  7795. return [point[0] * k + dx, dy - point[1] * k];
  7796. }
  7797. function invert(point) {
  7798. point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
  7799. return point && [point[0] * degrees$1, point[1] * degrees$1];
  7800. }
  7801. function projectTransform(x, y) {
  7802. return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
  7803. }
  7804. projection.stream = function(stream) {
  7805. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  7806. };
  7807. projection.preclip = function(_) {
  7808. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  7809. };
  7810. projection.postclip = function(_) {
  7811. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  7812. };
  7813. projection.clipAngle = function(_) {
  7814. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  7815. };
  7816. projection.clipExtent = function(_) {
  7817. 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]];
  7818. };
  7819. projection.scale = function(_) {
  7820. return arguments.length ? (k = +_, recenter()) : k;
  7821. };
  7822. projection.translate = function(_) {
  7823. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  7824. };
  7825. projection.center = function(_) {
  7826. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  7827. };
  7828. projection.rotate = function(_) {
  7829. 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];
  7830. };
  7831. projection.precision = function(_) {
  7832. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  7833. };
  7834. projection.fitExtent = function(extent, object) {
  7835. return fitExtent(projection, extent, object);
  7836. };
  7837. projection.fitSize = function(size, object) {
  7838. return fitSize(projection, size, object);
  7839. };
  7840. function recenter() {
  7841. projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
  7842. var center = project(lambda, phi);
  7843. dx = x - center[0] * k;
  7844. dy = y + center[1] * k;
  7845. return reset();
  7846. }
  7847. function reset() {
  7848. cache = cacheStream = null;
  7849. return projection;
  7850. }
  7851. return function() {
  7852. project = projectAt.apply(this, arguments);
  7853. projection.invert = project.invert && invert;
  7854. return recenter();
  7855. };
  7856. }
  7857. function conicProjection(projectAt) {
  7858. var phi0 = 0,
  7859. phi1 = pi$3 / 3,
  7860. m = projectionMutator(projectAt),
  7861. p = m(phi0, phi1);
  7862. p.parallels = function(_) {
  7863. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  7864. };
  7865. return p;
  7866. }
  7867. function cylindricalEqualAreaRaw(phi0) {
  7868. var cosPhi0 = cos$1(phi0);
  7869. function forward(lambda, phi) {
  7870. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  7871. }
  7872. forward.invert = function(x, y) {
  7873. return [x / cosPhi0, asin(y * cosPhi0)];
  7874. };
  7875. return forward;
  7876. }
  7877. function conicEqualAreaRaw(y0, y1) {
  7878. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  7879. // Are the parallels symmetrical around the Equator?
  7880. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  7881. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  7882. function project(x, y) {
  7883. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  7884. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  7885. }
  7886. project.invert = function(x, y) {
  7887. var r0y = r0 - y;
  7888. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  7889. };
  7890. return project;
  7891. }
  7892. var conicEqualArea = function() {
  7893. return conicProjection(conicEqualAreaRaw)
  7894. .scale(155.424)
  7895. .center([0, 33.6442]);
  7896. };
  7897. var albers = function() {
  7898. return conicEqualArea()
  7899. .parallels([29.5, 45.5])
  7900. .scale(1070)
  7901. .translate([480, 250])
  7902. .rotate([96, 0])
  7903. .center([-0.6, 38.7]);
  7904. };
  7905. // The projections must have mutually exclusive clip regions on the sphere,
  7906. // as this will avoid emitting interleaving lines and polygons.
  7907. function multiplex(streams) {
  7908. var n = streams.length;
  7909. return {
  7910. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  7911. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  7912. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  7913. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  7914. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  7915. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  7916. };
  7917. }
  7918. // A composite projection for the United States, configured by default for
  7919. // 960×500. The projection also works quite well at 960×600 if you change the
  7920. // scale to 1285 and adjust the translate accordingly. The set of standard
  7921. // parallels for each region comes from USGS, which is published here:
  7922. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  7923. var albersUsa = function() {
  7924. var cache,
  7925. cacheStream,
  7926. lower48 = albers(), lower48Point,
  7927. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  7928. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  7929. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  7930. function albersUsa(coordinates) {
  7931. var x = coordinates[0], y = coordinates[1];
  7932. return point = null,
  7933. (lower48Point.point(x, y), point)
  7934. || (alaskaPoint.point(x, y), point)
  7935. || (hawaiiPoint.point(x, y), point);
  7936. }
  7937. albersUsa.invert = function(coordinates) {
  7938. var k = lower48.scale(),
  7939. t = lower48.translate(),
  7940. x = (coordinates[0] - t[0]) / k,
  7941. y = (coordinates[1] - t[1]) / k;
  7942. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  7943. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  7944. : lower48).invert(coordinates);
  7945. };
  7946. albersUsa.stream = function(stream) {
  7947. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  7948. };
  7949. albersUsa.precision = function(_) {
  7950. if (!arguments.length) return lower48.precision();
  7951. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  7952. return reset();
  7953. };
  7954. albersUsa.scale = function(_) {
  7955. if (!arguments.length) return lower48.scale();
  7956. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  7957. return albersUsa.translate(lower48.translate());
  7958. };
  7959. albersUsa.translate = function(_) {
  7960. if (!arguments.length) return lower48.translate();
  7961. var k = lower48.scale(), x = +_[0], y = +_[1];
  7962. lower48Point = lower48
  7963. .translate(_)
  7964. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  7965. .stream(pointStream);
  7966. alaskaPoint = alaska
  7967. .translate([x - 0.307 * k, y + 0.201 * k])
  7968. .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]])
  7969. .stream(pointStream);
  7970. hawaiiPoint = hawaii
  7971. .translate([x - 0.205 * k, y + 0.212 * k])
  7972. .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]])
  7973. .stream(pointStream);
  7974. return reset();
  7975. };
  7976. albersUsa.fitExtent = function(extent, object) {
  7977. return fitExtent(albersUsa, extent, object);
  7978. };
  7979. albersUsa.fitSize = function(size, object) {
  7980. return fitSize(albersUsa, size, object);
  7981. };
  7982. function reset() {
  7983. cache = cacheStream = null;
  7984. return albersUsa;
  7985. }
  7986. return albersUsa.scale(1070);
  7987. };
  7988. function azimuthalRaw(scale) {
  7989. return function(x, y) {
  7990. var cx = cos$1(x),
  7991. cy = cos$1(y),
  7992. k = scale(cx * cy);
  7993. return [
  7994. k * cy * sin$1(x),
  7995. k * sin$1(y)
  7996. ];
  7997. }
  7998. }
  7999. function azimuthalInvert(angle) {
  8000. return function(x, y) {
  8001. var z = sqrt(x * x + y * y),
  8002. c = angle(z),
  8003. sc = sin$1(c),
  8004. cc = cos$1(c);
  8005. return [
  8006. atan2(x * sc, z * cc),
  8007. asin(z && y * sc / z)
  8008. ];
  8009. }
  8010. }
  8011. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8012. return sqrt(2 / (1 + cxcy));
  8013. });
  8014. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8015. return 2 * asin(z / 2);
  8016. });
  8017. var azimuthalEqualArea = function() {
  8018. return projection(azimuthalEqualAreaRaw)
  8019. .scale(124.75)
  8020. .clipAngle(180 - 1e-3);
  8021. };
  8022. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8023. return (c = acos(c)) && c / sin$1(c);
  8024. });
  8025. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8026. return z;
  8027. });
  8028. var azimuthalEquidistant = function() {
  8029. return projection(azimuthalEquidistantRaw)
  8030. .scale(79.4188)
  8031. .clipAngle(180 - 1e-3);
  8032. };
  8033. function mercatorRaw(lambda, phi) {
  8034. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8035. }
  8036. mercatorRaw.invert = function(x, y) {
  8037. return [x, 2 * atan(exp(y)) - halfPi$2];
  8038. };
  8039. var mercator = function() {
  8040. return mercatorProjection(mercatorRaw)
  8041. .scale(961 / tau$3);
  8042. };
  8043. function mercatorProjection(project) {
  8044. var m = projection(project),
  8045. center = m.center,
  8046. scale = m.scale,
  8047. translate = m.translate,
  8048. clipExtent = m.clipExtent,
  8049. x0 = null, y0, x1, y1; // clip extent
  8050. m.scale = function(_) {
  8051. return arguments.length ? (scale(_), reclip()) : scale();
  8052. };
  8053. m.translate = function(_) {
  8054. return arguments.length ? (translate(_), reclip()) : translate();
  8055. };
  8056. m.center = function(_) {
  8057. return arguments.length ? (center(_), reclip()) : center();
  8058. };
  8059. m.clipExtent = function(_) {
  8060. 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]];
  8061. };
  8062. function reclip() {
  8063. var k = pi$3 * scale(),
  8064. t = m(rotation(m.rotate()).invert([0, 0]));
  8065. return clipExtent(x0 == null
  8066. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8067. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8068. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8069. }
  8070. return reclip();
  8071. }
  8072. function tany(y) {
  8073. return tan((halfPi$2 + y) / 2);
  8074. }
  8075. function conicConformalRaw(y0, y1) {
  8076. var cy0 = cos$1(y0),
  8077. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8078. f = cy0 * pow(tany(y0), n) / n;
  8079. if (!n) return mercatorRaw;
  8080. function project(x, y) {
  8081. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8082. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8083. var r = f / pow(tany(y), n);
  8084. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8085. }
  8086. project.invert = function(x, y) {
  8087. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8088. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8089. };
  8090. return project;
  8091. }
  8092. var conicConformal = function() {
  8093. return conicProjection(conicConformalRaw)
  8094. .scale(109.5)
  8095. .parallels([30, 30]);
  8096. };
  8097. function equirectangularRaw(lambda, phi) {
  8098. return [lambda, phi];
  8099. }
  8100. equirectangularRaw.invert = equirectangularRaw;
  8101. var equirectangular = function() {
  8102. return projection(equirectangularRaw)
  8103. .scale(152.63);
  8104. };
  8105. function conicEquidistantRaw(y0, y1) {
  8106. var cy0 = cos$1(y0),
  8107. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8108. g = cy0 / n + y0;
  8109. if (abs(n) < epsilon$2) return equirectangularRaw;
  8110. function project(x, y) {
  8111. var gy = g - y, nx = n * x;
  8112. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8113. }
  8114. project.invert = function(x, y) {
  8115. var gy = g - y;
  8116. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8117. };
  8118. return project;
  8119. }
  8120. var conicEquidistant = function() {
  8121. return conicProjection(conicEquidistantRaw)
  8122. .scale(131.154)
  8123. .center([0, 13.9389]);
  8124. };
  8125. function gnomonicRaw(x, y) {
  8126. var cy = cos$1(y), k = cos$1(x) * cy;
  8127. return [cy * sin$1(x) / k, sin$1(y) / k];
  8128. }
  8129. gnomonicRaw.invert = azimuthalInvert(atan);
  8130. var gnomonic = function() {
  8131. return projection(gnomonicRaw)
  8132. .scale(144.049)
  8133. .clipAngle(60);
  8134. };
  8135. function scaleTranslate(kx, ky, tx, ty) {
  8136. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8137. point: function(x, y) {
  8138. this.stream.point(x * kx + tx, y * ky + ty);
  8139. }
  8140. });
  8141. }
  8142. var identity$5 = function() {
  8143. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
  8144. x0 = null, y0, x1, y1, // clip extent
  8145. postclip = identity$4,
  8146. cache,
  8147. cacheStream,
  8148. projection;
  8149. function reset() {
  8150. cache = cacheStream = null;
  8151. return projection;
  8152. }
  8153. return projection = {
  8154. stream: function(stream) {
  8155. return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
  8156. },
  8157. postclip: function(_) {
  8158. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8159. },
  8160. clipExtent: function(_) {
  8161. 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]];
  8162. },
  8163. scale: function(_) {
  8164. return arguments.length ? (transform$$1 = scaleTranslate((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8165. },
  8166. translate: function(_) {
  8167. return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8168. },
  8169. reflectX: function(_) {
  8170. return arguments.length ? (transform$$1 = scaleTranslate(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8171. },
  8172. reflectY: function(_) {
  8173. return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8174. },
  8175. fitExtent: function(extent, object) {
  8176. return fitExtent(projection, extent, object);
  8177. },
  8178. fitSize: function(size, object) {
  8179. return fitSize(projection, size, object);
  8180. }
  8181. };
  8182. };
  8183. function naturalEarth1Raw(lambda, phi) {
  8184. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8185. return [
  8186. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  8187. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  8188. ];
  8189. }
  8190. naturalEarth1Raw.invert = function(x, y) {
  8191. var phi = y, i = 25, delta;
  8192. do {
  8193. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8194. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  8195. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  8196. } while (abs(delta) > epsilon$2 && --i > 0);
  8197. return [
  8198. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  8199. phi
  8200. ];
  8201. };
  8202. var naturalEarth1 = function() {
  8203. return projection(naturalEarth1Raw)
  8204. .scale(175.295);
  8205. };
  8206. function orthographicRaw(x, y) {
  8207. return [cos$1(y) * sin$1(x), sin$1(y)];
  8208. }
  8209. orthographicRaw.invert = azimuthalInvert(asin);
  8210. var orthographic = function() {
  8211. return projection(orthographicRaw)
  8212. .scale(249.5)
  8213. .clipAngle(90 + epsilon$2);
  8214. };
  8215. function stereographicRaw(x, y) {
  8216. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  8217. return [cy * sin$1(x) / k, sin$1(y) / k];
  8218. }
  8219. stereographicRaw.invert = azimuthalInvert(function(z) {
  8220. return 2 * atan(z);
  8221. });
  8222. var stereographic = function() {
  8223. return projection(stereographicRaw)
  8224. .scale(250)
  8225. .clipAngle(142);
  8226. };
  8227. function transverseMercatorRaw(lambda, phi) {
  8228. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  8229. }
  8230. transverseMercatorRaw.invert = function(x, y) {
  8231. return [-y, 2 * atan(exp(x)) - halfPi$2];
  8232. };
  8233. var transverseMercator = function() {
  8234. var m = mercatorProjection(transverseMercatorRaw),
  8235. center = m.center,
  8236. rotate = m.rotate;
  8237. m.center = function(_) {
  8238. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  8239. };
  8240. m.rotate = function(_) {
  8241. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  8242. };
  8243. return rotate([0, 0, 90])
  8244. .scale(159.155);
  8245. };
  8246. function defaultSeparation(a, b) {
  8247. return a.parent === b.parent ? 1 : 2;
  8248. }
  8249. function meanX(children) {
  8250. return children.reduce(meanXReduce, 0) / children.length;
  8251. }
  8252. function meanXReduce(x, c) {
  8253. return x + c.x;
  8254. }
  8255. function maxY(children) {
  8256. return 1 + children.reduce(maxYReduce, 0);
  8257. }
  8258. function maxYReduce(y, c) {
  8259. return Math.max(y, c.y);
  8260. }
  8261. function leafLeft(node) {
  8262. var children;
  8263. while (children = node.children) node = children[0];
  8264. return node;
  8265. }
  8266. function leafRight(node) {
  8267. var children;
  8268. while (children = node.children) node = children[children.length - 1];
  8269. return node;
  8270. }
  8271. var cluster = function() {
  8272. var separation = defaultSeparation,
  8273. dx = 1,
  8274. dy = 1,
  8275. nodeSize = false;
  8276. function cluster(root) {
  8277. var previousNode,
  8278. x = 0;
  8279. // First walk, computing the initial x & y values.
  8280. root.eachAfter(function(node) {
  8281. var children = node.children;
  8282. if (children) {
  8283. node.x = meanX(children);
  8284. node.y = maxY(children);
  8285. } else {
  8286. node.x = previousNode ? x += separation(node, previousNode) : 0;
  8287. node.y = 0;
  8288. previousNode = node;
  8289. }
  8290. });
  8291. var left = leafLeft(root),
  8292. right = leafRight(root),
  8293. x0 = left.x - separation(left, right) / 2,
  8294. x1 = right.x + separation(right, left) / 2;
  8295. // Second walk, normalizing x & y to the desired size.
  8296. return root.eachAfter(nodeSize ? function(node) {
  8297. node.x = (node.x - root.x) * dx;
  8298. node.y = (root.y - node.y) * dy;
  8299. } : function(node) {
  8300. node.x = (node.x - x0) / (x1 - x0) * dx;
  8301. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  8302. });
  8303. }
  8304. cluster.separation = function(x) {
  8305. return arguments.length ? (separation = x, cluster) : separation;
  8306. };
  8307. cluster.size = function(x) {
  8308. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  8309. };
  8310. cluster.nodeSize = function(x) {
  8311. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  8312. };
  8313. return cluster;
  8314. };
  8315. function count(node) {
  8316. var sum = 0,
  8317. children = node.children,
  8318. i = children && children.length;
  8319. if (!i) sum = 1;
  8320. else while (--i >= 0) sum += children[i].value;
  8321. node.value = sum;
  8322. }
  8323. var node_count = function() {
  8324. return this.eachAfter(count);
  8325. };
  8326. var node_each = function(callback) {
  8327. var node = this, current, next = [node], children, i, n;
  8328. do {
  8329. current = next.reverse(), next = [];
  8330. while (node = current.pop()) {
  8331. callback(node), children = node.children;
  8332. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8333. next.push(children[i]);
  8334. }
  8335. }
  8336. } while (next.length);
  8337. return this;
  8338. };
  8339. var node_eachBefore = function(callback) {
  8340. var node = this, nodes = [node], children, i;
  8341. while (node = nodes.pop()) {
  8342. callback(node), children = node.children;
  8343. if (children) for (i = children.length - 1; i >= 0; --i) {
  8344. nodes.push(children[i]);
  8345. }
  8346. }
  8347. return this;
  8348. };
  8349. var node_eachAfter = function(callback) {
  8350. var node = this, nodes = [node], next = [], children, i, n;
  8351. while (node = nodes.pop()) {
  8352. next.push(node), children = node.children;
  8353. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8354. nodes.push(children[i]);
  8355. }
  8356. }
  8357. while (node = next.pop()) {
  8358. callback(node);
  8359. }
  8360. return this;
  8361. };
  8362. var node_sum = function(value) {
  8363. return this.eachAfter(function(node) {
  8364. var sum = +value(node.data) || 0,
  8365. children = node.children,
  8366. i = children && children.length;
  8367. while (--i >= 0) sum += children[i].value;
  8368. node.value = sum;
  8369. });
  8370. };
  8371. var node_sort = function(compare) {
  8372. return this.eachBefore(function(node) {
  8373. if (node.children) {
  8374. node.children.sort(compare);
  8375. }
  8376. });
  8377. };
  8378. var node_path = function(end) {
  8379. var start = this,
  8380. ancestor = leastCommonAncestor(start, end),
  8381. nodes = [start];
  8382. while (start !== ancestor) {
  8383. start = start.parent;
  8384. nodes.push(start);
  8385. }
  8386. var k = nodes.length;
  8387. while (end !== ancestor) {
  8388. nodes.splice(k, 0, end);
  8389. end = end.parent;
  8390. }
  8391. return nodes;
  8392. };
  8393. function leastCommonAncestor(a, b) {
  8394. if (a === b) return a;
  8395. var aNodes = a.ancestors(),
  8396. bNodes = b.ancestors(),
  8397. c = null;
  8398. a = aNodes.pop();
  8399. b = bNodes.pop();
  8400. while (a === b) {
  8401. c = a;
  8402. a = aNodes.pop();
  8403. b = bNodes.pop();
  8404. }
  8405. return c;
  8406. }
  8407. var node_ancestors = function() {
  8408. var node = this, nodes = [node];
  8409. while (node = node.parent) {
  8410. nodes.push(node);
  8411. }
  8412. return nodes;
  8413. };
  8414. var node_descendants = function() {
  8415. var nodes = [];
  8416. this.each(function(node) {
  8417. nodes.push(node);
  8418. });
  8419. return nodes;
  8420. };
  8421. var node_leaves = function() {
  8422. var leaves = [];
  8423. this.eachBefore(function(node) {
  8424. if (!node.children) {
  8425. leaves.push(node);
  8426. }
  8427. });
  8428. return leaves;
  8429. };
  8430. var node_links = function() {
  8431. var root = this, links = [];
  8432. root.each(function(node) {
  8433. if (node !== root) { // Don’t include the root’s parent, if any.
  8434. links.push({source: node.parent, target: node});
  8435. }
  8436. });
  8437. return links;
  8438. };
  8439. function hierarchy(data, children) {
  8440. var root = new Node(data),
  8441. valued = +data.value && (root.value = data.value),
  8442. node,
  8443. nodes = [root],
  8444. child,
  8445. childs,
  8446. i,
  8447. n;
  8448. if (children == null) children = defaultChildren;
  8449. while (node = nodes.pop()) {
  8450. if (valued) node.value = +node.data.value;
  8451. if ((childs = children(node.data)) && (n = childs.length)) {
  8452. node.children = new Array(n);
  8453. for (i = n - 1; i >= 0; --i) {
  8454. nodes.push(child = node.children[i] = new Node(childs[i]));
  8455. child.parent = node;
  8456. child.depth = node.depth + 1;
  8457. }
  8458. }
  8459. }
  8460. return root.eachBefore(computeHeight);
  8461. }
  8462. function node_copy() {
  8463. return hierarchy(this).eachBefore(copyData);
  8464. }
  8465. function defaultChildren(d) {
  8466. return d.children;
  8467. }
  8468. function copyData(node) {
  8469. node.data = node.data.data;
  8470. }
  8471. function computeHeight(node) {
  8472. var height = 0;
  8473. do node.height = height;
  8474. while ((node = node.parent) && (node.height < ++height));
  8475. }
  8476. function Node(data) {
  8477. this.data = data;
  8478. this.depth =
  8479. this.height = 0;
  8480. this.parent = null;
  8481. }
  8482. Node.prototype = hierarchy.prototype = {
  8483. constructor: Node,
  8484. count: node_count,
  8485. each: node_each,
  8486. eachAfter: node_eachAfter,
  8487. eachBefore: node_eachBefore,
  8488. sum: node_sum,
  8489. sort: node_sort,
  8490. path: node_path,
  8491. ancestors: node_ancestors,
  8492. descendants: node_descendants,
  8493. leaves: node_leaves,
  8494. links: node_links,
  8495. copy: node_copy
  8496. };
  8497. var slice$3 = Array.prototype.slice;
  8498. function shuffle$1(array) {
  8499. var m = array.length,
  8500. t,
  8501. i;
  8502. while (m) {
  8503. i = Math.random() * m-- | 0;
  8504. t = array[m];
  8505. array[m] = array[i];
  8506. array[i] = t;
  8507. }
  8508. return array;
  8509. }
  8510. var enclose = function(circles) {
  8511. var i = 0, n = (circles = shuffle$1(slice$3.call(circles))).length, B = [], p, e;
  8512. while (i < n) {
  8513. p = circles[i];
  8514. if (e && enclosesWeak(e, p)) ++i;
  8515. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  8516. }
  8517. return e;
  8518. };
  8519. function extendBasis(B, p) {
  8520. var i, j;
  8521. if (enclosesWeakAll(p, B)) return [p];
  8522. // If we get here then B must have at least one element.
  8523. for (i = 0; i < B.length; ++i) {
  8524. if (enclosesNot(p, B[i])
  8525. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  8526. return [B[i], p];
  8527. }
  8528. }
  8529. // If we get here then B must have at least two elements.
  8530. for (i = 0; i < B.length - 1; ++i) {
  8531. for (j = i + 1; j < B.length; ++j) {
  8532. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  8533. && enclosesNot(encloseBasis2(B[i], p), B[j])
  8534. && enclosesNot(encloseBasis2(B[j], p), B[i])
  8535. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  8536. return [B[i], B[j], p];
  8537. }
  8538. }
  8539. }
  8540. // If we get here then something is very wrong.
  8541. throw new Error;
  8542. }
  8543. function enclosesNot(a, b) {
  8544. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  8545. return dr < 0 || dr * dr < dx * dx + dy * dy;
  8546. }
  8547. function enclosesWeak(a, b) {
  8548. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  8549. return dr > 0 && dr * dr > dx * dx + dy * dy;
  8550. }
  8551. function enclosesWeakAll(a, B) {
  8552. for (var i = 0; i < B.length; ++i) {
  8553. if (!enclosesWeak(a, B[i])) {
  8554. return false;
  8555. }
  8556. }
  8557. return true;
  8558. }
  8559. function encloseBasis(B) {
  8560. switch (B.length) {
  8561. case 1: return encloseBasis1(B[0]);
  8562. case 2: return encloseBasis2(B[0], B[1]);
  8563. case 3: return encloseBasis3(B[0], B[1], B[2]);
  8564. }
  8565. }
  8566. function encloseBasis1(a) {
  8567. return {
  8568. x: a.x,
  8569. y: a.y,
  8570. r: a.r
  8571. };
  8572. }
  8573. function encloseBasis2(a, b) {
  8574. var x1 = a.x, y1 = a.y, r1 = a.r,
  8575. x2 = b.x, y2 = b.y, r2 = b.r,
  8576. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  8577. l = Math.sqrt(x21 * x21 + y21 * y21);
  8578. return {
  8579. x: (x1 + x2 + x21 / l * r21) / 2,
  8580. y: (y1 + y2 + y21 / l * r21) / 2,
  8581. r: (l + r1 + r2) / 2
  8582. };
  8583. }
  8584. function encloseBasis3(a, b, c) {
  8585. var x1 = a.x, y1 = a.y, r1 = a.r,
  8586. x2 = b.x, y2 = b.y, r2 = b.r,
  8587. x3 = c.x, y3 = c.y, r3 = c.r,
  8588. a2 = x1 - x2,
  8589. a3 = x1 - x3,
  8590. b2 = y1 - y2,
  8591. b3 = y1 - y3,
  8592. c2 = r2 - r1,
  8593. c3 = r3 - r1,
  8594. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  8595. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  8596. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  8597. ab = a3 * b2 - a2 * b3,
  8598. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  8599. xb = (b3 * c2 - b2 * c3) / ab,
  8600. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  8601. yb = (a2 * c3 - a3 * c2) / ab,
  8602. A = xb * xb + yb * yb - 1,
  8603. B = 2 * (r1 + xa * xb + ya * yb),
  8604. C = xa * xa + ya * ya - r1 * r1,
  8605. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  8606. return {
  8607. x: x1 + xa + xb * r,
  8608. y: y1 + ya + yb * r,
  8609. r: r
  8610. };
  8611. }
  8612. function place(a, b, c) {
  8613. var ax = a.x,
  8614. ay = a.y,
  8615. da = b.r + c.r,
  8616. db = a.r + c.r,
  8617. dx = b.x - ax,
  8618. dy = b.y - ay,
  8619. dc = dx * dx + dy * dy;
  8620. if (dc) {
  8621. var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
  8622. y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  8623. c.x = ax + x * dx + y * dy;
  8624. c.y = ay + x * dy - y * dx;
  8625. } else {
  8626. c.x = ax + db;
  8627. c.y = ay;
  8628. }
  8629. }
  8630. function intersects(a, b) {
  8631. var dx = b.x - a.x,
  8632. dy = b.y - a.y,
  8633. dr = a.r + b.r;
  8634. return dr * dr - 1e-6 > dx * dx + dy * dy;
  8635. }
  8636. function score(node) {
  8637. var a = node._,
  8638. b = node.next._,
  8639. ab = a.r + b.r,
  8640. dx = (a.x * b.r + b.x * a.r) / ab,
  8641. dy = (a.y * b.r + b.y * a.r) / ab;
  8642. return dx * dx + dy * dy;
  8643. }
  8644. function Node$1(circle) {
  8645. this._ = circle;
  8646. this.next = null;
  8647. this.previous = null;
  8648. }
  8649. function packEnclose(circles) {
  8650. if (!(n = circles.length)) return 0;
  8651. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  8652. // Place the first circle.
  8653. a = circles[0], a.x = 0, a.y = 0;
  8654. if (!(n > 1)) return a.r;
  8655. // Place the second circle.
  8656. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  8657. if (!(n > 2)) return a.r + b.r;
  8658. // Place the third circle.
  8659. place(b, a, c = circles[2]);
  8660. // Initialize the front-chain using the first three circles a, b and c.
  8661. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  8662. a.next = c.previous = b;
  8663. b.next = a.previous = c;
  8664. c.next = b.previous = a;
  8665. // Attempt to place each remaining circle…
  8666. pack: for (i = 3; i < n; ++i) {
  8667. place(a._, b._, c = circles[i]), c = new Node$1(c);
  8668. // Find the closest intersecting circle on the front-chain, if any.
  8669. // “Closeness” is determined by linear distance along the front-chain.
  8670. // “Ahead” or “behind” is likewise determined by linear distance.
  8671. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  8672. do {
  8673. if (sj <= sk) {
  8674. if (intersects(j._, c._)) {
  8675. b = j, a.next = b, b.previous = a, --i;
  8676. continue pack;
  8677. }
  8678. sj += j._.r, j = j.next;
  8679. } else {
  8680. if (intersects(k._, c._)) {
  8681. a = k, a.next = b, b.previous = a, --i;
  8682. continue pack;
  8683. }
  8684. sk += k._.r, k = k.previous;
  8685. }
  8686. } while (j !== k.next);
  8687. // Success! Insert the new circle c between a and b.
  8688. c.previous = a, c.next = b, a.next = b.previous = b = c;
  8689. // Compute the new closest circle pair to the centroid.
  8690. aa = score(a);
  8691. while ((c = c.next) !== b) {
  8692. if ((ca = score(c)) < aa) {
  8693. a = c, aa = ca;
  8694. }
  8695. }
  8696. b = a.next;
  8697. }
  8698. // Compute the enclosing circle of the front chain.
  8699. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  8700. // Translate the circles to put the enclosing circle around the origin.
  8701. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  8702. return c.r;
  8703. }
  8704. var siblings = function(circles) {
  8705. packEnclose(circles);
  8706. return circles;
  8707. };
  8708. function optional(f) {
  8709. return f == null ? null : required(f);
  8710. }
  8711. function required(f) {
  8712. if (typeof f !== "function") throw new Error;
  8713. return f;
  8714. }
  8715. function constantZero() {
  8716. return 0;
  8717. }
  8718. var constant$8 = function(x) {
  8719. return function() {
  8720. return x;
  8721. };
  8722. };
  8723. function defaultRadius$1(d) {
  8724. return Math.sqrt(d.value);
  8725. }
  8726. var index$2 = function() {
  8727. var radius = null,
  8728. dx = 1,
  8729. dy = 1,
  8730. padding = constantZero;
  8731. function pack(root) {
  8732. root.x = dx / 2, root.y = dy / 2;
  8733. if (radius) {
  8734. root.eachBefore(radiusLeaf(radius))
  8735. .eachAfter(packChildren(padding, 0.5))
  8736. .eachBefore(translateChild(1));
  8737. } else {
  8738. root.eachBefore(radiusLeaf(defaultRadius$1))
  8739. .eachAfter(packChildren(constantZero, 1))
  8740. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  8741. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  8742. }
  8743. return root;
  8744. }
  8745. pack.radius = function(x) {
  8746. return arguments.length ? (radius = optional(x), pack) : radius;
  8747. };
  8748. pack.size = function(x) {
  8749. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  8750. };
  8751. pack.padding = function(x) {
  8752. return arguments.length ? (padding = typeof x === "function" ? x : constant$8(+x), pack) : padding;
  8753. };
  8754. return pack;
  8755. };
  8756. function radiusLeaf(radius) {
  8757. return function(node) {
  8758. if (!node.children) {
  8759. node.r = Math.max(0, +radius(node) || 0);
  8760. }
  8761. };
  8762. }
  8763. function packChildren(padding, k) {
  8764. return function(node) {
  8765. if (children = node.children) {
  8766. var children,
  8767. i,
  8768. n = children.length,
  8769. r = padding(node) * k || 0,
  8770. e;
  8771. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  8772. e = packEnclose(children);
  8773. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  8774. node.r = e + r;
  8775. }
  8776. };
  8777. }
  8778. function translateChild(k) {
  8779. return function(node) {
  8780. var parent = node.parent;
  8781. node.r *= k;
  8782. if (parent) {
  8783. node.x = parent.x + k * node.x;
  8784. node.y = parent.y + k * node.y;
  8785. }
  8786. };
  8787. }
  8788. var roundNode = function(node) {
  8789. node.x0 = Math.round(node.x0);
  8790. node.y0 = Math.round(node.y0);
  8791. node.x1 = Math.round(node.x1);
  8792. node.y1 = Math.round(node.y1);
  8793. };
  8794. var treemapDice = function(parent, x0, y0, x1, y1) {
  8795. var nodes = parent.children,
  8796. node,
  8797. i = -1,
  8798. n = nodes.length,
  8799. k = parent.value && (x1 - x0) / parent.value;
  8800. while (++i < n) {
  8801. node = nodes[i], node.y0 = y0, node.y1 = y1;
  8802. node.x0 = x0, node.x1 = x0 += node.value * k;
  8803. }
  8804. };
  8805. var partition = function() {
  8806. var dx = 1,
  8807. dy = 1,
  8808. padding = 0,
  8809. round = false;
  8810. function partition(root) {
  8811. var n = root.height + 1;
  8812. root.x0 =
  8813. root.y0 = padding;
  8814. root.x1 = dx;
  8815. root.y1 = dy / n;
  8816. root.eachBefore(positionNode(dy, n));
  8817. if (round) root.eachBefore(roundNode);
  8818. return root;
  8819. }
  8820. function positionNode(dy, n) {
  8821. return function(node) {
  8822. if (node.children) {
  8823. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  8824. }
  8825. var x0 = node.x0,
  8826. y0 = node.y0,
  8827. x1 = node.x1 - padding,
  8828. y1 = node.y1 - padding;
  8829. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  8830. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  8831. node.x0 = x0;
  8832. node.y0 = y0;
  8833. node.x1 = x1;
  8834. node.y1 = y1;
  8835. };
  8836. }
  8837. partition.round = function(x) {
  8838. return arguments.length ? (round = !!x, partition) : round;
  8839. };
  8840. partition.size = function(x) {
  8841. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  8842. };
  8843. partition.padding = function(x) {
  8844. return arguments.length ? (padding = +x, partition) : padding;
  8845. };
  8846. return partition;
  8847. };
  8848. var keyPrefix$1 = "$";
  8849. var preroot = {depth: -1};
  8850. var ambiguous = {};
  8851. function defaultId(d) {
  8852. return d.id;
  8853. }
  8854. function defaultParentId(d) {
  8855. return d.parentId;
  8856. }
  8857. var stratify = function() {
  8858. var id = defaultId,
  8859. parentId = defaultParentId;
  8860. function stratify(data) {
  8861. var d,
  8862. i,
  8863. n = data.length,
  8864. root,
  8865. parent,
  8866. node,
  8867. nodes = new Array(n),
  8868. nodeId,
  8869. nodeKey,
  8870. nodeByKey = {};
  8871. for (i = 0; i < n; ++i) {
  8872. d = data[i], node = nodes[i] = new Node(d);
  8873. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  8874. nodeKey = keyPrefix$1 + (node.id = nodeId);
  8875. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  8876. }
  8877. }
  8878. for (i = 0; i < n; ++i) {
  8879. node = nodes[i], nodeId = parentId(data[i], i, data);
  8880. if (nodeId == null || !(nodeId += "")) {
  8881. if (root) throw new Error("multiple roots");
  8882. root = node;
  8883. } else {
  8884. parent = nodeByKey[keyPrefix$1 + nodeId];
  8885. if (!parent) throw new Error("missing: " + nodeId);
  8886. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  8887. if (parent.children) parent.children.push(node);
  8888. else parent.children = [node];
  8889. node.parent = parent;
  8890. }
  8891. }
  8892. if (!root) throw new Error("no root");
  8893. root.parent = preroot;
  8894. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  8895. root.parent = null;
  8896. if (n > 0) throw new Error("cycle");
  8897. return root;
  8898. }
  8899. stratify.id = function(x) {
  8900. return arguments.length ? (id = required(x), stratify) : id;
  8901. };
  8902. stratify.parentId = function(x) {
  8903. return arguments.length ? (parentId = required(x), stratify) : parentId;
  8904. };
  8905. return stratify;
  8906. };
  8907. function defaultSeparation$1(a, b) {
  8908. return a.parent === b.parent ? 1 : 2;
  8909. }
  8910. // function radialSeparation(a, b) {
  8911. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  8912. // }
  8913. // This function is used to traverse the left contour of a subtree (or
  8914. // subforest). It returns the successor of v on this contour. This successor is
  8915. // either given by the leftmost child of v or by the thread of v. The function
  8916. // returns null if and only if v is on the highest level of its subtree.
  8917. function nextLeft(v) {
  8918. var children = v.children;
  8919. return children ? children[0] : v.t;
  8920. }
  8921. // This function works analogously to nextLeft.
  8922. function nextRight(v) {
  8923. var children = v.children;
  8924. return children ? children[children.length - 1] : v.t;
  8925. }
  8926. // Shifts the current subtree rooted at w+. This is done by increasing
  8927. // prelim(w+) and mod(w+) by shift.
  8928. function moveSubtree(wm, wp, shift) {
  8929. var change = shift / (wp.i - wm.i);
  8930. wp.c -= change;
  8931. wp.s += shift;
  8932. wm.c += change;
  8933. wp.z += shift;
  8934. wp.m += shift;
  8935. }
  8936. // All other shifts, applied to the smaller subtrees between w- and w+, are
  8937. // performed by this function. To prepare the shifts, we have to adjust
  8938. // change(w+), shift(w+), and change(w-).
  8939. function executeShifts(v) {
  8940. var shift = 0,
  8941. change = 0,
  8942. children = v.children,
  8943. i = children.length,
  8944. w;
  8945. while (--i >= 0) {
  8946. w = children[i];
  8947. w.z += shift;
  8948. w.m += shift;
  8949. shift += w.s + (change += w.c);
  8950. }
  8951. }
  8952. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  8953. // returns the specified (default) ancestor.
  8954. function nextAncestor(vim, v, ancestor) {
  8955. return vim.a.parent === v.parent ? vim.a : ancestor;
  8956. }
  8957. function TreeNode(node, i) {
  8958. this._ = node;
  8959. this.parent = null;
  8960. this.children = null;
  8961. this.A = null; // default ancestor
  8962. this.a = this; // ancestor
  8963. this.z = 0; // prelim
  8964. this.m = 0; // mod
  8965. this.c = 0; // change
  8966. this.s = 0; // shift
  8967. this.t = null; // thread
  8968. this.i = i; // number
  8969. }
  8970. TreeNode.prototype = Object.create(Node.prototype);
  8971. function treeRoot(root) {
  8972. var tree = new TreeNode(root, 0),
  8973. node,
  8974. nodes = [tree],
  8975. child,
  8976. children,
  8977. i,
  8978. n;
  8979. while (node = nodes.pop()) {
  8980. if (children = node._.children) {
  8981. node.children = new Array(n = children.length);
  8982. for (i = n - 1; i >= 0; --i) {
  8983. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  8984. child.parent = node;
  8985. }
  8986. }
  8987. }
  8988. (tree.parent = new TreeNode(null, 0)).children = [tree];
  8989. return tree;
  8990. }
  8991. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  8992. var tree = function() {
  8993. var separation = defaultSeparation$1,
  8994. dx = 1,
  8995. dy = 1,
  8996. nodeSize = null;
  8997. function tree(root) {
  8998. var t = treeRoot(root);
  8999. // Compute the layout using Buchheim et al.’s algorithm.
  9000. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9001. t.eachBefore(secondWalk);
  9002. // If a fixed node size is specified, scale x and y.
  9003. if (nodeSize) root.eachBefore(sizeNode);
  9004. // If a fixed tree size is specified, scale x and y based on the extent.
  9005. // Compute the left-most, right-most, and depth-most nodes for extents.
  9006. else {
  9007. var left = root,
  9008. right = root,
  9009. bottom = root;
  9010. root.eachBefore(function(node) {
  9011. if (node.x < left.x) left = node;
  9012. if (node.x > right.x) right = node;
  9013. if (node.depth > bottom.depth) bottom = node;
  9014. });
  9015. var s = left === right ? 1 : separation(left, right) / 2,
  9016. tx = s - left.x,
  9017. kx = dx / (right.x + s + tx),
  9018. ky = dy / (bottom.depth || 1);
  9019. root.eachBefore(function(node) {
  9020. node.x = (node.x + tx) * kx;
  9021. node.y = node.depth * ky;
  9022. });
  9023. }
  9024. return root;
  9025. }
  9026. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9027. // applied recursively to the children of v, as well as the function
  9028. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9029. // node v is placed to the midpoint of its outermost children.
  9030. function firstWalk(v) {
  9031. var children = v.children,
  9032. siblings = v.parent.children,
  9033. w = v.i ? siblings[v.i - 1] : null;
  9034. if (children) {
  9035. executeShifts(v);
  9036. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9037. if (w) {
  9038. v.z = w.z + separation(v._, w._);
  9039. v.m = v.z - midpoint;
  9040. } else {
  9041. v.z = midpoint;
  9042. }
  9043. } else if (w) {
  9044. v.z = w.z + separation(v._, w._);
  9045. }
  9046. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9047. }
  9048. // Computes all real x-coordinates by summing up the modifiers recursively.
  9049. function secondWalk(v) {
  9050. v._.x = v.z + v.parent.m;
  9051. v.m += v.parent.m;
  9052. }
  9053. // The core of the algorithm. Here, a new subtree is combined with the
  9054. // previous subtrees. Threads are used to traverse the inside and outside
  9055. // contours of the left and right subtree up to the highest common level. The
  9056. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9057. // superscript o means outside and i means inside, the subscript - means left
  9058. // subtree and + means right subtree. For summing up the modifiers along the
  9059. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9060. // nodes of the inside contours conflict, we compute the left one of the
  9061. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9062. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9063. // Finally, we add a new thread (if necessary).
  9064. function apportion(v, w, ancestor) {
  9065. if (w) {
  9066. var vip = v,
  9067. vop = v,
  9068. vim = w,
  9069. vom = vip.parent.children[0],
  9070. sip = vip.m,
  9071. sop = vop.m,
  9072. sim = vim.m,
  9073. som = vom.m,
  9074. shift;
  9075. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9076. vom = nextLeft(vom);
  9077. vop = nextRight(vop);
  9078. vop.a = v;
  9079. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9080. if (shift > 0) {
  9081. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9082. sip += shift;
  9083. sop += shift;
  9084. }
  9085. sim += vim.m;
  9086. sip += vip.m;
  9087. som += vom.m;
  9088. sop += vop.m;
  9089. }
  9090. if (vim && !nextRight(vop)) {
  9091. vop.t = vim;
  9092. vop.m += sim - sop;
  9093. }
  9094. if (vip && !nextLeft(vom)) {
  9095. vom.t = vip;
  9096. vom.m += sip - som;
  9097. ancestor = v;
  9098. }
  9099. }
  9100. return ancestor;
  9101. }
  9102. function sizeNode(node) {
  9103. node.x *= dx;
  9104. node.y = node.depth * dy;
  9105. }
  9106. tree.separation = function(x) {
  9107. return arguments.length ? (separation = x, tree) : separation;
  9108. };
  9109. tree.size = function(x) {
  9110. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9111. };
  9112. tree.nodeSize = function(x) {
  9113. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9114. };
  9115. return tree;
  9116. };
  9117. var treemapSlice = function(parent, x0, y0, x1, y1) {
  9118. var nodes = parent.children,
  9119. node,
  9120. i = -1,
  9121. n = nodes.length,
  9122. k = parent.value && (y1 - y0) / parent.value;
  9123. while (++i < n) {
  9124. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9125. node.y0 = y0, node.y1 = y0 += node.value * k;
  9126. }
  9127. };
  9128. var phi = (1 + Math.sqrt(5)) / 2;
  9129. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9130. var rows = [],
  9131. nodes = parent.children,
  9132. row,
  9133. nodeValue,
  9134. i0 = 0,
  9135. i1 = 0,
  9136. n = nodes.length,
  9137. dx, dy,
  9138. value = parent.value,
  9139. sumValue,
  9140. minValue,
  9141. maxValue,
  9142. newRatio,
  9143. minRatio,
  9144. alpha,
  9145. beta;
  9146. while (i0 < n) {
  9147. dx = x1 - x0, dy = y1 - y0;
  9148. // Find the next non-empty node.
  9149. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9150. minValue = maxValue = sumValue;
  9151. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9152. beta = sumValue * sumValue * alpha;
  9153. minRatio = Math.max(maxValue / beta, beta / minValue);
  9154. // Keep adding nodes while the aspect ratio maintains or improves.
  9155. for (; i1 < n; ++i1) {
  9156. sumValue += nodeValue = nodes[i1].value;
  9157. if (nodeValue < minValue) minValue = nodeValue;
  9158. if (nodeValue > maxValue) maxValue = nodeValue;
  9159. beta = sumValue * sumValue * alpha;
  9160. newRatio = Math.max(maxValue / beta, beta / minValue);
  9161. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9162. minRatio = newRatio;
  9163. }
  9164. // Position and record the row orientation.
  9165. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9166. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9167. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9168. value -= sumValue, i0 = i1;
  9169. }
  9170. return rows;
  9171. }
  9172. var squarify = (function custom(ratio) {
  9173. function squarify(parent, x0, y0, x1, y1) {
  9174. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9175. }
  9176. squarify.ratio = function(x) {
  9177. return custom((x = +x) > 1 ? x : 1);
  9178. };
  9179. return squarify;
  9180. })(phi);
  9181. var index$3 = function() {
  9182. var tile = squarify,
  9183. round = false,
  9184. dx = 1,
  9185. dy = 1,
  9186. paddingStack = [0],
  9187. paddingInner = constantZero,
  9188. paddingTop = constantZero,
  9189. paddingRight = constantZero,
  9190. paddingBottom = constantZero,
  9191. paddingLeft = constantZero;
  9192. function treemap(root) {
  9193. root.x0 =
  9194. root.y0 = 0;
  9195. root.x1 = dx;
  9196. root.y1 = dy;
  9197. root.eachBefore(positionNode);
  9198. paddingStack = [0];
  9199. if (round) root.eachBefore(roundNode);
  9200. return root;
  9201. }
  9202. function positionNode(node) {
  9203. var p = paddingStack[node.depth],
  9204. x0 = node.x0 + p,
  9205. y0 = node.y0 + p,
  9206. x1 = node.x1 - p,
  9207. y1 = node.y1 - p;
  9208. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9209. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9210. node.x0 = x0;
  9211. node.y0 = y0;
  9212. node.x1 = x1;
  9213. node.y1 = y1;
  9214. if (node.children) {
  9215. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  9216. x0 += paddingLeft(node) - p;
  9217. y0 += paddingTop(node) - p;
  9218. x1 -= paddingRight(node) - p;
  9219. y1 -= paddingBottom(node) - p;
  9220. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9221. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9222. tile(node, x0, y0, x1, y1);
  9223. }
  9224. }
  9225. treemap.round = function(x) {
  9226. return arguments.length ? (round = !!x, treemap) : round;
  9227. };
  9228. treemap.size = function(x) {
  9229. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  9230. };
  9231. treemap.tile = function(x) {
  9232. return arguments.length ? (tile = required(x), treemap) : tile;
  9233. };
  9234. treemap.padding = function(x) {
  9235. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  9236. };
  9237. treemap.paddingInner = function(x) {
  9238. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$8(+x), treemap) : paddingInner;
  9239. };
  9240. treemap.paddingOuter = function(x) {
  9241. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  9242. };
  9243. treemap.paddingTop = function(x) {
  9244. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$8(+x), treemap) : paddingTop;
  9245. };
  9246. treemap.paddingRight = function(x) {
  9247. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$8(+x), treemap) : paddingRight;
  9248. };
  9249. treemap.paddingBottom = function(x) {
  9250. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$8(+x), treemap) : paddingBottom;
  9251. };
  9252. treemap.paddingLeft = function(x) {
  9253. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$8(+x), treemap) : paddingLeft;
  9254. };
  9255. return treemap;
  9256. };
  9257. var binary = function(parent, x0, y0, x1, y1) {
  9258. var nodes = parent.children,
  9259. i, n = nodes.length,
  9260. sum, sums = new Array(n + 1);
  9261. for (sums[0] = sum = i = 0; i < n; ++i) {
  9262. sums[i + 1] = sum += nodes[i].value;
  9263. }
  9264. partition(0, n, parent.value, x0, y0, x1, y1);
  9265. function partition(i, j, value, x0, y0, x1, y1) {
  9266. if (i >= j - 1) {
  9267. var node = nodes[i];
  9268. node.x0 = x0, node.y0 = y0;
  9269. node.x1 = x1, node.y1 = y1;
  9270. return;
  9271. }
  9272. var valueOffset = sums[i],
  9273. valueTarget = (value / 2) + valueOffset,
  9274. k = i + 1,
  9275. hi = j - 1;
  9276. while (k < hi) {
  9277. var mid = k + hi >>> 1;
  9278. if (sums[mid] < valueTarget) k = mid + 1;
  9279. else hi = mid;
  9280. }
  9281. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  9282. var valueLeft = sums[k] - valueOffset,
  9283. valueRight = value - valueLeft;
  9284. if ((x1 - x0) > (y1 - y0)) {
  9285. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  9286. partition(i, k, valueLeft, x0, y0, xk, y1);
  9287. partition(k, j, valueRight, xk, y0, x1, y1);
  9288. } else {
  9289. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  9290. partition(i, k, valueLeft, x0, y0, x1, yk);
  9291. partition(k, j, valueRight, x0, yk, x1, y1);
  9292. }
  9293. }
  9294. };
  9295. var sliceDice = function(parent, x0, y0, x1, y1) {
  9296. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  9297. };
  9298. var resquarify = (function custom(ratio) {
  9299. function resquarify(parent, x0, y0, x1, y1) {
  9300. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  9301. var rows,
  9302. row,
  9303. nodes,
  9304. i,
  9305. j = -1,
  9306. n,
  9307. m = rows.length,
  9308. value = parent.value;
  9309. while (++j < m) {
  9310. row = rows[j], nodes = row.children;
  9311. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  9312. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  9313. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  9314. value -= row.value;
  9315. }
  9316. } else {
  9317. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9318. rows.ratio = ratio;
  9319. }
  9320. }
  9321. resquarify.ratio = function(x) {
  9322. return custom((x = +x) > 1 ? x : 1);
  9323. };
  9324. return resquarify;
  9325. })(phi);
  9326. var area$1 = function(polygon) {
  9327. var i = -1,
  9328. n = polygon.length,
  9329. a,
  9330. b = polygon[n - 1],
  9331. area = 0;
  9332. while (++i < n) {
  9333. a = b;
  9334. b = polygon[i];
  9335. area += a[1] * b[0] - a[0] * b[1];
  9336. }
  9337. return area / 2;
  9338. };
  9339. var centroid$1 = function(polygon) {
  9340. var i = -1,
  9341. n = polygon.length,
  9342. x = 0,
  9343. y = 0,
  9344. a,
  9345. b = polygon[n - 1],
  9346. c,
  9347. k = 0;
  9348. while (++i < n) {
  9349. a = b;
  9350. b = polygon[i];
  9351. k += c = a[0] * b[1] - b[0] * a[1];
  9352. x += (a[0] + b[0]) * c;
  9353. y += (a[1] + b[1]) * c;
  9354. }
  9355. return k *= 3, [x / k, y / k];
  9356. };
  9357. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  9358. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  9359. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  9360. // negative if clockwise, and zero if the points are collinear.
  9361. var cross$1 = function(a, b, c) {
  9362. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  9363. };
  9364. function lexicographicOrder(a, b) {
  9365. return a[0] - b[0] || a[1] - b[1];
  9366. }
  9367. // Computes the upper convex hull per the monotone chain algorithm.
  9368. // Assumes points.length >= 3, is sorted by x, unique in y.
  9369. // Returns an array of indices into points in left-to-right order.
  9370. function computeUpperHullIndexes(points) {
  9371. var n = points.length,
  9372. indexes = [0, 1],
  9373. size = 2;
  9374. for (var i = 2; i < n; ++i) {
  9375. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  9376. indexes[size++] = i;
  9377. }
  9378. return indexes.slice(0, size); // remove popped points
  9379. }
  9380. var hull = function(points) {
  9381. if ((n = points.length) < 3) return null;
  9382. var i,
  9383. n,
  9384. sortedPoints = new Array(n),
  9385. flippedPoints = new Array(n);
  9386. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  9387. sortedPoints.sort(lexicographicOrder);
  9388. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  9389. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  9390. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  9391. // Construct the hull polygon, removing possible duplicate endpoints.
  9392. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  9393. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  9394. hull = [];
  9395. // Add upper hull in right-to-l order.
  9396. // Then add lower hull in left-to-right order.
  9397. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  9398. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  9399. return hull;
  9400. };
  9401. var contains$1 = function(polygon, point) {
  9402. var n = polygon.length,
  9403. p = polygon[n - 1],
  9404. x = point[0], y = point[1],
  9405. x0 = p[0], y0 = p[1],
  9406. x1, y1,
  9407. inside = false;
  9408. for (var i = 0; i < n; ++i) {
  9409. p = polygon[i], x1 = p[0], y1 = p[1];
  9410. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  9411. x0 = x1, y0 = y1;
  9412. }
  9413. return inside;
  9414. };
  9415. var length$2 = function(polygon) {
  9416. var i = -1,
  9417. n = polygon.length,
  9418. b = polygon[n - 1],
  9419. xa,
  9420. ya,
  9421. xb = b[0],
  9422. yb = b[1],
  9423. perimeter = 0;
  9424. while (++i < n) {
  9425. xa = xb;
  9426. ya = yb;
  9427. b = polygon[i];
  9428. xb = b[0];
  9429. yb = b[1];
  9430. xa -= xb;
  9431. ya -= yb;
  9432. perimeter += Math.sqrt(xa * xa + ya * ya);
  9433. }
  9434. return perimeter;
  9435. };
  9436. var slice$4 = [].slice;
  9437. var noabort = {};
  9438. function Queue(size) {
  9439. this._size = size;
  9440. this._call =
  9441. this._error = null;
  9442. this._tasks = [];
  9443. this._data = [];
  9444. this._waiting =
  9445. this._active =
  9446. this._ended =
  9447. this._start = 0; // inside a synchronous task callback?
  9448. }
  9449. Queue.prototype = queue.prototype = {
  9450. constructor: Queue,
  9451. defer: function(callback) {
  9452. if (typeof callback !== "function") throw new Error("invalid callback");
  9453. if (this._call) throw new Error("defer after await");
  9454. if (this._error != null) return this;
  9455. var t = slice$4.call(arguments, 1);
  9456. t.push(callback);
  9457. ++this._waiting, this._tasks.push(t);
  9458. poke$1(this);
  9459. return this;
  9460. },
  9461. abort: function() {
  9462. if (this._error == null) abort(this, new Error("abort"));
  9463. return this;
  9464. },
  9465. await: function(callback) {
  9466. if (typeof callback !== "function") throw new Error("invalid callback");
  9467. if (this._call) throw new Error("multiple await");
  9468. this._call = function(error, results) { callback.apply(null, [error].concat(results)); };
  9469. maybeNotify(this);
  9470. return this;
  9471. },
  9472. awaitAll: function(callback) {
  9473. if (typeof callback !== "function") throw new Error("invalid callback");
  9474. if (this._call) throw new Error("multiple await");
  9475. this._call = callback;
  9476. maybeNotify(this);
  9477. return this;
  9478. }
  9479. };
  9480. function poke$1(q) {
  9481. if (!q._start) {
  9482. try { start$1(q); } // let the current task complete
  9483. catch (e) {
  9484. if (q._tasks[q._ended + q._active - 1]) abort(q, e); // task errored synchronously
  9485. else if (!q._data) throw e; // await callback errored synchronously
  9486. }
  9487. }
  9488. }
  9489. function start$1(q) {
  9490. while (q._start = q._waiting && q._active < q._size) {
  9491. var i = q._ended + q._active,
  9492. t = q._tasks[i],
  9493. j = t.length - 1,
  9494. c = t[j];
  9495. t[j] = end(q, i);
  9496. --q._waiting, ++q._active;
  9497. t = c.apply(null, t);
  9498. if (!q._tasks[i]) continue; // task finished synchronously
  9499. q._tasks[i] = t || noabort;
  9500. }
  9501. }
  9502. function end(q, i) {
  9503. return function(e, r) {
  9504. if (!q._tasks[i]) return; // ignore multiple callbacks
  9505. --q._active, ++q._ended;
  9506. q._tasks[i] = null;
  9507. if (q._error != null) return; // ignore secondary errors
  9508. if (e != null) {
  9509. abort(q, e);
  9510. } else {
  9511. q._data[i] = r;
  9512. if (q._waiting) poke$1(q);
  9513. else maybeNotify(q);
  9514. }
  9515. };
  9516. }
  9517. function abort(q, e) {
  9518. var i = q._tasks.length, t;
  9519. q._error = e; // ignore active callbacks
  9520. q._data = undefined; // allow gc
  9521. q._waiting = NaN; // prevent starting
  9522. while (--i >= 0) {
  9523. if (t = q._tasks[i]) {
  9524. q._tasks[i] = null;
  9525. if (t.abort) {
  9526. try { t.abort(); }
  9527. catch (e) { /* ignore */ }
  9528. }
  9529. }
  9530. }
  9531. q._active = NaN; // allow notification
  9532. maybeNotify(q);
  9533. }
  9534. function maybeNotify(q) {
  9535. if (!q._active && q._call) {
  9536. var d = q._data;
  9537. q._data = undefined; // allow gc
  9538. q._call(q._error, d);
  9539. }
  9540. }
  9541. function queue(concurrency) {
  9542. if (concurrency == null) concurrency = Infinity;
  9543. else if (!((concurrency = +concurrency) >= 1)) throw new Error("invalid concurrency");
  9544. return new Queue(concurrency);
  9545. }
  9546. var defaultSource$1 = function() {
  9547. return Math.random();
  9548. };
  9549. var uniform = (function sourceRandomUniform(source) {
  9550. function randomUniform(min, max) {
  9551. min = min == null ? 0 : +min;
  9552. max = max == null ? 1 : +max;
  9553. if (arguments.length === 1) max = min, min = 0;
  9554. else max -= min;
  9555. return function() {
  9556. return source() * max + min;
  9557. };
  9558. }
  9559. randomUniform.source = sourceRandomUniform;
  9560. return randomUniform;
  9561. })(defaultSource$1);
  9562. var normal = (function sourceRandomNormal(source) {
  9563. function randomNormal(mu, sigma) {
  9564. var x, r;
  9565. mu = mu == null ? 0 : +mu;
  9566. sigma = sigma == null ? 1 : +sigma;
  9567. return function() {
  9568. var y;
  9569. // If available, use the second previously-generated uniform random.
  9570. if (x != null) y = x, x = null;
  9571. // Otherwise, generate a new x and y.
  9572. else do {
  9573. x = source() * 2 - 1;
  9574. y = source() * 2 - 1;
  9575. r = x * x + y * y;
  9576. } while (!r || r > 1);
  9577. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  9578. };
  9579. }
  9580. randomNormal.source = sourceRandomNormal;
  9581. return randomNormal;
  9582. })(defaultSource$1);
  9583. var logNormal = (function sourceRandomLogNormal(source) {
  9584. function randomLogNormal() {
  9585. var randomNormal = normal.source(source).apply(this, arguments);
  9586. return function() {
  9587. return Math.exp(randomNormal());
  9588. };
  9589. }
  9590. randomLogNormal.source = sourceRandomLogNormal;
  9591. return randomLogNormal;
  9592. })(defaultSource$1);
  9593. var irwinHall = (function sourceRandomIrwinHall(source) {
  9594. function randomIrwinHall(n) {
  9595. return function() {
  9596. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  9597. return sum;
  9598. };
  9599. }
  9600. randomIrwinHall.source = sourceRandomIrwinHall;
  9601. return randomIrwinHall;
  9602. })(defaultSource$1);
  9603. var bates = (function sourceRandomBates(source) {
  9604. function randomBates(n) {
  9605. var randomIrwinHall = irwinHall.source(source)(n);
  9606. return function() {
  9607. return randomIrwinHall() / n;
  9608. };
  9609. }
  9610. randomBates.source = sourceRandomBates;
  9611. return randomBates;
  9612. })(defaultSource$1);
  9613. var exponential$1 = (function sourceRandomExponential(source) {
  9614. function randomExponential(lambda) {
  9615. return function() {
  9616. return -Math.log(1 - source()) / lambda;
  9617. };
  9618. }
  9619. randomExponential.source = sourceRandomExponential;
  9620. return randomExponential;
  9621. })(defaultSource$1);
  9622. var request = function(url, callback) {
  9623. var request,
  9624. event = dispatch("beforesend", "progress", "load", "error"),
  9625. mimeType,
  9626. headers = map$1(),
  9627. xhr = new XMLHttpRequest,
  9628. user = null,
  9629. password = null,
  9630. response,
  9631. responseType,
  9632. timeout = 0;
  9633. // If IE does not support CORS, use XDomainRequest.
  9634. if (typeof XDomainRequest !== "undefined"
  9635. && !("withCredentials" in xhr)
  9636. && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
  9637. "onload" in xhr
  9638. ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
  9639. : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
  9640. function respond(o) {
  9641. var status = xhr.status, result;
  9642. if (!status && hasResponse(xhr)
  9643. || status >= 200 && status < 300
  9644. || status === 304) {
  9645. if (response) {
  9646. try {
  9647. result = response.call(request, xhr);
  9648. } catch (e) {
  9649. event.call("error", request, e);
  9650. return;
  9651. }
  9652. } else {
  9653. result = xhr;
  9654. }
  9655. event.call("load", request, result);
  9656. } else {
  9657. event.call("error", request, o);
  9658. }
  9659. }
  9660. xhr.onprogress = function(e) {
  9661. event.call("progress", request, e);
  9662. };
  9663. request = {
  9664. header: function(name, value) {
  9665. name = (name + "").toLowerCase();
  9666. if (arguments.length < 2) return headers.get(name);
  9667. if (value == null) headers.remove(name);
  9668. else headers.set(name, value + "");
  9669. return request;
  9670. },
  9671. // If mimeType is non-null and no Accept header is set, a default is used.
  9672. mimeType: function(value) {
  9673. if (!arguments.length) return mimeType;
  9674. mimeType = value == null ? null : value + "";
  9675. return request;
  9676. },
  9677. // Specifies what type the response value should take;
  9678. // for instance, arraybuffer, blob, document, or text.
  9679. responseType: function(value) {
  9680. if (!arguments.length) return responseType;
  9681. responseType = value;
  9682. return request;
  9683. },
  9684. timeout: function(value) {
  9685. if (!arguments.length) return timeout;
  9686. timeout = +value;
  9687. return request;
  9688. },
  9689. user: function(value) {
  9690. return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
  9691. },
  9692. password: function(value) {
  9693. return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
  9694. },
  9695. // Specify how to convert the response content to a specific type;
  9696. // changes the callback value on "load" events.
  9697. response: function(value) {
  9698. response = value;
  9699. return request;
  9700. },
  9701. // Alias for send("GET", …).
  9702. get: function(data, callback) {
  9703. return request.send("GET", data, callback);
  9704. },
  9705. // Alias for send("POST", …).
  9706. post: function(data, callback) {
  9707. return request.send("POST", data, callback);
  9708. },
  9709. // If callback is non-null, it will be used for error and load events.
  9710. send: function(method, data, callback) {
  9711. xhr.open(method, url, true, user, password);
  9712. if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
  9713. if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
  9714. if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
  9715. if (responseType != null) xhr.responseType = responseType;
  9716. if (timeout > 0) xhr.timeout = timeout;
  9717. if (callback == null && typeof data === "function") callback = data, data = null;
  9718. if (callback != null && callback.length === 1) callback = fixCallback(callback);
  9719. if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
  9720. event.call("beforesend", request, xhr);
  9721. xhr.send(data == null ? null : data);
  9722. return request;
  9723. },
  9724. abort: function() {
  9725. xhr.abort();
  9726. return request;
  9727. },
  9728. on: function() {
  9729. var value = event.on.apply(event, arguments);
  9730. return value === event ? request : value;
  9731. }
  9732. };
  9733. if (callback != null) {
  9734. if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
  9735. return request.get(callback);
  9736. }
  9737. return request;
  9738. };
  9739. function fixCallback(callback) {
  9740. return function(error, xhr) {
  9741. callback(error == null ? xhr : null);
  9742. };
  9743. }
  9744. function hasResponse(xhr) {
  9745. var type = xhr.responseType;
  9746. return type && type !== "text"
  9747. ? xhr.response // null on error
  9748. : xhr.responseText; // "" on error
  9749. }
  9750. var type$1 = function(defaultMimeType, response) {
  9751. return function(url, callback) {
  9752. var r = request(url).mimeType(defaultMimeType).response(response);
  9753. if (callback != null) {
  9754. if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
  9755. return r.get(callback);
  9756. }
  9757. return r;
  9758. };
  9759. };
  9760. var html = type$1("text/html", function(xhr) {
  9761. return document.createRange().createContextualFragment(xhr.responseText);
  9762. });
  9763. var json = type$1("application/json", function(xhr) {
  9764. return JSON.parse(xhr.responseText);
  9765. });
  9766. var text = type$1("text/plain", function(xhr) {
  9767. return xhr.responseText;
  9768. });
  9769. var xml = type$1("application/xml", function(xhr) {
  9770. var xml = xhr.responseXML;
  9771. if (!xml) throw new Error("parse error");
  9772. return xml;
  9773. });
  9774. var dsv$1 = function(defaultMimeType, parse) {
  9775. return function(url, row, callback) {
  9776. if (arguments.length < 3) callback = row, row = null;
  9777. var r = request(url).mimeType(defaultMimeType);
  9778. r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
  9779. r.row(row);
  9780. return callback ? r.get(callback) : r;
  9781. };
  9782. };
  9783. function responseOf(parse, row) {
  9784. return function(request$$1) {
  9785. return parse(request$$1.responseText, row);
  9786. };
  9787. }
  9788. var csv$1 = dsv$1("text/csv", csvParse);
  9789. var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
  9790. var array$2 = Array.prototype;
  9791. var map$3 = array$2.map;
  9792. var slice$5 = array$2.slice;
  9793. var implicit = {name: "implicit"};
  9794. function ordinal(range) {
  9795. var index = map$1(),
  9796. domain = [],
  9797. unknown = implicit;
  9798. range = range == null ? [] : slice$5.call(range);
  9799. function scale(d) {
  9800. var key = d + "", i = index.get(key);
  9801. if (!i) {
  9802. if (unknown !== implicit) return unknown;
  9803. index.set(key, i = domain.push(d));
  9804. }
  9805. return range[(i - 1) % range.length];
  9806. }
  9807. scale.domain = function(_) {
  9808. if (!arguments.length) return domain.slice();
  9809. domain = [], index = map$1();
  9810. var i = -1, n = _.length, d, key;
  9811. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  9812. return scale;
  9813. };
  9814. scale.range = function(_) {
  9815. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  9816. };
  9817. scale.unknown = function(_) {
  9818. return arguments.length ? (unknown = _, scale) : unknown;
  9819. };
  9820. scale.copy = function() {
  9821. return ordinal()
  9822. .domain(domain)
  9823. .range(range)
  9824. .unknown(unknown);
  9825. };
  9826. return scale;
  9827. }
  9828. function band() {
  9829. var scale = ordinal().unknown(undefined),
  9830. domain = scale.domain,
  9831. ordinalRange = scale.range,
  9832. range$$1 = [0, 1],
  9833. step,
  9834. bandwidth,
  9835. round = false,
  9836. paddingInner = 0,
  9837. paddingOuter = 0,
  9838. align = 0.5;
  9839. delete scale.unknown;
  9840. function rescale() {
  9841. var n = domain().length,
  9842. reverse = range$$1[1] < range$$1[0],
  9843. start = range$$1[reverse - 0],
  9844. stop = range$$1[1 - reverse];
  9845. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  9846. if (round) step = Math.floor(step);
  9847. start += (stop - start - step * (n - paddingInner)) * align;
  9848. bandwidth = step * (1 - paddingInner);
  9849. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  9850. var values = sequence(n).map(function(i) { return start + step * i; });
  9851. return ordinalRange(reverse ? values.reverse() : values);
  9852. }
  9853. scale.domain = function(_) {
  9854. return arguments.length ? (domain(_), rescale()) : domain();
  9855. };
  9856. scale.range = function(_) {
  9857. return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
  9858. };
  9859. scale.rangeRound = function(_) {
  9860. return range$$1 = [+_[0], +_[1]], round = true, rescale();
  9861. };
  9862. scale.bandwidth = function() {
  9863. return bandwidth;
  9864. };
  9865. scale.step = function() {
  9866. return step;
  9867. };
  9868. scale.round = function(_) {
  9869. return arguments.length ? (round = !!_, rescale()) : round;
  9870. };
  9871. scale.padding = function(_) {
  9872. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  9873. };
  9874. scale.paddingInner = function(_) {
  9875. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  9876. };
  9877. scale.paddingOuter = function(_) {
  9878. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  9879. };
  9880. scale.align = function(_) {
  9881. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  9882. };
  9883. scale.copy = function() {
  9884. return band()
  9885. .domain(domain())
  9886. .range(range$$1)
  9887. .round(round)
  9888. .paddingInner(paddingInner)
  9889. .paddingOuter(paddingOuter)
  9890. .align(align);
  9891. };
  9892. return rescale();
  9893. }
  9894. function pointish(scale) {
  9895. var copy = scale.copy;
  9896. scale.padding = scale.paddingOuter;
  9897. delete scale.paddingInner;
  9898. delete scale.paddingOuter;
  9899. scale.copy = function() {
  9900. return pointish(copy());
  9901. };
  9902. return scale;
  9903. }
  9904. function point$1() {
  9905. return pointish(band().paddingInner(1));
  9906. }
  9907. var constant$9 = function(x) {
  9908. return function() {
  9909. return x;
  9910. };
  9911. };
  9912. var number$2 = function(x) {
  9913. return +x;
  9914. };
  9915. var unit = [0, 1];
  9916. function deinterpolateLinear(a, b) {
  9917. return (b -= (a = +a))
  9918. ? function(x) { return (x - a) / b; }
  9919. : constant$9(b);
  9920. }
  9921. function deinterpolateClamp(deinterpolate) {
  9922. return function(a, b) {
  9923. var d = deinterpolate(a = +a, b = +b);
  9924. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  9925. };
  9926. }
  9927. function reinterpolateClamp(reinterpolate) {
  9928. return function(a, b) {
  9929. var r = reinterpolate(a = +a, b = +b);
  9930. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  9931. };
  9932. }
  9933. function bimap(domain, range, deinterpolate, reinterpolate) {
  9934. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  9935. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
  9936. else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
  9937. return function(x) { return r0(d0(x)); };
  9938. }
  9939. function polymap(domain, range, deinterpolate, reinterpolate) {
  9940. var j = Math.min(domain.length, range.length) - 1,
  9941. d = new Array(j),
  9942. r = new Array(j),
  9943. i = -1;
  9944. // Reverse descending domains.
  9945. if (domain[j] < domain[0]) {
  9946. domain = domain.slice().reverse();
  9947. range = range.slice().reverse();
  9948. }
  9949. while (++i < j) {
  9950. d[i] = deinterpolate(domain[i], domain[i + 1]);
  9951. r[i] = reinterpolate(range[i], range[i + 1]);
  9952. }
  9953. return function(x) {
  9954. var i = bisectRight(domain, x, 1, j) - 1;
  9955. return r[i](d[i](x));
  9956. };
  9957. }
  9958. function copy(source, target) {
  9959. return target
  9960. .domain(source.domain())
  9961. .range(source.range())
  9962. .interpolate(source.interpolate())
  9963. .clamp(source.clamp());
  9964. }
  9965. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  9966. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  9967. function continuous(deinterpolate, reinterpolate) {
  9968. var domain = unit,
  9969. range = unit,
  9970. interpolate$$1 = interpolateValue,
  9971. clamp = false,
  9972. piecewise,
  9973. output,
  9974. input;
  9975. function rescale() {
  9976. piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  9977. output = input = null;
  9978. return scale;
  9979. }
  9980. function scale(x) {
  9981. return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  9982. }
  9983. scale.invert = function(y) {
  9984. return (input || (input = piecewise(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
  9985. };
  9986. scale.domain = function(_) {
  9987. return arguments.length ? (domain = map$3.call(_, number$2), rescale()) : domain.slice();
  9988. };
  9989. scale.range = function(_) {
  9990. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  9991. };
  9992. scale.rangeRound = function(_) {
  9993. return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
  9994. };
  9995. scale.clamp = function(_) {
  9996. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  9997. };
  9998. scale.interpolate = function(_) {
  9999. return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
  10000. };
  10001. return rescale();
  10002. }
  10003. var tickFormat = function(domain, count, specifier) {
  10004. var start = domain[0],
  10005. stop = domain[domain.length - 1],
  10006. step = tickStep(start, stop, count == null ? 10 : count),
  10007. precision;
  10008. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10009. switch (specifier.type) {
  10010. case "s": {
  10011. var value = Math.max(Math.abs(start), Math.abs(stop));
  10012. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10013. return exports.formatPrefix(specifier, value);
  10014. }
  10015. case "":
  10016. case "e":
  10017. case "g":
  10018. case "p":
  10019. case "r": {
  10020. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10021. break;
  10022. }
  10023. case "f":
  10024. case "%": {
  10025. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10026. break;
  10027. }
  10028. }
  10029. return exports.format(specifier);
  10030. };
  10031. function linearish(scale) {
  10032. var domain = scale.domain;
  10033. scale.ticks = function(count) {
  10034. var d = domain();
  10035. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10036. };
  10037. scale.tickFormat = function(count, specifier) {
  10038. return tickFormat(domain(), count, specifier);
  10039. };
  10040. scale.nice = function(count) {
  10041. if (count == null) count = 10;
  10042. var d = domain(),
  10043. i0 = 0,
  10044. i1 = d.length - 1,
  10045. start = d[i0],
  10046. stop = d[i1],
  10047. step;
  10048. if (stop < start) {
  10049. step = start, start = stop, stop = step;
  10050. step = i0, i0 = i1, i1 = step;
  10051. }
  10052. step = tickIncrement(start, stop, count);
  10053. if (step > 0) {
  10054. start = Math.floor(start / step) * step;
  10055. stop = Math.ceil(stop / step) * step;
  10056. step = tickIncrement(start, stop, count);
  10057. } else if (step < 0) {
  10058. start = Math.ceil(start * step) / step;
  10059. stop = Math.floor(stop * step) / step;
  10060. step = tickIncrement(start, stop, count);
  10061. }
  10062. if (step > 0) {
  10063. d[i0] = Math.floor(start / step) * step;
  10064. d[i1] = Math.ceil(stop / step) * step;
  10065. domain(d);
  10066. } else if (step < 0) {
  10067. d[i0] = Math.ceil(start * step) / step;
  10068. d[i1] = Math.floor(stop * step) / step;
  10069. domain(d);
  10070. }
  10071. return scale;
  10072. };
  10073. return scale;
  10074. }
  10075. function linear$2() {
  10076. var scale = continuous(deinterpolateLinear, reinterpolate);
  10077. scale.copy = function() {
  10078. return copy(scale, linear$2());
  10079. };
  10080. return linearish(scale);
  10081. }
  10082. function identity$6() {
  10083. var domain = [0, 1];
  10084. function scale(x) {
  10085. return +x;
  10086. }
  10087. scale.invert = scale;
  10088. scale.domain = scale.range = function(_) {
  10089. return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
  10090. };
  10091. scale.copy = function() {
  10092. return identity$6().domain(domain);
  10093. };
  10094. return linearish(scale);
  10095. }
  10096. var nice = function(domain, interval) {
  10097. domain = domain.slice();
  10098. var i0 = 0,
  10099. i1 = domain.length - 1,
  10100. x0 = domain[i0],
  10101. x1 = domain[i1],
  10102. t;
  10103. if (x1 < x0) {
  10104. t = i0, i0 = i1, i1 = t;
  10105. t = x0, x0 = x1, x1 = t;
  10106. }
  10107. domain[i0] = interval.floor(x0);
  10108. domain[i1] = interval.ceil(x1);
  10109. return domain;
  10110. };
  10111. function deinterpolate(a, b) {
  10112. return (b = Math.log(b / a))
  10113. ? function(x) { return Math.log(x / a) / b; }
  10114. : constant$9(b);
  10115. }
  10116. function reinterpolate$1(a, b) {
  10117. return a < 0
  10118. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  10119. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  10120. }
  10121. function pow10(x) {
  10122. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10123. }
  10124. function powp(base) {
  10125. return base === 10 ? pow10
  10126. : base === Math.E ? Math.exp
  10127. : function(x) { return Math.pow(base, x); };
  10128. }
  10129. function logp(base) {
  10130. return base === Math.E ? Math.log
  10131. : base === 10 && Math.log10
  10132. || base === 2 && Math.log2
  10133. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10134. }
  10135. function reflect(f) {
  10136. return function(x) {
  10137. return -f(-x);
  10138. };
  10139. }
  10140. function log$1() {
  10141. var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
  10142. domain = scale.domain,
  10143. base = 10,
  10144. logs = logp(10),
  10145. pows = powp(10);
  10146. function rescale() {
  10147. logs = logp(base), pows = powp(base);
  10148. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  10149. return scale;
  10150. }
  10151. scale.base = function(_) {
  10152. return arguments.length ? (base = +_, rescale()) : base;
  10153. };
  10154. scale.domain = function(_) {
  10155. return arguments.length ? (domain(_), rescale()) : domain();
  10156. };
  10157. scale.ticks = function(count) {
  10158. var d = domain(),
  10159. u = d[0],
  10160. v = d[d.length - 1],
  10161. r;
  10162. if (r = v < u) i = u, u = v, v = i;
  10163. var i = logs(u),
  10164. j = logs(v),
  10165. p,
  10166. k,
  10167. t,
  10168. n = count == null ? 10 : +count,
  10169. z = [];
  10170. if (!(base % 1) && j - i < n) {
  10171. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10172. if (u > 0) for (; i < j; ++i) {
  10173. for (k = 1, p = pows(i); k < base; ++k) {
  10174. t = p * k;
  10175. if (t < u) continue;
  10176. if (t > v) break;
  10177. z.push(t);
  10178. }
  10179. } else for (; i < j; ++i) {
  10180. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10181. t = p * k;
  10182. if (t < u) continue;
  10183. if (t > v) break;
  10184. z.push(t);
  10185. }
  10186. }
  10187. } else {
  10188. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10189. }
  10190. return r ? z.reverse() : z;
  10191. };
  10192. scale.tickFormat = function(count, specifier) {
  10193. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10194. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10195. if (count === Infinity) return specifier;
  10196. if (count == null) count = 10;
  10197. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10198. return function(d) {
  10199. var i = d / pows(Math.round(logs(d)));
  10200. if (i * base < base - 0.5) i *= base;
  10201. return i <= k ? specifier(d) : "";
  10202. };
  10203. };
  10204. scale.nice = function() {
  10205. return domain(nice(domain(), {
  10206. floor: function(x) { return pows(Math.floor(logs(x))); },
  10207. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10208. }));
  10209. };
  10210. scale.copy = function() {
  10211. return copy(scale, log$1().base(base));
  10212. };
  10213. return scale;
  10214. }
  10215. function raise$1(x, exponent) {
  10216. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10217. }
  10218. function pow$1() {
  10219. var exponent = 1,
  10220. scale = continuous(deinterpolate, reinterpolate),
  10221. domain = scale.domain;
  10222. function deinterpolate(a, b) {
  10223. return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
  10224. ? function(x) { return (raise$1(x, exponent) - a) / b; }
  10225. : constant$9(b);
  10226. }
  10227. function reinterpolate(a, b) {
  10228. b = raise$1(b, exponent) - (a = raise$1(a, exponent));
  10229. return function(t) { return raise$1(a + b * t, 1 / exponent); };
  10230. }
  10231. scale.exponent = function(_) {
  10232. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  10233. };
  10234. scale.copy = function() {
  10235. return copy(scale, pow$1().exponent(exponent));
  10236. };
  10237. return linearish(scale);
  10238. }
  10239. function sqrt$1() {
  10240. return pow$1().exponent(0.5);
  10241. }
  10242. function quantile$$1() {
  10243. var domain = [],
  10244. range = [],
  10245. thresholds = [];
  10246. function rescale() {
  10247. var i = 0, n = Math.max(1, range.length);
  10248. thresholds = new Array(n - 1);
  10249. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10250. return scale;
  10251. }
  10252. function scale(x) {
  10253. if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
  10254. }
  10255. scale.invertExtent = function(y) {
  10256. var i = range.indexOf(y);
  10257. return i < 0 ? [NaN, NaN] : [
  10258. i > 0 ? thresholds[i - 1] : domain[0],
  10259. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10260. ];
  10261. };
  10262. scale.domain = function(_) {
  10263. if (!arguments.length) return domain.slice();
  10264. domain = [];
  10265. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10266. domain.sort(ascending);
  10267. return rescale();
  10268. };
  10269. scale.range = function(_) {
  10270. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10271. };
  10272. scale.quantiles = function() {
  10273. return thresholds.slice();
  10274. };
  10275. scale.copy = function() {
  10276. return quantile$$1()
  10277. .domain(domain)
  10278. .range(range);
  10279. };
  10280. return scale;
  10281. }
  10282. function quantize$1() {
  10283. var x0 = 0,
  10284. x1 = 1,
  10285. n = 1,
  10286. domain = [0.5],
  10287. range = [0, 1];
  10288. function scale(x) {
  10289. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10290. }
  10291. function rescale() {
  10292. var i = -1;
  10293. domain = new Array(n);
  10294. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10295. return scale;
  10296. }
  10297. scale.domain = function(_) {
  10298. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10299. };
  10300. scale.range = function(_) {
  10301. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10302. };
  10303. scale.invertExtent = function(y) {
  10304. var i = range.indexOf(y);
  10305. return i < 0 ? [NaN, NaN]
  10306. : i < 1 ? [x0, domain[0]]
  10307. : i >= n ? [domain[n - 1], x1]
  10308. : [domain[i - 1], domain[i]];
  10309. };
  10310. scale.copy = function() {
  10311. return quantize$1()
  10312. .domain([x0, x1])
  10313. .range(range);
  10314. };
  10315. return linearish(scale);
  10316. }
  10317. function threshold$1() {
  10318. var domain = [0.5],
  10319. range = [0, 1],
  10320. n = 1;
  10321. function scale(x) {
  10322. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10323. }
  10324. scale.domain = function(_) {
  10325. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10326. };
  10327. scale.range = function(_) {
  10328. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10329. };
  10330. scale.invertExtent = function(y) {
  10331. var i = range.indexOf(y);
  10332. return [domain[i - 1], domain[i]];
  10333. };
  10334. scale.copy = function() {
  10335. return threshold$1()
  10336. .domain(domain)
  10337. .range(range);
  10338. };
  10339. return scale;
  10340. }
  10341. var t0$1 = new Date;
  10342. var t1$1 = new Date;
  10343. function newInterval(floori, offseti, count, field) {
  10344. function interval(date) {
  10345. return floori(date = new Date(+date)), date;
  10346. }
  10347. interval.floor = interval;
  10348. interval.ceil = function(date) {
  10349. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10350. };
  10351. interval.round = function(date) {
  10352. var d0 = interval(date),
  10353. d1 = interval.ceil(date);
  10354. return date - d0 < d1 - date ? d0 : d1;
  10355. };
  10356. interval.offset = function(date, step) {
  10357. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10358. };
  10359. interval.range = function(start, stop, step) {
  10360. var range = [];
  10361. start = interval.ceil(start);
  10362. step = step == null ? 1 : Math.floor(step);
  10363. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10364. do range.push(new Date(+start)); while (offseti(start, step), floori(start), start < stop)
  10365. return range;
  10366. };
  10367. interval.filter = function(test) {
  10368. return newInterval(function(date) {
  10369. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10370. }, function(date, step) {
  10371. if (date >= date) {
  10372. if (step < 0) while (++step <= 0) {
  10373. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10374. } else while (--step >= 0) {
  10375. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10376. }
  10377. }
  10378. });
  10379. };
  10380. if (count) {
  10381. interval.count = function(start, end) {
  10382. t0$1.setTime(+start), t1$1.setTime(+end);
  10383. floori(t0$1), floori(t1$1);
  10384. return Math.floor(count(t0$1, t1$1));
  10385. };
  10386. interval.every = function(step) {
  10387. step = Math.floor(step);
  10388. return !isFinite(step) || !(step > 0) ? null
  10389. : !(step > 1) ? interval
  10390. : interval.filter(field
  10391. ? function(d) { return field(d) % step === 0; }
  10392. : function(d) { return interval.count(0, d) % step === 0; });
  10393. };
  10394. }
  10395. return interval;
  10396. }
  10397. var millisecond = newInterval(function() {
  10398. // noop
  10399. }, function(date, step) {
  10400. date.setTime(+date + step);
  10401. }, function(start, end) {
  10402. return end - start;
  10403. });
  10404. // An optimized implementation for this simple case.
  10405. millisecond.every = function(k) {
  10406. k = Math.floor(k);
  10407. if (!isFinite(k) || !(k > 0)) return null;
  10408. if (!(k > 1)) return millisecond;
  10409. return newInterval(function(date) {
  10410. date.setTime(Math.floor(date / k) * k);
  10411. }, function(date, step) {
  10412. date.setTime(+date + step * k);
  10413. }, function(start, end) {
  10414. return (end - start) / k;
  10415. });
  10416. };
  10417. var milliseconds = millisecond.range;
  10418. var durationSecond$1 = 1e3;
  10419. var durationMinute$1 = 6e4;
  10420. var durationHour$1 = 36e5;
  10421. var durationDay$1 = 864e5;
  10422. var durationWeek$1 = 6048e5;
  10423. var second = newInterval(function(date) {
  10424. date.setTime(Math.floor(date / durationSecond$1) * durationSecond$1);
  10425. }, function(date, step) {
  10426. date.setTime(+date + step * durationSecond$1);
  10427. }, function(start, end) {
  10428. return (end - start) / durationSecond$1;
  10429. }, function(date) {
  10430. return date.getUTCSeconds();
  10431. });
  10432. var seconds = second.range;
  10433. var minute = newInterval(function(date) {
  10434. date.setTime(Math.floor(date / durationMinute$1) * durationMinute$1);
  10435. }, function(date, step) {
  10436. date.setTime(+date + step * durationMinute$1);
  10437. }, function(start, end) {
  10438. return (end - start) / durationMinute$1;
  10439. }, function(date) {
  10440. return date.getMinutes();
  10441. });
  10442. var minutes = minute.range;
  10443. var hour = newInterval(function(date) {
  10444. var offset = date.getTimezoneOffset() * durationMinute$1 % durationHour$1;
  10445. if (offset < 0) offset += durationHour$1;
  10446. date.setTime(Math.floor((+date - offset) / durationHour$1) * durationHour$1 + offset);
  10447. }, function(date, step) {
  10448. date.setTime(+date + step * durationHour$1);
  10449. }, function(start, end) {
  10450. return (end - start) / durationHour$1;
  10451. }, function(date) {
  10452. return date.getHours();
  10453. });
  10454. var hours = hour.range;
  10455. var day = newInterval(function(date) {
  10456. date.setHours(0, 0, 0, 0);
  10457. }, function(date, step) {
  10458. date.setDate(date.getDate() + step);
  10459. }, function(start, end) {
  10460. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationDay$1;
  10461. }, function(date) {
  10462. return date.getDate() - 1;
  10463. });
  10464. var days = day.range;
  10465. function weekday(i) {
  10466. return newInterval(function(date) {
  10467. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  10468. date.setHours(0, 0, 0, 0);
  10469. }, function(date, step) {
  10470. date.setDate(date.getDate() + step * 7);
  10471. }, function(start, end) {
  10472. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationWeek$1;
  10473. });
  10474. }
  10475. var sunday = weekday(0);
  10476. var monday = weekday(1);
  10477. var tuesday = weekday(2);
  10478. var wednesday = weekday(3);
  10479. var thursday = weekday(4);
  10480. var friday = weekday(5);
  10481. var saturday = weekday(6);
  10482. var sundays = sunday.range;
  10483. var mondays = monday.range;
  10484. var tuesdays = tuesday.range;
  10485. var wednesdays = wednesday.range;
  10486. var thursdays = thursday.range;
  10487. var fridays = friday.range;
  10488. var saturdays = saturday.range;
  10489. var month = newInterval(function(date) {
  10490. date.setDate(1);
  10491. date.setHours(0, 0, 0, 0);
  10492. }, function(date, step) {
  10493. date.setMonth(date.getMonth() + step);
  10494. }, function(start, end) {
  10495. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  10496. }, function(date) {
  10497. return date.getMonth();
  10498. });
  10499. var months = month.range;
  10500. var year = newInterval(function(date) {
  10501. date.setMonth(0, 1);
  10502. date.setHours(0, 0, 0, 0);
  10503. }, function(date, step) {
  10504. date.setFullYear(date.getFullYear() + step);
  10505. }, function(start, end) {
  10506. return end.getFullYear() - start.getFullYear();
  10507. }, function(date) {
  10508. return date.getFullYear();
  10509. });
  10510. // An optimized implementation for this simple case.
  10511. year.every = function(k) {
  10512. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10513. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  10514. date.setMonth(0, 1);
  10515. date.setHours(0, 0, 0, 0);
  10516. }, function(date, step) {
  10517. date.setFullYear(date.getFullYear() + step * k);
  10518. });
  10519. };
  10520. var years = year.range;
  10521. var utcMinute = newInterval(function(date) {
  10522. date.setUTCSeconds(0, 0);
  10523. }, function(date, step) {
  10524. date.setTime(+date + step * durationMinute$1);
  10525. }, function(start, end) {
  10526. return (end - start) / durationMinute$1;
  10527. }, function(date) {
  10528. return date.getUTCMinutes();
  10529. });
  10530. var utcMinutes = utcMinute.range;
  10531. var utcHour = newInterval(function(date) {
  10532. date.setUTCMinutes(0, 0, 0);
  10533. }, function(date, step) {
  10534. date.setTime(+date + step * durationHour$1);
  10535. }, function(start, end) {
  10536. return (end - start) / durationHour$1;
  10537. }, function(date) {
  10538. return date.getUTCHours();
  10539. });
  10540. var utcHours = utcHour.range;
  10541. var utcDay = newInterval(function(date) {
  10542. date.setUTCHours(0, 0, 0, 0);
  10543. }, function(date, step) {
  10544. date.setUTCDate(date.getUTCDate() + step);
  10545. }, function(start, end) {
  10546. return (end - start) / durationDay$1;
  10547. }, function(date) {
  10548. return date.getUTCDate() - 1;
  10549. });
  10550. var utcDays = utcDay.range;
  10551. function utcWeekday(i) {
  10552. return newInterval(function(date) {
  10553. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  10554. date.setUTCHours(0, 0, 0, 0);
  10555. }, function(date, step) {
  10556. date.setUTCDate(date.getUTCDate() + step * 7);
  10557. }, function(start, end) {
  10558. return (end - start) / durationWeek$1;
  10559. });
  10560. }
  10561. var utcSunday = utcWeekday(0);
  10562. var utcMonday = utcWeekday(1);
  10563. var utcTuesday = utcWeekday(2);
  10564. var utcWednesday = utcWeekday(3);
  10565. var utcThursday = utcWeekday(4);
  10566. var utcFriday = utcWeekday(5);
  10567. var utcSaturday = utcWeekday(6);
  10568. var utcSundays = utcSunday.range;
  10569. var utcMondays = utcMonday.range;
  10570. var utcTuesdays = utcTuesday.range;
  10571. var utcWednesdays = utcWednesday.range;
  10572. var utcThursdays = utcThursday.range;
  10573. var utcFridays = utcFriday.range;
  10574. var utcSaturdays = utcSaturday.range;
  10575. var utcMonth = newInterval(function(date) {
  10576. date.setUTCDate(1);
  10577. date.setUTCHours(0, 0, 0, 0);
  10578. }, function(date, step) {
  10579. date.setUTCMonth(date.getUTCMonth() + step);
  10580. }, function(start, end) {
  10581. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  10582. }, function(date) {
  10583. return date.getUTCMonth();
  10584. });
  10585. var utcMonths = utcMonth.range;
  10586. var utcYear = newInterval(function(date) {
  10587. date.setUTCMonth(0, 1);
  10588. date.setUTCHours(0, 0, 0, 0);
  10589. }, function(date, step) {
  10590. date.setUTCFullYear(date.getUTCFullYear() + step);
  10591. }, function(start, end) {
  10592. return end.getUTCFullYear() - start.getUTCFullYear();
  10593. }, function(date) {
  10594. return date.getUTCFullYear();
  10595. });
  10596. // An optimized implementation for this simple case.
  10597. utcYear.every = function(k) {
  10598. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10599. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  10600. date.setUTCMonth(0, 1);
  10601. date.setUTCHours(0, 0, 0, 0);
  10602. }, function(date, step) {
  10603. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  10604. });
  10605. };
  10606. var utcYears = utcYear.range;
  10607. function localDate(d) {
  10608. if (0 <= d.y && d.y < 100) {
  10609. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  10610. date.setFullYear(d.y);
  10611. return date;
  10612. }
  10613. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  10614. }
  10615. function utcDate(d) {
  10616. if (0 <= d.y && d.y < 100) {
  10617. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  10618. date.setUTCFullYear(d.y);
  10619. return date;
  10620. }
  10621. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  10622. }
  10623. function newYear(y) {
  10624. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  10625. }
  10626. function formatLocale$1(locale) {
  10627. var locale_dateTime = locale.dateTime,
  10628. locale_date = locale.date,
  10629. locale_time = locale.time,
  10630. locale_periods = locale.periods,
  10631. locale_weekdays = locale.days,
  10632. locale_shortWeekdays = locale.shortDays,
  10633. locale_months = locale.months,
  10634. locale_shortMonths = locale.shortMonths;
  10635. var periodRe = formatRe(locale_periods),
  10636. periodLookup = formatLookup(locale_periods),
  10637. weekdayRe = formatRe(locale_weekdays),
  10638. weekdayLookup = formatLookup(locale_weekdays),
  10639. shortWeekdayRe = formatRe(locale_shortWeekdays),
  10640. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  10641. monthRe = formatRe(locale_months),
  10642. monthLookup = formatLookup(locale_months),
  10643. shortMonthRe = formatRe(locale_shortMonths),
  10644. shortMonthLookup = formatLookup(locale_shortMonths);
  10645. var formats = {
  10646. "a": formatShortWeekday,
  10647. "A": formatWeekday,
  10648. "b": formatShortMonth,
  10649. "B": formatMonth,
  10650. "c": null,
  10651. "d": formatDayOfMonth,
  10652. "e": formatDayOfMonth,
  10653. "H": formatHour24,
  10654. "I": formatHour12,
  10655. "j": formatDayOfYear,
  10656. "L": formatMilliseconds,
  10657. "m": formatMonthNumber,
  10658. "M": formatMinutes,
  10659. "p": formatPeriod,
  10660. "S": formatSeconds,
  10661. "U": formatWeekNumberSunday,
  10662. "w": formatWeekdayNumber,
  10663. "W": formatWeekNumberMonday,
  10664. "x": null,
  10665. "X": null,
  10666. "y": formatYear,
  10667. "Y": formatFullYear,
  10668. "Z": formatZone,
  10669. "%": formatLiteralPercent
  10670. };
  10671. var utcFormats = {
  10672. "a": formatUTCShortWeekday,
  10673. "A": formatUTCWeekday,
  10674. "b": formatUTCShortMonth,
  10675. "B": formatUTCMonth,
  10676. "c": null,
  10677. "d": formatUTCDayOfMonth,
  10678. "e": formatUTCDayOfMonth,
  10679. "H": formatUTCHour24,
  10680. "I": formatUTCHour12,
  10681. "j": formatUTCDayOfYear,
  10682. "L": formatUTCMilliseconds,
  10683. "m": formatUTCMonthNumber,
  10684. "M": formatUTCMinutes,
  10685. "p": formatUTCPeriod,
  10686. "S": formatUTCSeconds,
  10687. "U": formatUTCWeekNumberSunday,
  10688. "w": formatUTCWeekdayNumber,
  10689. "W": formatUTCWeekNumberMonday,
  10690. "x": null,
  10691. "X": null,
  10692. "y": formatUTCYear,
  10693. "Y": formatUTCFullYear,
  10694. "Z": formatUTCZone,
  10695. "%": formatLiteralPercent
  10696. };
  10697. var parses = {
  10698. "a": parseShortWeekday,
  10699. "A": parseWeekday,
  10700. "b": parseShortMonth,
  10701. "B": parseMonth,
  10702. "c": parseLocaleDateTime,
  10703. "d": parseDayOfMonth,
  10704. "e": parseDayOfMonth,
  10705. "H": parseHour24,
  10706. "I": parseHour24,
  10707. "j": parseDayOfYear,
  10708. "L": parseMilliseconds,
  10709. "m": parseMonthNumber,
  10710. "M": parseMinutes,
  10711. "p": parsePeriod,
  10712. "S": parseSeconds,
  10713. "U": parseWeekNumberSunday,
  10714. "w": parseWeekdayNumber,
  10715. "W": parseWeekNumberMonday,
  10716. "x": parseLocaleDate,
  10717. "X": parseLocaleTime,
  10718. "y": parseYear,
  10719. "Y": parseFullYear,
  10720. "Z": parseZone,
  10721. "%": parseLiteralPercent
  10722. };
  10723. // These recursive directive definitions must be deferred.
  10724. formats.x = newFormat(locale_date, formats);
  10725. formats.X = newFormat(locale_time, formats);
  10726. formats.c = newFormat(locale_dateTime, formats);
  10727. utcFormats.x = newFormat(locale_date, utcFormats);
  10728. utcFormats.X = newFormat(locale_time, utcFormats);
  10729. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  10730. function newFormat(specifier, formats) {
  10731. return function(date) {
  10732. var string = [],
  10733. i = -1,
  10734. j = 0,
  10735. n = specifier.length,
  10736. c,
  10737. pad,
  10738. format;
  10739. if (!(date instanceof Date)) date = new Date(+date);
  10740. while (++i < n) {
  10741. if (specifier.charCodeAt(i) === 37) {
  10742. string.push(specifier.slice(j, i));
  10743. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  10744. else pad = c === "e" ? " " : "0";
  10745. if (format = formats[c]) c = format(date, pad);
  10746. string.push(c);
  10747. j = i + 1;
  10748. }
  10749. }
  10750. string.push(specifier.slice(j, i));
  10751. return string.join("");
  10752. };
  10753. }
  10754. function newParse(specifier, newDate) {
  10755. return function(string) {
  10756. var d = newYear(1900),
  10757. i = parseSpecifier(d, specifier, string += "", 0);
  10758. if (i != string.length) return null;
  10759. // The am-pm flag is 0 for AM, and 1 for PM.
  10760. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  10761. // Convert day-of-week and week-of-year to day-of-year.
  10762. if ("W" in d || "U" in d) {
  10763. if (!("w" in d)) d.w = "W" in d ? 1 : 0;
  10764. var day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  10765. d.m = 0;
  10766. 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;
  10767. }
  10768. // If a time zone is specified, all fields are interpreted as UTC and then
  10769. // offset according to the specified time zone.
  10770. if ("Z" in d) {
  10771. d.H += d.Z / 100 | 0;
  10772. d.M += d.Z % 100;
  10773. return utcDate(d);
  10774. }
  10775. // Otherwise, all fields are in local time.
  10776. return newDate(d);
  10777. };
  10778. }
  10779. function parseSpecifier(d, specifier, string, j) {
  10780. var i = 0,
  10781. n = specifier.length,
  10782. m = string.length,
  10783. c,
  10784. parse;
  10785. while (i < n) {
  10786. if (j >= m) return -1;
  10787. c = specifier.charCodeAt(i++);
  10788. if (c === 37) {
  10789. c = specifier.charAt(i++);
  10790. parse = parses[c in pads ? specifier.charAt(i++) : c];
  10791. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  10792. } else if (c != string.charCodeAt(j++)) {
  10793. return -1;
  10794. }
  10795. }
  10796. return j;
  10797. }
  10798. function parsePeriod(d, string, i) {
  10799. var n = periodRe.exec(string.slice(i));
  10800. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10801. }
  10802. function parseShortWeekday(d, string, i) {
  10803. var n = shortWeekdayRe.exec(string.slice(i));
  10804. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10805. }
  10806. function parseWeekday(d, string, i) {
  10807. var n = weekdayRe.exec(string.slice(i));
  10808. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10809. }
  10810. function parseShortMonth(d, string, i) {
  10811. var n = shortMonthRe.exec(string.slice(i));
  10812. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10813. }
  10814. function parseMonth(d, string, i) {
  10815. var n = monthRe.exec(string.slice(i));
  10816. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10817. }
  10818. function parseLocaleDateTime(d, string, i) {
  10819. return parseSpecifier(d, locale_dateTime, string, i);
  10820. }
  10821. function parseLocaleDate(d, string, i) {
  10822. return parseSpecifier(d, locale_date, string, i);
  10823. }
  10824. function parseLocaleTime(d, string, i) {
  10825. return parseSpecifier(d, locale_time, string, i);
  10826. }
  10827. function formatShortWeekday(d) {
  10828. return locale_shortWeekdays[d.getDay()];
  10829. }
  10830. function formatWeekday(d) {
  10831. return locale_weekdays[d.getDay()];
  10832. }
  10833. function formatShortMonth(d) {
  10834. return locale_shortMonths[d.getMonth()];
  10835. }
  10836. function formatMonth(d) {
  10837. return locale_months[d.getMonth()];
  10838. }
  10839. function formatPeriod(d) {
  10840. return locale_periods[+(d.getHours() >= 12)];
  10841. }
  10842. function formatUTCShortWeekday(d) {
  10843. return locale_shortWeekdays[d.getUTCDay()];
  10844. }
  10845. function formatUTCWeekday(d) {
  10846. return locale_weekdays[d.getUTCDay()];
  10847. }
  10848. function formatUTCShortMonth(d) {
  10849. return locale_shortMonths[d.getUTCMonth()];
  10850. }
  10851. function formatUTCMonth(d) {
  10852. return locale_months[d.getUTCMonth()];
  10853. }
  10854. function formatUTCPeriod(d) {
  10855. return locale_periods[+(d.getUTCHours() >= 12)];
  10856. }
  10857. return {
  10858. format: function(specifier) {
  10859. var f = newFormat(specifier += "", formats);
  10860. f.toString = function() { return specifier; };
  10861. return f;
  10862. },
  10863. parse: function(specifier) {
  10864. var p = newParse(specifier += "", localDate);
  10865. p.toString = function() { return specifier; };
  10866. return p;
  10867. },
  10868. utcFormat: function(specifier) {
  10869. var f = newFormat(specifier += "", utcFormats);
  10870. f.toString = function() { return specifier; };
  10871. return f;
  10872. },
  10873. utcParse: function(specifier) {
  10874. var p = newParse(specifier, utcDate);
  10875. p.toString = function() { return specifier; };
  10876. return p;
  10877. }
  10878. };
  10879. }
  10880. var pads = {"-": "", "_": " ", "0": "0"};
  10881. var numberRe = /^\s*\d+/;
  10882. var percentRe = /^%/;
  10883. var requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  10884. function pad(value, fill, width) {
  10885. var sign = value < 0 ? "-" : "",
  10886. string = (sign ? -value : value) + "",
  10887. length = string.length;
  10888. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  10889. }
  10890. function requote(s) {
  10891. return s.replace(requoteRe, "\\$&");
  10892. }
  10893. function formatRe(names) {
  10894. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  10895. }
  10896. function formatLookup(names) {
  10897. var map = {}, i = -1, n = names.length;
  10898. while (++i < n) map[names[i].toLowerCase()] = i;
  10899. return map;
  10900. }
  10901. function parseWeekdayNumber(d, string, i) {
  10902. var n = numberRe.exec(string.slice(i, i + 1));
  10903. return n ? (d.w = +n[0], i + n[0].length) : -1;
  10904. }
  10905. function parseWeekNumberSunday(d, string, i) {
  10906. var n = numberRe.exec(string.slice(i));
  10907. return n ? (d.U = +n[0], i + n[0].length) : -1;
  10908. }
  10909. function parseWeekNumberMonday(d, string, i) {
  10910. var n = numberRe.exec(string.slice(i));
  10911. return n ? (d.W = +n[0], i + n[0].length) : -1;
  10912. }
  10913. function parseFullYear(d, string, i) {
  10914. var n = numberRe.exec(string.slice(i, i + 4));
  10915. return n ? (d.y = +n[0], i + n[0].length) : -1;
  10916. }
  10917. function parseYear(d, string, i) {
  10918. var n = numberRe.exec(string.slice(i, i + 2));
  10919. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  10920. }
  10921. function parseZone(d, string, i) {
  10922. var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6));
  10923. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  10924. }
  10925. function parseMonthNumber(d, string, i) {
  10926. var n = numberRe.exec(string.slice(i, i + 2));
  10927. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  10928. }
  10929. function parseDayOfMonth(d, string, i) {
  10930. var n = numberRe.exec(string.slice(i, i + 2));
  10931. return n ? (d.d = +n[0], i + n[0].length) : -1;
  10932. }
  10933. function parseDayOfYear(d, string, i) {
  10934. var n = numberRe.exec(string.slice(i, i + 3));
  10935. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  10936. }
  10937. function parseHour24(d, string, i) {
  10938. var n = numberRe.exec(string.slice(i, i + 2));
  10939. return n ? (d.H = +n[0], i + n[0].length) : -1;
  10940. }
  10941. function parseMinutes(d, string, i) {
  10942. var n = numberRe.exec(string.slice(i, i + 2));
  10943. return n ? (d.M = +n[0], i + n[0].length) : -1;
  10944. }
  10945. function parseSeconds(d, string, i) {
  10946. var n = numberRe.exec(string.slice(i, i + 2));
  10947. return n ? (d.S = +n[0], i + n[0].length) : -1;
  10948. }
  10949. function parseMilliseconds(d, string, i) {
  10950. var n = numberRe.exec(string.slice(i, i + 3));
  10951. return n ? (d.L = +n[0], i + n[0].length) : -1;
  10952. }
  10953. function parseLiteralPercent(d, string, i) {
  10954. var n = percentRe.exec(string.slice(i, i + 1));
  10955. return n ? i + n[0].length : -1;
  10956. }
  10957. function formatDayOfMonth(d, p) {
  10958. return pad(d.getDate(), p, 2);
  10959. }
  10960. function formatHour24(d, p) {
  10961. return pad(d.getHours(), p, 2);
  10962. }
  10963. function formatHour12(d, p) {
  10964. return pad(d.getHours() % 12 || 12, p, 2);
  10965. }
  10966. function formatDayOfYear(d, p) {
  10967. return pad(1 + day.count(year(d), d), p, 3);
  10968. }
  10969. function formatMilliseconds(d, p) {
  10970. return pad(d.getMilliseconds(), p, 3);
  10971. }
  10972. function formatMonthNumber(d, p) {
  10973. return pad(d.getMonth() + 1, p, 2);
  10974. }
  10975. function formatMinutes(d, p) {
  10976. return pad(d.getMinutes(), p, 2);
  10977. }
  10978. function formatSeconds(d, p) {
  10979. return pad(d.getSeconds(), p, 2);
  10980. }
  10981. function formatWeekNumberSunday(d, p) {
  10982. return pad(sunday.count(year(d), d), p, 2);
  10983. }
  10984. function formatWeekdayNumber(d) {
  10985. return d.getDay();
  10986. }
  10987. function formatWeekNumberMonday(d, p) {
  10988. return pad(monday.count(year(d), d), p, 2);
  10989. }
  10990. function formatYear(d, p) {
  10991. return pad(d.getFullYear() % 100, p, 2);
  10992. }
  10993. function formatFullYear(d, p) {
  10994. return pad(d.getFullYear() % 10000, p, 4);
  10995. }
  10996. function formatZone(d) {
  10997. var z = d.getTimezoneOffset();
  10998. return (z > 0 ? "-" : (z *= -1, "+"))
  10999. + pad(z / 60 | 0, "0", 2)
  11000. + pad(z % 60, "0", 2);
  11001. }
  11002. function formatUTCDayOfMonth(d, p) {
  11003. return pad(d.getUTCDate(), p, 2);
  11004. }
  11005. function formatUTCHour24(d, p) {
  11006. return pad(d.getUTCHours(), p, 2);
  11007. }
  11008. function formatUTCHour12(d, p) {
  11009. return pad(d.getUTCHours() % 12 || 12, p, 2);
  11010. }
  11011. function formatUTCDayOfYear(d, p) {
  11012. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  11013. }
  11014. function formatUTCMilliseconds(d, p) {
  11015. return pad(d.getUTCMilliseconds(), p, 3);
  11016. }
  11017. function formatUTCMonthNumber(d, p) {
  11018. return pad(d.getUTCMonth() + 1, p, 2);
  11019. }
  11020. function formatUTCMinutes(d, p) {
  11021. return pad(d.getUTCMinutes(), p, 2);
  11022. }
  11023. function formatUTCSeconds(d, p) {
  11024. return pad(d.getUTCSeconds(), p, 2);
  11025. }
  11026. function formatUTCWeekNumberSunday(d, p) {
  11027. return pad(utcSunday.count(utcYear(d), d), p, 2);
  11028. }
  11029. function formatUTCWeekdayNumber(d) {
  11030. return d.getUTCDay();
  11031. }
  11032. function formatUTCWeekNumberMonday(d, p) {
  11033. return pad(utcMonday.count(utcYear(d), d), p, 2);
  11034. }
  11035. function formatUTCYear(d, p) {
  11036. return pad(d.getUTCFullYear() % 100, p, 2);
  11037. }
  11038. function formatUTCFullYear(d, p) {
  11039. return pad(d.getUTCFullYear() % 10000, p, 4);
  11040. }
  11041. function formatUTCZone() {
  11042. return "+0000";
  11043. }
  11044. function formatLiteralPercent() {
  11045. return "%";
  11046. }
  11047. var locale$1;
  11048. defaultLocale$1({
  11049. dateTime: "%x, %X",
  11050. date: "%-m/%-d/%Y",
  11051. time: "%-I:%M:%S %p",
  11052. periods: ["AM", "PM"],
  11053. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11054. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11055. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11056. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11057. });
  11058. function defaultLocale$1(definition) {
  11059. locale$1 = formatLocale$1(definition);
  11060. exports.timeFormat = locale$1.format;
  11061. exports.timeParse = locale$1.parse;
  11062. exports.utcFormat = locale$1.utcFormat;
  11063. exports.utcParse = locale$1.utcParse;
  11064. return locale$1;
  11065. }
  11066. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11067. function formatIsoNative(date) {
  11068. return date.toISOString();
  11069. }
  11070. var formatIso = Date.prototype.toISOString
  11071. ? formatIsoNative
  11072. : exports.utcFormat(isoSpecifier);
  11073. function parseIsoNative(string) {
  11074. var date = new Date(string);
  11075. return isNaN(date) ? null : date;
  11076. }
  11077. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11078. ? parseIsoNative
  11079. : exports.utcParse(isoSpecifier);
  11080. var durationSecond = 1000;
  11081. var durationMinute = durationSecond * 60;
  11082. var durationHour = durationMinute * 60;
  11083. var durationDay = durationHour * 24;
  11084. var durationWeek = durationDay * 7;
  11085. var durationMonth = durationDay * 30;
  11086. var durationYear = durationDay * 365;
  11087. function date$1(t) {
  11088. return new Date(t);
  11089. }
  11090. function number$3(t) {
  11091. return t instanceof Date ? +t : +new Date(+t);
  11092. }
  11093. function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
  11094. var scale = continuous(deinterpolateLinear, reinterpolate),
  11095. invert = scale.invert,
  11096. domain = scale.domain;
  11097. var formatMillisecond = format(".%L"),
  11098. formatSecond = format(":%S"),
  11099. formatMinute = format("%I:%M"),
  11100. formatHour = format("%I %p"),
  11101. formatDay = format("%a %d"),
  11102. formatWeek = format("%b %d"),
  11103. formatMonth = format("%B"),
  11104. formatYear = format("%Y");
  11105. var tickIntervals = [
  11106. [second$$1, 1, durationSecond],
  11107. [second$$1, 5, 5 * durationSecond],
  11108. [second$$1, 15, 15 * durationSecond],
  11109. [second$$1, 30, 30 * durationSecond],
  11110. [minute$$1, 1, durationMinute],
  11111. [minute$$1, 5, 5 * durationMinute],
  11112. [minute$$1, 15, 15 * durationMinute],
  11113. [minute$$1, 30, 30 * durationMinute],
  11114. [ hour$$1, 1, durationHour ],
  11115. [ hour$$1, 3, 3 * durationHour ],
  11116. [ hour$$1, 6, 6 * durationHour ],
  11117. [ hour$$1, 12, 12 * durationHour ],
  11118. [ day$$1, 1, durationDay ],
  11119. [ day$$1, 2, 2 * durationDay ],
  11120. [ week, 1, durationWeek ],
  11121. [ month$$1, 1, durationMonth ],
  11122. [ month$$1, 3, 3 * durationMonth ],
  11123. [ year$$1, 1, durationYear ]
  11124. ];
  11125. function tickFormat(date) {
  11126. return (second$$1(date) < date ? formatMillisecond
  11127. : minute$$1(date) < date ? formatSecond
  11128. : hour$$1(date) < date ? formatMinute
  11129. : day$$1(date) < date ? formatHour
  11130. : month$$1(date) < date ? (week(date) < date ? formatDay : formatWeek)
  11131. : year$$1(date) < date ? formatMonth
  11132. : formatYear)(date);
  11133. }
  11134. function tickInterval(interval, start, stop, step) {
  11135. if (interval == null) interval = 10;
  11136. // If a desired tick count is specified, pick a reasonable tick interval
  11137. // based on the extent of the domain and a rough estimate of tick size.
  11138. // Otherwise, assume interval is already a time interval and use it.
  11139. if (typeof interval === "number") {
  11140. var target = Math.abs(stop - start) / interval,
  11141. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11142. if (i === tickIntervals.length) {
  11143. step = tickStep(start / durationYear, stop / durationYear, interval);
  11144. interval = year$$1;
  11145. } else if (i) {
  11146. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11147. step = i[1];
  11148. interval = i[0];
  11149. } else {
  11150. step = tickStep(start, stop, interval);
  11151. interval = millisecond$$1;
  11152. }
  11153. }
  11154. return step == null ? interval : interval.every(step);
  11155. }
  11156. scale.invert = function(y) {
  11157. return new Date(invert(y));
  11158. };
  11159. scale.domain = function(_) {
  11160. return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
  11161. };
  11162. scale.ticks = function(interval, step) {
  11163. var d = domain(),
  11164. t0 = d[0],
  11165. t1 = d[d.length - 1],
  11166. r = t1 < t0,
  11167. t;
  11168. if (r) t = t0, t0 = t1, t1 = t;
  11169. t = tickInterval(interval, t0, t1, step);
  11170. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11171. return r ? t.reverse() : t;
  11172. };
  11173. scale.tickFormat = function(count, specifier) {
  11174. return specifier == null ? tickFormat : format(specifier);
  11175. };
  11176. scale.nice = function(interval, step) {
  11177. var d = domain();
  11178. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11179. ? domain(nice(d, interval))
  11180. : scale;
  11181. };
  11182. scale.copy = function() {
  11183. return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
  11184. };
  11185. return scale;
  11186. }
  11187. var time = function() {
  11188. return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  11189. };
  11190. var utcTime = function() {
  11191. return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  11192. };
  11193. var colors = function(s) {
  11194. return s.match(/.{6}/g).map(function(x) {
  11195. return "#" + x;
  11196. });
  11197. };
  11198. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  11199. var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
  11200. var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
  11201. var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
  11202. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  11203. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11204. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11205. var rainbow = cubehelix();
  11206. var rainbow$1 = function(t) {
  11207. if (t < 0 || t > 1) t -= Math.floor(t);
  11208. var ts = Math.abs(t - 0.5);
  11209. rainbow.h = 360 * t - 100;
  11210. rainbow.s = 1.5 - 1.5 * ts;
  11211. rainbow.l = 0.8 - 0.9 * ts;
  11212. return rainbow + "";
  11213. };
  11214. function ramp(range) {
  11215. var n = range.length;
  11216. return function(t) {
  11217. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  11218. };
  11219. }
  11220. var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  11221. var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  11222. var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  11223. var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  11224. function sequential(interpolator) {
  11225. var x0 = 0,
  11226. x1 = 1,
  11227. clamp = false;
  11228. function scale(x) {
  11229. var t = (x - x0) / (x1 - x0);
  11230. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11231. }
  11232. scale.domain = function(_) {
  11233. return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
  11234. };
  11235. scale.clamp = function(_) {
  11236. return arguments.length ? (clamp = !!_, scale) : clamp;
  11237. };
  11238. scale.interpolator = function(_) {
  11239. return arguments.length ? (interpolator = _, scale) : interpolator;
  11240. };
  11241. scale.copy = function() {
  11242. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  11243. };
  11244. return linearish(scale);
  11245. }
  11246. var constant$10 = function(x) {
  11247. return function constant() {
  11248. return x;
  11249. };
  11250. };
  11251. var abs$1 = Math.abs;
  11252. var atan2$1 = Math.atan2;
  11253. var cos$2 = Math.cos;
  11254. var max$2 = Math.max;
  11255. var min$1 = Math.min;
  11256. var sin$2 = Math.sin;
  11257. var sqrt$2 = Math.sqrt;
  11258. var epsilon$3 = 1e-12;
  11259. var pi$4 = Math.PI;
  11260. var halfPi$3 = pi$4 / 2;
  11261. var tau$4 = 2 * pi$4;
  11262. function acos$1(x) {
  11263. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  11264. }
  11265. function asin$1(x) {
  11266. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  11267. }
  11268. function arcInnerRadius(d) {
  11269. return d.innerRadius;
  11270. }
  11271. function arcOuterRadius(d) {
  11272. return d.outerRadius;
  11273. }
  11274. function arcStartAngle(d) {
  11275. return d.startAngle;
  11276. }
  11277. function arcEndAngle(d) {
  11278. return d.endAngle;
  11279. }
  11280. function arcPadAngle(d) {
  11281. return d && d.padAngle; // Note: optional!
  11282. }
  11283. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  11284. var x10 = x1 - x0, y10 = y1 - y0,
  11285. x32 = x3 - x2, y32 = y3 - y2,
  11286. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  11287. return [x0 + t * x10, y0 + t * y10];
  11288. }
  11289. // Compute perpendicular offset line of length rc.
  11290. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  11291. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  11292. var x01 = x0 - x1,
  11293. y01 = y0 - y1,
  11294. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  11295. ox = lo * y01,
  11296. oy = -lo * x01,
  11297. x11 = x0 + ox,
  11298. y11 = y0 + oy,
  11299. x10 = x1 + ox,
  11300. y10 = y1 + oy,
  11301. x00 = (x11 + x10) / 2,
  11302. y00 = (y11 + y10) / 2,
  11303. dx = x10 - x11,
  11304. dy = y10 - y11,
  11305. d2 = dx * dx + dy * dy,
  11306. r = r1 - rc,
  11307. D = x11 * y10 - x10 * y11,
  11308. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  11309. cx0 = (D * dy - dx * d) / d2,
  11310. cy0 = (-D * dx - dy * d) / d2,
  11311. cx1 = (D * dy + dx * d) / d2,
  11312. cy1 = (-D * dx + dy * d) / d2,
  11313. dx0 = cx0 - x00,
  11314. dy0 = cy0 - y00,
  11315. dx1 = cx1 - x00,
  11316. dy1 = cy1 - y00;
  11317. // Pick the closer of the two intersection points.
  11318. // TODO Is there a faster way to determine which intersection to use?
  11319. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  11320. return {
  11321. cx: cx0,
  11322. cy: cy0,
  11323. x01: -ox,
  11324. y01: -oy,
  11325. x11: cx0 * (r1 / r - 1),
  11326. y11: cy0 * (r1 / r - 1)
  11327. };
  11328. }
  11329. var arc = function() {
  11330. var innerRadius = arcInnerRadius,
  11331. outerRadius = arcOuterRadius,
  11332. cornerRadius = constant$10(0),
  11333. padRadius = null,
  11334. startAngle = arcStartAngle,
  11335. endAngle = arcEndAngle,
  11336. padAngle = arcPadAngle,
  11337. context = null;
  11338. function arc() {
  11339. var buffer,
  11340. r,
  11341. r0 = +innerRadius.apply(this, arguments),
  11342. r1 = +outerRadius.apply(this, arguments),
  11343. a0 = startAngle.apply(this, arguments) - halfPi$3,
  11344. a1 = endAngle.apply(this, arguments) - halfPi$3,
  11345. da = abs$1(a1 - a0),
  11346. cw = a1 > a0;
  11347. if (!context) context = buffer = path();
  11348. // Ensure that the outer radius is always larger than the inner radius.
  11349. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  11350. // Is it a point?
  11351. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  11352. // Or is it a circle or annulus?
  11353. else if (da > tau$4 - epsilon$3) {
  11354. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  11355. context.arc(0, 0, r1, a0, a1, !cw);
  11356. if (r0 > epsilon$3) {
  11357. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  11358. context.arc(0, 0, r0, a1, a0, cw);
  11359. }
  11360. }
  11361. // Or is it a circular or annular sector?
  11362. else {
  11363. var a01 = a0,
  11364. a11 = a1,
  11365. a00 = a0,
  11366. a10 = a1,
  11367. da0 = da,
  11368. da1 = da,
  11369. ap = padAngle.apply(this, arguments) / 2,
  11370. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  11371. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  11372. rc0 = rc,
  11373. rc1 = rc,
  11374. t0,
  11375. t1;
  11376. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  11377. if (rp > epsilon$3) {
  11378. var p0 = asin$1(rp / r0 * sin$2(ap)),
  11379. p1 = asin$1(rp / r1 * sin$2(ap));
  11380. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  11381. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  11382. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  11383. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  11384. }
  11385. var x01 = r1 * cos$2(a01),
  11386. y01 = r1 * sin$2(a01),
  11387. x10 = r0 * cos$2(a10),
  11388. y10 = r0 * sin$2(a10);
  11389. // Apply rounded corners?
  11390. if (rc > epsilon$3) {
  11391. var x11 = r1 * cos$2(a11),
  11392. y11 = r1 * sin$2(a11),
  11393. x00 = r0 * cos$2(a00),
  11394. y00 = r0 * sin$2(a00);
  11395. // Restrict the corner radius according to the sector angle.
  11396. if (da < pi$4) {
  11397. var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  11398. ax = x01 - oc[0],
  11399. ay = y01 - oc[1],
  11400. bx = x11 - oc[0],
  11401. by = y11 - oc[1],
  11402. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  11403. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  11404. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  11405. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  11406. }
  11407. }
  11408. // Is the sector collapsed to a line?
  11409. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  11410. // Does the sector’s outer ring have rounded corners?
  11411. else if (rc1 > epsilon$3) {
  11412. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  11413. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  11414. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  11415. // Have the corners merged?
  11416. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  11417. // Otherwise, draw the two corners and the ring.
  11418. else {
  11419. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  11420. 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);
  11421. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  11422. }
  11423. }
  11424. // Or is the outer ring just a circular arc?
  11425. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  11426. // Is there no inner ring, and it’s a circular sector?
  11427. // Or perhaps it’s an annular sector collapsed due to padding?
  11428. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  11429. // Does the sector’s inner ring (or point) have rounded corners?
  11430. else if (rc0 > epsilon$3) {
  11431. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  11432. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  11433. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  11434. // Have the corners merged?
  11435. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  11436. // Otherwise, draw the two corners and the ring.
  11437. else {
  11438. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  11439. 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);
  11440. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  11441. }
  11442. }
  11443. // Or is the inner ring just a circular arc?
  11444. else context.arc(0, 0, r0, a10, a00, cw);
  11445. }
  11446. context.closePath();
  11447. if (buffer) return context = null, buffer + "" || null;
  11448. }
  11449. arc.centroid = function() {
  11450. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  11451. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  11452. return [cos$2(a) * r, sin$2(a) * r];
  11453. };
  11454. arc.innerRadius = function(_) {
  11455. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : innerRadius;
  11456. };
  11457. arc.outerRadius = function(_) {
  11458. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : outerRadius;
  11459. };
  11460. arc.cornerRadius = function(_) {
  11461. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : cornerRadius;
  11462. };
  11463. arc.padRadius = function(_) {
  11464. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), arc) : padRadius;
  11465. };
  11466. arc.startAngle = function(_) {
  11467. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : startAngle;
  11468. };
  11469. arc.endAngle = function(_) {
  11470. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : endAngle;
  11471. };
  11472. arc.padAngle = function(_) {
  11473. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : padAngle;
  11474. };
  11475. arc.context = function(_) {
  11476. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  11477. };
  11478. return arc;
  11479. };
  11480. function Linear(context) {
  11481. this._context = context;
  11482. }
  11483. Linear.prototype = {
  11484. areaStart: function() {
  11485. this._line = 0;
  11486. },
  11487. areaEnd: function() {
  11488. this._line = NaN;
  11489. },
  11490. lineStart: function() {
  11491. this._point = 0;
  11492. },
  11493. lineEnd: function() {
  11494. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  11495. this._line = 1 - this._line;
  11496. },
  11497. point: function(x, y) {
  11498. x = +x, y = +y;
  11499. switch (this._point) {
  11500. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  11501. case 1: this._point = 2; // proceed
  11502. default: this._context.lineTo(x, y); break;
  11503. }
  11504. }
  11505. };
  11506. var curveLinear = function(context) {
  11507. return new Linear(context);
  11508. };
  11509. function x$3(p) {
  11510. return p[0];
  11511. }
  11512. function y$3(p) {
  11513. return p[1];
  11514. }
  11515. var line = function() {
  11516. var x$$1 = x$3,
  11517. y$$1 = y$3,
  11518. defined = constant$10(true),
  11519. context = null,
  11520. curve = curveLinear,
  11521. output = null;
  11522. function line(data) {
  11523. var i,
  11524. n = data.length,
  11525. d,
  11526. defined0 = false,
  11527. buffer;
  11528. if (context == null) output = curve(buffer = path());
  11529. for (i = 0; i <= n; ++i) {
  11530. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  11531. if (defined0 = !defined0) output.lineStart();
  11532. else output.lineEnd();
  11533. }
  11534. if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
  11535. }
  11536. if (buffer) return output = null, buffer + "" || null;
  11537. }
  11538. line.x = function(_) {
  11539. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : x$$1;
  11540. };
  11541. line.y = function(_) {
  11542. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : y$$1;
  11543. };
  11544. line.defined = function(_) {
  11545. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), line) : defined;
  11546. };
  11547. line.curve = function(_) {
  11548. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  11549. };
  11550. line.context = function(_) {
  11551. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  11552. };
  11553. return line;
  11554. };
  11555. var area$2 = function() {
  11556. var x0 = x$3,
  11557. x1 = null,
  11558. y0 = constant$10(0),
  11559. y1 = y$3,
  11560. defined = constant$10(true),
  11561. context = null,
  11562. curve = curveLinear,
  11563. output = null;
  11564. function area(data) {
  11565. var i,
  11566. j,
  11567. k,
  11568. n = data.length,
  11569. d,
  11570. defined0 = false,
  11571. buffer,
  11572. x0z = new Array(n),
  11573. y0z = new Array(n);
  11574. if (context == null) output = curve(buffer = path());
  11575. for (i = 0; i <= n; ++i) {
  11576. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  11577. if (defined0 = !defined0) {
  11578. j = i;
  11579. output.areaStart();
  11580. output.lineStart();
  11581. } else {
  11582. output.lineEnd();
  11583. output.lineStart();
  11584. for (k = i - 1; k >= j; --k) {
  11585. output.point(x0z[k], y0z[k]);
  11586. }
  11587. output.lineEnd();
  11588. output.areaEnd();
  11589. }
  11590. }
  11591. if (defined0) {
  11592. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  11593. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  11594. }
  11595. }
  11596. if (buffer) return output = null, buffer + "" || null;
  11597. }
  11598. function arealine() {
  11599. return line().defined(defined).curve(curve).context(context);
  11600. }
  11601. area.x = function(_) {
  11602. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), x1 = null, area) : x0;
  11603. };
  11604. area.x0 = function(_) {
  11605. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), area) : x0;
  11606. };
  11607. area.x1 = function(_) {
  11608. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : x1;
  11609. };
  11610. area.y = function(_) {
  11611. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), y1 = null, area) : y0;
  11612. };
  11613. area.y0 = function(_) {
  11614. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), area) : y0;
  11615. };
  11616. area.y1 = function(_) {
  11617. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : y1;
  11618. };
  11619. area.lineX0 =
  11620. area.lineY0 = function() {
  11621. return arealine().x(x0).y(y0);
  11622. };
  11623. area.lineY1 = function() {
  11624. return arealine().x(x0).y(y1);
  11625. };
  11626. area.lineX1 = function() {
  11627. return arealine().x(x1).y(y0);
  11628. };
  11629. area.defined = function(_) {
  11630. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), area) : defined;
  11631. };
  11632. area.curve = function(_) {
  11633. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  11634. };
  11635. area.context = function(_) {
  11636. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  11637. };
  11638. return area;
  11639. };
  11640. var descending$1 = function(a, b) {
  11641. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  11642. };
  11643. var identity$7 = function(d) {
  11644. return d;
  11645. };
  11646. var pie = function() {
  11647. var value = identity$7,
  11648. sortValues = descending$1,
  11649. sort = null,
  11650. startAngle = constant$10(0),
  11651. endAngle = constant$10(tau$4),
  11652. padAngle = constant$10(0);
  11653. function pie(data) {
  11654. var i,
  11655. n = data.length,
  11656. j,
  11657. k,
  11658. sum = 0,
  11659. index = new Array(n),
  11660. arcs = new Array(n),
  11661. a0 = +startAngle.apply(this, arguments),
  11662. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  11663. a1,
  11664. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  11665. pa = p * (da < 0 ? -1 : 1),
  11666. v;
  11667. for (i = 0; i < n; ++i) {
  11668. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  11669. sum += v;
  11670. }
  11671. }
  11672. // Optionally sort the arcs by previously-computed values or by data.
  11673. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  11674. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  11675. // Compute the arcs! They are stored in the original data's order.
  11676. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  11677. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  11678. data: data[j],
  11679. index: i,
  11680. value: v,
  11681. startAngle: a0,
  11682. endAngle: a1,
  11683. padAngle: p
  11684. };
  11685. }
  11686. return arcs;
  11687. }
  11688. pie.value = function(_) {
  11689. return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), pie) : value;
  11690. };
  11691. pie.sortValues = function(_) {
  11692. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  11693. };
  11694. pie.sort = function(_) {
  11695. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  11696. };
  11697. pie.startAngle = function(_) {
  11698. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : startAngle;
  11699. };
  11700. pie.endAngle = function(_) {
  11701. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : endAngle;
  11702. };
  11703. pie.padAngle = function(_) {
  11704. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : padAngle;
  11705. };
  11706. return pie;
  11707. };
  11708. var curveRadialLinear = curveRadial(curveLinear);
  11709. function Radial(curve) {
  11710. this._curve = curve;
  11711. }
  11712. Radial.prototype = {
  11713. areaStart: function() {
  11714. this._curve.areaStart();
  11715. },
  11716. areaEnd: function() {
  11717. this._curve.areaEnd();
  11718. },
  11719. lineStart: function() {
  11720. this._curve.lineStart();
  11721. },
  11722. lineEnd: function() {
  11723. this._curve.lineEnd();
  11724. },
  11725. point: function(a, r) {
  11726. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  11727. }
  11728. };
  11729. function curveRadial(curve) {
  11730. function radial(context) {
  11731. return new Radial(curve(context));
  11732. }
  11733. radial._curve = curve;
  11734. return radial;
  11735. }
  11736. function lineRadial(l) {
  11737. var c = l.curve;
  11738. l.angle = l.x, delete l.x;
  11739. l.radius = l.y, delete l.y;
  11740. l.curve = function(_) {
  11741. return arguments.length ? c(curveRadial(_)) : c()._curve;
  11742. };
  11743. return l;
  11744. }
  11745. var lineRadial$1 = function() {
  11746. return lineRadial(line().curve(curveRadialLinear));
  11747. };
  11748. var areaRadial = function() {
  11749. var a = area$2().curve(curveRadialLinear),
  11750. c = a.curve,
  11751. x0 = a.lineX0,
  11752. x1 = a.lineX1,
  11753. y0 = a.lineY0,
  11754. y1 = a.lineY1;
  11755. a.angle = a.x, delete a.x;
  11756. a.startAngle = a.x0, delete a.x0;
  11757. a.endAngle = a.x1, delete a.x1;
  11758. a.radius = a.y, delete a.y;
  11759. a.innerRadius = a.y0, delete a.y0;
  11760. a.outerRadius = a.y1, delete a.y1;
  11761. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  11762. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  11763. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  11764. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  11765. a.curve = function(_) {
  11766. return arguments.length ? c(curveRadial(_)) : c()._curve;
  11767. };
  11768. return a;
  11769. };
  11770. var pointRadial = function(x, y) {
  11771. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  11772. };
  11773. var slice$6 = Array.prototype.slice;
  11774. function linkSource(d) {
  11775. return d.source;
  11776. }
  11777. function linkTarget(d) {
  11778. return d.target;
  11779. }
  11780. function link$2(curve) {
  11781. var source = linkSource,
  11782. target = linkTarget,
  11783. x$$1 = x$3,
  11784. y$$1 = y$3,
  11785. context = null;
  11786. function link() {
  11787. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  11788. if (!context) context = buffer = path();
  11789. curve(context, +x$$1.apply(this, (argv[0] = s, argv)), +y$$1.apply(this, argv), +x$$1.apply(this, (argv[0] = t, argv)), +y$$1.apply(this, argv));
  11790. if (buffer) return context = null, buffer + "" || null;
  11791. }
  11792. link.source = function(_) {
  11793. return arguments.length ? (source = _, link) : source;
  11794. };
  11795. link.target = function(_) {
  11796. return arguments.length ? (target = _, link) : target;
  11797. };
  11798. link.x = function(_) {
  11799. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : x$$1;
  11800. };
  11801. link.y = function(_) {
  11802. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : y$$1;
  11803. };
  11804. link.context = function(_) {
  11805. return arguments.length ? ((context = _ == null ? null : _), link) : context;
  11806. };
  11807. return link;
  11808. }
  11809. function curveHorizontal(context, x0, y0, x1, y1) {
  11810. context.moveTo(x0, y0);
  11811. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  11812. }
  11813. function curveVertical(context, x0, y0, x1, y1) {
  11814. context.moveTo(x0, y0);
  11815. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  11816. }
  11817. function curveRadial$1(context, x0, y0, x1, y1) {
  11818. var p0 = pointRadial(x0, y0),
  11819. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  11820. p2 = pointRadial(x1, y0),
  11821. p3 = pointRadial(x1, y1);
  11822. context.moveTo(p0[0], p0[1]);
  11823. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  11824. }
  11825. function linkHorizontal() {
  11826. return link$2(curveHorizontal);
  11827. }
  11828. function linkVertical() {
  11829. return link$2(curveVertical);
  11830. }
  11831. function linkRadial() {
  11832. var l = link$2(curveRadial$1);
  11833. l.angle = l.x, delete l.x;
  11834. l.radius = l.y, delete l.y;
  11835. return l;
  11836. }
  11837. var circle$2 = {
  11838. draw: function(context, size) {
  11839. var r = Math.sqrt(size / pi$4);
  11840. context.moveTo(r, 0);
  11841. context.arc(0, 0, r, 0, tau$4);
  11842. }
  11843. };
  11844. var cross$2 = {
  11845. draw: function(context, size) {
  11846. var r = Math.sqrt(size / 5) / 2;
  11847. context.moveTo(-3 * r, -r);
  11848. context.lineTo(-r, -r);
  11849. context.lineTo(-r, -3 * r);
  11850. context.lineTo(r, -3 * r);
  11851. context.lineTo(r, -r);
  11852. context.lineTo(3 * r, -r);
  11853. context.lineTo(3 * r, r);
  11854. context.lineTo(r, r);
  11855. context.lineTo(r, 3 * r);
  11856. context.lineTo(-r, 3 * r);
  11857. context.lineTo(-r, r);
  11858. context.lineTo(-3 * r, r);
  11859. context.closePath();
  11860. }
  11861. };
  11862. var tan30 = Math.sqrt(1 / 3);
  11863. var tan30_2 = tan30 * 2;
  11864. var diamond = {
  11865. draw: function(context, size) {
  11866. var y = Math.sqrt(size / tan30_2),
  11867. x = y * tan30;
  11868. context.moveTo(0, -y);
  11869. context.lineTo(x, 0);
  11870. context.lineTo(0, y);
  11871. context.lineTo(-x, 0);
  11872. context.closePath();
  11873. }
  11874. };
  11875. var ka = 0.89081309152928522810;
  11876. var kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10);
  11877. var kx = Math.sin(tau$4 / 10) * kr;
  11878. var ky = -Math.cos(tau$4 / 10) * kr;
  11879. var star = {
  11880. draw: function(context, size) {
  11881. var r = Math.sqrt(size * ka),
  11882. x = kx * r,
  11883. y = ky * r;
  11884. context.moveTo(0, -r);
  11885. context.lineTo(x, y);
  11886. for (var i = 1; i < 5; ++i) {
  11887. var a = tau$4 * i / 5,
  11888. c = Math.cos(a),
  11889. s = Math.sin(a);
  11890. context.lineTo(s * r, -c * r);
  11891. context.lineTo(c * x - s * y, s * x + c * y);
  11892. }
  11893. context.closePath();
  11894. }
  11895. };
  11896. var square = {
  11897. draw: function(context, size) {
  11898. var w = Math.sqrt(size),
  11899. x = -w / 2;
  11900. context.rect(x, x, w, w);
  11901. }
  11902. };
  11903. var sqrt3 = Math.sqrt(3);
  11904. var triangle = {
  11905. draw: function(context, size) {
  11906. var y = -Math.sqrt(size / (sqrt3 * 3));
  11907. context.moveTo(0, y * 2);
  11908. context.lineTo(-sqrt3 * y, -y);
  11909. context.lineTo(sqrt3 * y, -y);
  11910. context.closePath();
  11911. }
  11912. };
  11913. var c = -0.5;
  11914. var s = Math.sqrt(3) / 2;
  11915. var k = 1 / Math.sqrt(12);
  11916. var a = (k / 2 + 1) * 3;
  11917. var wye = {
  11918. draw: function(context, size) {
  11919. var r = Math.sqrt(size / a),
  11920. x0 = r / 2,
  11921. y0 = r * k,
  11922. x1 = x0,
  11923. y1 = r * k + r,
  11924. x2 = -x1,
  11925. y2 = y1;
  11926. context.moveTo(x0, y0);
  11927. context.lineTo(x1, y1);
  11928. context.lineTo(x2, y2);
  11929. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  11930. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  11931. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  11932. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  11933. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  11934. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  11935. context.closePath();
  11936. }
  11937. };
  11938. var symbols = [
  11939. circle$2,
  11940. cross$2,
  11941. diamond,
  11942. square,
  11943. star,
  11944. triangle,
  11945. wye
  11946. ];
  11947. var symbol = function() {
  11948. var type = constant$10(circle$2),
  11949. size = constant$10(64),
  11950. context = null;
  11951. function symbol() {
  11952. var buffer;
  11953. if (!context) context = buffer = path();
  11954. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  11955. if (buffer) return context = null, buffer + "" || null;
  11956. }
  11957. symbol.type = function(_) {
  11958. return arguments.length ? (type = typeof _ === "function" ? _ : constant$10(_), symbol) : type;
  11959. };
  11960. symbol.size = function(_) {
  11961. return arguments.length ? (size = typeof _ === "function" ? _ : constant$10(+_), symbol) : size;
  11962. };
  11963. symbol.context = function(_) {
  11964. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  11965. };
  11966. return symbol;
  11967. };
  11968. var noop$2 = function() {};
  11969. function point$2(that, x, y) {
  11970. that._context.bezierCurveTo(
  11971. (2 * that._x0 + that._x1) / 3,
  11972. (2 * that._y0 + that._y1) / 3,
  11973. (that._x0 + 2 * that._x1) / 3,
  11974. (that._y0 + 2 * that._y1) / 3,
  11975. (that._x0 + 4 * that._x1 + x) / 6,
  11976. (that._y0 + 4 * that._y1 + y) / 6
  11977. );
  11978. }
  11979. function Basis(context) {
  11980. this._context = context;
  11981. }
  11982. Basis.prototype = {
  11983. areaStart: function() {
  11984. this._line = 0;
  11985. },
  11986. areaEnd: function() {
  11987. this._line = NaN;
  11988. },
  11989. lineStart: function() {
  11990. this._x0 = this._x1 =
  11991. this._y0 = this._y1 = NaN;
  11992. this._point = 0;
  11993. },
  11994. lineEnd: function() {
  11995. switch (this._point) {
  11996. case 3: point$2(this, this._x1, this._y1); // proceed
  11997. case 2: this._context.lineTo(this._x1, this._y1); break;
  11998. }
  11999. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12000. this._line = 1 - this._line;
  12001. },
  12002. point: function(x, y) {
  12003. x = +x, y = +y;
  12004. switch (this._point) {
  12005. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12006. case 1: this._point = 2; break;
  12007. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  12008. default: point$2(this, x, y); break;
  12009. }
  12010. this._x0 = this._x1, this._x1 = x;
  12011. this._y0 = this._y1, this._y1 = y;
  12012. }
  12013. };
  12014. var basis$2 = function(context) {
  12015. return new Basis(context);
  12016. };
  12017. function BasisClosed(context) {
  12018. this._context = context;
  12019. }
  12020. BasisClosed.prototype = {
  12021. areaStart: noop$2,
  12022. areaEnd: noop$2,
  12023. lineStart: function() {
  12024. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  12025. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  12026. this._point = 0;
  12027. },
  12028. lineEnd: function() {
  12029. switch (this._point) {
  12030. case 1: {
  12031. this._context.moveTo(this._x2, this._y2);
  12032. this._context.closePath();
  12033. break;
  12034. }
  12035. case 2: {
  12036. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  12037. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  12038. this._context.closePath();
  12039. break;
  12040. }
  12041. case 3: {
  12042. this.point(this._x2, this._y2);
  12043. this.point(this._x3, this._y3);
  12044. this.point(this._x4, this._y4);
  12045. break;
  12046. }
  12047. }
  12048. },
  12049. point: function(x, y) {
  12050. x = +x, y = +y;
  12051. switch (this._point) {
  12052. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  12053. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  12054. 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;
  12055. default: point$2(this, x, y); break;
  12056. }
  12057. this._x0 = this._x1, this._x1 = x;
  12058. this._y0 = this._y1, this._y1 = y;
  12059. }
  12060. };
  12061. var basisClosed$1 = function(context) {
  12062. return new BasisClosed(context);
  12063. };
  12064. function BasisOpen(context) {
  12065. this._context = context;
  12066. }
  12067. BasisOpen.prototype = {
  12068. areaStart: function() {
  12069. this._line = 0;
  12070. },
  12071. areaEnd: function() {
  12072. this._line = NaN;
  12073. },
  12074. lineStart: function() {
  12075. this._x0 = this._x1 =
  12076. this._y0 = this._y1 = NaN;
  12077. this._point = 0;
  12078. },
  12079. lineEnd: function() {
  12080. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12081. this._line = 1 - this._line;
  12082. },
  12083. point: function(x, y) {
  12084. x = +x, y = +y;
  12085. switch (this._point) {
  12086. case 0: this._point = 1; break;
  12087. case 1: this._point = 2; break;
  12088. 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;
  12089. case 3: this._point = 4; // proceed
  12090. default: point$2(this, x, y); break;
  12091. }
  12092. this._x0 = this._x1, this._x1 = x;
  12093. this._y0 = this._y1, this._y1 = y;
  12094. }
  12095. };
  12096. var basisOpen = function(context) {
  12097. return new BasisOpen(context);
  12098. };
  12099. function Bundle(context, beta) {
  12100. this._basis = new Basis(context);
  12101. this._beta = beta;
  12102. }
  12103. Bundle.prototype = {
  12104. lineStart: function() {
  12105. this._x = [];
  12106. this._y = [];
  12107. this._basis.lineStart();
  12108. },
  12109. lineEnd: function() {
  12110. var x = this._x,
  12111. y = this._y,
  12112. j = x.length - 1;
  12113. if (j > 0) {
  12114. var x0 = x[0],
  12115. y0 = y[0],
  12116. dx = x[j] - x0,
  12117. dy = y[j] - y0,
  12118. i = -1,
  12119. t;
  12120. while (++i <= j) {
  12121. t = i / j;
  12122. this._basis.point(
  12123. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  12124. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  12125. );
  12126. }
  12127. }
  12128. this._x = this._y = null;
  12129. this._basis.lineEnd();
  12130. },
  12131. point: function(x, y) {
  12132. this._x.push(+x);
  12133. this._y.push(+y);
  12134. }
  12135. };
  12136. var bundle = (function custom(beta) {
  12137. function bundle(context) {
  12138. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  12139. }
  12140. bundle.beta = function(beta) {
  12141. return custom(+beta);
  12142. };
  12143. return bundle;
  12144. })(0.85);
  12145. function point$3(that, x, y) {
  12146. that._context.bezierCurveTo(
  12147. that._x1 + that._k * (that._x2 - that._x0),
  12148. that._y1 + that._k * (that._y2 - that._y0),
  12149. that._x2 + that._k * (that._x1 - x),
  12150. that._y2 + that._k * (that._y1 - y),
  12151. that._x2,
  12152. that._y2
  12153. );
  12154. }
  12155. function Cardinal(context, tension) {
  12156. this._context = context;
  12157. this._k = (1 - tension) / 6;
  12158. }
  12159. Cardinal.prototype = {
  12160. areaStart: function() {
  12161. this._line = 0;
  12162. },
  12163. areaEnd: function() {
  12164. this._line = NaN;
  12165. },
  12166. lineStart: function() {
  12167. this._x0 = this._x1 = this._x2 =
  12168. this._y0 = this._y1 = this._y2 = NaN;
  12169. this._point = 0;
  12170. },
  12171. lineEnd: function() {
  12172. switch (this._point) {
  12173. case 2: this._context.lineTo(this._x2, this._y2); break;
  12174. case 3: point$3(this, this._x1, this._y1); break;
  12175. }
  12176. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12177. this._line = 1 - this._line;
  12178. },
  12179. point: function(x, y) {
  12180. x = +x, y = +y;
  12181. switch (this._point) {
  12182. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12183. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  12184. case 2: this._point = 3; // proceed
  12185. default: point$3(this, x, y); break;
  12186. }
  12187. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12188. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12189. }
  12190. };
  12191. var cardinal = (function custom(tension) {
  12192. function cardinal(context) {
  12193. return new Cardinal(context, tension);
  12194. }
  12195. cardinal.tension = function(tension) {
  12196. return custom(+tension);
  12197. };
  12198. return cardinal;
  12199. })(0);
  12200. function CardinalClosed(context, tension) {
  12201. this._context = context;
  12202. this._k = (1 - tension) / 6;
  12203. }
  12204. CardinalClosed.prototype = {
  12205. areaStart: noop$2,
  12206. areaEnd: noop$2,
  12207. lineStart: function() {
  12208. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12209. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12210. this._point = 0;
  12211. },
  12212. lineEnd: function() {
  12213. switch (this._point) {
  12214. case 1: {
  12215. this._context.moveTo(this._x3, this._y3);
  12216. this._context.closePath();
  12217. break;
  12218. }
  12219. case 2: {
  12220. this._context.lineTo(this._x3, this._y3);
  12221. this._context.closePath();
  12222. break;
  12223. }
  12224. case 3: {
  12225. this.point(this._x3, this._y3);
  12226. this.point(this._x4, this._y4);
  12227. this.point(this._x5, this._y5);
  12228. break;
  12229. }
  12230. }
  12231. },
  12232. point: function(x, y) {
  12233. x = +x, y = +y;
  12234. switch (this._point) {
  12235. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12236. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12237. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12238. default: point$3(this, x, y); break;
  12239. }
  12240. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12241. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12242. }
  12243. };
  12244. var cardinalClosed = (function custom(tension) {
  12245. function cardinal$$1(context) {
  12246. return new CardinalClosed(context, tension);
  12247. }
  12248. cardinal$$1.tension = function(tension) {
  12249. return custom(+tension);
  12250. };
  12251. return cardinal$$1;
  12252. })(0);
  12253. function CardinalOpen(context, tension) {
  12254. this._context = context;
  12255. this._k = (1 - tension) / 6;
  12256. }
  12257. CardinalOpen.prototype = {
  12258. areaStart: function() {
  12259. this._line = 0;
  12260. },
  12261. areaEnd: function() {
  12262. this._line = NaN;
  12263. },
  12264. lineStart: function() {
  12265. this._x0 = this._x1 = this._x2 =
  12266. this._y0 = this._y1 = this._y2 = NaN;
  12267. this._point = 0;
  12268. },
  12269. lineEnd: function() {
  12270. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12271. this._line = 1 - this._line;
  12272. },
  12273. point: function(x, y) {
  12274. x = +x, y = +y;
  12275. switch (this._point) {
  12276. case 0: this._point = 1; break;
  12277. case 1: this._point = 2; break;
  12278. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12279. case 3: this._point = 4; // proceed
  12280. default: point$3(this, x, y); break;
  12281. }
  12282. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12283. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12284. }
  12285. };
  12286. var cardinalOpen = (function custom(tension) {
  12287. function cardinal$$1(context) {
  12288. return new CardinalOpen(context, tension);
  12289. }
  12290. cardinal$$1.tension = function(tension) {
  12291. return custom(+tension);
  12292. };
  12293. return cardinal$$1;
  12294. })(0);
  12295. function point$4(that, x, y) {
  12296. var x1 = that._x1,
  12297. y1 = that._y1,
  12298. x2 = that._x2,
  12299. y2 = that._y2;
  12300. if (that._l01_a > epsilon$3) {
  12301. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  12302. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  12303. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  12304. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  12305. }
  12306. if (that._l23_a > epsilon$3) {
  12307. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  12308. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  12309. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  12310. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  12311. }
  12312. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  12313. }
  12314. function CatmullRom(context, alpha) {
  12315. this._context = context;
  12316. this._alpha = alpha;
  12317. }
  12318. CatmullRom.prototype = {
  12319. areaStart: function() {
  12320. this._line = 0;
  12321. },
  12322. areaEnd: function() {
  12323. this._line = NaN;
  12324. },
  12325. lineStart: function() {
  12326. this._x0 = this._x1 = this._x2 =
  12327. this._y0 = this._y1 = this._y2 = NaN;
  12328. this._l01_a = this._l12_a = this._l23_a =
  12329. this._l01_2a = this._l12_2a = this._l23_2a =
  12330. this._point = 0;
  12331. },
  12332. lineEnd: function() {
  12333. switch (this._point) {
  12334. case 2: this._context.lineTo(this._x2, this._y2); break;
  12335. case 3: this.point(this._x2, this._y2); break;
  12336. }
  12337. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12338. this._line = 1 - this._line;
  12339. },
  12340. point: function(x, y) {
  12341. x = +x, y = +y;
  12342. if (this._point) {
  12343. var x23 = this._x2 - x,
  12344. y23 = this._y2 - y;
  12345. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12346. }
  12347. switch (this._point) {
  12348. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12349. case 1: this._point = 2; break;
  12350. case 2: this._point = 3; // proceed
  12351. default: point$4(this, x, y); break;
  12352. }
  12353. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12354. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12355. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12356. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12357. }
  12358. };
  12359. var catmullRom = (function custom(alpha) {
  12360. function catmullRom(context) {
  12361. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  12362. }
  12363. catmullRom.alpha = function(alpha) {
  12364. return custom(+alpha);
  12365. };
  12366. return catmullRom;
  12367. })(0.5);
  12368. function CatmullRomClosed(context, alpha) {
  12369. this._context = context;
  12370. this._alpha = alpha;
  12371. }
  12372. CatmullRomClosed.prototype = {
  12373. areaStart: noop$2,
  12374. areaEnd: noop$2,
  12375. lineStart: function() {
  12376. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12377. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12378. this._l01_a = this._l12_a = this._l23_a =
  12379. this._l01_2a = this._l12_2a = this._l23_2a =
  12380. this._point = 0;
  12381. },
  12382. lineEnd: function() {
  12383. switch (this._point) {
  12384. case 1: {
  12385. this._context.moveTo(this._x3, this._y3);
  12386. this._context.closePath();
  12387. break;
  12388. }
  12389. case 2: {
  12390. this._context.lineTo(this._x3, this._y3);
  12391. this._context.closePath();
  12392. break;
  12393. }
  12394. case 3: {
  12395. this.point(this._x3, this._y3);
  12396. this.point(this._x4, this._y4);
  12397. this.point(this._x5, this._y5);
  12398. break;
  12399. }
  12400. }
  12401. },
  12402. point: function(x, y) {
  12403. x = +x, y = +y;
  12404. if (this._point) {
  12405. var x23 = this._x2 - x,
  12406. y23 = this._y2 - y;
  12407. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12408. }
  12409. switch (this._point) {
  12410. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12411. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12412. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12413. default: point$4(this, x, y); break;
  12414. }
  12415. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12416. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12417. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12418. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12419. }
  12420. };
  12421. var catmullRomClosed = (function custom(alpha) {
  12422. function catmullRom$$1(context) {
  12423. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  12424. }
  12425. catmullRom$$1.alpha = function(alpha) {
  12426. return custom(+alpha);
  12427. };
  12428. return catmullRom$$1;
  12429. })(0.5);
  12430. function CatmullRomOpen(context, alpha) {
  12431. this._context = context;
  12432. this._alpha = alpha;
  12433. }
  12434. CatmullRomOpen.prototype = {
  12435. areaStart: function() {
  12436. this._line = 0;
  12437. },
  12438. areaEnd: function() {
  12439. this._line = NaN;
  12440. },
  12441. lineStart: function() {
  12442. this._x0 = this._x1 = this._x2 =
  12443. this._y0 = this._y1 = this._y2 = NaN;
  12444. this._l01_a = this._l12_a = this._l23_a =
  12445. this._l01_2a = this._l12_2a = this._l23_2a =
  12446. this._point = 0;
  12447. },
  12448. lineEnd: function() {
  12449. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12450. this._line = 1 - this._line;
  12451. },
  12452. point: function(x, y) {
  12453. x = +x, y = +y;
  12454. if (this._point) {
  12455. var x23 = this._x2 - x,
  12456. y23 = this._y2 - y;
  12457. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12458. }
  12459. switch (this._point) {
  12460. case 0: this._point = 1; break;
  12461. case 1: this._point = 2; break;
  12462. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12463. case 3: this._point = 4; // proceed
  12464. default: point$4(this, x, y); break;
  12465. }
  12466. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12467. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12468. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12469. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12470. }
  12471. };
  12472. var catmullRomOpen = (function custom(alpha) {
  12473. function catmullRom$$1(context) {
  12474. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  12475. }
  12476. catmullRom$$1.alpha = function(alpha) {
  12477. return custom(+alpha);
  12478. };
  12479. return catmullRom$$1;
  12480. })(0.5);
  12481. function LinearClosed(context) {
  12482. this._context = context;
  12483. }
  12484. LinearClosed.prototype = {
  12485. areaStart: noop$2,
  12486. areaEnd: noop$2,
  12487. lineStart: function() {
  12488. this._point = 0;
  12489. },
  12490. lineEnd: function() {
  12491. if (this._point) this._context.closePath();
  12492. },
  12493. point: function(x, y) {
  12494. x = +x, y = +y;
  12495. if (this._point) this._context.lineTo(x, y);
  12496. else this._point = 1, this._context.moveTo(x, y);
  12497. }
  12498. };
  12499. var linearClosed = function(context) {
  12500. return new LinearClosed(context);
  12501. };
  12502. function sign$1(x) {
  12503. return x < 0 ? -1 : 1;
  12504. }
  12505. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  12506. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  12507. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  12508. // NOV(II), P. 443, 1990.
  12509. function slope3(that, x2, y2) {
  12510. var h0 = that._x1 - that._x0,
  12511. h1 = x2 - that._x1,
  12512. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  12513. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  12514. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  12515. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  12516. }
  12517. // Calculate a one-sided slope.
  12518. function slope2(that, t) {
  12519. var h = that._x1 - that._x0;
  12520. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  12521. }
  12522. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  12523. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  12524. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  12525. function point$5(that, t0, t1) {
  12526. var x0 = that._x0,
  12527. y0 = that._y0,
  12528. x1 = that._x1,
  12529. y1 = that._y1,
  12530. dx = (x1 - x0) / 3;
  12531. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  12532. }
  12533. function MonotoneX(context) {
  12534. this._context = context;
  12535. }
  12536. MonotoneX.prototype = {
  12537. areaStart: function() {
  12538. this._line = 0;
  12539. },
  12540. areaEnd: function() {
  12541. this._line = NaN;
  12542. },
  12543. lineStart: function() {
  12544. this._x0 = this._x1 =
  12545. this._y0 = this._y1 =
  12546. this._t0 = NaN;
  12547. this._point = 0;
  12548. },
  12549. lineEnd: function() {
  12550. switch (this._point) {
  12551. case 2: this._context.lineTo(this._x1, this._y1); break;
  12552. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  12553. }
  12554. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12555. this._line = 1 - this._line;
  12556. },
  12557. point: function(x, y) {
  12558. var t1 = NaN;
  12559. x = +x, y = +y;
  12560. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  12561. switch (this._point) {
  12562. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12563. case 1: this._point = 2; break;
  12564. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  12565. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  12566. }
  12567. this._x0 = this._x1, this._x1 = x;
  12568. this._y0 = this._y1, this._y1 = y;
  12569. this._t0 = t1;
  12570. }
  12571. };
  12572. function MonotoneY(context) {
  12573. this._context = new ReflectContext(context);
  12574. }
  12575. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  12576. MonotoneX.prototype.point.call(this, y, x);
  12577. };
  12578. function ReflectContext(context) {
  12579. this._context = context;
  12580. }
  12581. ReflectContext.prototype = {
  12582. moveTo: function(x, y) { this._context.moveTo(y, x); },
  12583. closePath: function() { this._context.closePath(); },
  12584. lineTo: function(x, y) { this._context.lineTo(y, x); },
  12585. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  12586. };
  12587. function monotoneX(context) {
  12588. return new MonotoneX(context);
  12589. }
  12590. function monotoneY(context) {
  12591. return new MonotoneY(context);
  12592. }
  12593. function Natural(context) {
  12594. this._context = context;
  12595. }
  12596. Natural.prototype = {
  12597. areaStart: function() {
  12598. this._line = 0;
  12599. },
  12600. areaEnd: function() {
  12601. this._line = NaN;
  12602. },
  12603. lineStart: function() {
  12604. this._x = [];
  12605. this._y = [];
  12606. },
  12607. lineEnd: function() {
  12608. var x = this._x,
  12609. y = this._y,
  12610. n = x.length;
  12611. if (n) {
  12612. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  12613. if (n === 2) {
  12614. this._context.lineTo(x[1], y[1]);
  12615. } else {
  12616. var px = controlPoints(x),
  12617. py = controlPoints(y);
  12618. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  12619. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  12620. }
  12621. }
  12622. }
  12623. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  12624. this._line = 1 - this._line;
  12625. this._x = this._y = null;
  12626. },
  12627. point: function(x, y) {
  12628. this._x.push(+x);
  12629. this._y.push(+y);
  12630. }
  12631. };
  12632. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  12633. function controlPoints(x) {
  12634. var i,
  12635. n = x.length - 1,
  12636. m,
  12637. a = new Array(n),
  12638. b = new Array(n),
  12639. r = new Array(n);
  12640. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  12641. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  12642. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  12643. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  12644. a[n - 1] = r[n - 1] / b[n - 1];
  12645. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  12646. b[n - 1] = (x[n] + a[n - 1]) / 2;
  12647. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  12648. return [a, b];
  12649. }
  12650. var natural = function(context) {
  12651. return new Natural(context);
  12652. };
  12653. function Step(context, t) {
  12654. this._context = context;
  12655. this._t = t;
  12656. }
  12657. Step.prototype = {
  12658. areaStart: function() {
  12659. this._line = 0;
  12660. },
  12661. areaEnd: function() {
  12662. this._line = NaN;
  12663. },
  12664. lineStart: function() {
  12665. this._x = this._y = NaN;
  12666. this._point = 0;
  12667. },
  12668. lineEnd: function() {
  12669. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  12670. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12671. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  12672. },
  12673. point: function(x, y) {
  12674. x = +x, y = +y;
  12675. switch (this._point) {
  12676. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12677. case 1: this._point = 2; // proceed
  12678. default: {
  12679. if (this._t <= 0) {
  12680. this._context.lineTo(this._x, y);
  12681. this._context.lineTo(x, y);
  12682. } else {
  12683. var x1 = this._x * (1 - this._t) + x * this._t;
  12684. this._context.lineTo(x1, this._y);
  12685. this._context.lineTo(x1, y);
  12686. }
  12687. break;
  12688. }
  12689. }
  12690. this._x = x, this._y = y;
  12691. }
  12692. };
  12693. var step = function(context) {
  12694. return new Step(context, 0.5);
  12695. };
  12696. function stepBefore(context) {
  12697. return new Step(context, 0);
  12698. }
  12699. function stepAfter(context) {
  12700. return new Step(context, 1);
  12701. }
  12702. var none$1 = function(series, order) {
  12703. if (!((n = series.length) > 1)) return;
  12704. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  12705. s0 = s1, s1 = series[order[i]];
  12706. for (j = 0; j < m; ++j) {
  12707. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  12708. }
  12709. }
  12710. };
  12711. var none$2 = function(series) {
  12712. var n = series.length, o = new Array(n);
  12713. while (--n >= 0) o[n] = n;
  12714. return o;
  12715. };
  12716. function stackValue(d, key) {
  12717. return d[key];
  12718. }
  12719. var stack = function() {
  12720. var keys = constant$10([]),
  12721. order = none$2,
  12722. offset = none$1,
  12723. value = stackValue;
  12724. function stack(data) {
  12725. var kz = keys.apply(this, arguments),
  12726. i,
  12727. m = data.length,
  12728. n = kz.length,
  12729. sz = new Array(n),
  12730. oz;
  12731. for (i = 0; i < n; ++i) {
  12732. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  12733. si[j] = sij = [0, +value(data[j], ki, j, data)];
  12734. sij.data = data[j];
  12735. }
  12736. si.key = ki;
  12737. }
  12738. for (i = 0, oz = order(sz); i < n; ++i) {
  12739. sz[oz[i]].index = i;
  12740. }
  12741. offset(sz, oz);
  12742. return sz;
  12743. }
  12744. stack.keys = function(_) {
  12745. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : keys;
  12746. };
  12747. stack.value = function(_) {
  12748. return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), stack) : value;
  12749. };
  12750. stack.order = function(_) {
  12751. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : order;
  12752. };
  12753. stack.offset = function(_) {
  12754. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  12755. };
  12756. return stack;
  12757. };
  12758. var expand = function(series, order) {
  12759. if (!((n = series.length) > 0)) return;
  12760. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  12761. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  12762. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  12763. }
  12764. none$1(series, order);
  12765. };
  12766. var diverging = function(series, order) {
  12767. if (!((n = series.length) > 1)) return;
  12768. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  12769. for (yp = yn = 0, i = 0; i < n; ++i) {
  12770. if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
  12771. d[0] = yp, d[1] = yp += dy;
  12772. } else if (dy < 0) {
  12773. d[1] = yn, d[0] = yn += dy;
  12774. } else {
  12775. d[0] = yp;
  12776. }
  12777. }
  12778. }
  12779. };
  12780. var silhouette = function(series, order) {
  12781. if (!((n = series.length) > 0)) return;
  12782. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  12783. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  12784. s0[j][1] += s0[j][0] = -y / 2;
  12785. }
  12786. none$1(series, order);
  12787. };
  12788. var wiggle = function(series, order) {
  12789. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  12790. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  12791. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  12792. var si = series[order[i]],
  12793. sij0 = si[j][1] || 0,
  12794. sij1 = si[j - 1][1] || 0,
  12795. s3 = (sij0 - sij1) / 2;
  12796. for (var k = 0; k < i; ++k) {
  12797. var sk = series[order[k]],
  12798. skj0 = sk[j][1] || 0,
  12799. skj1 = sk[j - 1][1] || 0;
  12800. s3 += skj0 - skj1;
  12801. }
  12802. s1 += sij0, s2 += s3 * sij0;
  12803. }
  12804. s0[j - 1][1] += s0[j - 1][0] = y;
  12805. if (s1) y -= s2 / s1;
  12806. }
  12807. s0[j - 1][1] += s0[j - 1][0] = y;
  12808. none$1(series, order);
  12809. };
  12810. var ascending$2 = function(series) {
  12811. var sums = series.map(sum$2);
  12812. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  12813. };
  12814. function sum$2(series) {
  12815. var s = 0, i = -1, n = series.length, v;
  12816. while (++i < n) if (v = +series[i][1]) s += v;
  12817. return s;
  12818. }
  12819. var descending$2 = function(series) {
  12820. return ascending$2(series).reverse();
  12821. };
  12822. var insideOut = function(series) {
  12823. var n = series.length,
  12824. i,
  12825. j,
  12826. sums = series.map(sum$2),
  12827. order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  12828. top = 0,
  12829. bottom = 0,
  12830. tops = [],
  12831. bottoms = [];
  12832. for (i = 0; i < n; ++i) {
  12833. j = order[i];
  12834. if (top < bottom) {
  12835. top += sums[j];
  12836. tops.push(j);
  12837. } else {
  12838. bottom += sums[j];
  12839. bottoms.push(j);
  12840. }
  12841. }
  12842. return bottoms.reverse().concat(tops);
  12843. };
  12844. var reverse = function(series) {
  12845. return none$2(series).reverse();
  12846. };
  12847. var constant$11 = function(x) {
  12848. return function() {
  12849. return x;
  12850. };
  12851. };
  12852. function x$4(d) {
  12853. return d[0];
  12854. }
  12855. function y$4(d) {
  12856. return d[1];
  12857. }
  12858. function RedBlackTree() {
  12859. this._ = null; // root node
  12860. }
  12861. function RedBlackNode(node) {
  12862. node.U = // parent node
  12863. node.C = // color - true for red, false for black
  12864. node.L = // left node
  12865. node.R = // right node
  12866. node.P = // previous node
  12867. node.N = null; // next node
  12868. }
  12869. RedBlackTree.prototype = {
  12870. constructor: RedBlackTree,
  12871. insert: function(after, node) {
  12872. var parent, grandpa, uncle;
  12873. if (after) {
  12874. node.P = after;
  12875. node.N = after.N;
  12876. if (after.N) after.N.P = node;
  12877. after.N = node;
  12878. if (after.R) {
  12879. after = after.R;
  12880. while (after.L) after = after.L;
  12881. after.L = node;
  12882. } else {
  12883. after.R = node;
  12884. }
  12885. parent = after;
  12886. } else if (this._) {
  12887. after = RedBlackFirst(this._);
  12888. node.P = null;
  12889. node.N = after;
  12890. after.P = after.L = node;
  12891. parent = after;
  12892. } else {
  12893. node.P = node.N = null;
  12894. this._ = node;
  12895. parent = null;
  12896. }
  12897. node.L = node.R = null;
  12898. node.U = parent;
  12899. node.C = true;
  12900. after = node;
  12901. while (parent && parent.C) {
  12902. grandpa = parent.U;
  12903. if (parent === grandpa.L) {
  12904. uncle = grandpa.R;
  12905. if (uncle && uncle.C) {
  12906. parent.C = uncle.C = false;
  12907. grandpa.C = true;
  12908. after = grandpa;
  12909. } else {
  12910. if (after === parent.R) {
  12911. RedBlackRotateLeft(this, parent);
  12912. after = parent;
  12913. parent = after.U;
  12914. }
  12915. parent.C = false;
  12916. grandpa.C = true;
  12917. RedBlackRotateRight(this, grandpa);
  12918. }
  12919. } else {
  12920. uncle = grandpa.L;
  12921. if (uncle && uncle.C) {
  12922. parent.C = uncle.C = false;
  12923. grandpa.C = true;
  12924. after = grandpa;
  12925. } else {
  12926. if (after === parent.L) {
  12927. RedBlackRotateRight(this, parent);
  12928. after = parent;
  12929. parent = after.U;
  12930. }
  12931. parent.C = false;
  12932. grandpa.C = true;
  12933. RedBlackRotateLeft(this, grandpa);
  12934. }
  12935. }
  12936. parent = after.U;
  12937. }
  12938. this._.C = false;
  12939. },
  12940. remove: function(node) {
  12941. if (node.N) node.N.P = node.P;
  12942. if (node.P) node.P.N = node.N;
  12943. node.N = node.P = null;
  12944. var parent = node.U,
  12945. sibling,
  12946. left = node.L,
  12947. right = node.R,
  12948. next,
  12949. red;
  12950. if (!left) next = right;
  12951. else if (!right) next = left;
  12952. else next = RedBlackFirst(right);
  12953. if (parent) {
  12954. if (parent.L === node) parent.L = next;
  12955. else parent.R = next;
  12956. } else {
  12957. this._ = next;
  12958. }
  12959. if (left && right) {
  12960. red = next.C;
  12961. next.C = node.C;
  12962. next.L = left;
  12963. left.U = next;
  12964. if (next !== right) {
  12965. parent = next.U;
  12966. next.U = node.U;
  12967. node = next.R;
  12968. parent.L = node;
  12969. next.R = right;
  12970. right.U = next;
  12971. } else {
  12972. next.U = parent;
  12973. parent = next;
  12974. node = next.R;
  12975. }
  12976. } else {
  12977. red = node.C;
  12978. node = next;
  12979. }
  12980. if (node) node.U = parent;
  12981. if (red) return;
  12982. if (node && node.C) { node.C = false; return; }
  12983. do {
  12984. if (node === this._) break;
  12985. if (node === parent.L) {
  12986. sibling = parent.R;
  12987. if (sibling.C) {
  12988. sibling.C = false;
  12989. parent.C = true;
  12990. RedBlackRotateLeft(this, parent);
  12991. sibling = parent.R;
  12992. }
  12993. if ((sibling.L && sibling.L.C)
  12994. || (sibling.R && sibling.R.C)) {
  12995. if (!sibling.R || !sibling.R.C) {
  12996. sibling.L.C = false;
  12997. sibling.C = true;
  12998. RedBlackRotateRight(this, sibling);
  12999. sibling = parent.R;
  13000. }
  13001. sibling.C = parent.C;
  13002. parent.C = sibling.R.C = false;
  13003. RedBlackRotateLeft(this, parent);
  13004. node = this._;
  13005. break;
  13006. }
  13007. } else {
  13008. sibling = parent.L;
  13009. if (sibling.C) {
  13010. sibling.C = false;
  13011. parent.C = true;
  13012. RedBlackRotateRight(this, parent);
  13013. sibling = parent.L;
  13014. }
  13015. if ((sibling.L && sibling.L.C)
  13016. || (sibling.R && sibling.R.C)) {
  13017. if (!sibling.L || !sibling.L.C) {
  13018. sibling.R.C = false;
  13019. sibling.C = true;
  13020. RedBlackRotateLeft(this, sibling);
  13021. sibling = parent.L;
  13022. }
  13023. sibling.C = parent.C;
  13024. parent.C = sibling.L.C = false;
  13025. RedBlackRotateRight(this, parent);
  13026. node = this._;
  13027. break;
  13028. }
  13029. }
  13030. sibling.C = true;
  13031. node = parent;
  13032. parent = parent.U;
  13033. } while (!node.C);
  13034. if (node) node.C = false;
  13035. }
  13036. };
  13037. function RedBlackRotateLeft(tree, node) {
  13038. var p = node,
  13039. q = node.R,
  13040. parent = p.U;
  13041. if (parent) {
  13042. if (parent.L === p) parent.L = q;
  13043. else parent.R = q;
  13044. } else {
  13045. tree._ = q;
  13046. }
  13047. q.U = parent;
  13048. p.U = q;
  13049. p.R = q.L;
  13050. if (p.R) p.R.U = p;
  13051. q.L = p;
  13052. }
  13053. function RedBlackRotateRight(tree, node) {
  13054. var p = node,
  13055. q = node.L,
  13056. parent = p.U;
  13057. if (parent) {
  13058. if (parent.L === p) parent.L = q;
  13059. else parent.R = q;
  13060. } else {
  13061. tree._ = q;
  13062. }
  13063. q.U = parent;
  13064. p.U = q;
  13065. p.L = q.R;
  13066. if (p.L) p.L.U = p;
  13067. q.R = p;
  13068. }
  13069. function RedBlackFirst(node) {
  13070. while (node.L) node = node.L;
  13071. return node;
  13072. }
  13073. function createEdge(left, right, v0, v1) {
  13074. var edge = [null, null],
  13075. index = edges.push(edge) - 1;
  13076. edge.left = left;
  13077. edge.right = right;
  13078. if (v0) setEdgeEnd(edge, left, right, v0);
  13079. if (v1) setEdgeEnd(edge, right, left, v1);
  13080. cells[left.index].halfedges.push(index);
  13081. cells[right.index].halfedges.push(index);
  13082. return edge;
  13083. }
  13084. function createBorderEdge(left, v0, v1) {
  13085. var edge = [v0, v1];
  13086. edge.left = left;
  13087. return edge;
  13088. }
  13089. function setEdgeEnd(edge, left, right, vertex) {
  13090. if (!edge[0] && !edge[1]) {
  13091. edge[0] = vertex;
  13092. edge.left = left;
  13093. edge.right = right;
  13094. } else if (edge.left === right) {
  13095. edge[1] = vertex;
  13096. } else {
  13097. edge[0] = vertex;
  13098. }
  13099. }
  13100. // Liang–Barsky line clipping.
  13101. function clipEdge(edge, x0, y0, x1, y1) {
  13102. var a = edge[0],
  13103. b = edge[1],
  13104. ax = a[0],
  13105. ay = a[1],
  13106. bx = b[0],
  13107. by = b[1],
  13108. t0 = 0,
  13109. t1 = 1,
  13110. dx = bx - ax,
  13111. dy = by - ay,
  13112. r;
  13113. r = x0 - ax;
  13114. if (!dx && r > 0) return;
  13115. r /= dx;
  13116. if (dx < 0) {
  13117. if (r < t0) return;
  13118. if (r < t1) t1 = r;
  13119. } else if (dx > 0) {
  13120. if (r > t1) return;
  13121. if (r > t0) t0 = r;
  13122. }
  13123. r = x1 - ax;
  13124. if (!dx && r < 0) return;
  13125. r /= dx;
  13126. if (dx < 0) {
  13127. if (r > t1) return;
  13128. if (r > t0) t0 = r;
  13129. } else if (dx > 0) {
  13130. if (r < t0) return;
  13131. if (r < t1) t1 = r;
  13132. }
  13133. r = y0 - ay;
  13134. if (!dy && r > 0) return;
  13135. r /= dy;
  13136. if (dy < 0) {
  13137. if (r < t0) return;
  13138. if (r < t1) t1 = r;
  13139. } else if (dy > 0) {
  13140. if (r > t1) return;
  13141. if (r > t0) t0 = r;
  13142. }
  13143. r = y1 - ay;
  13144. if (!dy && r < 0) return;
  13145. r /= dy;
  13146. if (dy < 0) {
  13147. if (r > t1) return;
  13148. if (r > t0) t0 = r;
  13149. } else if (dy > 0) {
  13150. if (r < t0) return;
  13151. if (r < t1) t1 = r;
  13152. }
  13153. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  13154. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  13155. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  13156. return true;
  13157. }
  13158. function connectEdge(edge, x0, y0, x1, y1) {
  13159. var v1 = edge[1];
  13160. if (v1) return true;
  13161. var v0 = edge[0],
  13162. left = edge.left,
  13163. right = edge.right,
  13164. lx = left[0],
  13165. ly = left[1],
  13166. rx = right[0],
  13167. ry = right[1],
  13168. fx = (lx + rx) / 2,
  13169. fy = (ly + ry) / 2,
  13170. fm,
  13171. fb;
  13172. if (ry === ly) {
  13173. if (fx < x0 || fx >= x1) return;
  13174. if (lx > rx) {
  13175. if (!v0) v0 = [fx, y0];
  13176. else if (v0[1] >= y1) return;
  13177. v1 = [fx, y1];
  13178. } else {
  13179. if (!v0) v0 = [fx, y1];
  13180. else if (v0[1] < y0) return;
  13181. v1 = [fx, y0];
  13182. }
  13183. } else {
  13184. fm = (lx - rx) / (ry - ly);
  13185. fb = fy - fm * fx;
  13186. if (fm < -1 || fm > 1) {
  13187. if (lx > rx) {
  13188. if (!v0) v0 = [(y0 - fb) / fm, y0];
  13189. else if (v0[1] >= y1) return;
  13190. v1 = [(y1 - fb) / fm, y1];
  13191. } else {
  13192. if (!v0) v0 = [(y1 - fb) / fm, y1];
  13193. else if (v0[1] < y0) return;
  13194. v1 = [(y0 - fb) / fm, y0];
  13195. }
  13196. } else {
  13197. if (ly < ry) {
  13198. if (!v0) v0 = [x0, fm * x0 + fb];
  13199. else if (v0[0] >= x1) return;
  13200. v1 = [x1, fm * x1 + fb];
  13201. } else {
  13202. if (!v0) v0 = [x1, fm * x1 + fb];
  13203. else if (v0[0] < x0) return;
  13204. v1 = [x0, fm * x0 + fb];
  13205. }
  13206. }
  13207. }
  13208. edge[0] = v0;
  13209. edge[1] = v1;
  13210. return true;
  13211. }
  13212. function clipEdges(x0, y0, x1, y1) {
  13213. var i = edges.length,
  13214. edge;
  13215. while (i--) {
  13216. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  13217. || !clipEdge(edge, x0, y0, x1, y1)
  13218. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  13219. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  13220. delete edges[i];
  13221. }
  13222. }
  13223. }
  13224. function createCell(site) {
  13225. return cells[site.index] = {
  13226. site: site,
  13227. halfedges: []
  13228. };
  13229. }
  13230. function cellHalfedgeAngle(cell, edge) {
  13231. var site = cell.site,
  13232. va = edge.left,
  13233. vb = edge.right;
  13234. if (site === vb) vb = va, va = site;
  13235. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  13236. if (site === va) va = edge[1], vb = edge[0];
  13237. else va = edge[0], vb = edge[1];
  13238. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  13239. }
  13240. function cellHalfedgeStart(cell, edge) {
  13241. return edge[+(edge.left !== cell.site)];
  13242. }
  13243. function cellHalfedgeEnd(cell, edge) {
  13244. return edge[+(edge.left === cell.site)];
  13245. }
  13246. function sortCellHalfedges() {
  13247. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  13248. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  13249. var index = new Array(m),
  13250. array = new Array(m);
  13251. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  13252. index.sort(function(i, j) { return array[j] - array[i]; });
  13253. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  13254. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  13255. }
  13256. }
  13257. }
  13258. function clipCells(x0, y0, x1, y1) {
  13259. var nCells = cells.length,
  13260. iCell,
  13261. cell,
  13262. site,
  13263. iHalfedge,
  13264. halfedges,
  13265. nHalfedges,
  13266. start,
  13267. startX,
  13268. startY,
  13269. end,
  13270. endX,
  13271. endY,
  13272. cover = true;
  13273. for (iCell = 0; iCell < nCells; ++iCell) {
  13274. if (cell = cells[iCell]) {
  13275. site = cell.site;
  13276. halfedges = cell.halfedges;
  13277. iHalfedge = halfedges.length;
  13278. // Remove any dangling clipped edges.
  13279. while (iHalfedge--) {
  13280. if (!edges[halfedges[iHalfedge]]) {
  13281. halfedges.splice(iHalfedge, 1);
  13282. }
  13283. }
  13284. // Insert any border edges as necessary.
  13285. iHalfedge = 0, nHalfedges = halfedges.length;
  13286. while (iHalfedge < nHalfedges) {
  13287. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  13288. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  13289. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  13290. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  13291. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  13292. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  13293. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  13294. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  13295. : null)) - 1);
  13296. ++nHalfedges;
  13297. }
  13298. }
  13299. if (nHalfedges) cover = false;
  13300. }
  13301. }
  13302. // If there weren’t any edges, have the closest site cover the extent.
  13303. // It doesn’t matter which corner of the extent we measure!
  13304. if (cover) {
  13305. var dx, dy, d2, dc = Infinity;
  13306. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  13307. if (cell = cells[iCell]) {
  13308. site = cell.site;
  13309. dx = site[0] - x0;
  13310. dy = site[1] - y0;
  13311. d2 = dx * dx + dy * dy;
  13312. if (d2 < dc) dc = d2, cover = cell;
  13313. }
  13314. }
  13315. if (cover) {
  13316. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  13317. cover.halfedges.push(
  13318. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  13319. edges.push(createBorderEdge(site, v01, v11)) - 1,
  13320. edges.push(createBorderEdge(site, v11, v10)) - 1,
  13321. edges.push(createBorderEdge(site, v10, v00)) - 1
  13322. );
  13323. }
  13324. }
  13325. // Lastly delete any cells with no edges; these were entirely clipped.
  13326. for (iCell = 0; iCell < nCells; ++iCell) {
  13327. if (cell = cells[iCell]) {
  13328. if (!cell.halfedges.length) {
  13329. delete cells[iCell];
  13330. }
  13331. }
  13332. }
  13333. }
  13334. var circlePool = [];
  13335. var firstCircle;
  13336. function Circle() {
  13337. RedBlackNode(this);
  13338. this.x =
  13339. this.y =
  13340. this.arc =
  13341. this.site =
  13342. this.cy = null;
  13343. }
  13344. function attachCircle(arc) {
  13345. var lArc = arc.P,
  13346. rArc = arc.N;
  13347. if (!lArc || !rArc) return;
  13348. var lSite = lArc.site,
  13349. cSite = arc.site,
  13350. rSite = rArc.site;
  13351. if (lSite === rSite) return;
  13352. var bx = cSite[0],
  13353. by = cSite[1],
  13354. ax = lSite[0] - bx,
  13355. ay = lSite[1] - by,
  13356. cx = rSite[0] - bx,
  13357. cy = rSite[1] - by;
  13358. var d = 2 * (ax * cy - ay * cx);
  13359. if (d >= -epsilon2$2) return;
  13360. var ha = ax * ax + ay * ay,
  13361. hc = cx * cx + cy * cy,
  13362. x = (cy * ha - ay * hc) / d,
  13363. y = (ax * hc - cx * ha) / d;
  13364. var circle = circlePool.pop() || new Circle;
  13365. circle.arc = arc;
  13366. circle.site = cSite;
  13367. circle.x = x + bx;
  13368. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  13369. arc.circle = circle;
  13370. var before = null,
  13371. node = circles._;
  13372. while (node) {
  13373. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  13374. if (node.L) node = node.L;
  13375. else { before = node.P; break; }
  13376. } else {
  13377. if (node.R) node = node.R;
  13378. else { before = node; break; }
  13379. }
  13380. }
  13381. circles.insert(before, circle);
  13382. if (!before) firstCircle = circle;
  13383. }
  13384. function detachCircle(arc) {
  13385. var circle = arc.circle;
  13386. if (circle) {
  13387. if (!circle.P) firstCircle = circle.N;
  13388. circles.remove(circle);
  13389. circlePool.push(circle);
  13390. RedBlackNode(circle);
  13391. arc.circle = null;
  13392. }
  13393. }
  13394. var beachPool = [];
  13395. function Beach() {
  13396. RedBlackNode(this);
  13397. this.edge =
  13398. this.site =
  13399. this.circle = null;
  13400. }
  13401. function createBeach(site) {
  13402. var beach = beachPool.pop() || new Beach;
  13403. beach.site = site;
  13404. return beach;
  13405. }
  13406. function detachBeach(beach) {
  13407. detachCircle(beach);
  13408. beaches.remove(beach);
  13409. beachPool.push(beach);
  13410. RedBlackNode(beach);
  13411. }
  13412. function removeBeach(beach) {
  13413. var circle = beach.circle,
  13414. x = circle.x,
  13415. y = circle.cy,
  13416. vertex = [x, y],
  13417. previous = beach.P,
  13418. next = beach.N,
  13419. disappearing = [beach];
  13420. detachBeach(beach);
  13421. var lArc = previous;
  13422. while (lArc.circle
  13423. && Math.abs(x - lArc.circle.x) < epsilon$4
  13424. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  13425. previous = lArc.P;
  13426. disappearing.unshift(lArc);
  13427. detachBeach(lArc);
  13428. lArc = previous;
  13429. }
  13430. disappearing.unshift(lArc);
  13431. detachCircle(lArc);
  13432. var rArc = next;
  13433. while (rArc.circle
  13434. && Math.abs(x - rArc.circle.x) < epsilon$4
  13435. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  13436. next = rArc.N;
  13437. disappearing.push(rArc);
  13438. detachBeach(rArc);
  13439. rArc = next;
  13440. }
  13441. disappearing.push(rArc);
  13442. detachCircle(rArc);
  13443. var nArcs = disappearing.length,
  13444. iArc;
  13445. for (iArc = 1; iArc < nArcs; ++iArc) {
  13446. rArc = disappearing[iArc];
  13447. lArc = disappearing[iArc - 1];
  13448. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  13449. }
  13450. lArc = disappearing[0];
  13451. rArc = disappearing[nArcs - 1];
  13452. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  13453. attachCircle(lArc);
  13454. attachCircle(rArc);
  13455. }
  13456. function addBeach(site) {
  13457. var x = site[0],
  13458. directrix = site[1],
  13459. lArc,
  13460. rArc,
  13461. dxl,
  13462. dxr,
  13463. node = beaches._;
  13464. while (node) {
  13465. dxl = leftBreakPoint(node, directrix) - x;
  13466. if (dxl > epsilon$4) node = node.L; else {
  13467. dxr = x - rightBreakPoint(node, directrix);
  13468. if (dxr > epsilon$4) {
  13469. if (!node.R) {
  13470. lArc = node;
  13471. break;
  13472. }
  13473. node = node.R;
  13474. } else {
  13475. if (dxl > -epsilon$4) {
  13476. lArc = node.P;
  13477. rArc = node;
  13478. } else if (dxr > -epsilon$4) {
  13479. lArc = node;
  13480. rArc = node.N;
  13481. } else {
  13482. lArc = rArc = node;
  13483. }
  13484. break;
  13485. }
  13486. }
  13487. }
  13488. createCell(site);
  13489. var newArc = createBeach(site);
  13490. beaches.insert(lArc, newArc);
  13491. if (!lArc && !rArc) return;
  13492. if (lArc === rArc) {
  13493. detachCircle(lArc);
  13494. rArc = createBeach(lArc.site);
  13495. beaches.insert(newArc, rArc);
  13496. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  13497. attachCircle(lArc);
  13498. attachCircle(rArc);
  13499. return;
  13500. }
  13501. if (!rArc) { // && lArc
  13502. newArc.edge = createEdge(lArc.site, newArc.site);
  13503. return;
  13504. }
  13505. // else lArc !== rArc
  13506. detachCircle(lArc);
  13507. detachCircle(rArc);
  13508. var lSite = lArc.site,
  13509. ax = lSite[0],
  13510. ay = lSite[1],
  13511. bx = site[0] - ax,
  13512. by = site[1] - ay,
  13513. rSite = rArc.site,
  13514. cx = rSite[0] - ax,
  13515. cy = rSite[1] - ay,
  13516. d = 2 * (bx * cy - by * cx),
  13517. hb = bx * bx + by * by,
  13518. hc = cx * cx + cy * cy,
  13519. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  13520. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  13521. newArc.edge = createEdge(lSite, site, null, vertex);
  13522. rArc.edge = createEdge(site, rSite, null, vertex);
  13523. attachCircle(lArc);
  13524. attachCircle(rArc);
  13525. }
  13526. function leftBreakPoint(arc, directrix) {
  13527. var site = arc.site,
  13528. rfocx = site[0],
  13529. rfocy = site[1],
  13530. pby2 = rfocy - directrix;
  13531. if (!pby2) return rfocx;
  13532. var lArc = arc.P;
  13533. if (!lArc) return -Infinity;
  13534. site = lArc.site;
  13535. var lfocx = site[0],
  13536. lfocy = site[1],
  13537. plby2 = lfocy - directrix;
  13538. if (!plby2) return lfocx;
  13539. var hl = lfocx - rfocx,
  13540. aby2 = 1 / pby2 - 1 / plby2,
  13541. b = hl / plby2;
  13542. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  13543. return (rfocx + lfocx) / 2;
  13544. }
  13545. function rightBreakPoint(arc, directrix) {
  13546. var rArc = arc.N;
  13547. if (rArc) return leftBreakPoint(rArc, directrix);
  13548. var site = arc.site;
  13549. return site[1] === directrix ? site[0] : Infinity;
  13550. }
  13551. var epsilon$4 = 1e-6;
  13552. var epsilon2$2 = 1e-12;
  13553. var beaches;
  13554. var cells;
  13555. var circles;
  13556. var edges;
  13557. function triangleArea(a, b, c) {
  13558. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  13559. }
  13560. function lexicographic(a, b) {
  13561. return b[1] - a[1]
  13562. || b[0] - a[0];
  13563. }
  13564. function Diagram(sites, extent) {
  13565. var site = sites.sort(lexicographic).pop(),
  13566. x,
  13567. y,
  13568. circle;
  13569. edges = [];
  13570. cells = new Array(sites.length);
  13571. beaches = new RedBlackTree;
  13572. circles = new RedBlackTree;
  13573. while (true) {
  13574. circle = firstCircle;
  13575. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  13576. if (site[0] !== x || site[1] !== y) {
  13577. addBeach(site);
  13578. x = site[0], y = site[1];
  13579. }
  13580. site = sites.pop();
  13581. } else if (circle) {
  13582. removeBeach(circle.arc);
  13583. } else {
  13584. break;
  13585. }
  13586. }
  13587. sortCellHalfedges();
  13588. if (extent) {
  13589. var x0 = +extent[0][0],
  13590. y0 = +extent[0][1],
  13591. x1 = +extent[1][0],
  13592. y1 = +extent[1][1];
  13593. clipEdges(x0, y0, x1, y1);
  13594. clipCells(x0, y0, x1, y1);
  13595. }
  13596. this.edges = edges;
  13597. this.cells = cells;
  13598. beaches =
  13599. circles =
  13600. edges =
  13601. cells = null;
  13602. }
  13603. Diagram.prototype = {
  13604. constructor: Diagram,
  13605. polygons: function() {
  13606. var edges = this.edges;
  13607. return this.cells.map(function(cell) {
  13608. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  13609. polygon.data = cell.site.data;
  13610. return polygon;
  13611. });
  13612. },
  13613. triangles: function() {
  13614. var triangles = [],
  13615. edges = this.edges;
  13616. this.cells.forEach(function(cell, i) {
  13617. if (!(m = (halfedges = cell.halfedges).length)) return;
  13618. var site = cell.site,
  13619. halfedges,
  13620. j = -1,
  13621. m,
  13622. s0,
  13623. e1 = edges[halfedges[m - 1]],
  13624. s1 = e1.left === site ? e1.right : e1.left;
  13625. while (++j < m) {
  13626. s0 = s1;
  13627. e1 = edges[halfedges[j]];
  13628. s1 = e1.left === site ? e1.right : e1.left;
  13629. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  13630. triangles.push([site.data, s0.data, s1.data]);
  13631. }
  13632. }
  13633. });
  13634. return triangles;
  13635. },
  13636. links: function() {
  13637. return this.edges.filter(function(edge) {
  13638. return edge.right;
  13639. }).map(function(edge) {
  13640. return {
  13641. source: edge.left.data,
  13642. target: edge.right.data
  13643. };
  13644. });
  13645. },
  13646. find: function(x, y, radius) {
  13647. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  13648. // Use the previously-found cell, or start with an arbitrary one.
  13649. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  13650. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  13651. // Traverse the half-edges to find a closer cell, if any.
  13652. do {
  13653. cell = that.cells[i0 = i1], i1 = null;
  13654. cell.halfedges.forEach(function(e) {
  13655. var edge = that.edges[e], v = edge.left;
  13656. if ((v === cell.site || !v) && !(v = edge.right)) return;
  13657. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  13658. if (v2 < d2) d2 = v2, i1 = v.index;
  13659. });
  13660. } while (i1 !== null);
  13661. that._found = i0;
  13662. return radius == null || d2 <= radius * radius ? cell.site : null;
  13663. }
  13664. };
  13665. var voronoi = function() {
  13666. var x$$1 = x$4,
  13667. y$$1 = y$4,
  13668. extent = null;
  13669. function voronoi(data) {
  13670. return new Diagram(data.map(function(d, i) {
  13671. var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
  13672. s.index = i;
  13673. s.data = d;
  13674. return s;
  13675. }), extent);
  13676. }
  13677. voronoi.polygons = function(data) {
  13678. return voronoi(data).polygons();
  13679. };
  13680. voronoi.links = function(data) {
  13681. return voronoi(data).links();
  13682. };
  13683. voronoi.triangles = function(data) {
  13684. return voronoi(data).triangles();
  13685. };
  13686. voronoi.x = function(_) {
  13687. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : x$$1;
  13688. };
  13689. voronoi.y = function(_) {
  13690. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : y$$1;
  13691. };
  13692. voronoi.extent = function(_) {
  13693. 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]]];
  13694. };
  13695. voronoi.size = function(_) {
  13696. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  13697. };
  13698. return voronoi;
  13699. };
  13700. var constant$12 = function(x) {
  13701. return function() {
  13702. return x;
  13703. };
  13704. };
  13705. function ZoomEvent(target, type, transform) {
  13706. this.target = target;
  13707. this.type = type;
  13708. this.transform = transform;
  13709. }
  13710. function Transform(k, x, y) {
  13711. this.k = k;
  13712. this.x = x;
  13713. this.y = y;
  13714. }
  13715. Transform.prototype = {
  13716. constructor: Transform,
  13717. scale: function(k) {
  13718. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  13719. },
  13720. translate: function(x, y) {
  13721. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  13722. },
  13723. apply: function(point) {
  13724. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  13725. },
  13726. applyX: function(x) {
  13727. return x * this.k + this.x;
  13728. },
  13729. applyY: function(y) {
  13730. return y * this.k + this.y;
  13731. },
  13732. invert: function(location) {
  13733. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  13734. },
  13735. invertX: function(x) {
  13736. return (x - this.x) / this.k;
  13737. },
  13738. invertY: function(y) {
  13739. return (y - this.y) / this.k;
  13740. },
  13741. rescaleX: function(x) {
  13742. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  13743. },
  13744. rescaleY: function(y) {
  13745. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  13746. },
  13747. toString: function() {
  13748. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  13749. }
  13750. };
  13751. var identity$8 = new Transform(1, 0, 0);
  13752. transform$1.prototype = Transform.prototype;
  13753. function transform$1(node) {
  13754. return node.__zoom || identity$8;
  13755. }
  13756. function nopropagation$2() {
  13757. exports.event.stopImmediatePropagation();
  13758. }
  13759. var noevent$2 = function() {
  13760. exports.event.preventDefault();
  13761. exports.event.stopImmediatePropagation();
  13762. };
  13763. // Ignore right-click, since that should open the context menu.
  13764. function defaultFilter$2() {
  13765. return !exports.event.button;
  13766. }
  13767. function defaultExtent$1() {
  13768. var e = this, w, h;
  13769. if (e instanceof SVGElement) {
  13770. e = e.ownerSVGElement || e;
  13771. w = e.width.baseVal.value;
  13772. h = e.height.baseVal.value;
  13773. } else {
  13774. w = e.clientWidth;
  13775. h = e.clientHeight;
  13776. }
  13777. return [[0, 0], [w, h]];
  13778. }
  13779. function defaultTransform() {
  13780. return this.__zoom || identity$8;
  13781. }
  13782. function defaultWheelDelta() {
  13783. return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
  13784. }
  13785. function defaultTouchable$1() {
  13786. return "ontouchstart" in this;
  13787. }
  13788. var zoom = function() {
  13789. var filter = defaultFilter$2,
  13790. extent = defaultExtent$1,
  13791. wheelDelta = defaultWheelDelta,
  13792. touchable = defaultTouchable$1,
  13793. k0 = 0,
  13794. k1 = Infinity,
  13795. x0 = -k1,
  13796. x1 = k1,
  13797. y0 = x0,
  13798. y1 = x1,
  13799. duration = 250,
  13800. interpolate = interpolateZoom,
  13801. gestures = [],
  13802. listeners = dispatch("start", "zoom", "end"),
  13803. touchstarting,
  13804. touchending,
  13805. touchDelay = 500,
  13806. wheelDelay = 150,
  13807. clickDistance2 = 0;
  13808. function zoom(selection) {
  13809. selection
  13810. .property("__zoom", defaultTransform)
  13811. .on("wheel.zoom", wheeled)
  13812. .on("mousedown.zoom", mousedowned)
  13813. .on("dblclick.zoom", dblclicked)
  13814. .filter(touchable)
  13815. .on("touchstart.zoom", touchstarted)
  13816. .on("touchmove.zoom", touchmoved)
  13817. .on("touchend.zoom touchcancel.zoom", touchended)
  13818. .style("touch-action", "none")
  13819. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  13820. }
  13821. zoom.transform = function(collection, transform$$1) {
  13822. var selection = collection.selection ? collection.selection() : collection;
  13823. selection.property("__zoom", defaultTransform);
  13824. if (collection !== selection) {
  13825. schedule(collection, transform$$1);
  13826. } else {
  13827. selection.interrupt().each(function() {
  13828. gesture(this, arguments)
  13829. .start()
  13830. .zoom(null, typeof transform$$1 === "function" ? transform$$1.apply(this, arguments) : transform$$1)
  13831. .end();
  13832. });
  13833. }
  13834. };
  13835. zoom.scaleBy = function(selection, k) {
  13836. zoom.scaleTo(selection, function() {
  13837. var k0 = this.__zoom.k,
  13838. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  13839. return k0 * k1;
  13840. });
  13841. };
  13842. zoom.scaleTo = function(selection, k) {
  13843. zoom.transform(selection, function() {
  13844. var e = extent.apply(this, arguments),
  13845. t0 = this.__zoom,
  13846. p0 = centroid(e),
  13847. p1 = t0.invert(p0),
  13848. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  13849. return constrain(translate(scale(t0, k1), p0, p1), e);
  13850. });
  13851. };
  13852. zoom.translateBy = function(selection, x, y) {
  13853. zoom.transform(selection, function() {
  13854. return constrain(this.__zoom.translate(
  13855. typeof x === "function" ? x.apply(this, arguments) : x,
  13856. typeof y === "function" ? y.apply(this, arguments) : y
  13857. ), extent.apply(this, arguments));
  13858. });
  13859. };
  13860. zoom.translateTo = function(selection, x, y) {
  13861. zoom.transform(selection, function() {
  13862. var e = extent.apply(this, arguments),
  13863. t = this.__zoom,
  13864. p = centroid(e);
  13865. return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
  13866. typeof x === "function" ? -x.apply(this, arguments) : -x,
  13867. typeof y === "function" ? -y.apply(this, arguments) : -y
  13868. ), e);
  13869. });
  13870. };
  13871. function scale(transform$$1, k) {
  13872. k = Math.max(k0, Math.min(k1, k));
  13873. return k === transform$$1.k ? transform$$1 : new Transform(k, transform$$1.x, transform$$1.y);
  13874. }
  13875. function translate(transform$$1, p0, p1) {
  13876. var x = p0[0] - p1[0] * transform$$1.k, y = p0[1] - p1[1] * transform$$1.k;
  13877. return x === transform$$1.x && y === transform$$1.y ? transform$$1 : new Transform(transform$$1.k, x, y);
  13878. }
  13879. function constrain(transform$$1, extent) {
  13880. var dx0 = transform$$1.invertX(extent[0][0]) - x0,
  13881. dx1 = transform$$1.invertX(extent[1][0]) - x1,
  13882. dy0 = transform$$1.invertY(extent[0][1]) - y0,
  13883. dy1 = transform$$1.invertY(extent[1][1]) - y1;
  13884. return transform$$1.translate(
  13885. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  13886. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  13887. );
  13888. }
  13889. function centroid(extent) {
  13890. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  13891. }
  13892. function schedule(transition, transform$$1, center) {
  13893. transition
  13894. .on("start.zoom", function() { gesture(this, arguments).start(); })
  13895. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  13896. .tween("zoom", function() {
  13897. var that = this,
  13898. args = arguments,
  13899. g = gesture(that, args),
  13900. e = extent.apply(that, args),
  13901. p = center || centroid(e),
  13902. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  13903. a = that.__zoom,
  13904. b = typeof transform$$1 === "function" ? transform$$1.apply(that, args) : transform$$1,
  13905. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  13906. return function(t) {
  13907. if (t === 1) t = b; // Avoid rounding error on end.
  13908. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  13909. g.zoom(null, t);
  13910. };
  13911. });
  13912. }
  13913. function gesture(that, args) {
  13914. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  13915. if ((g = gestures[i]).that === that) {
  13916. return g;
  13917. }
  13918. }
  13919. return new Gesture(that, args);
  13920. }
  13921. function Gesture(that, args) {
  13922. this.that = that;
  13923. this.args = args;
  13924. this.index = -1;
  13925. this.active = 0;
  13926. this.extent = extent.apply(that, args);
  13927. }
  13928. Gesture.prototype = {
  13929. start: function() {
  13930. if (++this.active === 1) {
  13931. this.index = gestures.push(this) - 1;
  13932. this.emit("start");
  13933. }
  13934. return this;
  13935. },
  13936. zoom: function(key, transform$$1) {
  13937. if (this.mouse && key !== "mouse") this.mouse[1] = transform$$1.invert(this.mouse[0]);
  13938. if (this.touch0 && key !== "touch") this.touch0[1] = transform$$1.invert(this.touch0[0]);
  13939. if (this.touch1 && key !== "touch") this.touch1[1] = transform$$1.invert(this.touch1[0]);
  13940. this.that.__zoom = transform$$1;
  13941. this.emit("zoom");
  13942. return this;
  13943. },
  13944. end: function() {
  13945. if (--this.active === 0) {
  13946. gestures.splice(this.index, 1);
  13947. this.index = -1;
  13948. this.emit("end");
  13949. }
  13950. return this;
  13951. },
  13952. emit: function(type) {
  13953. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  13954. }
  13955. };
  13956. function wheeled() {
  13957. if (!filter.apply(this, arguments)) return;
  13958. var g = gesture(this, arguments),
  13959. t = this.__zoom,
  13960. k = Math.max(k0, Math.min(k1, t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  13961. p = mouse(this);
  13962. // If the mouse is in the same location as before, reuse it.
  13963. // If there were recent wheel events, reset the wheel idle timeout.
  13964. if (g.wheel) {
  13965. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  13966. g.mouse[1] = t.invert(g.mouse[0] = p);
  13967. }
  13968. clearTimeout(g.wheel);
  13969. }
  13970. // If this wheel event won’t trigger a transform change, ignore it.
  13971. else if (t.k === k) return;
  13972. // Otherwise, capture the mouse point and location at the start.
  13973. else {
  13974. g.mouse = [p, t.invert(p)];
  13975. interrupt(this);
  13976. g.start();
  13977. }
  13978. noevent$2();
  13979. g.wheel = setTimeout(wheelidled, wheelDelay);
  13980. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent));
  13981. function wheelidled() {
  13982. g.wheel = null;
  13983. g.end();
  13984. }
  13985. }
  13986. function mousedowned() {
  13987. if (touchending || !filter.apply(this, arguments)) return;
  13988. var g = gesture(this, arguments),
  13989. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  13990. p = mouse(this),
  13991. x0 = exports.event.clientX,
  13992. y0 = exports.event.clientY;
  13993. dragDisable(exports.event.view);
  13994. nopropagation$2();
  13995. g.mouse = [p, this.__zoom.invert(p)];
  13996. interrupt(this);
  13997. g.start();
  13998. function mousemoved() {
  13999. noevent$2();
  14000. if (!g.moved) {
  14001. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  14002. g.moved = dx * dx + dy * dy > clickDistance2;
  14003. }
  14004. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent));
  14005. }
  14006. function mouseupped() {
  14007. v.on("mousemove.zoom mouseup.zoom", null);
  14008. yesdrag(exports.event.view, g.moved);
  14009. noevent$2();
  14010. g.end();
  14011. }
  14012. }
  14013. function dblclicked() {
  14014. if (!filter.apply(this, arguments)) return;
  14015. var t0 = this.__zoom,
  14016. p0 = mouse(this),
  14017. p1 = t0.invert(p0),
  14018. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  14019. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments));
  14020. noevent$2();
  14021. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  14022. else select(this).call(zoom.transform, t1);
  14023. }
  14024. function touchstarted() {
  14025. if (!filter.apply(this, arguments)) return;
  14026. var g = gesture(this, arguments),
  14027. touches = exports.event.changedTouches,
  14028. started,
  14029. n = touches.length, i, t, p;
  14030. nopropagation$2();
  14031. for (i = 0; i < n; ++i) {
  14032. t = touches[i], p = touch(this, touches, t.identifier);
  14033. p = [p, this.__zoom.invert(p), t.identifier];
  14034. if (!g.touch0) g.touch0 = p, started = true;
  14035. else if (!g.touch1) g.touch1 = p;
  14036. }
  14037. // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
  14038. if (touchstarting) {
  14039. touchstarting = clearTimeout(touchstarting);
  14040. if (!g.touch1) {
  14041. g.end();
  14042. p = select(this).on("dblclick.zoom");
  14043. if (p) p.apply(this, arguments);
  14044. return;
  14045. }
  14046. }
  14047. if (started) {
  14048. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  14049. interrupt(this);
  14050. g.start();
  14051. }
  14052. }
  14053. function touchmoved() {
  14054. var g = gesture(this, arguments),
  14055. touches = exports.event.changedTouches,
  14056. n = touches.length, i, t, p, l;
  14057. noevent$2();
  14058. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  14059. for (i = 0; i < n; ++i) {
  14060. t = touches[i], p = touch(this, touches, t.identifier);
  14061. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  14062. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  14063. }
  14064. t = g.that.__zoom;
  14065. if (g.touch1) {
  14066. var p0 = g.touch0[0], l0 = g.touch0[1],
  14067. p1 = g.touch1[0], l1 = g.touch1[1],
  14068. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  14069. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  14070. t = scale(t, Math.sqrt(dp / dl));
  14071. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  14072. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  14073. }
  14074. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  14075. else return;
  14076. g.zoom("touch", constrain(translate(t, p, l), g.extent));
  14077. }
  14078. function touchended() {
  14079. var g = gesture(this, arguments),
  14080. touches = exports.event.changedTouches,
  14081. n = touches.length, i, t;
  14082. nopropagation$2();
  14083. if (touchending) clearTimeout(touchending);
  14084. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  14085. for (i = 0; i < n; ++i) {
  14086. t = touches[i];
  14087. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  14088. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  14089. }
  14090. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  14091. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  14092. else g.end();
  14093. }
  14094. zoom.wheelDelta = function(_) {
  14095. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$12(+_), zoom) : wheelDelta;
  14096. };
  14097. zoom.filter = function(_) {
  14098. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$12(!!_), zoom) : filter;
  14099. };
  14100. zoom.touchable = function(_) {
  14101. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$12(!!_), zoom) : touchable;
  14102. };
  14103. zoom.extent = function(_) {
  14104. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$12([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  14105. };
  14106. zoom.scaleExtent = function(_) {
  14107. return arguments.length ? (k0 = +_[0], k1 = +_[1], zoom) : [k0, k1];
  14108. };
  14109. zoom.translateExtent = function(_) {
  14110. return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], zoom) : [[x0, y0], [x1, y1]];
  14111. };
  14112. zoom.duration = function(_) {
  14113. return arguments.length ? (duration = +_, zoom) : duration;
  14114. };
  14115. zoom.interpolate = function(_) {
  14116. return arguments.length ? (interpolate = _, zoom) : interpolate;
  14117. };
  14118. zoom.on = function() {
  14119. var value = listeners.on.apply(listeners, arguments);
  14120. return value === listeners ? zoom : value;
  14121. };
  14122. zoom.clickDistance = function(_) {
  14123. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  14124. };
  14125. return zoom;
  14126. };
  14127. exports.version = version;
  14128. exports.bisect = bisectRight;
  14129. exports.bisectRight = bisectRight;
  14130. exports.bisectLeft = bisectLeft;
  14131. exports.ascending = ascending;
  14132. exports.bisector = bisector;
  14133. exports.cross = cross;
  14134. exports.descending = descending;
  14135. exports.deviation = deviation;
  14136. exports.extent = extent;
  14137. exports.histogram = histogram;
  14138. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  14139. exports.thresholdScott = scott;
  14140. exports.thresholdSturges = sturges;
  14141. exports.max = max;
  14142. exports.mean = mean;
  14143. exports.median = median;
  14144. exports.merge = merge;
  14145. exports.min = min;
  14146. exports.pairs = pairs;
  14147. exports.permute = permute;
  14148. exports.quantile = threshold;
  14149. exports.range = sequence;
  14150. exports.scan = scan;
  14151. exports.shuffle = shuffle;
  14152. exports.sum = sum;
  14153. exports.ticks = ticks;
  14154. exports.tickIncrement = tickIncrement;
  14155. exports.tickStep = tickStep;
  14156. exports.transpose = transpose;
  14157. exports.variance = variance;
  14158. exports.zip = zip;
  14159. exports.axisTop = axisTop;
  14160. exports.axisRight = axisRight;
  14161. exports.axisBottom = axisBottom;
  14162. exports.axisLeft = axisLeft;
  14163. exports.brush = brush;
  14164. exports.brushX = brushX;
  14165. exports.brushY = brushY;
  14166. exports.brushSelection = brushSelection;
  14167. exports.chord = chord;
  14168. exports.ribbon = ribbon;
  14169. exports.nest = nest;
  14170. exports.set = set$2;
  14171. exports.map = map$1;
  14172. exports.keys = keys;
  14173. exports.values = values;
  14174. exports.entries = entries;
  14175. exports.color = color;
  14176. exports.rgb = rgb;
  14177. exports.hsl = hsl;
  14178. exports.lab = lab;
  14179. exports.hcl = hcl;
  14180. exports.cubehelix = cubehelix;
  14181. exports.dispatch = dispatch;
  14182. exports.drag = drag;
  14183. exports.dragDisable = dragDisable;
  14184. exports.dragEnable = yesdrag;
  14185. exports.dsvFormat = dsv;
  14186. exports.csvParse = csvParse;
  14187. exports.csvParseRows = csvParseRows;
  14188. exports.csvFormat = csvFormat;
  14189. exports.csvFormatRows = csvFormatRows;
  14190. exports.tsvParse = tsvParse;
  14191. exports.tsvParseRows = tsvParseRows;
  14192. exports.tsvFormat = tsvFormat;
  14193. exports.tsvFormatRows = tsvFormatRows;
  14194. exports.easeLinear = linear$1;
  14195. exports.easeQuad = quadInOut;
  14196. exports.easeQuadIn = quadIn;
  14197. exports.easeQuadOut = quadOut;
  14198. exports.easeQuadInOut = quadInOut;
  14199. exports.easeCubic = cubicInOut;
  14200. exports.easeCubicIn = cubicIn;
  14201. exports.easeCubicOut = cubicOut;
  14202. exports.easeCubicInOut = cubicInOut;
  14203. exports.easePoly = polyInOut;
  14204. exports.easePolyIn = polyIn;
  14205. exports.easePolyOut = polyOut;
  14206. exports.easePolyInOut = polyInOut;
  14207. exports.easeSin = sinInOut;
  14208. exports.easeSinIn = sinIn;
  14209. exports.easeSinOut = sinOut;
  14210. exports.easeSinInOut = sinInOut;
  14211. exports.easeExp = expInOut;
  14212. exports.easeExpIn = expIn;
  14213. exports.easeExpOut = expOut;
  14214. exports.easeExpInOut = expInOut;
  14215. exports.easeCircle = circleInOut;
  14216. exports.easeCircleIn = circleIn;
  14217. exports.easeCircleOut = circleOut;
  14218. exports.easeCircleInOut = circleInOut;
  14219. exports.easeBounce = bounceOut;
  14220. exports.easeBounceIn = bounceIn;
  14221. exports.easeBounceOut = bounceOut;
  14222. exports.easeBounceInOut = bounceInOut;
  14223. exports.easeBack = backInOut;
  14224. exports.easeBackIn = backIn;
  14225. exports.easeBackOut = backOut;
  14226. exports.easeBackInOut = backInOut;
  14227. exports.easeElastic = elasticOut;
  14228. exports.easeElasticIn = elasticIn;
  14229. exports.easeElasticOut = elasticOut;
  14230. exports.easeElasticInOut = elasticInOut;
  14231. exports.forceCenter = center$1;
  14232. exports.forceCollide = collide;
  14233. exports.forceLink = link;
  14234. exports.forceManyBody = manyBody;
  14235. exports.forceRadial = radial;
  14236. exports.forceSimulation = simulation;
  14237. exports.forceX = x$2;
  14238. exports.forceY = y$2;
  14239. exports.formatDefaultLocale = defaultLocale;
  14240. exports.formatLocale = formatLocale;
  14241. exports.formatSpecifier = formatSpecifier;
  14242. exports.precisionFixed = precisionFixed;
  14243. exports.precisionPrefix = precisionPrefix;
  14244. exports.precisionRound = precisionRound;
  14245. exports.geoArea = area;
  14246. exports.geoBounds = bounds;
  14247. exports.geoCentroid = centroid;
  14248. exports.geoCircle = circle;
  14249. exports.geoClipAntimeridian = clipAntimeridian;
  14250. exports.geoClipCircle = clipCircle;
  14251. exports.geoClipExtent = extent$1;
  14252. exports.geoClipRectangle = clipRectangle;
  14253. exports.geoContains = contains;
  14254. exports.geoDistance = distance;
  14255. exports.geoGraticule = graticule;
  14256. exports.geoGraticule10 = graticule10;
  14257. exports.geoInterpolate = interpolate$1;
  14258. exports.geoLength = length$1;
  14259. exports.geoPath = index$1;
  14260. exports.geoAlbers = albers;
  14261. exports.geoAlbersUsa = albersUsa;
  14262. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  14263. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  14264. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  14265. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  14266. exports.geoConicConformal = conicConformal;
  14267. exports.geoConicConformalRaw = conicConformalRaw;
  14268. exports.geoConicEqualArea = conicEqualArea;
  14269. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  14270. exports.geoConicEquidistant = conicEquidistant;
  14271. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  14272. exports.geoEquirectangular = equirectangular;
  14273. exports.geoEquirectangularRaw = equirectangularRaw;
  14274. exports.geoGnomonic = gnomonic;
  14275. exports.geoGnomonicRaw = gnomonicRaw;
  14276. exports.geoIdentity = identity$5;
  14277. exports.geoProjection = projection;
  14278. exports.geoProjectionMutator = projectionMutator;
  14279. exports.geoMercator = mercator;
  14280. exports.geoMercatorRaw = mercatorRaw;
  14281. exports.geoNaturalEarth1 = naturalEarth1;
  14282. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  14283. exports.geoOrthographic = orthographic;
  14284. exports.geoOrthographicRaw = orthographicRaw;
  14285. exports.geoStereographic = stereographic;
  14286. exports.geoStereographicRaw = stereographicRaw;
  14287. exports.geoTransverseMercator = transverseMercator;
  14288. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  14289. exports.geoRotation = rotation;
  14290. exports.geoStream = geoStream;
  14291. exports.geoTransform = transform;
  14292. exports.cluster = cluster;
  14293. exports.hierarchy = hierarchy;
  14294. exports.pack = index$2;
  14295. exports.packSiblings = siblings;
  14296. exports.packEnclose = enclose;
  14297. exports.partition = partition;
  14298. exports.stratify = stratify;
  14299. exports.tree = tree;
  14300. exports.treemap = index$3;
  14301. exports.treemapBinary = binary;
  14302. exports.treemapDice = treemapDice;
  14303. exports.treemapSlice = treemapSlice;
  14304. exports.treemapSliceDice = sliceDice;
  14305. exports.treemapSquarify = squarify;
  14306. exports.treemapResquarify = resquarify;
  14307. exports.interpolate = interpolateValue;
  14308. exports.interpolateArray = array$1;
  14309. exports.interpolateBasis = basis$1;
  14310. exports.interpolateBasisClosed = basisClosed;
  14311. exports.interpolateDate = date;
  14312. exports.interpolateNumber = reinterpolate;
  14313. exports.interpolateObject = object;
  14314. exports.interpolateRound = interpolateRound;
  14315. exports.interpolateString = interpolateString;
  14316. exports.interpolateTransformCss = interpolateTransformCss;
  14317. exports.interpolateTransformSvg = interpolateTransformSvg;
  14318. exports.interpolateZoom = interpolateZoom;
  14319. exports.interpolateRgb = interpolateRgb;
  14320. exports.interpolateRgbBasis = rgbBasis;
  14321. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  14322. exports.interpolateHsl = hsl$2;
  14323. exports.interpolateHslLong = hslLong;
  14324. exports.interpolateLab = lab$1;
  14325. exports.interpolateHcl = hcl$2;
  14326. exports.interpolateHclLong = hclLong;
  14327. exports.interpolateCubehelix = cubehelix$2;
  14328. exports.interpolateCubehelixLong = cubehelixLong;
  14329. exports.quantize = quantize;
  14330. exports.path = path;
  14331. exports.polygonArea = area$1;
  14332. exports.polygonCentroid = centroid$1;
  14333. exports.polygonHull = hull;
  14334. exports.polygonContains = contains$1;
  14335. exports.polygonLength = length$2;
  14336. exports.quadtree = quadtree;
  14337. exports.queue = queue;
  14338. exports.randomUniform = uniform;
  14339. exports.randomNormal = normal;
  14340. exports.randomLogNormal = logNormal;
  14341. exports.randomBates = bates;
  14342. exports.randomIrwinHall = irwinHall;
  14343. exports.randomExponential = exponential$1;
  14344. exports.request = request;
  14345. exports.html = html;
  14346. exports.json = json;
  14347. exports.text = text;
  14348. exports.xml = xml;
  14349. exports.csv = csv$1;
  14350. exports.tsv = tsv$1;
  14351. exports.scaleBand = band;
  14352. exports.scalePoint = point$1;
  14353. exports.scaleIdentity = identity$6;
  14354. exports.scaleLinear = linear$2;
  14355. exports.scaleLog = log$1;
  14356. exports.scaleOrdinal = ordinal;
  14357. exports.scaleImplicit = implicit;
  14358. exports.scalePow = pow$1;
  14359. exports.scaleSqrt = sqrt$1;
  14360. exports.scaleQuantile = quantile$$1;
  14361. exports.scaleQuantize = quantize$1;
  14362. exports.scaleThreshold = threshold$1;
  14363. exports.scaleTime = time;
  14364. exports.scaleUtc = utcTime;
  14365. exports.schemeCategory10 = category10;
  14366. exports.schemeCategory20b = category20b;
  14367. exports.schemeCategory20c = category20c;
  14368. exports.schemeCategory20 = category20;
  14369. exports.interpolateCubehelixDefault = cubehelix$3;
  14370. exports.interpolateRainbow = rainbow$1;
  14371. exports.interpolateWarm = warm;
  14372. exports.interpolateCool = cool;
  14373. exports.interpolateViridis = viridis;
  14374. exports.interpolateMagma = magma;
  14375. exports.interpolateInferno = inferno;
  14376. exports.interpolatePlasma = plasma;
  14377. exports.scaleSequential = sequential;
  14378. exports.creator = creator;
  14379. exports.local = local$1;
  14380. exports.matcher = matcher$1;
  14381. exports.mouse = mouse;
  14382. exports.namespace = namespace;
  14383. exports.namespaces = namespaces;
  14384. exports.select = select;
  14385. exports.selectAll = selectAll;
  14386. exports.selection = selection;
  14387. exports.selector = selector;
  14388. exports.selectorAll = selectorAll;
  14389. exports.style = styleValue;
  14390. exports.touch = touch;
  14391. exports.touches = touches;
  14392. exports.window = defaultView;
  14393. exports.customEvent = customEvent;
  14394. exports.arc = arc;
  14395. exports.area = area$2;
  14396. exports.line = line;
  14397. exports.pie = pie;
  14398. exports.areaRadial = areaRadial;
  14399. exports.radialArea = areaRadial;
  14400. exports.lineRadial = lineRadial$1;
  14401. exports.radialLine = lineRadial$1;
  14402. exports.pointRadial = pointRadial;
  14403. exports.linkHorizontal = linkHorizontal;
  14404. exports.linkVertical = linkVertical;
  14405. exports.linkRadial = linkRadial;
  14406. exports.symbol = symbol;
  14407. exports.symbols = symbols;
  14408. exports.symbolCircle = circle$2;
  14409. exports.symbolCross = cross$2;
  14410. exports.symbolDiamond = diamond;
  14411. exports.symbolSquare = square;
  14412. exports.symbolStar = star;
  14413. exports.symbolTriangle = triangle;
  14414. exports.symbolWye = wye;
  14415. exports.curveBasisClosed = basisClosed$1;
  14416. exports.curveBasisOpen = basisOpen;
  14417. exports.curveBasis = basis$2;
  14418. exports.curveBundle = bundle;
  14419. exports.curveCardinalClosed = cardinalClosed;
  14420. exports.curveCardinalOpen = cardinalOpen;
  14421. exports.curveCardinal = cardinal;
  14422. exports.curveCatmullRomClosed = catmullRomClosed;
  14423. exports.curveCatmullRomOpen = catmullRomOpen;
  14424. exports.curveCatmullRom = catmullRom;
  14425. exports.curveLinearClosed = linearClosed;
  14426. exports.curveLinear = curveLinear;
  14427. exports.curveMonotoneX = monotoneX;
  14428. exports.curveMonotoneY = monotoneY;
  14429. exports.curveNatural = natural;
  14430. exports.curveStep = step;
  14431. exports.curveStepAfter = stepAfter;
  14432. exports.curveStepBefore = stepBefore;
  14433. exports.stack = stack;
  14434. exports.stackOffsetExpand = expand;
  14435. exports.stackOffsetDiverging = diverging;
  14436. exports.stackOffsetNone = none$1;
  14437. exports.stackOffsetSilhouette = silhouette;
  14438. exports.stackOffsetWiggle = wiggle;
  14439. exports.stackOrderAscending = ascending$2;
  14440. exports.stackOrderDescending = descending$2;
  14441. exports.stackOrderInsideOut = insideOut;
  14442. exports.stackOrderNone = none$2;
  14443. exports.stackOrderReverse = reverse;
  14444. exports.timeInterval = newInterval;
  14445. exports.timeMillisecond = millisecond;
  14446. exports.timeMilliseconds = milliseconds;
  14447. exports.utcMillisecond = millisecond;
  14448. exports.utcMilliseconds = milliseconds;
  14449. exports.timeSecond = second;
  14450. exports.timeSeconds = seconds;
  14451. exports.utcSecond = second;
  14452. exports.utcSeconds = seconds;
  14453. exports.timeMinute = minute;
  14454. exports.timeMinutes = minutes;
  14455. exports.timeHour = hour;
  14456. exports.timeHours = hours;
  14457. exports.timeDay = day;
  14458. exports.timeDays = days;
  14459. exports.timeWeek = sunday;
  14460. exports.timeWeeks = sundays;
  14461. exports.timeSunday = sunday;
  14462. exports.timeSundays = sundays;
  14463. exports.timeMonday = monday;
  14464. exports.timeMondays = mondays;
  14465. exports.timeTuesday = tuesday;
  14466. exports.timeTuesdays = tuesdays;
  14467. exports.timeWednesday = wednesday;
  14468. exports.timeWednesdays = wednesdays;
  14469. exports.timeThursday = thursday;
  14470. exports.timeThursdays = thursdays;
  14471. exports.timeFriday = friday;
  14472. exports.timeFridays = fridays;
  14473. exports.timeSaturday = saturday;
  14474. exports.timeSaturdays = saturdays;
  14475. exports.timeMonth = month;
  14476. exports.timeMonths = months;
  14477. exports.timeYear = year;
  14478. exports.timeYears = years;
  14479. exports.utcMinute = utcMinute;
  14480. exports.utcMinutes = utcMinutes;
  14481. exports.utcHour = utcHour;
  14482. exports.utcHours = utcHours;
  14483. exports.utcDay = utcDay;
  14484. exports.utcDays = utcDays;
  14485. exports.utcWeek = utcSunday;
  14486. exports.utcWeeks = utcSundays;
  14487. exports.utcSunday = utcSunday;
  14488. exports.utcSundays = utcSundays;
  14489. exports.utcMonday = utcMonday;
  14490. exports.utcMondays = utcMondays;
  14491. exports.utcTuesday = utcTuesday;
  14492. exports.utcTuesdays = utcTuesdays;
  14493. exports.utcWednesday = utcWednesday;
  14494. exports.utcWednesdays = utcWednesdays;
  14495. exports.utcThursday = utcThursday;
  14496. exports.utcThursdays = utcThursdays;
  14497. exports.utcFriday = utcFriday;
  14498. exports.utcFridays = utcFridays;
  14499. exports.utcSaturday = utcSaturday;
  14500. exports.utcSaturdays = utcSaturdays;
  14501. exports.utcMonth = utcMonth;
  14502. exports.utcMonths = utcMonths;
  14503. exports.utcYear = utcYear;
  14504. exports.utcYears = utcYears;
  14505. exports.timeFormatDefaultLocale = defaultLocale$1;
  14506. exports.timeFormatLocale = formatLocale$1;
  14507. exports.isoFormat = formatIso;
  14508. exports.isoParse = parseIso;
  14509. exports.now = now;
  14510. exports.timer = timer;
  14511. exports.timerFlush = timerFlush;
  14512. exports.timeout = timeout$1;
  14513. exports.interval = interval$1;
  14514. exports.transition = transition;
  14515. exports.active = active;
  14516. exports.interrupt = interrupt;
  14517. exports.voronoi = voronoi;
  14518. exports.zoom = zoom;
  14519. exports.zoomTransform = transform$1;
  14520. exports.zoomIdentity = identity$8;
  14521. Object.defineProperty(exports, '__esModule', { value: true });
  14522. })));