d3.v4.js 461 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178
  1. // https://d3js.org Version 4.13.0. Copyright 2018 Mike Bostock.
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (factory((global.d3 = global.d3 || {})));
  6. }(this, (function (exports) { 'use strict';
  7. var version = "4.13.0";
  8. function ascending(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function bisector(compare) {
  12. if (compare.length === 1) compare = ascendingComparator(compare);
  13. return {
  14. left: function(a, x, lo, hi) {
  15. if (lo == null) lo = 0;
  16. if (hi == null) hi = a.length;
  17. while (lo < hi) {
  18. var mid = lo + hi >>> 1;
  19. if (compare(a[mid], x) < 0) lo = mid + 1;
  20. else hi = mid;
  21. }
  22. return lo;
  23. },
  24. right: function(a, x, lo, hi) {
  25. if (lo == null) lo = 0;
  26. if (hi == null) hi = a.length;
  27. while (lo < hi) {
  28. var mid = lo + hi >>> 1;
  29. if (compare(a[mid], x) > 0) hi = mid;
  30. else lo = mid + 1;
  31. }
  32. return lo;
  33. }
  34. };
  35. }
  36. function ascendingComparator(f) {
  37. return function(d, x) {
  38. return ascending(f(d), x);
  39. };
  40. }
  41. var ascendingBisect = bisector(ascending);
  42. var bisectRight = ascendingBisect.right;
  43. var bisectLeft = ascendingBisect.left;
  44. function pairs(array, f) {
  45. if (f == null) f = pair;
  46. var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
  47. while (i < n) pairs[i] = f(p, p = array[++i]);
  48. return pairs;
  49. }
  50. function pair(a, b) {
  51. return [a, b];
  52. }
  53. function cross(values0, values1, reduce) {
  54. var n0 = values0.length,
  55. n1 = values1.length,
  56. values = new Array(n0 * n1),
  57. i0,
  58. i1,
  59. i,
  60. value0;
  61. if (reduce == null) reduce = pair;
  62. for (i0 = i = 0; i0 < n0; ++i0) {
  63. for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
  64. values[i] = reduce(value0, values1[i1]);
  65. }
  66. }
  67. return values;
  68. }
  69. function descending(a, b) {
  70. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  71. }
  72. function number(x) {
  73. return x === null ? NaN : +x;
  74. }
  75. function variance(values, valueof) {
  76. var n = values.length,
  77. m = 0,
  78. i = -1,
  79. mean = 0,
  80. value,
  81. delta,
  82. sum = 0;
  83. if (valueof == null) {
  84. while (++i < n) {
  85. if (!isNaN(value = number(values[i]))) {
  86. delta = value - mean;
  87. mean += delta / ++m;
  88. sum += delta * (value - mean);
  89. }
  90. }
  91. }
  92. else {
  93. while (++i < n) {
  94. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  95. delta = value - mean;
  96. mean += delta / ++m;
  97. sum += delta * (value - mean);
  98. }
  99. }
  100. }
  101. if (m > 1) return sum / (m - 1);
  102. }
  103. function deviation(array, f) {
  104. var v = variance(array, f);
  105. return v ? Math.sqrt(v) : v;
  106. }
  107. function extent(values, valueof) {
  108. var n = values.length,
  109. i = -1,
  110. value,
  111. min,
  112. max;
  113. if (valueof == null) {
  114. while (++i < n) { // Find the first comparable value.
  115. if ((value = values[i]) != null && value >= value) {
  116. min = max = value;
  117. while (++i < n) { // Compare the remaining values.
  118. if ((value = values[i]) != null) {
  119. if (min > value) min = value;
  120. if (max < value) max = value;
  121. }
  122. }
  123. }
  124. }
  125. }
  126. else {
  127. while (++i < n) { // Find the first comparable value.
  128. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  129. min = max = value;
  130. while (++i < n) { // Compare the remaining values.
  131. if ((value = valueof(values[i], i, values)) != null) {
  132. if (min > value) min = value;
  133. if (max < value) max = value;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. return [min, max];
  140. }
  141. var array = Array.prototype;
  142. var slice = array.slice;
  143. var map = array.map;
  144. function constant(x) {
  145. return function() {
  146. return x;
  147. };
  148. }
  149. function identity(x) {
  150. return x;
  151. }
  152. function sequence(start, stop, step) {
  153. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  154. var i = -1,
  155. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  156. range = new Array(n);
  157. while (++i < n) {
  158. range[i] = start + i * step;
  159. }
  160. return range;
  161. }
  162. var e10 = Math.sqrt(50);
  163. var e5 = Math.sqrt(10);
  164. var e2 = Math.sqrt(2);
  165. function ticks(start, stop, count) {
  166. var reverse,
  167. i = -1,
  168. n,
  169. ticks,
  170. step;
  171. stop = +stop, start = +start, count = +count;
  172. if (start === stop && count > 0) return [start];
  173. if (reverse = stop < start) n = start, start = stop, stop = n;
  174. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  175. if (step > 0) {
  176. start = Math.ceil(start / step);
  177. stop = Math.floor(stop / step);
  178. ticks = new Array(n = Math.ceil(stop - start + 1));
  179. while (++i < n) ticks[i] = (start + i) * step;
  180. } else {
  181. start = Math.floor(start * step);
  182. stop = Math.ceil(stop * step);
  183. ticks = new Array(n = Math.ceil(start - stop + 1));
  184. while (++i < n) ticks[i] = (start - i) / step;
  185. }
  186. if (reverse) ticks.reverse();
  187. return ticks;
  188. }
  189. function tickIncrement(start, stop, count) {
  190. var step = (stop - start) / Math.max(0, count),
  191. power = Math.floor(Math.log(step) / Math.LN10),
  192. error = step / Math.pow(10, power);
  193. return power >= 0
  194. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  195. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  196. }
  197. function tickStep(start, stop, count) {
  198. var step0 = Math.abs(stop - start) / Math.max(0, count),
  199. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  200. error = step0 / step1;
  201. if (error >= e10) step1 *= 10;
  202. else if (error >= e5) step1 *= 5;
  203. else if (error >= e2) step1 *= 2;
  204. return stop < start ? -step1 : step1;
  205. }
  206. function sturges(values) {
  207. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  208. }
  209. function histogram() {
  210. var value = identity,
  211. domain = extent,
  212. threshold = 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. function threshold(values, p, valueof) {
  263. if (valueof == null) valueof = number;
  264. if (!(n = values.length)) return;
  265. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  266. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  267. var n,
  268. i = (n - 1) * p,
  269. i0 = Math.floor(i),
  270. value0 = +valueof(values[i0], i0, values),
  271. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  272. return value0 + (value1 - value0) * (i - i0);
  273. }
  274. function freedmanDiaconis(values, min, max) {
  275. values = map.call(values, number).sort(ascending);
  276. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  277. }
  278. function scott(values, min, max) {
  279. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  280. }
  281. function max(values, valueof) {
  282. var n = values.length,
  283. i = -1,
  284. value,
  285. max;
  286. if (valueof == null) {
  287. while (++i < n) { // Find the first comparable value.
  288. if ((value = values[i]) != null && value >= value) {
  289. max = value;
  290. while (++i < n) { // Compare the remaining values.
  291. if ((value = values[i]) != null && value > max) {
  292. max = value;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. else {
  299. while (++i < n) { // Find the first comparable value.
  300. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  301. max = value;
  302. while (++i < n) { // Compare the remaining values.
  303. if ((value = valueof(values[i], i, values)) != null && value > max) {
  304. max = value;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. return max;
  311. }
  312. function mean(values, valueof) {
  313. var n = values.length,
  314. m = n,
  315. i = -1,
  316. value,
  317. sum = 0;
  318. if (valueof == null) {
  319. while (++i < n) {
  320. if (!isNaN(value = number(values[i]))) sum += value;
  321. else --m;
  322. }
  323. }
  324. else {
  325. while (++i < n) {
  326. if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
  327. else --m;
  328. }
  329. }
  330. if (m) return sum / m;
  331. }
  332. function median(values, valueof) {
  333. var n = values.length,
  334. i = -1,
  335. value,
  336. numbers = [];
  337. if (valueof == null) {
  338. while (++i < n) {
  339. if (!isNaN(value = number(values[i]))) {
  340. numbers.push(value);
  341. }
  342. }
  343. }
  344. else {
  345. while (++i < n) {
  346. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  347. numbers.push(value);
  348. }
  349. }
  350. }
  351. return threshold(numbers.sort(ascending), 0.5);
  352. }
  353. function merge(arrays) {
  354. var n = arrays.length,
  355. m,
  356. i = -1,
  357. j = 0,
  358. merged,
  359. array;
  360. while (++i < n) j += arrays[i].length;
  361. merged = new Array(j);
  362. while (--n >= 0) {
  363. array = arrays[n];
  364. m = array.length;
  365. while (--m >= 0) {
  366. merged[--j] = array[m];
  367. }
  368. }
  369. return merged;
  370. }
  371. function min(values, valueof) {
  372. var n = values.length,
  373. i = -1,
  374. value,
  375. min;
  376. if (valueof == null) {
  377. while (++i < n) { // Find the first comparable value.
  378. if ((value = values[i]) != null && value >= value) {
  379. min = value;
  380. while (++i < n) { // Compare the remaining values.
  381. if ((value = values[i]) != null && min > value) {
  382. min = value;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. else {
  389. while (++i < n) { // Find the first comparable value.
  390. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  391. min = value;
  392. while (++i < n) { // Compare the remaining values.
  393. if ((value = valueof(values[i], i, values)) != null && min > value) {
  394. min = value;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. return min;
  401. }
  402. function permute(array, indexes) {
  403. var i = indexes.length, permutes = new Array(i);
  404. while (i--) permutes[i] = array[indexes[i]];
  405. return permutes;
  406. }
  407. function scan(values, compare) {
  408. if (!(n = values.length)) return;
  409. var n,
  410. i = 0,
  411. j = 0,
  412. xi,
  413. xj = values[j];
  414. if (compare == null) compare = ascending;
  415. while (++i < n) {
  416. if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
  417. xj = xi, j = i;
  418. }
  419. }
  420. if (compare(xj, xj) === 0) return j;
  421. }
  422. function shuffle(array, i0, i1) {
  423. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  424. t,
  425. i;
  426. while (m) {
  427. i = Math.random() * m-- | 0;
  428. t = array[m + i0];
  429. array[m + i0] = array[i + i0];
  430. array[i + i0] = t;
  431. }
  432. return array;
  433. }
  434. function sum(values, valueof) {
  435. var n = values.length,
  436. i = -1,
  437. value,
  438. sum = 0;
  439. if (valueof == null) {
  440. while (++i < n) {
  441. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  442. }
  443. }
  444. else {
  445. while (++i < n) {
  446. if (value = +valueof(values[i], i, values)) sum += value;
  447. }
  448. }
  449. return sum;
  450. }
  451. function transpose(matrix) {
  452. if (!(n = matrix.length)) return [];
  453. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  454. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  455. row[j] = matrix[j][i];
  456. }
  457. }
  458. return transpose;
  459. }
  460. function length(d) {
  461. return d.length;
  462. }
  463. function zip() {
  464. return transpose(arguments);
  465. }
  466. var slice$1 = Array.prototype.slice;
  467. function identity$1(x) {
  468. return x;
  469. }
  470. var top = 1;
  471. 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. function namespace(name) {
  688. var prefix = name += "", i = prefix.indexOf(":");
  689. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  690. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  691. }
  692. function creatorInherit(name) {
  693. return function() {
  694. var document = this.ownerDocument,
  695. uri = this.namespaceURI;
  696. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  697. ? document.createElement(name)
  698. : document.createElementNS(uri, name);
  699. };
  700. }
  701. function creatorFixed(fullname) {
  702. return function() {
  703. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  704. };
  705. }
  706. function creator(name) {
  707. var fullname = namespace(name);
  708. return (fullname.local
  709. ? creatorFixed
  710. : creatorInherit)(fullname);
  711. }
  712. function none() {}
  713. function selector(selector) {
  714. return selector == null ? none : function() {
  715. return this.querySelector(selector);
  716. };
  717. }
  718. function selection_select(select) {
  719. if (typeof select !== "function") select = selector(select);
  720. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  721. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  722. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  723. if ("__data__" in node) subnode.__data__ = node.__data__;
  724. subgroup[i] = subnode;
  725. }
  726. }
  727. }
  728. return new Selection(subgroups, this._parents);
  729. }
  730. function empty$1() {
  731. return [];
  732. }
  733. function selectorAll(selector) {
  734. return selector == null ? empty$1 : function() {
  735. return this.querySelectorAll(selector);
  736. };
  737. }
  738. function selection_selectAll(select) {
  739. if (typeof select !== "function") select = selectorAll(select);
  740. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  741. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  742. if (node = group[i]) {
  743. subgroups.push(select.call(node, node.__data__, i, group));
  744. parents.push(node);
  745. }
  746. }
  747. }
  748. return new Selection(subgroups, parents);
  749. }
  750. var matcher = function(selector) {
  751. return function() {
  752. return this.matches(selector);
  753. };
  754. };
  755. if (typeof document !== "undefined") {
  756. var element = document.documentElement;
  757. if (!element.matches) {
  758. var vendorMatches = element.webkitMatchesSelector
  759. || element.msMatchesSelector
  760. || element.mozMatchesSelector
  761. || element.oMatchesSelector;
  762. matcher = function(selector) {
  763. return function() {
  764. return vendorMatches.call(this, selector);
  765. };
  766. };
  767. }
  768. }
  769. var matcher$1 = matcher;
  770. function selection_filter(match) {
  771. if (typeof match !== "function") match = matcher$1(match);
  772. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  773. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  774. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  775. subgroup.push(node);
  776. }
  777. }
  778. }
  779. return new Selection(subgroups, this._parents);
  780. }
  781. function sparse(update) {
  782. return new Array(update.length);
  783. }
  784. function selection_enter() {
  785. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  786. }
  787. function EnterNode(parent, datum) {
  788. this.ownerDocument = parent.ownerDocument;
  789. this.namespaceURI = parent.namespaceURI;
  790. this._next = null;
  791. this._parent = parent;
  792. this.__data__ = datum;
  793. }
  794. EnterNode.prototype = {
  795. constructor: EnterNode,
  796. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  797. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  798. querySelector: function(selector) { return this._parent.querySelector(selector); },
  799. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  800. };
  801. function constant$1(x) {
  802. return function() {
  803. return x;
  804. };
  805. }
  806. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  807. function bindIndex(parent, group, enter, update, exit, data) {
  808. var i = 0,
  809. node,
  810. groupLength = group.length,
  811. dataLength = data.length;
  812. // Put any non-null nodes that fit into update.
  813. // Put any null nodes into enter.
  814. // Put any remaining data into enter.
  815. for (; i < dataLength; ++i) {
  816. if (node = group[i]) {
  817. node.__data__ = data[i];
  818. update[i] = node;
  819. } else {
  820. enter[i] = new EnterNode(parent, data[i]);
  821. }
  822. }
  823. // Put any non-null nodes that don’t fit into exit.
  824. for (; i < groupLength; ++i) {
  825. if (node = group[i]) {
  826. exit[i] = node;
  827. }
  828. }
  829. }
  830. function bindKey(parent, group, enter, update, exit, data, key) {
  831. var i,
  832. node,
  833. nodeByKeyValue = {},
  834. groupLength = group.length,
  835. dataLength = data.length,
  836. keyValues = new Array(groupLength),
  837. keyValue;
  838. // Compute the key for each node.
  839. // If multiple nodes have the same key, the duplicates are added to exit.
  840. for (i = 0; i < groupLength; ++i) {
  841. if (node = group[i]) {
  842. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  843. if (keyValue in nodeByKeyValue) {
  844. exit[i] = node;
  845. } else {
  846. nodeByKeyValue[keyValue] = node;
  847. }
  848. }
  849. }
  850. // Compute the key for each datum.
  851. // If there a node associated with this key, join and add it to update.
  852. // If there is not (or the key is a duplicate), add it to enter.
  853. for (i = 0; i < dataLength; ++i) {
  854. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  855. if (node = nodeByKeyValue[keyValue]) {
  856. update[i] = node;
  857. node.__data__ = data[i];
  858. nodeByKeyValue[keyValue] = null;
  859. } else {
  860. enter[i] = new EnterNode(parent, data[i]);
  861. }
  862. }
  863. // Add any remaining nodes that were not bound to data to exit.
  864. for (i = 0; i < groupLength; ++i) {
  865. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  866. exit[i] = node;
  867. }
  868. }
  869. }
  870. function selection_data(value, key) {
  871. if (!value) {
  872. data = new Array(this.size()), j = -1;
  873. this.each(function(d) { data[++j] = d; });
  874. return data;
  875. }
  876. var bind = key ? bindKey : bindIndex,
  877. parents = this._parents,
  878. groups = this._groups;
  879. if (typeof value !== "function") value = constant$1(value);
  880. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  881. var parent = parents[j],
  882. group = groups[j],
  883. groupLength = group.length,
  884. data = value.call(parent, parent && parent.__data__, j, parents),
  885. dataLength = data.length,
  886. enterGroup = enter[j] = new Array(dataLength),
  887. updateGroup = update[j] = new Array(dataLength),
  888. exitGroup = exit[j] = new Array(groupLength);
  889. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  890. // Now connect the enter nodes to their following update node, such that
  891. // appendChild can insert the materialized enter node before this node,
  892. // rather than at the end of the parent node.
  893. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  894. if (previous = enterGroup[i0]) {
  895. if (i0 >= i1) i1 = i0 + 1;
  896. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  897. previous._next = next || null;
  898. }
  899. }
  900. }
  901. update = new Selection(update, parents);
  902. update._enter = enter;
  903. update._exit = exit;
  904. return update;
  905. }
  906. function selection_exit() {
  907. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  908. }
  909. function selection_merge(selection$$1) {
  910. for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  911. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  912. if (node = group0[i] || group1[i]) {
  913. merge[i] = node;
  914. }
  915. }
  916. }
  917. for (; j < m0; ++j) {
  918. merges[j] = groups0[j];
  919. }
  920. return new Selection(merges, this._parents);
  921. }
  922. function selection_order() {
  923. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  924. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  925. if (node = group[i]) {
  926. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  927. next = node;
  928. }
  929. }
  930. }
  931. return this;
  932. }
  933. function selection_sort(compare) {
  934. if (!compare) compare = ascending$1;
  935. function compareNode(a, b) {
  936. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  937. }
  938. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  939. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  940. if (node = group[i]) {
  941. sortgroup[i] = node;
  942. }
  943. }
  944. sortgroup.sort(compareNode);
  945. }
  946. return new Selection(sortgroups, this._parents).order();
  947. }
  948. function ascending$1(a, b) {
  949. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  950. }
  951. function selection_call() {
  952. var callback = arguments[0];
  953. arguments[0] = this;
  954. callback.apply(null, arguments);
  955. return this;
  956. }
  957. function selection_nodes() {
  958. var nodes = new Array(this.size()), i = -1;
  959. this.each(function() { nodes[++i] = this; });
  960. return nodes;
  961. }
  962. function selection_node() {
  963. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  964. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  965. var node = group[i];
  966. if (node) return node;
  967. }
  968. }
  969. return null;
  970. }
  971. function selection_size() {
  972. var size = 0;
  973. this.each(function() { ++size; });
  974. return size;
  975. }
  976. function selection_empty() {
  977. return !this.node();
  978. }
  979. function selection_each(callback) {
  980. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  981. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  982. if (node = group[i]) callback.call(node, node.__data__, i, group);
  983. }
  984. }
  985. return this;
  986. }
  987. function attrRemove(name) {
  988. return function() {
  989. this.removeAttribute(name);
  990. };
  991. }
  992. function attrRemoveNS(fullname) {
  993. return function() {
  994. this.removeAttributeNS(fullname.space, fullname.local);
  995. };
  996. }
  997. function attrConstant(name, value) {
  998. return function() {
  999. this.setAttribute(name, value);
  1000. };
  1001. }
  1002. function attrConstantNS(fullname, value) {
  1003. return function() {
  1004. this.setAttributeNS(fullname.space, fullname.local, value);
  1005. };
  1006. }
  1007. function attrFunction(name, value) {
  1008. return function() {
  1009. var v = value.apply(this, arguments);
  1010. if (v == null) this.removeAttribute(name);
  1011. else this.setAttribute(name, v);
  1012. };
  1013. }
  1014. function attrFunctionNS(fullname, value) {
  1015. return function() {
  1016. var v = value.apply(this, arguments);
  1017. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1018. else this.setAttributeNS(fullname.space, fullname.local, v);
  1019. };
  1020. }
  1021. function selection_attr(name, value) {
  1022. var fullname = namespace(name);
  1023. if (arguments.length < 2) {
  1024. var node = this.node();
  1025. return fullname.local
  1026. ? node.getAttributeNS(fullname.space, fullname.local)
  1027. : node.getAttribute(fullname);
  1028. }
  1029. return this.each((value == null
  1030. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1031. ? (fullname.local ? attrFunctionNS : attrFunction)
  1032. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1033. }
  1034. function defaultView(node) {
  1035. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1036. || (node.document && node) // node is a Window
  1037. || node.defaultView; // node is a Document
  1038. }
  1039. function styleRemove(name) {
  1040. return function() {
  1041. this.style.removeProperty(name);
  1042. };
  1043. }
  1044. function styleConstant(name, value, priority) {
  1045. return function() {
  1046. this.style.setProperty(name, value, priority);
  1047. };
  1048. }
  1049. function styleFunction(name, value, priority) {
  1050. return function() {
  1051. var v = value.apply(this, arguments);
  1052. if (v == null) this.style.removeProperty(name);
  1053. else this.style.setProperty(name, v, priority);
  1054. };
  1055. }
  1056. function selection_style(name, value, priority) {
  1057. return arguments.length > 1
  1058. ? this.each((value == null
  1059. ? styleRemove : typeof value === "function"
  1060. ? styleFunction
  1061. : styleConstant)(name, value, priority == null ? "" : priority))
  1062. : styleValue(this.node(), name);
  1063. }
  1064. function styleValue(node, name) {
  1065. return node.style.getPropertyValue(name)
  1066. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1067. }
  1068. function propertyRemove(name) {
  1069. return function() {
  1070. delete this[name];
  1071. };
  1072. }
  1073. function propertyConstant(name, value) {
  1074. return function() {
  1075. this[name] = value;
  1076. };
  1077. }
  1078. function propertyFunction(name, value) {
  1079. return function() {
  1080. var v = value.apply(this, arguments);
  1081. if (v == null) delete this[name];
  1082. else this[name] = v;
  1083. };
  1084. }
  1085. function selection_property(name, value) {
  1086. return arguments.length > 1
  1087. ? this.each((value == null
  1088. ? propertyRemove : typeof value === "function"
  1089. ? propertyFunction
  1090. : propertyConstant)(name, value))
  1091. : this.node()[name];
  1092. }
  1093. function classArray(string) {
  1094. return string.trim().split(/^|\s+/);
  1095. }
  1096. function classList(node) {
  1097. return node.classList || new ClassList(node);
  1098. }
  1099. function ClassList(node) {
  1100. this._node = node;
  1101. this._names = classArray(node.getAttribute("class") || "");
  1102. }
  1103. ClassList.prototype = {
  1104. add: function(name) {
  1105. var i = this._names.indexOf(name);
  1106. if (i < 0) {
  1107. this._names.push(name);
  1108. this._node.setAttribute("class", this._names.join(" "));
  1109. }
  1110. },
  1111. remove: function(name) {
  1112. var i = this._names.indexOf(name);
  1113. if (i >= 0) {
  1114. this._names.splice(i, 1);
  1115. this._node.setAttribute("class", this._names.join(" "));
  1116. }
  1117. },
  1118. contains: function(name) {
  1119. return this._names.indexOf(name) >= 0;
  1120. }
  1121. };
  1122. function classedAdd(node, names) {
  1123. var list = classList(node), i = -1, n = names.length;
  1124. while (++i < n) list.add(names[i]);
  1125. }
  1126. function classedRemove(node, names) {
  1127. var list = classList(node), i = -1, n = names.length;
  1128. while (++i < n) list.remove(names[i]);
  1129. }
  1130. function classedTrue(names) {
  1131. return function() {
  1132. classedAdd(this, names);
  1133. };
  1134. }
  1135. function classedFalse(names) {
  1136. return function() {
  1137. classedRemove(this, names);
  1138. };
  1139. }
  1140. function classedFunction(names, value) {
  1141. return function() {
  1142. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1143. };
  1144. }
  1145. function selection_classed(name, value) {
  1146. var names = classArray(name + "");
  1147. if (arguments.length < 2) {
  1148. var list = classList(this.node()), i = -1, n = names.length;
  1149. while (++i < n) if (!list.contains(names[i])) return false;
  1150. return true;
  1151. }
  1152. return this.each((typeof value === "function"
  1153. ? classedFunction : value
  1154. ? classedTrue
  1155. : classedFalse)(names, value));
  1156. }
  1157. function textRemove() {
  1158. this.textContent = "";
  1159. }
  1160. function textConstant(value) {
  1161. return function() {
  1162. this.textContent = value;
  1163. };
  1164. }
  1165. function textFunction(value) {
  1166. return function() {
  1167. var v = value.apply(this, arguments);
  1168. this.textContent = v == null ? "" : v;
  1169. };
  1170. }
  1171. function selection_text(value) {
  1172. return arguments.length
  1173. ? this.each(value == null
  1174. ? textRemove : (typeof value === "function"
  1175. ? textFunction
  1176. : textConstant)(value))
  1177. : this.node().textContent;
  1178. }
  1179. function htmlRemove() {
  1180. this.innerHTML = "";
  1181. }
  1182. function htmlConstant(value) {
  1183. return function() {
  1184. this.innerHTML = value;
  1185. };
  1186. }
  1187. function htmlFunction(value) {
  1188. return function() {
  1189. var v = value.apply(this, arguments);
  1190. this.innerHTML = v == null ? "" : v;
  1191. };
  1192. }
  1193. function selection_html(value) {
  1194. return arguments.length
  1195. ? this.each(value == null
  1196. ? htmlRemove : (typeof value === "function"
  1197. ? htmlFunction
  1198. : htmlConstant)(value))
  1199. : this.node().innerHTML;
  1200. }
  1201. function raise() {
  1202. if (this.nextSibling) this.parentNode.appendChild(this);
  1203. }
  1204. function selection_raise() {
  1205. return this.each(raise);
  1206. }
  1207. function lower() {
  1208. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1209. }
  1210. function selection_lower() {
  1211. return this.each(lower);
  1212. }
  1213. function selection_append(name) {
  1214. var create = typeof name === "function" ? name : creator(name);
  1215. return this.select(function() {
  1216. return this.appendChild(create.apply(this, arguments));
  1217. });
  1218. }
  1219. function constantNull() {
  1220. return null;
  1221. }
  1222. function selection_insert(name, before) {
  1223. var create = typeof name === "function" ? name : creator(name),
  1224. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1225. return this.select(function() {
  1226. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1227. });
  1228. }
  1229. function remove() {
  1230. var parent = this.parentNode;
  1231. if (parent) parent.removeChild(this);
  1232. }
  1233. function selection_remove() {
  1234. return this.each(remove);
  1235. }
  1236. function selection_cloneShallow() {
  1237. return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
  1238. }
  1239. function selection_cloneDeep() {
  1240. return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
  1241. }
  1242. function selection_clone(deep) {
  1243. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  1244. }
  1245. function selection_datum(value) {
  1246. return arguments.length
  1247. ? this.property("__data__", value)
  1248. : this.node().__data__;
  1249. }
  1250. var filterEvents = {};
  1251. exports.event = null;
  1252. if (typeof document !== "undefined") {
  1253. var element$1 = document.documentElement;
  1254. if (!("onmouseenter" in element$1)) {
  1255. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  1256. }
  1257. }
  1258. function filterContextListener(listener, index, group) {
  1259. listener = contextListener(listener, index, group);
  1260. return function(event) {
  1261. var related = event.relatedTarget;
  1262. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  1263. listener.call(this, event);
  1264. }
  1265. };
  1266. }
  1267. function contextListener(listener, index, group) {
  1268. return function(event1) {
  1269. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  1270. exports.event = event1;
  1271. try {
  1272. listener.call(this, this.__data__, index, group);
  1273. } finally {
  1274. exports.event = event0;
  1275. }
  1276. };
  1277. }
  1278. function parseTypenames$1(typenames) {
  1279. return typenames.trim().split(/^|\s+/).map(function(t) {
  1280. var name = "", i = t.indexOf(".");
  1281. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1282. return {type: t, name: name};
  1283. });
  1284. }
  1285. function onRemove(typename) {
  1286. return function() {
  1287. var on = this.__on;
  1288. if (!on) return;
  1289. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  1290. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  1291. this.removeEventListener(o.type, o.listener, o.capture);
  1292. } else {
  1293. on[++i] = o;
  1294. }
  1295. }
  1296. if (++i) on.length = i;
  1297. else delete this.__on;
  1298. };
  1299. }
  1300. function onAdd(typename, value, capture) {
  1301. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  1302. return function(d, i, group) {
  1303. var on = this.__on, o, listener = wrap(value, i, group);
  1304. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  1305. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  1306. this.removeEventListener(o.type, o.listener, o.capture);
  1307. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  1308. o.value = value;
  1309. return;
  1310. }
  1311. }
  1312. this.addEventListener(typename.type, listener, capture);
  1313. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  1314. if (!on) this.__on = [o];
  1315. else on.push(o);
  1316. };
  1317. }
  1318. function selection_on(typename, value, capture) {
  1319. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  1320. if (arguments.length < 2) {
  1321. var on = this.node().__on;
  1322. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  1323. for (i = 0, o = on[j]; i < n; ++i) {
  1324. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  1325. return o.value;
  1326. }
  1327. }
  1328. }
  1329. return;
  1330. }
  1331. on = value ? onAdd : onRemove;
  1332. if (capture == null) capture = false;
  1333. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  1334. return this;
  1335. }
  1336. function customEvent(event1, listener, that, args) {
  1337. var event0 = exports.event;
  1338. event1.sourceEvent = exports.event;
  1339. exports.event = event1;
  1340. try {
  1341. return listener.apply(that, args);
  1342. } finally {
  1343. exports.event = event0;
  1344. }
  1345. }
  1346. function dispatchEvent(node, type, params) {
  1347. var window = defaultView(node),
  1348. event = window.CustomEvent;
  1349. if (typeof event === "function") {
  1350. event = new event(type, params);
  1351. } else {
  1352. event = window.document.createEvent("Event");
  1353. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1354. else event.initEvent(type, false, false);
  1355. }
  1356. node.dispatchEvent(event);
  1357. }
  1358. function dispatchConstant(type, params) {
  1359. return function() {
  1360. return dispatchEvent(this, type, params);
  1361. };
  1362. }
  1363. function dispatchFunction(type, params) {
  1364. return function() {
  1365. return dispatchEvent(this, type, params.apply(this, arguments));
  1366. };
  1367. }
  1368. function selection_dispatch(type, params) {
  1369. return this.each((typeof params === "function"
  1370. ? dispatchFunction
  1371. : dispatchConstant)(type, params));
  1372. }
  1373. var root = [null];
  1374. function Selection(groups, parents) {
  1375. this._groups = groups;
  1376. this._parents = parents;
  1377. }
  1378. function selection() {
  1379. return new Selection([[document.documentElement]], root);
  1380. }
  1381. Selection.prototype = selection.prototype = {
  1382. constructor: Selection,
  1383. select: selection_select,
  1384. selectAll: selection_selectAll,
  1385. filter: selection_filter,
  1386. data: selection_data,
  1387. enter: selection_enter,
  1388. exit: selection_exit,
  1389. merge: selection_merge,
  1390. order: selection_order,
  1391. sort: selection_sort,
  1392. call: selection_call,
  1393. nodes: selection_nodes,
  1394. node: selection_node,
  1395. size: selection_size,
  1396. empty: selection_empty,
  1397. each: selection_each,
  1398. attr: selection_attr,
  1399. style: selection_style,
  1400. property: selection_property,
  1401. classed: selection_classed,
  1402. text: selection_text,
  1403. html: selection_html,
  1404. raise: selection_raise,
  1405. lower: selection_lower,
  1406. append: selection_append,
  1407. insert: selection_insert,
  1408. remove: selection_remove,
  1409. clone: selection_clone,
  1410. datum: selection_datum,
  1411. on: selection_on,
  1412. dispatch: selection_dispatch
  1413. };
  1414. function select(selector) {
  1415. return typeof selector === "string"
  1416. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1417. : new Selection([[selector]], root);
  1418. }
  1419. function create(name) {
  1420. return select(creator(name).call(document.documentElement));
  1421. }
  1422. var nextId = 0;
  1423. function local$1() {
  1424. return new Local;
  1425. }
  1426. function Local() {
  1427. this._ = "@" + (++nextId).toString(36);
  1428. }
  1429. Local.prototype = local$1.prototype = {
  1430. constructor: Local,
  1431. get: function(node) {
  1432. var id = this._;
  1433. while (!(id in node)) if (!(node = node.parentNode)) return;
  1434. return node[id];
  1435. },
  1436. set: function(node, value) {
  1437. return node[this._] = value;
  1438. },
  1439. remove: function(node) {
  1440. return this._ in node && delete node[this._];
  1441. },
  1442. toString: function() {
  1443. return this._;
  1444. }
  1445. };
  1446. function sourceEvent() {
  1447. var current = exports.event, source;
  1448. while (source = current.sourceEvent) current = source;
  1449. return current;
  1450. }
  1451. function point(node, event) {
  1452. var svg = node.ownerSVGElement || node;
  1453. if (svg.createSVGPoint) {
  1454. var point = svg.createSVGPoint();
  1455. point.x = event.clientX, point.y = event.clientY;
  1456. point = point.matrixTransform(node.getScreenCTM().inverse());
  1457. return [point.x, point.y];
  1458. }
  1459. var rect = node.getBoundingClientRect();
  1460. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  1461. }
  1462. function mouse(node) {
  1463. var event = sourceEvent();
  1464. if (event.changedTouches) event = event.changedTouches[0];
  1465. return point(node, event);
  1466. }
  1467. function selectAll(selector) {
  1468. return typeof selector === "string"
  1469. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1470. : new Selection([selector == null ? [] : selector], root);
  1471. }
  1472. function touch(node, touches, identifier) {
  1473. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1474. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1475. if ((touch = touches[i]).identifier === identifier) {
  1476. return point(node, touch);
  1477. }
  1478. }
  1479. return null;
  1480. }
  1481. function touches(node, touches) {
  1482. if (touches == null) touches = sourceEvent().touches;
  1483. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1484. points[i] = point(node, touches[i]);
  1485. }
  1486. return points;
  1487. }
  1488. function nopropagation() {
  1489. exports.event.stopImmediatePropagation();
  1490. }
  1491. function noevent() {
  1492. exports.event.preventDefault();
  1493. exports.event.stopImmediatePropagation();
  1494. }
  1495. function dragDisable(view) {
  1496. var root = view.document.documentElement,
  1497. selection = select(view).on("dragstart.drag", noevent, true);
  1498. if ("onselectstart" in root) {
  1499. selection.on("selectstart.drag", noevent, true);
  1500. } else {
  1501. root.__noselect = root.style.MozUserSelect;
  1502. root.style.MozUserSelect = "none";
  1503. }
  1504. }
  1505. function yesdrag(view, noclick) {
  1506. var root = view.document.documentElement,
  1507. selection = select(view).on("dragstart.drag", null);
  1508. if (noclick) {
  1509. selection.on("click.drag", noevent, true);
  1510. setTimeout(function() { selection.on("click.drag", null); }, 0);
  1511. }
  1512. if ("onselectstart" in root) {
  1513. selection.on("selectstart.drag", null);
  1514. } else {
  1515. root.style.MozUserSelect = root.__noselect;
  1516. delete root.__noselect;
  1517. }
  1518. }
  1519. function constant$2(x) {
  1520. return function() {
  1521. return x;
  1522. };
  1523. }
  1524. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1525. this.target = target;
  1526. this.type = type;
  1527. this.subject = subject;
  1528. this.identifier = id;
  1529. this.active = active;
  1530. this.x = x;
  1531. this.y = y;
  1532. this.dx = dx;
  1533. this.dy = dy;
  1534. this._ = dispatch;
  1535. }
  1536. DragEvent.prototype.on = function() {
  1537. var value = this._.on.apply(this._, arguments);
  1538. return value === this._ ? this : value;
  1539. };
  1540. // Ignore right-click, since that should open the context menu.
  1541. function defaultFilter$1() {
  1542. return !exports.event.button;
  1543. }
  1544. function defaultContainer() {
  1545. return this.parentNode;
  1546. }
  1547. function defaultSubject(d) {
  1548. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1549. }
  1550. function defaultTouchable() {
  1551. return "ontouchstart" in this;
  1552. }
  1553. function drag() {
  1554. var filter = defaultFilter$1,
  1555. container = defaultContainer,
  1556. subject = defaultSubject,
  1557. touchable = defaultTouchable,
  1558. gestures = {},
  1559. listeners = dispatch("start", "drag", "end"),
  1560. active = 0,
  1561. mousedownx,
  1562. mousedowny,
  1563. mousemoving,
  1564. touchending,
  1565. clickDistance2 = 0;
  1566. function drag(selection) {
  1567. selection
  1568. .on("mousedown.drag", mousedowned)
  1569. .filter(touchable)
  1570. .on("touchstart.drag", touchstarted)
  1571. .on("touchmove.drag", touchmoved)
  1572. .on("touchend.drag touchcancel.drag", touchended)
  1573. .style("touch-action", "none")
  1574. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1575. }
  1576. function mousedowned() {
  1577. if (touchending || !filter.apply(this, arguments)) return;
  1578. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1579. if (!gesture) return;
  1580. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1581. dragDisable(exports.event.view);
  1582. nopropagation();
  1583. mousemoving = false;
  1584. mousedownx = exports.event.clientX;
  1585. mousedowny = exports.event.clientY;
  1586. gesture("start");
  1587. }
  1588. function mousemoved() {
  1589. noevent();
  1590. if (!mousemoving) {
  1591. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1592. mousemoving = dx * dx + dy * dy > clickDistance2;
  1593. }
  1594. gestures.mouse("drag");
  1595. }
  1596. function mouseupped() {
  1597. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1598. yesdrag(exports.event.view, mousemoving);
  1599. noevent();
  1600. gestures.mouse("end");
  1601. }
  1602. function touchstarted() {
  1603. if (!filter.apply(this, arguments)) return;
  1604. var touches = exports.event.changedTouches,
  1605. c = container.apply(this, arguments),
  1606. n = touches.length, i, gesture;
  1607. for (i = 0; i < n; ++i) {
  1608. if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
  1609. nopropagation();
  1610. gesture("start");
  1611. }
  1612. }
  1613. }
  1614. function touchmoved() {
  1615. var touches = exports.event.changedTouches,
  1616. n = touches.length, i, gesture;
  1617. for (i = 0; i < n; ++i) {
  1618. if (gesture = gestures[touches[i].identifier]) {
  1619. noevent();
  1620. gesture("drag");
  1621. }
  1622. }
  1623. }
  1624. function touchended() {
  1625. var touches = exports.event.changedTouches,
  1626. n = touches.length, i, gesture;
  1627. if (touchending) clearTimeout(touchending);
  1628. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1629. for (i = 0; i < n; ++i) {
  1630. if (gesture = gestures[touches[i].identifier]) {
  1631. nopropagation();
  1632. gesture("end");
  1633. }
  1634. }
  1635. }
  1636. function beforestart(id, container, point, that, args) {
  1637. var p = point(container, id), s, dx, dy,
  1638. sublisteners = listeners.copy();
  1639. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1640. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1641. dx = s.x - p[0] || 0;
  1642. dy = s.y - p[1] || 0;
  1643. return true;
  1644. })) return;
  1645. return function gesture(type) {
  1646. var p0 = p, n;
  1647. switch (type) {
  1648. case "start": gestures[id] = gesture, n = active++; break;
  1649. case "end": delete gestures[id], --active; // nobreak
  1650. case "drag": p = point(container, id), n = active; break;
  1651. }
  1652. customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
  1653. };
  1654. }
  1655. drag.filter = function(_) {
  1656. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1657. };
  1658. drag.container = function(_) {
  1659. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1660. };
  1661. drag.subject = function(_) {
  1662. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1663. };
  1664. drag.touchable = function(_) {
  1665. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
  1666. };
  1667. drag.on = function() {
  1668. var value = listeners.on.apply(listeners, arguments);
  1669. return value === listeners ? drag : value;
  1670. };
  1671. drag.clickDistance = function(_) {
  1672. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1673. };
  1674. return drag;
  1675. }
  1676. function define(constructor, factory, prototype) {
  1677. constructor.prototype = factory.prototype = prototype;
  1678. prototype.constructor = constructor;
  1679. }
  1680. function extend(parent, definition) {
  1681. var prototype = Object.create(parent.prototype);
  1682. for (var key in definition) prototype[key] = definition[key];
  1683. return prototype;
  1684. }
  1685. function Color() {}
  1686. var darker = 0.7;
  1687. var brighter = 1 / darker;
  1688. var reI = "\\s*([+-]?\\d+)\\s*";
  1689. var reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*";
  1690. var reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*";
  1691. var reHex3 = /^#([0-9a-f]{3})$/;
  1692. var reHex6 = /^#([0-9a-f]{6})$/;
  1693. var reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$");
  1694. var reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$");
  1695. var reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$");
  1696. var reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$");
  1697. var reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$");
  1698. var reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1699. var named = {
  1700. aliceblue: 0xf0f8ff,
  1701. antiquewhite: 0xfaebd7,
  1702. aqua: 0x00ffff,
  1703. aquamarine: 0x7fffd4,
  1704. azure: 0xf0ffff,
  1705. beige: 0xf5f5dc,
  1706. bisque: 0xffe4c4,
  1707. black: 0x000000,
  1708. blanchedalmond: 0xffebcd,
  1709. blue: 0x0000ff,
  1710. blueviolet: 0x8a2be2,
  1711. brown: 0xa52a2a,
  1712. burlywood: 0xdeb887,
  1713. cadetblue: 0x5f9ea0,
  1714. chartreuse: 0x7fff00,
  1715. chocolate: 0xd2691e,
  1716. coral: 0xff7f50,
  1717. cornflowerblue: 0x6495ed,
  1718. cornsilk: 0xfff8dc,
  1719. crimson: 0xdc143c,
  1720. cyan: 0x00ffff,
  1721. darkblue: 0x00008b,
  1722. darkcyan: 0x008b8b,
  1723. darkgoldenrod: 0xb8860b,
  1724. darkgray: 0xa9a9a9,
  1725. darkgreen: 0x006400,
  1726. darkgrey: 0xa9a9a9,
  1727. darkkhaki: 0xbdb76b,
  1728. darkmagenta: 0x8b008b,
  1729. darkolivegreen: 0x556b2f,
  1730. darkorange: 0xff8c00,
  1731. darkorchid: 0x9932cc,
  1732. darkred: 0x8b0000,
  1733. darksalmon: 0xe9967a,
  1734. darkseagreen: 0x8fbc8f,
  1735. darkslateblue: 0x483d8b,
  1736. darkslategray: 0x2f4f4f,
  1737. darkslategrey: 0x2f4f4f,
  1738. darkturquoise: 0x00ced1,
  1739. darkviolet: 0x9400d3,
  1740. deeppink: 0xff1493,
  1741. deepskyblue: 0x00bfff,
  1742. dimgray: 0x696969,
  1743. dimgrey: 0x696969,
  1744. dodgerblue: 0x1e90ff,
  1745. firebrick: 0xb22222,
  1746. floralwhite: 0xfffaf0,
  1747. forestgreen: 0x228b22,
  1748. fuchsia: 0xff00ff,
  1749. gainsboro: 0xdcdcdc,
  1750. ghostwhite: 0xf8f8ff,
  1751. gold: 0xffd700,
  1752. goldenrod: 0xdaa520,
  1753. gray: 0x808080,
  1754. green: 0x008000,
  1755. greenyellow: 0xadff2f,
  1756. grey: 0x808080,
  1757. honeydew: 0xf0fff0,
  1758. hotpink: 0xff69b4,
  1759. indianred: 0xcd5c5c,
  1760. indigo: 0x4b0082,
  1761. ivory: 0xfffff0,
  1762. khaki: 0xf0e68c,
  1763. lavender: 0xe6e6fa,
  1764. lavenderblush: 0xfff0f5,
  1765. lawngreen: 0x7cfc00,
  1766. lemonchiffon: 0xfffacd,
  1767. lightblue: 0xadd8e6,
  1768. lightcoral: 0xf08080,
  1769. lightcyan: 0xe0ffff,
  1770. lightgoldenrodyellow: 0xfafad2,
  1771. lightgray: 0xd3d3d3,
  1772. lightgreen: 0x90ee90,
  1773. lightgrey: 0xd3d3d3,
  1774. lightpink: 0xffb6c1,
  1775. lightsalmon: 0xffa07a,
  1776. lightseagreen: 0x20b2aa,
  1777. lightskyblue: 0x87cefa,
  1778. lightslategray: 0x778899,
  1779. lightslategrey: 0x778899,
  1780. lightsteelblue: 0xb0c4de,
  1781. lightyellow: 0xffffe0,
  1782. lime: 0x00ff00,
  1783. limegreen: 0x32cd32,
  1784. linen: 0xfaf0e6,
  1785. magenta: 0xff00ff,
  1786. maroon: 0x800000,
  1787. mediumaquamarine: 0x66cdaa,
  1788. mediumblue: 0x0000cd,
  1789. mediumorchid: 0xba55d3,
  1790. mediumpurple: 0x9370db,
  1791. mediumseagreen: 0x3cb371,
  1792. mediumslateblue: 0x7b68ee,
  1793. mediumspringgreen: 0x00fa9a,
  1794. mediumturquoise: 0x48d1cc,
  1795. mediumvioletred: 0xc71585,
  1796. midnightblue: 0x191970,
  1797. mintcream: 0xf5fffa,
  1798. mistyrose: 0xffe4e1,
  1799. moccasin: 0xffe4b5,
  1800. navajowhite: 0xffdead,
  1801. navy: 0x000080,
  1802. oldlace: 0xfdf5e6,
  1803. olive: 0x808000,
  1804. olivedrab: 0x6b8e23,
  1805. orange: 0xffa500,
  1806. orangered: 0xff4500,
  1807. orchid: 0xda70d6,
  1808. palegoldenrod: 0xeee8aa,
  1809. palegreen: 0x98fb98,
  1810. paleturquoise: 0xafeeee,
  1811. palevioletred: 0xdb7093,
  1812. papayawhip: 0xffefd5,
  1813. peachpuff: 0xffdab9,
  1814. peru: 0xcd853f,
  1815. pink: 0xffc0cb,
  1816. plum: 0xdda0dd,
  1817. powderblue: 0xb0e0e6,
  1818. purple: 0x800080,
  1819. rebeccapurple: 0x663399,
  1820. red: 0xff0000,
  1821. rosybrown: 0xbc8f8f,
  1822. royalblue: 0x4169e1,
  1823. saddlebrown: 0x8b4513,
  1824. salmon: 0xfa8072,
  1825. sandybrown: 0xf4a460,
  1826. seagreen: 0x2e8b57,
  1827. seashell: 0xfff5ee,
  1828. sienna: 0xa0522d,
  1829. silver: 0xc0c0c0,
  1830. skyblue: 0x87ceeb,
  1831. slateblue: 0x6a5acd,
  1832. slategray: 0x708090,
  1833. slategrey: 0x708090,
  1834. snow: 0xfffafa,
  1835. springgreen: 0x00ff7f,
  1836. steelblue: 0x4682b4,
  1837. tan: 0xd2b48c,
  1838. teal: 0x008080,
  1839. thistle: 0xd8bfd8,
  1840. tomato: 0xff6347,
  1841. turquoise: 0x40e0d0,
  1842. violet: 0xee82ee,
  1843. wheat: 0xf5deb3,
  1844. white: 0xffffff,
  1845. whitesmoke: 0xf5f5f5,
  1846. yellow: 0xffff00,
  1847. yellowgreen: 0x9acd32
  1848. };
  1849. define(Color, color, {
  1850. displayable: function() {
  1851. return this.rgb().displayable();
  1852. },
  1853. toString: function() {
  1854. return this.rgb() + "";
  1855. }
  1856. });
  1857. function color(format) {
  1858. var m;
  1859. format = (format + "").trim().toLowerCase();
  1860. return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
  1861. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  1862. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1863. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1864. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1865. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1866. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1867. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1868. : named.hasOwnProperty(format) ? rgbn(named[format])
  1869. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1870. : null;
  1871. }
  1872. function rgbn(n) {
  1873. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1874. }
  1875. function rgba(r, g, b, a) {
  1876. if (a <= 0) r = g = b = NaN;
  1877. return new Rgb(r, g, b, a);
  1878. }
  1879. function rgbConvert(o) {
  1880. if (!(o instanceof Color)) o = color(o);
  1881. if (!o) return new Rgb;
  1882. o = o.rgb();
  1883. return new Rgb(o.r, o.g, o.b, o.opacity);
  1884. }
  1885. function rgb(r, g, b, opacity) {
  1886. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1887. }
  1888. function Rgb(r, g, b, opacity) {
  1889. this.r = +r;
  1890. this.g = +g;
  1891. this.b = +b;
  1892. this.opacity = +opacity;
  1893. }
  1894. define(Rgb, rgb, extend(Color, {
  1895. brighter: function(k) {
  1896. k = k == null ? brighter : Math.pow(brighter, k);
  1897. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1898. },
  1899. darker: function(k) {
  1900. k = k == null ? darker : Math.pow(darker, k);
  1901. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1902. },
  1903. rgb: function() {
  1904. return this;
  1905. },
  1906. displayable: function() {
  1907. return (0 <= this.r && this.r <= 255)
  1908. && (0 <= this.g && this.g <= 255)
  1909. && (0 <= this.b && this.b <= 255)
  1910. && (0 <= this.opacity && this.opacity <= 1);
  1911. },
  1912. toString: function() {
  1913. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1914. return (a === 1 ? "rgb(" : "rgba(")
  1915. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1916. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1917. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1918. + (a === 1 ? ")" : ", " + a + ")");
  1919. }
  1920. }));
  1921. function hsla(h, s, l, a) {
  1922. if (a <= 0) h = s = l = NaN;
  1923. else if (l <= 0 || l >= 1) h = s = NaN;
  1924. else if (s <= 0) h = NaN;
  1925. return new Hsl(h, s, l, a);
  1926. }
  1927. function hslConvert(o) {
  1928. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1929. if (!(o instanceof Color)) o = color(o);
  1930. if (!o) return new Hsl;
  1931. if (o instanceof Hsl) return o;
  1932. o = o.rgb();
  1933. var r = o.r / 255,
  1934. g = o.g / 255,
  1935. b = o.b / 255,
  1936. min = Math.min(r, g, b),
  1937. max = Math.max(r, g, b),
  1938. h = NaN,
  1939. s = max - min,
  1940. l = (max + min) / 2;
  1941. if (s) {
  1942. if (r === max) h = (g - b) / s + (g < b) * 6;
  1943. else if (g === max) h = (b - r) / s + 2;
  1944. else h = (r - g) / s + 4;
  1945. s /= l < 0.5 ? max + min : 2 - max - min;
  1946. h *= 60;
  1947. } else {
  1948. s = l > 0 && l < 1 ? 0 : h;
  1949. }
  1950. return new Hsl(h, s, l, o.opacity);
  1951. }
  1952. function hsl(h, s, l, opacity) {
  1953. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1954. }
  1955. function Hsl(h, s, l, opacity) {
  1956. this.h = +h;
  1957. this.s = +s;
  1958. this.l = +l;
  1959. this.opacity = +opacity;
  1960. }
  1961. define(Hsl, hsl, extend(Color, {
  1962. brighter: function(k) {
  1963. k = k == null ? brighter : Math.pow(brighter, k);
  1964. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1965. },
  1966. darker: function(k) {
  1967. k = k == null ? darker : Math.pow(darker, k);
  1968. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1969. },
  1970. rgb: function() {
  1971. var h = this.h % 360 + (this.h < 0) * 360,
  1972. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1973. l = this.l,
  1974. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1975. m1 = 2 * l - m2;
  1976. return new Rgb(
  1977. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  1978. hsl2rgb(h, m1, m2),
  1979. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  1980. this.opacity
  1981. );
  1982. },
  1983. displayable: function() {
  1984. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  1985. && (0 <= this.l && this.l <= 1)
  1986. && (0 <= this.opacity && this.opacity <= 1);
  1987. }
  1988. }));
  1989. /* From FvD 13.37, CSS Color Module Level 3 */
  1990. function hsl2rgb(h, m1, m2) {
  1991. return (h < 60 ? m1 + (m2 - m1) * h / 60
  1992. : h < 180 ? m2
  1993. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  1994. : m1) * 255;
  1995. }
  1996. var deg2rad = Math.PI / 180;
  1997. var rad2deg = 180 / Math.PI;
  1998. var Kn = 18;
  1999. var Xn = 0.950470;
  2000. var Yn = 1;
  2001. var Zn = 1.088830;
  2002. var t0 = 4 / 29;
  2003. var t1 = 6 / 29;
  2004. var t2 = 3 * t1 * t1;
  2005. var t3 = t1 * t1 * t1;
  2006. function labConvert(o) {
  2007. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2008. if (o instanceof Hcl) {
  2009. var h = o.h * deg2rad;
  2010. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2011. }
  2012. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2013. var b = rgb2xyz(o.r),
  2014. a = rgb2xyz(o.g),
  2015. l = rgb2xyz(o.b),
  2016. x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
  2017. y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
  2018. z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
  2019. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2020. }
  2021. function lab(l, a, b, opacity) {
  2022. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2023. }
  2024. function Lab(l, a, b, opacity) {
  2025. this.l = +l;
  2026. this.a = +a;
  2027. this.b = +b;
  2028. this.opacity = +opacity;
  2029. }
  2030. define(Lab, lab, extend(Color, {
  2031. brighter: function(k) {
  2032. return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2033. },
  2034. darker: function(k) {
  2035. return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2036. },
  2037. rgb: function() {
  2038. var y = (this.l + 16) / 116,
  2039. x = isNaN(this.a) ? y : y + this.a / 500,
  2040. z = isNaN(this.b) ? y : y - this.b / 200;
  2041. y = Yn * lab2xyz(y);
  2042. x = Xn * lab2xyz(x);
  2043. z = Zn * lab2xyz(z);
  2044. return new Rgb(
  2045. xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
  2046. xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
  2047. xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
  2048. this.opacity
  2049. );
  2050. }
  2051. }));
  2052. function xyz2lab(t) {
  2053. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2054. }
  2055. function lab2xyz(t) {
  2056. return t > t1 ? t * t * t : t2 * (t - t0);
  2057. }
  2058. function xyz2rgb(x) {
  2059. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2060. }
  2061. function rgb2xyz(x) {
  2062. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2063. }
  2064. function hclConvert(o) {
  2065. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2066. if (!(o instanceof Lab)) o = labConvert(o);
  2067. var h = Math.atan2(o.b, o.a) * rad2deg;
  2068. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2069. }
  2070. function hcl(h, c, l, opacity) {
  2071. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2072. }
  2073. function Hcl(h, c, l, opacity) {
  2074. this.h = +h;
  2075. this.c = +c;
  2076. this.l = +l;
  2077. this.opacity = +opacity;
  2078. }
  2079. define(Hcl, hcl, extend(Color, {
  2080. brighter: function(k) {
  2081. return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
  2082. },
  2083. darker: function(k) {
  2084. return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
  2085. },
  2086. rgb: function() {
  2087. return labConvert(this).rgb();
  2088. }
  2089. }));
  2090. var A = -0.14861;
  2091. var B = +1.78277;
  2092. var C = -0.29227;
  2093. var D = -0.90649;
  2094. var E = +1.97294;
  2095. var ED = E * D;
  2096. var EB = E * B;
  2097. var BC_DA = B * C - D * A;
  2098. function cubehelixConvert(o) {
  2099. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2100. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2101. var r = o.r / 255,
  2102. g = o.g / 255,
  2103. b = o.b / 255,
  2104. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2105. bl = b - l,
  2106. k = (E * (g - l) - C * bl) / D,
  2107. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2108. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2109. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2110. }
  2111. function cubehelix(h, s, l, opacity) {
  2112. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2113. }
  2114. function Cubehelix(h, s, l, opacity) {
  2115. this.h = +h;
  2116. this.s = +s;
  2117. this.l = +l;
  2118. this.opacity = +opacity;
  2119. }
  2120. define(Cubehelix, cubehelix, extend(Color, {
  2121. brighter: function(k) {
  2122. k = k == null ? brighter : Math.pow(brighter, k);
  2123. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2124. },
  2125. darker: function(k) {
  2126. k = k == null ? darker : Math.pow(darker, k);
  2127. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2128. },
  2129. rgb: function() {
  2130. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2131. l = +this.l,
  2132. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2133. cosh = Math.cos(h),
  2134. sinh = Math.sin(h);
  2135. return new Rgb(
  2136. 255 * (l + a * (A * cosh + B * sinh)),
  2137. 255 * (l + a * (C * cosh + D * sinh)),
  2138. 255 * (l + a * (E * cosh)),
  2139. this.opacity
  2140. );
  2141. }
  2142. }));
  2143. function basis(t1, v0, v1, v2, v3) {
  2144. var t2 = t1 * t1, t3 = t2 * t1;
  2145. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2146. + (4 - 6 * t2 + 3 * t3) * v1
  2147. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2148. + t3 * v3) / 6;
  2149. }
  2150. function basis$1(values) {
  2151. var n = values.length - 1;
  2152. return function(t) {
  2153. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2154. v1 = values[i],
  2155. v2 = values[i + 1],
  2156. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2157. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2158. return basis((t - i / n) * n, v0, v1, v2, v3);
  2159. };
  2160. }
  2161. function basisClosed(values) {
  2162. var n = values.length;
  2163. return function(t) {
  2164. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2165. v0 = values[(i + n - 1) % n],
  2166. v1 = values[i % n],
  2167. v2 = values[(i + 1) % n],
  2168. v3 = values[(i + 2) % n];
  2169. return basis((t - i / n) * n, v0, v1, v2, v3);
  2170. };
  2171. }
  2172. function constant$3(x) {
  2173. return function() {
  2174. return x;
  2175. };
  2176. }
  2177. function linear(a, d) {
  2178. return function(t) {
  2179. return a + t * d;
  2180. };
  2181. }
  2182. function exponential(a, b, y) {
  2183. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2184. return Math.pow(a + t * b, y);
  2185. };
  2186. }
  2187. function hue(a, b) {
  2188. var d = b - a;
  2189. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2190. }
  2191. function gamma(y) {
  2192. return (y = +y) === 1 ? nogamma : function(a, b) {
  2193. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2194. };
  2195. }
  2196. function nogamma(a, b) {
  2197. var d = b - a;
  2198. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2199. }
  2200. var interpolateRgb = (function rgbGamma(y) {
  2201. var color$$1 = gamma(y);
  2202. function rgb$$1(start, end) {
  2203. var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
  2204. g = color$$1(start.g, end.g),
  2205. b = color$$1(start.b, end.b),
  2206. opacity = nogamma(start.opacity, end.opacity);
  2207. return function(t) {
  2208. start.r = r(t);
  2209. start.g = g(t);
  2210. start.b = b(t);
  2211. start.opacity = opacity(t);
  2212. return start + "";
  2213. };
  2214. }
  2215. rgb$$1.gamma = rgbGamma;
  2216. return rgb$$1;
  2217. })(1);
  2218. function rgbSpline(spline) {
  2219. return function(colors) {
  2220. var n = colors.length,
  2221. r = new Array(n),
  2222. g = new Array(n),
  2223. b = new Array(n),
  2224. i, color$$1;
  2225. for (i = 0; i < n; ++i) {
  2226. color$$1 = rgb(colors[i]);
  2227. r[i] = color$$1.r || 0;
  2228. g[i] = color$$1.g || 0;
  2229. b[i] = color$$1.b || 0;
  2230. }
  2231. r = spline(r);
  2232. g = spline(g);
  2233. b = spline(b);
  2234. color$$1.opacity = 1;
  2235. return function(t) {
  2236. color$$1.r = r(t);
  2237. color$$1.g = g(t);
  2238. color$$1.b = b(t);
  2239. return color$$1 + "";
  2240. };
  2241. };
  2242. }
  2243. var rgbBasis = rgbSpline(basis$1);
  2244. var rgbBasisClosed = rgbSpline(basisClosed);
  2245. function array$1(a, b) {
  2246. var nb = b ? b.length : 0,
  2247. na = a ? Math.min(nb, a.length) : 0,
  2248. x = new Array(na),
  2249. c = new Array(nb),
  2250. i;
  2251. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2252. for (; i < nb; ++i) c[i] = b[i];
  2253. return function(t) {
  2254. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2255. return c;
  2256. };
  2257. }
  2258. function date(a, b) {
  2259. var d = new Date;
  2260. return a = +a, b -= a, function(t) {
  2261. return d.setTime(a + b * t), d;
  2262. };
  2263. }
  2264. function reinterpolate(a, b) {
  2265. return a = +a, b -= a, function(t) {
  2266. return a + b * t;
  2267. };
  2268. }
  2269. function object(a, b) {
  2270. var i = {},
  2271. c = {},
  2272. k;
  2273. if (a === null || typeof a !== "object") a = {};
  2274. if (b === null || typeof b !== "object") b = {};
  2275. for (k in b) {
  2276. if (k in a) {
  2277. i[k] = interpolateValue(a[k], b[k]);
  2278. } else {
  2279. c[k] = b[k];
  2280. }
  2281. }
  2282. return function(t) {
  2283. for (k in i) c[k] = i[k](t);
  2284. return c;
  2285. };
  2286. }
  2287. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
  2288. var reB = new RegExp(reA.source, "g");
  2289. function zero(b) {
  2290. return function() {
  2291. return b;
  2292. };
  2293. }
  2294. function one(b) {
  2295. return function(t) {
  2296. return b(t) + "";
  2297. };
  2298. }
  2299. function interpolateString(a, b) {
  2300. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2301. am, // current match in a
  2302. bm, // current match in b
  2303. bs, // string preceding current number in b, if any
  2304. i = -1, // index in s
  2305. s = [], // string constants and placeholders
  2306. q = []; // number interpolators
  2307. // Coerce inputs to strings.
  2308. a = a + "", b = b + "";
  2309. // Interpolate pairs of numbers in a & b.
  2310. while ((am = reA.exec(a))
  2311. && (bm = reB.exec(b))) {
  2312. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2313. bs = b.slice(bi, bs);
  2314. if (s[i]) s[i] += bs; // coalesce with previous string
  2315. else s[++i] = bs;
  2316. }
  2317. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2318. if (s[i]) s[i] += bm; // coalesce with previous string
  2319. else s[++i] = bm;
  2320. } else { // interpolate non-matching numbers
  2321. s[++i] = null;
  2322. q.push({i: i, x: reinterpolate(am, bm)});
  2323. }
  2324. bi = reB.lastIndex;
  2325. }
  2326. // Add remains of b.
  2327. if (bi < b.length) {
  2328. bs = b.slice(bi);
  2329. if (s[i]) s[i] += bs; // coalesce with previous string
  2330. else s[++i] = bs;
  2331. }
  2332. // Special optimization for only a single match.
  2333. // Otherwise, interpolate each of the numbers and rejoin the string.
  2334. return s.length < 2 ? (q[0]
  2335. ? one(q[0].x)
  2336. : zero(b))
  2337. : (b = q.length, function(t) {
  2338. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2339. return s.join("");
  2340. });
  2341. }
  2342. function interpolateValue(a, b) {
  2343. var t = typeof b, c;
  2344. return b == null || t === "boolean" ? constant$3(b)
  2345. : (t === "number" ? reinterpolate
  2346. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2347. : b instanceof color ? interpolateRgb
  2348. : b instanceof Date ? date
  2349. : Array.isArray(b) ? array$1
  2350. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2351. : reinterpolate)(a, b);
  2352. }
  2353. function interpolateRound(a, b) {
  2354. return a = +a, b -= a, function(t) {
  2355. return Math.round(a + b * t);
  2356. };
  2357. }
  2358. var degrees = 180 / Math.PI;
  2359. var identity$2 = {
  2360. translateX: 0,
  2361. translateY: 0,
  2362. rotate: 0,
  2363. skewX: 0,
  2364. scaleX: 1,
  2365. scaleY: 1
  2366. };
  2367. function decompose(a, b, c, d, e, f) {
  2368. var scaleX, scaleY, skewX;
  2369. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2370. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2371. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2372. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2373. return {
  2374. translateX: e,
  2375. translateY: f,
  2376. rotate: Math.atan2(b, a) * degrees,
  2377. skewX: Math.atan(skewX) * degrees,
  2378. scaleX: scaleX,
  2379. scaleY: scaleY
  2380. };
  2381. }
  2382. var cssNode;
  2383. var cssRoot;
  2384. var cssView;
  2385. var svgNode;
  2386. function parseCss(value) {
  2387. if (value === "none") return identity$2;
  2388. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2389. cssNode.style.transform = value;
  2390. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2391. cssRoot.removeChild(cssNode);
  2392. value = value.slice(7, -1).split(",");
  2393. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2394. }
  2395. function parseSvg(value) {
  2396. if (value == null) return identity$2;
  2397. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2398. svgNode.setAttribute("transform", value);
  2399. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2400. value = value.matrix;
  2401. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2402. }
  2403. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2404. function pop(s) {
  2405. return s.length ? s.pop() + " " : "";
  2406. }
  2407. function translate(xa, ya, xb, yb, s, q) {
  2408. if (xa !== xb || ya !== yb) {
  2409. var i = s.push("translate(", null, pxComma, null, pxParen);
  2410. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2411. } else if (xb || yb) {
  2412. s.push("translate(" + xb + pxComma + yb + pxParen);
  2413. }
  2414. }
  2415. function rotate(a, b, s, q) {
  2416. if (a !== b) {
  2417. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2418. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
  2419. } else if (b) {
  2420. s.push(pop(s) + "rotate(" + b + degParen);
  2421. }
  2422. }
  2423. function skewX(a, b, s, q) {
  2424. if (a !== b) {
  2425. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
  2426. } else if (b) {
  2427. s.push(pop(s) + "skewX(" + b + degParen);
  2428. }
  2429. }
  2430. function scale(xa, ya, xb, yb, s, q) {
  2431. if (xa !== xb || ya !== yb) {
  2432. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2433. q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
  2434. } else if (xb !== 1 || yb !== 1) {
  2435. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2436. }
  2437. }
  2438. return function(a, b) {
  2439. var s = [], // string constants and placeholders
  2440. q = []; // number interpolators
  2441. a = parse(a), b = parse(b);
  2442. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2443. rotate(a.rotate, b.rotate, s, q);
  2444. skewX(a.skewX, b.skewX, s, q);
  2445. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2446. a = b = null; // gc
  2447. return function(t) {
  2448. var i = -1, n = q.length, o;
  2449. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2450. return s.join("");
  2451. };
  2452. };
  2453. }
  2454. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2455. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2456. var rho = Math.SQRT2;
  2457. var rho2 = 2;
  2458. var rho4 = 4;
  2459. var epsilon2 = 1e-12;
  2460. function cosh(x) {
  2461. return ((x = Math.exp(x)) + 1 / x) / 2;
  2462. }
  2463. function sinh(x) {
  2464. return ((x = Math.exp(x)) - 1 / x) / 2;
  2465. }
  2466. function tanh(x) {
  2467. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2468. }
  2469. // p0 = [ux0, uy0, w0]
  2470. // p1 = [ux1, uy1, w1]
  2471. function interpolateZoom(p0, p1) {
  2472. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2473. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2474. dx = ux1 - ux0,
  2475. dy = uy1 - uy0,
  2476. d2 = dx * dx + dy * dy,
  2477. i,
  2478. S;
  2479. // Special case for u0 ≅ u1.
  2480. if (d2 < epsilon2) {
  2481. S = Math.log(w1 / w0) / rho;
  2482. i = function(t) {
  2483. return [
  2484. ux0 + t * dx,
  2485. uy0 + t * dy,
  2486. w0 * Math.exp(rho * t * S)
  2487. ];
  2488. };
  2489. }
  2490. // General case.
  2491. else {
  2492. var d1 = Math.sqrt(d2),
  2493. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2494. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2495. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2496. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2497. S = (r1 - r0) / rho;
  2498. i = function(t) {
  2499. var s = t * S,
  2500. coshr0 = cosh(r0),
  2501. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2502. return [
  2503. ux0 + u * dx,
  2504. uy0 + u * dy,
  2505. w0 * coshr0 / cosh(rho * s + r0)
  2506. ];
  2507. };
  2508. }
  2509. i.duration = S * 1000;
  2510. return i;
  2511. }
  2512. function hsl$1(hue$$1) {
  2513. return function(start, end) {
  2514. var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
  2515. s = nogamma(start.s, end.s),
  2516. l = nogamma(start.l, end.l),
  2517. opacity = nogamma(start.opacity, end.opacity);
  2518. return function(t) {
  2519. start.h = h(t);
  2520. start.s = s(t);
  2521. start.l = l(t);
  2522. start.opacity = opacity(t);
  2523. return start + "";
  2524. };
  2525. }
  2526. }
  2527. var hsl$2 = hsl$1(hue);
  2528. var hslLong = hsl$1(nogamma);
  2529. function lab$1(start, end) {
  2530. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2531. a = nogamma(start.a, end.a),
  2532. b = nogamma(start.b, end.b),
  2533. opacity = nogamma(start.opacity, end.opacity);
  2534. return function(t) {
  2535. start.l = l(t);
  2536. start.a = a(t);
  2537. start.b = b(t);
  2538. start.opacity = opacity(t);
  2539. return start + "";
  2540. };
  2541. }
  2542. function hcl$1(hue$$1) {
  2543. return function(start, end) {
  2544. var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
  2545. c = nogamma(start.c, end.c),
  2546. l = nogamma(start.l, end.l),
  2547. opacity = nogamma(start.opacity, end.opacity);
  2548. return function(t) {
  2549. start.h = h(t);
  2550. start.c = c(t);
  2551. start.l = l(t);
  2552. start.opacity = opacity(t);
  2553. return start + "";
  2554. };
  2555. }
  2556. }
  2557. var hcl$2 = hcl$1(hue);
  2558. var hclLong = hcl$1(nogamma);
  2559. function cubehelix$1(hue$$1) {
  2560. return (function cubehelixGamma(y) {
  2561. y = +y;
  2562. function cubehelix$$1(start, end) {
  2563. var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2564. s = nogamma(start.s, end.s),
  2565. l = nogamma(start.l, end.l),
  2566. opacity = nogamma(start.opacity, end.opacity);
  2567. return function(t) {
  2568. start.h = h(t);
  2569. start.s = s(t);
  2570. start.l = l(Math.pow(t, y));
  2571. start.opacity = opacity(t);
  2572. return start + "";
  2573. };
  2574. }
  2575. cubehelix$$1.gamma = cubehelixGamma;
  2576. return cubehelix$$1;
  2577. })(1);
  2578. }
  2579. var cubehelix$2 = cubehelix$1(hue);
  2580. var cubehelixLong = cubehelix$1(nogamma);
  2581. function quantize(interpolator, n) {
  2582. var samples = new Array(n);
  2583. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2584. return samples;
  2585. }
  2586. var frame = 0;
  2587. var timeout = 0;
  2588. var interval = 0;
  2589. var pokeDelay = 1000;
  2590. var taskHead;
  2591. var taskTail;
  2592. var clockLast = 0;
  2593. var clockNow = 0;
  2594. var clockSkew = 0;
  2595. var clock = typeof performance === "object" && performance.now ? performance : Date;
  2596. var setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2597. function now() {
  2598. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2599. }
  2600. function clearNow() {
  2601. clockNow = 0;
  2602. }
  2603. function Timer() {
  2604. this._call =
  2605. this._time =
  2606. this._next = null;
  2607. }
  2608. Timer.prototype = timer.prototype = {
  2609. constructor: Timer,
  2610. restart: function(callback, delay, time) {
  2611. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2612. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2613. if (!this._next && taskTail !== this) {
  2614. if (taskTail) taskTail._next = this;
  2615. else taskHead = this;
  2616. taskTail = this;
  2617. }
  2618. this._call = callback;
  2619. this._time = time;
  2620. sleep();
  2621. },
  2622. stop: function() {
  2623. if (this._call) {
  2624. this._call = null;
  2625. this._time = Infinity;
  2626. sleep();
  2627. }
  2628. }
  2629. };
  2630. function timer(callback, delay, time) {
  2631. var t = new Timer;
  2632. t.restart(callback, delay, time);
  2633. return t;
  2634. }
  2635. function timerFlush() {
  2636. now(); // Get the current time, if not already set.
  2637. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2638. var t = taskHead, e;
  2639. while (t) {
  2640. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2641. t = t._next;
  2642. }
  2643. --frame;
  2644. }
  2645. function wake() {
  2646. clockNow = (clockLast = clock.now()) + clockSkew;
  2647. frame = timeout = 0;
  2648. try {
  2649. timerFlush();
  2650. } finally {
  2651. frame = 0;
  2652. nap();
  2653. clockNow = 0;
  2654. }
  2655. }
  2656. function poke() {
  2657. var now = clock.now(), delay = now - clockLast;
  2658. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2659. }
  2660. function nap() {
  2661. var t0, t1 = taskHead, t2, time = Infinity;
  2662. while (t1) {
  2663. if (t1._call) {
  2664. if (time > t1._time) time = t1._time;
  2665. t0 = t1, t1 = t1._next;
  2666. } else {
  2667. t2 = t1._next, t1._next = null;
  2668. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2669. }
  2670. }
  2671. taskTail = t0;
  2672. sleep(time);
  2673. }
  2674. function sleep(time) {
  2675. if (frame) return; // Soonest alarm already set, or will be.
  2676. if (timeout) timeout = clearTimeout(timeout);
  2677. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2678. if (delay > 24) {
  2679. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2680. if (interval) interval = clearInterval(interval);
  2681. } else {
  2682. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2683. frame = 1, setFrame(wake);
  2684. }
  2685. }
  2686. function timeout$1(callback, delay, time) {
  2687. var t = new Timer;
  2688. delay = delay == null ? 0 : +delay;
  2689. t.restart(function(elapsed) {
  2690. t.stop();
  2691. callback(elapsed + delay);
  2692. }, delay, time);
  2693. return t;
  2694. }
  2695. function interval$1(callback, delay, time) {
  2696. var t = new Timer, total = delay;
  2697. if (delay == null) return t.restart(callback, delay, time), t;
  2698. delay = +delay, time = time == null ? now() : +time;
  2699. t.restart(function tick(elapsed) {
  2700. elapsed += total;
  2701. t.restart(tick, total += delay, time);
  2702. callback(elapsed);
  2703. }, delay, time);
  2704. return t;
  2705. }
  2706. var emptyOn = dispatch("start", "end", "interrupt");
  2707. var emptyTween = [];
  2708. var CREATED = 0;
  2709. var SCHEDULED = 1;
  2710. var STARTING = 2;
  2711. var STARTED = 3;
  2712. var RUNNING = 4;
  2713. var ENDING = 5;
  2714. var ENDED = 6;
  2715. function schedule(node, name, id, index, group, timing) {
  2716. var schedules = node.__transition;
  2717. if (!schedules) node.__transition = {};
  2718. else if (id in schedules) return;
  2719. create$1(node, id, {
  2720. name: name,
  2721. index: index, // For context during callback.
  2722. group: group, // For context during callback.
  2723. on: emptyOn,
  2724. tween: emptyTween,
  2725. time: timing.time,
  2726. delay: timing.delay,
  2727. duration: timing.duration,
  2728. ease: timing.ease,
  2729. timer: null,
  2730. state: CREATED
  2731. });
  2732. }
  2733. function init(node, id) {
  2734. var schedule = get$1(node, id);
  2735. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  2736. return schedule;
  2737. }
  2738. function set$1(node, id) {
  2739. var schedule = get$1(node, id);
  2740. if (schedule.state > STARTING) throw new Error("too late; already started");
  2741. return schedule;
  2742. }
  2743. function get$1(node, id) {
  2744. var schedule = node.__transition;
  2745. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  2746. return schedule;
  2747. }
  2748. function create$1(node, id, self) {
  2749. var schedules = node.__transition,
  2750. tween;
  2751. // Initialize the self timer when the transition is created.
  2752. // Note the actual delay is not known until the first callback!
  2753. schedules[id] = self;
  2754. self.timer = timer(schedule, 0, self.time);
  2755. function schedule(elapsed) {
  2756. self.state = SCHEDULED;
  2757. self.timer.restart(start, self.delay, self.time);
  2758. // If the elapsed delay is less than our first sleep, start immediately.
  2759. if (self.delay <= elapsed) start(elapsed - self.delay);
  2760. }
  2761. function start(elapsed) {
  2762. var i, j, n, o;
  2763. // If the state is not SCHEDULED, then we previously errored on start.
  2764. if (self.state !== SCHEDULED) return stop();
  2765. for (i in schedules) {
  2766. o = schedules[i];
  2767. if (o.name !== self.name) continue;
  2768. // While this element already has a starting transition during this frame,
  2769. // defer starting an interrupting transition until that transition has a
  2770. // chance to tick (and possibly end); see d3/d3-transition#54!
  2771. if (o.state === STARTED) return timeout$1(start);
  2772. // Interrupt the active transition, if any.
  2773. // Dispatch the interrupt event.
  2774. if (o.state === RUNNING) {
  2775. o.state = ENDED;
  2776. o.timer.stop();
  2777. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2778. delete schedules[i];
  2779. }
  2780. // Cancel any pre-empted transitions. No interrupt event is dispatched
  2781. // because the cancelled transitions never started. Note that this also
  2782. // removes this transition from the pending list!
  2783. else if (+i < id) {
  2784. o.state = ENDED;
  2785. o.timer.stop();
  2786. delete schedules[i];
  2787. }
  2788. }
  2789. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2790. // Note the transition may be canceled after start and before the first tick!
  2791. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2792. // Assuming this is successful, subsequent callbacks go straight to tick.
  2793. timeout$1(function() {
  2794. if (self.state === STARTED) {
  2795. self.state = RUNNING;
  2796. self.timer.restart(tick, self.delay, self.time);
  2797. tick(elapsed);
  2798. }
  2799. });
  2800. // Dispatch the start event.
  2801. // Note this must be done before the tween are initialized.
  2802. self.state = STARTING;
  2803. self.on.call("start", node, node.__data__, self.index, self.group);
  2804. if (self.state !== STARTING) return; // interrupted
  2805. self.state = STARTED;
  2806. // Initialize the tween, deleting null tween.
  2807. tween = new Array(n = self.tween.length);
  2808. for (i = 0, j = -1; i < n; ++i) {
  2809. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2810. tween[++j] = o;
  2811. }
  2812. }
  2813. tween.length = j + 1;
  2814. }
  2815. function tick(elapsed) {
  2816. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2817. i = -1,
  2818. n = tween.length;
  2819. while (++i < n) {
  2820. tween[i].call(null, t);
  2821. }
  2822. // Dispatch the end event.
  2823. if (self.state === ENDING) {
  2824. self.on.call("end", node, node.__data__, self.index, self.group);
  2825. stop();
  2826. }
  2827. }
  2828. function stop() {
  2829. self.state = ENDED;
  2830. self.timer.stop();
  2831. delete schedules[id];
  2832. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2833. delete node.__transition;
  2834. }
  2835. }
  2836. function interrupt(node, name) {
  2837. var schedules = node.__transition,
  2838. schedule$$1,
  2839. active,
  2840. empty = true,
  2841. i;
  2842. if (!schedules) return;
  2843. name = name == null ? null : name + "";
  2844. for (i in schedules) {
  2845. if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
  2846. active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
  2847. schedule$$1.state = ENDED;
  2848. schedule$$1.timer.stop();
  2849. if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
  2850. delete schedules[i];
  2851. }
  2852. if (empty) delete node.__transition;
  2853. }
  2854. function selection_interrupt(name) {
  2855. return this.each(function() {
  2856. interrupt(this, name);
  2857. });
  2858. }
  2859. function tweenRemove(id, name) {
  2860. var tween0, tween1;
  2861. return function() {
  2862. var schedule$$1 = set$1(this, id),
  2863. tween = schedule$$1.tween;
  2864. // If this node shared tween with the previous node,
  2865. // just assign the updated shared tween and we’re done!
  2866. // Otherwise, copy-on-write.
  2867. if (tween !== tween0) {
  2868. tween1 = tween0 = tween;
  2869. for (var i = 0, n = tween1.length; i < n; ++i) {
  2870. if (tween1[i].name === name) {
  2871. tween1 = tween1.slice();
  2872. tween1.splice(i, 1);
  2873. break;
  2874. }
  2875. }
  2876. }
  2877. schedule$$1.tween = tween1;
  2878. };
  2879. }
  2880. function tweenFunction(id, name, value) {
  2881. var tween0, tween1;
  2882. if (typeof value !== "function") throw new Error;
  2883. return function() {
  2884. var schedule$$1 = set$1(this, id),
  2885. tween = schedule$$1.tween;
  2886. // If this node shared tween with the previous node,
  2887. // just assign the updated shared tween and we’re done!
  2888. // Otherwise, copy-on-write.
  2889. if (tween !== tween0) {
  2890. tween1 = (tween0 = tween).slice();
  2891. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2892. if (tween1[i].name === name) {
  2893. tween1[i] = t;
  2894. break;
  2895. }
  2896. }
  2897. if (i === n) tween1.push(t);
  2898. }
  2899. schedule$$1.tween = tween1;
  2900. };
  2901. }
  2902. function transition_tween(name, value) {
  2903. var id = this._id;
  2904. name += "";
  2905. if (arguments.length < 2) {
  2906. var tween = get$1(this.node(), id).tween;
  2907. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2908. if ((t = tween[i]).name === name) {
  2909. return t.value;
  2910. }
  2911. }
  2912. return null;
  2913. }
  2914. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2915. }
  2916. function tweenValue(transition, name, value) {
  2917. var id = transition._id;
  2918. transition.each(function() {
  2919. var schedule$$1 = set$1(this, id);
  2920. (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
  2921. });
  2922. return function(node) {
  2923. return get$1(node, id).value[name];
  2924. };
  2925. }
  2926. function interpolate(a, b) {
  2927. var c;
  2928. return (typeof b === "number" ? reinterpolate
  2929. : b instanceof color ? interpolateRgb
  2930. : (c = color(b)) ? (b = c, interpolateRgb)
  2931. : interpolateString)(a, b);
  2932. }
  2933. function attrRemove$1(name) {
  2934. return function() {
  2935. this.removeAttribute(name);
  2936. };
  2937. }
  2938. function attrRemoveNS$1(fullname) {
  2939. return function() {
  2940. this.removeAttributeNS(fullname.space, fullname.local);
  2941. };
  2942. }
  2943. function attrConstant$1(name, interpolate$$1, value1) {
  2944. var value00,
  2945. interpolate0;
  2946. return function() {
  2947. var value0 = this.getAttribute(name);
  2948. return value0 === value1 ? null
  2949. : value0 === value00 ? interpolate0
  2950. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2951. };
  2952. }
  2953. function attrConstantNS$1(fullname, interpolate$$1, value1) {
  2954. var value00,
  2955. interpolate0;
  2956. return function() {
  2957. var value0 = this.getAttributeNS(fullname.space, fullname.local);
  2958. return value0 === value1 ? null
  2959. : value0 === value00 ? interpolate0
  2960. : interpolate0 = interpolate$$1(value00 = value0, value1);
  2961. };
  2962. }
  2963. function attrFunction$1(name, 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.removeAttribute(name);
  2970. value0 = this.getAttribute(name);
  2971. return value0 === value1 ? null
  2972. : value0 === value00 && value1 === value10 ? interpolate0
  2973. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  2974. };
  2975. }
  2976. function attrFunctionNS$1(fullname, interpolate$$1, value) {
  2977. var value00,
  2978. value10,
  2979. interpolate0;
  2980. return function() {
  2981. var value0, value1 = value(this);
  2982. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  2983. value0 = this.getAttributeNS(fullname.space, fullname.local);
  2984. return value0 === value1 ? null
  2985. : value0 === value00 && value1 === value10 ? interpolate0
  2986. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  2987. };
  2988. }
  2989. function transition_attr(name, value) {
  2990. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  2991. return this.attrTween(name, typeof value === "function"
  2992. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  2993. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  2994. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
  2995. }
  2996. function attrTweenNS(fullname, value) {
  2997. function tween() {
  2998. var node = this, i = value.apply(node, arguments);
  2999. return i && function(t) {
  3000. node.setAttributeNS(fullname.space, fullname.local, i(t));
  3001. };
  3002. }
  3003. tween._value = value;
  3004. return tween;
  3005. }
  3006. function attrTween(name, value) {
  3007. function tween() {
  3008. var node = this, i = value.apply(node, arguments);
  3009. return i && function(t) {
  3010. node.setAttribute(name, i(t));
  3011. };
  3012. }
  3013. tween._value = value;
  3014. return tween;
  3015. }
  3016. function transition_attrTween(name, value) {
  3017. var key = "attr." + name;
  3018. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3019. if (value == null) return this.tween(key, null);
  3020. if (typeof value !== "function") throw new Error;
  3021. var fullname = namespace(name);
  3022. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3023. }
  3024. function delayFunction(id, value) {
  3025. return function() {
  3026. init(this, id).delay = +value.apply(this, arguments);
  3027. };
  3028. }
  3029. function delayConstant(id, value) {
  3030. return value = +value, function() {
  3031. init(this, id).delay = value;
  3032. };
  3033. }
  3034. function transition_delay(value) {
  3035. var id = this._id;
  3036. return arguments.length
  3037. ? this.each((typeof value === "function"
  3038. ? delayFunction
  3039. : delayConstant)(id, value))
  3040. : get$1(this.node(), id).delay;
  3041. }
  3042. function durationFunction(id, value) {
  3043. return function() {
  3044. set$1(this, id).duration = +value.apply(this, arguments);
  3045. };
  3046. }
  3047. function durationConstant(id, value) {
  3048. return value = +value, function() {
  3049. set$1(this, id).duration = value;
  3050. };
  3051. }
  3052. function transition_duration(value) {
  3053. var id = this._id;
  3054. return arguments.length
  3055. ? this.each((typeof value === "function"
  3056. ? durationFunction
  3057. : durationConstant)(id, value))
  3058. : get$1(this.node(), id).duration;
  3059. }
  3060. function easeConstant(id, value) {
  3061. if (typeof value !== "function") throw new Error;
  3062. return function() {
  3063. set$1(this, id).ease = value;
  3064. };
  3065. }
  3066. function transition_ease(value) {
  3067. var id = this._id;
  3068. return arguments.length
  3069. ? this.each(easeConstant(id, value))
  3070. : get$1(this.node(), id).ease;
  3071. }
  3072. function transition_filter(match) {
  3073. if (typeof match !== "function") match = matcher$1(match);
  3074. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3075. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3076. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3077. subgroup.push(node);
  3078. }
  3079. }
  3080. }
  3081. return new Transition(subgroups, this._parents, this._name, this._id);
  3082. }
  3083. function transition_merge(transition$$1) {
  3084. if (transition$$1._id !== this._id) throw new Error;
  3085. 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) {
  3086. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3087. if (node = group0[i] || group1[i]) {
  3088. merge[i] = node;
  3089. }
  3090. }
  3091. }
  3092. for (; j < m0; ++j) {
  3093. merges[j] = groups0[j];
  3094. }
  3095. return new Transition(merges, this._parents, this._name, this._id);
  3096. }
  3097. function start(name) {
  3098. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3099. var i = t.indexOf(".");
  3100. if (i >= 0) t = t.slice(0, i);
  3101. return !t || t === "start";
  3102. });
  3103. }
  3104. function onFunction(id, name, listener) {
  3105. var on0, on1, sit = start(name) ? init : set$1;
  3106. return function() {
  3107. var schedule$$1 = sit(this, id),
  3108. on = schedule$$1.on;
  3109. // If this node shared a dispatch with the previous node,
  3110. // just assign the updated shared dispatch and we’re done!
  3111. // Otherwise, copy-on-write.
  3112. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3113. schedule$$1.on = on1;
  3114. };
  3115. }
  3116. function transition_on(name, listener) {
  3117. var id = this._id;
  3118. return arguments.length < 2
  3119. ? get$1(this.node(), id).on.on(name)
  3120. : this.each(onFunction(id, name, listener));
  3121. }
  3122. function removeFunction(id) {
  3123. return function() {
  3124. var parent = this.parentNode;
  3125. for (var i in this.__transition) if (+i !== id) return;
  3126. if (parent) parent.removeChild(this);
  3127. };
  3128. }
  3129. function transition_remove() {
  3130. return this.on("end.remove", removeFunction(this._id));
  3131. }
  3132. function transition_select(select) {
  3133. var name = this._name,
  3134. id = this._id;
  3135. if (typeof select !== "function") select = selector(select);
  3136. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3137. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3138. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  3139. if ("__data__" in node) subnode.__data__ = node.__data__;
  3140. subgroup[i] = subnode;
  3141. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3142. }
  3143. }
  3144. }
  3145. return new Transition(subgroups, this._parents, name, id);
  3146. }
  3147. function transition_selectAll(select) {
  3148. var name = this._name,
  3149. id = this._id;
  3150. if (typeof select !== "function") select = selectorAll(select);
  3151. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3152. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3153. if (node = group[i]) {
  3154. for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3155. if (child = children[k]) {
  3156. schedule(child, name, id, k, children, inherit);
  3157. }
  3158. }
  3159. subgroups.push(children);
  3160. parents.push(node);
  3161. }
  3162. }
  3163. }
  3164. return new Transition(subgroups, parents, name, id);
  3165. }
  3166. var Selection$1 = selection.prototype.constructor;
  3167. function transition_selection() {
  3168. return new Selection$1(this._groups, this._parents);
  3169. }
  3170. function styleRemove$1(name, interpolate$$1) {
  3171. var value00,
  3172. value10,
  3173. interpolate0;
  3174. return function() {
  3175. var value0 = styleValue(this, name),
  3176. value1 = (this.style.removeProperty(name), styleValue(this, name));
  3177. return value0 === value1 ? null
  3178. : value0 === value00 && value1 === value10 ? interpolate0
  3179. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3180. };
  3181. }
  3182. function styleRemoveEnd(name) {
  3183. return function() {
  3184. this.style.removeProperty(name);
  3185. };
  3186. }
  3187. function styleConstant$1(name, interpolate$$1, value1) {
  3188. var value00,
  3189. interpolate0;
  3190. return function() {
  3191. var value0 = styleValue(this, name);
  3192. return value0 === value1 ? null
  3193. : value0 === value00 ? interpolate0
  3194. : interpolate0 = interpolate$$1(value00 = value0, value1);
  3195. };
  3196. }
  3197. function styleFunction$1(name, interpolate$$1, value) {
  3198. var value00,
  3199. value10,
  3200. interpolate0;
  3201. return function() {
  3202. var value0 = styleValue(this, name),
  3203. value1 = value(this);
  3204. if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
  3205. return value0 === value1 ? null
  3206. : value0 === value00 && value1 === value10 ? interpolate0
  3207. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  3208. };
  3209. }
  3210. function transition_style(name, value, priority) {
  3211. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3212. return value == null ? this
  3213. .styleTween(name, styleRemove$1(name, i))
  3214. .on("end.style." + name, styleRemoveEnd(name))
  3215. : this.styleTween(name, typeof value === "function"
  3216. ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
  3217. : styleConstant$1(name, i, value + ""), priority);
  3218. }
  3219. function styleTween(name, value, priority) {
  3220. function tween() {
  3221. var node = this, i = value.apply(node, arguments);
  3222. return i && function(t) {
  3223. node.style.setProperty(name, i(t), priority);
  3224. };
  3225. }
  3226. tween._value = value;
  3227. return tween;
  3228. }
  3229. function transition_styleTween(name, value, priority) {
  3230. var key = "style." + (name += "");
  3231. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3232. if (value == null) return this.tween(key, null);
  3233. if (typeof value !== "function") throw new Error;
  3234. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3235. }
  3236. function textConstant$1(value) {
  3237. return function() {
  3238. this.textContent = value;
  3239. };
  3240. }
  3241. function textFunction$1(value) {
  3242. return function() {
  3243. var value1 = value(this);
  3244. this.textContent = value1 == null ? "" : value1;
  3245. };
  3246. }
  3247. function transition_text(value) {
  3248. return this.tween("text", typeof value === "function"
  3249. ? textFunction$1(tweenValue(this, "text", value))
  3250. : textConstant$1(value == null ? "" : value + ""));
  3251. }
  3252. function transition_transition() {
  3253. var name = this._name,
  3254. id0 = this._id,
  3255. id1 = newId();
  3256. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3257. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3258. if (node = group[i]) {
  3259. var inherit = get$1(node, id0);
  3260. schedule(node, name, id1, i, group, {
  3261. time: inherit.time + inherit.delay + inherit.duration,
  3262. delay: 0,
  3263. duration: inherit.duration,
  3264. ease: inherit.ease
  3265. });
  3266. }
  3267. }
  3268. }
  3269. return new Transition(groups, this._parents, name, id1);
  3270. }
  3271. var id = 0;
  3272. function Transition(groups, parents, name, id) {
  3273. this._groups = groups;
  3274. this._parents = parents;
  3275. this._name = name;
  3276. this._id = id;
  3277. }
  3278. function transition(name) {
  3279. return selection().transition(name);
  3280. }
  3281. function newId() {
  3282. return ++id;
  3283. }
  3284. var selection_prototype = selection.prototype;
  3285. Transition.prototype = transition.prototype = {
  3286. constructor: Transition,
  3287. select: transition_select,
  3288. selectAll: transition_selectAll,
  3289. filter: transition_filter,
  3290. merge: transition_merge,
  3291. selection: transition_selection,
  3292. transition: transition_transition,
  3293. call: selection_prototype.call,
  3294. nodes: selection_prototype.nodes,
  3295. node: selection_prototype.node,
  3296. size: selection_prototype.size,
  3297. empty: selection_prototype.empty,
  3298. each: selection_prototype.each,
  3299. on: transition_on,
  3300. attr: transition_attr,
  3301. attrTween: transition_attrTween,
  3302. style: transition_style,
  3303. styleTween: transition_styleTween,
  3304. text: transition_text,
  3305. remove: transition_remove,
  3306. tween: transition_tween,
  3307. delay: transition_delay,
  3308. duration: transition_duration,
  3309. ease: transition_ease
  3310. };
  3311. function linear$1(t) {
  3312. return +t;
  3313. }
  3314. function quadIn(t) {
  3315. return t * t;
  3316. }
  3317. function quadOut(t) {
  3318. return t * (2 - t);
  3319. }
  3320. function quadInOut(t) {
  3321. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3322. }
  3323. function cubicIn(t) {
  3324. return t * t * t;
  3325. }
  3326. function cubicOut(t) {
  3327. return --t * t * t + 1;
  3328. }
  3329. function cubicInOut(t) {
  3330. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3331. }
  3332. var exponent = 3;
  3333. var polyIn = (function custom(e) {
  3334. e = +e;
  3335. function polyIn(t) {
  3336. return Math.pow(t, e);
  3337. }
  3338. polyIn.exponent = custom;
  3339. return polyIn;
  3340. })(exponent);
  3341. var polyOut = (function custom(e) {
  3342. e = +e;
  3343. function polyOut(t) {
  3344. return 1 - Math.pow(1 - t, e);
  3345. }
  3346. polyOut.exponent = custom;
  3347. return polyOut;
  3348. })(exponent);
  3349. var polyInOut = (function custom(e) {
  3350. e = +e;
  3351. function polyInOut(t) {
  3352. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3353. }
  3354. polyInOut.exponent = custom;
  3355. return polyInOut;
  3356. })(exponent);
  3357. var pi = Math.PI;
  3358. var halfPi = pi / 2;
  3359. function sinIn(t) {
  3360. return 1 - Math.cos(t * halfPi);
  3361. }
  3362. function sinOut(t) {
  3363. return Math.sin(t * halfPi);
  3364. }
  3365. function sinInOut(t) {
  3366. return (1 - Math.cos(pi * t)) / 2;
  3367. }
  3368. function expIn(t) {
  3369. return Math.pow(2, 10 * t - 10);
  3370. }
  3371. function expOut(t) {
  3372. return 1 - Math.pow(2, -10 * t);
  3373. }
  3374. function expInOut(t) {
  3375. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3376. }
  3377. function circleIn(t) {
  3378. return 1 - Math.sqrt(1 - t * t);
  3379. }
  3380. function circleOut(t) {
  3381. return Math.sqrt(1 - --t * t);
  3382. }
  3383. function circleInOut(t) {
  3384. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3385. }
  3386. var b1 = 4 / 11;
  3387. var b2 = 6 / 11;
  3388. var b3 = 8 / 11;
  3389. var b4 = 3 / 4;
  3390. var b5 = 9 / 11;
  3391. var b6 = 10 / 11;
  3392. var b7 = 15 / 16;
  3393. var b8 = 21 / 22;
  3394. var b9 = 63 / 64;
  3395. var b0 = 1 / b1 / b1;
  3396. function bounceIn(t) {
  3397. return 1 - bounceOut(1 - t);
  3398. }
  3399. function bounceOut(t) {
  3400. 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;
  3401. }
  3402. function bounceInOut(t) {
  3403. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3404. }
  3405. var overshoot = 1.70158;
  3406. var backIn = (function custom(s) {
  3407. s = +s;
  3408. function backIn(t) {
  3409. return t * t * ((s + 1) * t - s);
  3410. }
  3411. backIn.overshoot = custom;
  3412. return backIn;
  3413. })(overshoot);
  3414. var backOut = (function custom(s) {
  3415. s = +s;
  3416. function backOut(t) {
  3417. return --t * t * ((s + 1) * t + s) + 1;
  3418. }
  3419. backOut.overshoot = custom;
  3420. return backOut;
  3421. })(overshoot);
  3422. var backInOut = (function custom(s) {
  3423. s = +s;
  3424. function backInOut(t) {
  3425. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3426. }
  3427. backInOut.overshoot = custom;
  3428. return backInOut;
  3429. })(overshoot);
  3430. var tau = 2 * Math.PI;
  3431. var amplitude = 1;
  3432. var period = 0.3;
  3433. var elasticIn = (function custom(a, p) {
  3434. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3435. function elasticIn(t) {
  3436. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3437. }
  3438. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3439. elasticIn.period = function(p) { return custom(a, p); };
  3440. return elasticIn;
  3441. })(amplitude, period);
  3442. var elasticOut = (function custom(a, p) {
  3443. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3444. function elasticOut(t) {
  3445. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3446. }
  3447. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3448. elasticOut.period = function(p) { return custom(a, p); };
  3449. return elasticOut;
  3450. })(amplitude, period);
  3451. var elasticInOut = (function custom(a, p) {
  3452. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3453. function elasticInOut(t) {
  3454. return ((t = t * 2 - 1) < 0
  3455. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3456. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3457. }
  3458. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3459. elasticInOut.period = function(p) { return custom(a, p); };
  3460. return elasticInOut;
  3461. })(amplitude, period);
  3462. var defaultTiming = {
  3463. time: null, // Set on use.
  3464. delay: 0,
  3465. duration: 250,
  3466. ease: cubicInOut
  3467. };
  3468. function inherit(node, id) {
  3469. var timing;
  3470. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3471. if (!(node = node.parentNode)) {
  3472. return defaultTiming.time = now(), defaultTiming;
  3473. }
  3474. }
  3475. return timing;
  3476. }
  3477. function selection_transition(name) {
  3478. var id,
  3479. timing;
  3480. if (name instanceof Transition) {
  3481. id = name._id, name = name._name;
  3482. } else {
  3483. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3484. }
  3485. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3486. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3487. if (node = group[i]) {
  3488. schedule(node, name, id, i, group, timing || inherit(node, id));
  3489. }
  3490. }
  3491. }
  3492. return new Transition(groups, this._parents, name, id);
  3493. }
  3494. selection.prototype.interrupt = selection_interrupt;
  3495. selection.prototype.transition = selection_transition;
  3496. var root$1 = [null];
  3497. function active(node, name) {
  3498. var schedules = node.__transition,
  3499. schedule$$1,
  3500. i;
  3501. if (schedules) {
  3502. name = name == null ? null : name + "";
  3503. for (i in schedules) {
  3504. if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
  3505. return new Transition([[node]], root$1, name, +i);
  3506. }
  3507. }
  3508. }
  3509. return null;
  3510. }
  3511. function constant$4(x) {
  3512. return function() {
  3513. return x;
  3514. };
  3515. }
  3516. function BrushEvent(target, type, selection) {
  3517. this.target = target;
  3518. this.type = type;
  3519. this.selection = selection;
  3520. }
  3521. function nopropagation$1() {
  3522. exports.event.stopImmediatePropagation();
  3523. }
  3524. function noevent$1() {
  3525. exports.event.preventDefault();
  3526. exports.event.stopImmediatePropagation();
  3527. }
  3528. var MODE_DRAG = {name: "drag"};
  3529. var MODE_SPACE = {name: "space"};
  3530. var MODE_HANDLE = {name: "handle"};
  3531. var MODE_CENTER = {name: "center"};
  3532. var X = {
  3533. name: "x",
  3534. handles: ["e", "w"].map(type),
  3535. input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
  3536. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3537. };
  3538. var Y = {
  3539. name: "y",
  3540. handles: ["n", "s"].map(type),
  3541. input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
  3542. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3543. };
  3544. var XY = {
  3545. name: "xy",
  3546. handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
  3547. input: function(xy) { return xy; },
  3548. output: function(xy) { return xy; }
  3549. };
  3550. var cursors = {
  3551. overlay: "crosshair",
  3552. selection: "move",
  3553. n: "ns-resize",
  3554. e: "ew-resize",
  3555. s: "ns-resize",
  3556. w: "ew-resize",
  3557. nw: "nwse-resize",
  3558. ne: "nesw-resize",
  3559. se: "nwse-resize",
  3560. sw: "nesw-resize"
  3561. };
  3562. var flipX = {
  3563. e: "w",
  3564. w: "e",
  3565. nw: "ne",
  3566. ne: "nw",
  3567. se: "sw",
  3568. sw: "se"
  3569. };
  3570. var flipY = {
  3571. n: "s",
  3572. s: "n",
  3573. nw: "sw",
  3574. ne: "se",
  3575. se: "ne",
  3576. sw: "nw"
  3577. };
  3578. var signsX = {
  3579. overlay: +1,
  3580. selection: +1,
  3581. n: null,
  3582. e: +1,
  3583. s: null,
  3584. w: -1,
  3585. nw: -1,
  3586. ne: +1,
  3587. se: +1,
  3588. sw: -1
  3589. };
  3590. var signsY = {
  3591. overlay: +1,
  3592. selection: +1,
  3593. n: -1,
  3594. e: null,
  3595. s: +1,
  3596. w: null,
  3597. nw: -1,
  3598. ne: -1,
  3599. se: +1,
  3600. sw: +1
  3601. };
  3602. function type(t) {
  3603. return {type: t};
  3604. }
  3605. // Ignore right-click, since that should open the context menu.
  3606. function defaultFilter() {
  3607. return !exports.event.button;
  3608. }
  3609. function defaultExtent() {
  3610. var svg = this.ownerSVGElement || this;
  3611. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3612. }
  3613. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3614. function local(node) {
  3615. while (!node.__brush) if (!(node = node.parentNode)) return;
  3616. return node.__brush;
  3617. }
  3618. function empty(extent) {
  3619. return extent[0][0] === extent[1][0]
  3620. || extent[0][1] === extent[1][1];
  3621. }
  3622. function brushSelection(node) {
  3623. var state = node.__brush;
  3624. return state ? state.dim.output(state.selection) : null;
  3625. }
  3626. function brushX() {
  3627. return brush$1(X);
  3628. }
  3629. function brushY() {
  3630. return brush$1(Y);
  3631. }
  3632. function brush() {
  3633. return brush$1(XY);
  3634. }
  3635. function brush$1(dim) {
  3636. var extent = defaultExtent,
  3637. filter = defaultFilter,
  3638. listeners = dispatch(brush, "start", "brush", "end"),
  3639. handleSize = 6,
  3640. touchending;
  3641. function brush(group) {
  3642. var overlay = group
  3643. .property("__brush", initialize)
  3644. .selectAll(".overlay")
  3645. .data([type("overlay")]);
  3646. overlay.enter().append("rect")
  3647. .attr("class", "overlay")
  3648. .attr("pointer-events", "all")
  3649. .attr("cursor", cursors.overlay)
  3650. .merge(overlay)
  3651. .each(function() {
  3652. var extent = local(this).extent;
  3653. select(this)
  3654. .attr("x", extent[0][0])
  3655. .attr("y", extent[0][1])
  3656. .attr("width", extent[1][0] - extent[0][0])
  3657. .attr("height", extent[1][1] - extent[0][1]);
  3658. });
  3659. group.selectAll(".selection")
  3660. .data([type("selection")])
  3661. .enter().append("rect")
  3662. .attr("class", "selection")
  3663. .attr("cursor", cursors.selection)
  3664. .attr("fill", "#777")
  3665. .attr("fill-opacity", 0.3)
  3666. .attr("stroke", "#fff")
  3667. .attr("shape-rendering", "crispEdges");
  3668. var handle = group.selectAll(".handle")
  3669. .data(dim.handles, function(d) { return d.type; });
  3670. handle.exit().remove();
  3671. handle.enter().append("rect")
  3672. .attr("class", function(d) { return "handle handle--" + d.type; })
  3673. .attr("cursor", function(d) { return cursors[d.type]; });
  3674. group
  3675. .each(redraw)
  3676. .attr("fill", "none")
  3677. .attr("pointer-events", "all")
  3678. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  3679. .on("mousedown.brush touchstart.brush", started);
  3680. }
  3681. brush.move = function(group, selection) {
  3682. if (group.selection) {
  3683. group
  3684. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3685. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3686. .tween("brush", function() {
  3687. var that = this,
  3688. state = that.__brush,
  3689. emit = emitter(that, arguments),
  3690. selection0 = state.selection,
  3691. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  3692. i = interpolateValue(selection0, selection1);
  3693. function tween(t) {
  3694. state.selection = t === 1 && empty(selection1) ? null : i(t);
  3695. redraw.call(that);
  3696. emit.brush();
  3697. }
  3698. return selection0 && selection1 ? tween : tween(1);
  3699. });
  3700. } else {
  3701. group
  3702. .each(function() {
  3703. var that = this,
  3704. args = arguments,
  3705. state = that.__brush,
  3706. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  3707. emit = emitter(that, args).beforestart();
  3708. interrupt(that);
  3709. state.selection = selection1 == null || empty(selection1) ? null : selection1;
  3710. redraw.call(that);
  3711. emit.start().brush().end();
  3712. });
  3713. }
  3714. };
  3715. function redraw() {
  3716. var group = select(this),
  3717. selection = local(this).selection;
  3718. if (selection) {
  3719. group.selectAll(".selection")
  3720. .style("display", null)
  3721. .attr("x", selection[0][0])
  3722. .attr("y", selection[0][1])
  3723. .attr("width", selection[1][0] - selection[0][0])
  3724. .attr("height", selection[1][1] - selection[0][1]);
  3725. group.selectAll(".handle")
  3726. .style("display", null)
  3727. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  3728. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  3729. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  3730. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  3731. }
  3732. else {
  3733. group.selectAll(".selection,.handle")
  3734. .style("display", "none")
  3735. .attr("x", null)
  3736. .attr("y", null)
  3737. .attr("width", null)
  3738. .attr("height", null);
  3739. }
  3740. }
  3741. function emitter(that, args) {
  3742. return that.__brush.emitter || new Emitter(that, args);
  3743. }
  3744. function Emitter(that, args) {
  3745. this.that = that;
  3746. this.args = args;
  3747. this.state = that.__brush;
  3748. this.active = 0;
  3749. }
  3750. Emitter.prototype = {
  3751. beforestart: function() {
  3752. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3753. return this;
  3754. },
  3755. start: function() {
  3756. if (this.starting) this.starting = false, this.emit("start");
  3757. return this;
  3758. },
  3759. brush: function() {
  3760. this.emit("brush");
  3761. return this;
  3762. },
  3763. end: function() {
  3764. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3765. return this;
  3766. },
  3767. emit: function(type) {
  3768. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3769. }
  3770. };
  3771. function started() {
  3772. if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
  3773. else if (touchending) return;
  3774. if (!filter.apply(this, arguments)) return;
  3775. var that = this,
  3776. type = exports.event.target.__data__.type,
  3777. mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3778. signX = dim === Y ? null : signsX[type],
  3779. signY = dim === X ? null : signsY[type],
  3780. state = local(that),
  3781. extent = state.extent,
  3782. selection = state.selection,
  3783. W = extent[0][0], w0, w1,
  3784. N = extent[0][1], n0, n1,
  3785. E = extent[1][0], e0, e1,
  3786. S = extent[1][1], s0, s1,
  3787. dx,
  3788. dy,
  3789. moving,
  3790. shifting = signX && signY && exports.event.shiftKey,
  3791. lockX,
  3792. lockY,
  3793. point0 = mouse(that),
  3794. point = point0,
  3795. emit = emitter(that, arguments).beforestart();
  3796. if (type === "overlay") {
  3797. state.selection = selection = [
  3798. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3799. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3800. ];
  3801. } else {
  3802. w0 = selection[0][0];
  3803. n0 = selection[0][1];
  3804. e0 = selection[1][0];
  3805. s0 = selection[1][1];
  3806. }
  3807. w1 = w0;
  3808. n1 = n0;
  3809. e1 = e0;
  3810. s1 = s0;
  3811. var group = select(that)
  3812. .attr("pointer-events", "none");
  3813. var overlay = group.selectAll(".overlay")
  3814. .attr("cursor", cursors[type]);
  3815. if (exports.event.touches) {
  3816. group
  3817. .on("touchmove.brush", moved, true)
  3818. .on("touchend.brush touchcancel.brush", ended, true);
  3819. } else {
  3820. var view = select(exports.event.view)
  3821. .on("keydown.brush", keydowned, true)
  3822. .on("keyup.brush", keyupped, true)
  3823. .on("mousemove.brush", moved, true)
  3824. .on("mouseup.brush", ended, true);
  3825. dragDisable(exports.event.view);
  3826. }
  3827. nopropagation$1();
  3828. interrupt(that);
  3829. redraw.call(that);
  3830. emit.start();
  3831. function moved() {
  3832. var point1 = mouse(that);
  3833. if (shifting && !lockX && !lockY) {
  3834. if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
  3835. else lockX = true;
  3836. }
  3837. point = point1;
  3838. moving = true;
  3839. noevent$1();
  3840. move();
  3841. }
  3842. function move() {
  3843. var t;
  3844. dx = point[0] - point0[0];
  3845. dy = point[1] - point0[1];
  3846. switch (mode) {
  3847. case MODE_SPACE:
  3848. case MODE_DRAG: {
  3849. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  3850. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  3851. break;
  3852. }
  3853. case MODE_HANDLE: {
  3854. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  3855. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  3856. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  3857. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  3858. break;
  3859. }
  3860. case MODE_CENTER: {
  3861. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  3862. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  3863. break;
  3864. }
  3865. }
  3866. if (e1 < w1) {
  3867. signX *= -1;
  3868. t = w0, w0 = e0, e0 = t;
  3869. t = w1, w1 = e1, e1 = t;
  3870. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  3871. }
  3872. if (s1 < n1) {
  3873. signY *= -1;
  3874. t = n0, n0 = s0, s0 = t;
  3875. t = n1, n1 = s1, s1 = t;
  3876. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  3877. }
  3878. if (state.selection) selection = state.selection; // May be set by brush.move!
  3879. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  3880. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  3881. if (selection[0][0] !== w1
  3882. || selection[0][1] !== n1
  3883. || selection[1][0] !== e1
  3884. || selection[1][1] !== s1) {
  3885. state.selection = [[w1, n1], [e1, s1]];
  3886. redraw.call(that);
  3887. emit.brush();
  3888. }
  3889. }
  3890. function ended() {
  3891. nopropagation$1();
  3892. if (exports.event.touches) {
  3893. if (exports.event.touches.length) return;
  3894. if (touchending) clearTimeout(touchending);
  3895. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  3896. group.on("touchmove.brush touchend.brush touchcancel.brush", null);
  3897. } else {
  3898. yesdrag(exports.event.view, moving);
  3899. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  3900. }
  3901. group.attr("pointer-events", "all");
  3902. overlay.attr("cursor", cursors.overlay);
  3903. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  3904. if (empty(selection)) state.selection = null, redraw.call(that);
  3905. emit.end();
  3906. }
  3907. function keydowned() {
  3908. switch (exports.event.keyCode) {
  3909. case 16: { // SHIFT
  3910. shifting = signX && signY;
  3911. break;
  3912. }
  3913. case 18: { // ALT
  3914. if (mode === MODE_HANDLE) {
  3915. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3916. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3917. mode = MODE_CENTER;
  3918. move();
  3919. }
  3920. break;
  3921. }
  3922. case 32: { // SPACE; takes priority over ALT
  3923. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  3924. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  3925. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  3926. mode = MODE_SPACE;
  3927. overlay.attr("cursor", cursors.selection);
  3928. move();
  3929. }
  3930. break;
  3931. }
  3932. default: return;
  3933. }
  3934. noevent$1();
  3935. }
  3936. function keyupped() {
  3937. switch (exports.event.keyCode) {
  3938. case 16: { // SHIFT
  3939. if (shifting) {
  3940. lockX = lockY = shifting = false;
  3941. move();
  3942. }
  3943. break;
  3944. }
  3945. case 18: { // ALT
  3946. if (mode === MODE_CENTER) {
  3947. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3948. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3949. mode = MODE_HANDLE;
  3950. move();
  3951. }
  3952. break;
  3953. }
  3954. case 32: { // SPACE
  3955. if (mode === MODE_SPACE) {
  3956. if (exports.event.altKey) {
  3957. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  3958. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  3959. mode = MODE_CENTER;
  3960. } else {
  3961. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  3962. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  3963. mode = MODE_HANDLE;
  3964. }
  3965. overlay.attr("cursor", cursors[type]);
  3966. move();
  3967. }
  3968. break;
  3969. }
  3970. default: return;
  3971. }
  3972. noevent$1();
  3973. }
  3974. }
  3975. function initialize() {
  3976. var state = this.__brush || {selection: null};
  3977. state.extent = extent.apply(this, arguments);
  3978. state.dim = dim;
  3979. return state;
  3980. }
  3981. brush.extent = function(_) {
  3982. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
  3983. };
  3984. brush.filter = function(_) {
  3985. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  3986. };
  3987. brush.handleSize = function(_) {
  3988. return arguments.length ? (handleSize = +_, brush) : handleSize;
  3989. };
  3990. brush.on = function() {
  3991. var value = listeners.on.apply(listeners, arguments);
  3992. return value === listeners ? brush : value;
  3993. };
  3994. return brush;
  3995. }
  3996. var cos = Math.cos;
  3997. var sin = Math.sin;
  3998. var pi$1 = Math.PI;
  3999. var halfPi$1 = pi$1 / 2;
  4000. var tau$1 = pi$1 * 2;
  4001. var max$1 = Math.max;
  4002. function compareValue(compare) {
  4003. return function(a, b) {
  4004. return compare(
  4005. a.source.value + a.target.value,
  4006. b.source.value + b.target.value
  4007. );
  4008. };
  4009. }
  4010. function chord() {
  4011. var padAngle = 0,
  4012. sortGroups = null,
  4013. sortSubgroups = null,
  4014. sortChords = null;
  4015. function chord(matrix) {
  4016. var n = matrix.length,
  4017. groupSums = [],
  4018. groupIndex = sequence(n),
  4019. subgroupIndex = [],
  4020. chords = [],
  4021. groups = chords.groups = new Array(n),
  4022. subgroups = new Array(n * n),
  4023. k,
  4024. x,
  4025. x0,
  4026. dx,
  4027. i,
  4028. j;
  4029. // Compute the sum.
  4030. k = 0, i = -1; while (++i < n) {
  4031. x = 0, j = -1; while (++j < n) {
  4032. x += matrix[i][j];
  4033. }
  4034. groupSums.push(x);
  4035. subgroupIndex.push(sequence(n));
  4036. k += x;
  4037. }
  4038. // Sort groups…
  4039. if (sortGroups) groupIndex.sort(function(a, b) {
  4040. return sortGroups(groupSums[a], groupSums[b]);
  4041. });
  4042. // Sort subgroups…
  4043. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4044. d.sort(function(a, b) {
  4045. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4046. });
  4047. });
  4048. // Convert the sum to scaling factor for [0, 2pi].
  4049. // TODO Allow start and end angle to be specified?
  4050. // TODO Allow padding to be specified as percentage?
  4051. k = max$1(0, tau$1 - padAngle * n) / k;
  4052. dx = k ? padAngle : tau$1 / n;
  4053. // Compute the start and end angle for each group and subgroup.
  4054. // Note: Opera has a bug reordering object literal properties!
  4055. x = 0, i = -1; while (++i < n) {
  4056. x0 = x, j = -1; while (++j < n) {
  4057. var di = groupIndex[i],
  4058. dj = subgroupIndex[di][j],
  4059. v = matrix[di][dj],
  4060. a0 = x,
  4061. a1 = x += v * k;
  4062. subgroups[dj * n + di] = {
  4063. index: di,
  4064. subindex: dj,
  4065. startAngle: a0,
  4066. endAngle: a1,
  4067. value: v
  4068. };
  4069. }
  4070. groups[di] = {
  4071. index: di,
  4072. startAngle: x0,
  4073. endAngle: x,
  4074. value: groupSums[di]
  4075. };
  4076. x += dx;
  4077. }
  4078. // Generate chords for each (non-empty) subgroup-subgroup link.
  4079. i = -1; while (++i < n) {
  4080. j = i - 1; while (++j < n) {
  4081. var source = subgroups[j * n + i],
  4082. target = subgroups[i * n + j];
  4083. if (source.value || target.value) {
  4084. chords.push(source.value < target.value
  4085. ? {source: target, target: source}
  4086. : {source: source, target: target});
  4087. }
  4088. }
  4089. }
  4090. return sortChords ? chords.sort(sortChords) : chords;
  4091. }
  4092. chord.padAngle = function(_) {
  4093. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4094. };
  4095. chord.sortGroups = function(_) {
  4096. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4097. };
  4098. chord.sortSubgroups = function(_) {
  4099. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4100. };
  4101. chord.sortChords = function(_) {
  4102. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4103. };
  4104. return chord;
  4105. }
  4106. var slice$2 = Array.prototype.slice;
  4107. function constant$5(x) {
  4108. return function() {
  4109. return x;
  4110. };
  4111. }
  4112. var pi$2 = Math.PI;
  4113. var tau$2 = 2 * pi$2;
  4114. var epsilon$1 = 1e-6;
  4115. var tauEpsilon = tau$2 - epsilon$1;
  4116. function Path() {
  4117. this._x0 = this._y0 = // start of current subpath
  4118. this._x1 = this._y1 = null; // end of current subpath
  4119. this._ = "";
  4120. }
  4121. function path() {
  4122. return new Path;
  4123. }
  4124. Path.prototype = path.prototype = {
  4125. constructor: Path,
  4126. moveTo: function(x, y) {
  4127. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4128. },
  4129. closePath: function() {
  4130. if (this._x1 !== null) {
  4131. this._x1 = this._x0, this._y1 = this._y0;
  4132. this._ += "Z";
  4133. }
  4134. },
  4135. lineTo: function(x, y) {
  4136. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4137. },
  4138. quadraticCurveTo: function(x1, y1, x, y) {
  4139. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4140. },
  4141. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4142. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4143. },
  4144. arcTo: function(x1, y1, x2, y2, r) {
  4145. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4146. var x0 = this._x1,
  4147. y0 = this._y1,
  4148. x21 = x2 - x1,
  4149. y21 = y2 - y1,
  4150. x01 = x0 - x1,
  4151. y01 = y0 - y1,
  4152. l01_2 = x01 * x01 + y01 * y01;
  4153. // Is the radius negative? Error.
  4154. if (r < 0) throw new Error("negative radius: " + r);
  4155. // Is this path empty? Move to (x1,y1).
  4156. if (this._x1 === null) {
  4157. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4158. }
  4159. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4160. else if (!(l01_2 > epsilon$1)) {}
  4161. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4162. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4163. // Or, is the radius zero? Line to (x1,y1).
  4164. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4165. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4166. }
  4167. // Otherwise, draw an arc!
  4168. else {
  4169. var x20 = x2 - x0,
  4170. y20 = y2 - y0,
  4171. l21_2 = x21 * x21 + y21 * y21,
  4172. l20_2 = x20 * x20 + y20 * y20,
  4173. l21 = Math.sqrt(l21_2),
  4174. l01 = Math.sqrt(l01_2),
  4175. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4176. t01 = l / l01,
  4177. t21 = l / l21;
  4178. // If the start tangent is not coincident with (x0,y0), line to.
  4179. if (Math.abs(t01 - 1) > epsilon$1) {
  4180. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4181. }
  4182. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4183. }
  4184. },
  4185. arc: function(x, y, r, a0, a1, ccw) {
  4186. x = +x, y = +y, r = +r;
  4187. var dx = r * Math.cos(a0),
  4188. dy = r * Math.sin(a0),
  4189. x0 = x + dx,
  4190. y0 = y + dy,
  4191. cw = 1 ^ ccw,
  4192. da = ccw ? a0 - a1 : a1 - a0;
  4193. // Is the radius negative? Error.
  4194. if (r < 0) throw new Error("negative radius: " + r);
  4195. // Is this path empty? Move to (x0,y0).
  4196. if (this._x1 === null) {
  4197. this._ += "M" + x0 + "," + y0;
  4198. }
  4199. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4200. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4201. this._ += "L" + x0 + "," + y0;
  4202. }
  4203. // Is this arc empty? We’re done.
  4204. if (!r) return;
  4205. // Does the angle go the wrong way? Flip the direction.
  4206. if (da < 0) da = da % tau$2 + tau$2;
  4207. // Is this a complete circle? Draw two arcs to complete the circle.
  4208. if (da > tauEpsilon) {
  4209. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4210. }
  4211. // Is this arc non-empty? Draw an arc!
  4212. else if (da > epsilon$1) {
  4213. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4214. }
  4215. },
  4216. rect: function(x, y, w, h) {
  4217. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4218. },
  4219. toString: function() {
  4220. return this._;
  4221. }
  4222. };
  4223. function defaultSource(d) {
  4224. return d.source;
  4225. }
  4226. function defaultTarget(d) {
  4227. return d.target;
  4228. }
  4229. function defaultRadius(d) {
  4230. return d.radius;
  4231. }
  4232. function defaultStartAngle(d) {
  4233. return d.startAngle;
  4234. }
  4235. function defaultEndAngle(d) {
  4236. return d.endAngle;
  4237. }
  4238. function ribbon() {
  4239. var source = defaultSource,
  4240. target = defaultTarget,
  4241. radius = defaultRadius,
  4242. startAngle = defaultStartAngle,
  4243. endAngle = defaultEndAngle,
  4244. context = null;
  4245. function ribbon() {
  4246. var buffer,
  4247. argv = slice$2.call(arguments),
  4248. s = source.apply(this, argv),
  4249. t = target.apply(this, argv),
  4250. sr = +radius.apply(this, (argv[0] = s, argv)),
  4251. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4252. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4253. sx0 = sr * cos(sa0),
  4254. sy0 = sr * sin(sa0),
  4255. tr = +radius.apply(this, (argv[0] = t, argv)),
  4256. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4257. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4258. if (!context) context = buffer = path();
  4259. context.moveTo(sx0, sy0);
  4260. context.arc(0, 0, sr, sa0, sa1);
  4261. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4262. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4263. context.arc(0, 0, tr, ta0, ta1);
  4264. }
  4265. context.quadraticCurveTo(0, 0, sx0, sy0);
  4266. context.closePath();
  4267. if (buffer) return context = null, buffer + "" || null;
  4268. }
  4269. ribbon.radius = function(_) {
  4270. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4271. };
  4272. ribbon.startAngle = function(_) {
  4273. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4274. };
  4275. ribbon.endAngle = function(_) {
  4276. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4277. };
  4278. ribbon.source = function(_) {
  4279. return arguments.length ? (source = _, ribbon) : source;
  4280. };
  4281. ribbon.target = function(_) {
  4282. return arguments.length ? (target = _, ribbon) : target;
  4283. };
  4284. ribbon.context = function(_) {
  4285. return arguments.length ? (context = _ == null ? null : _, ribbon) : context;
  4286. };
  4287. return ribbon;
  4288. }
  4289. var prefix = "$";
  4290. function Map() {}
  4291. Map.prototype = map$1.prototype = {
  4292. constructor: Map,
  4293. has: function(key) {
  4294. return (prefix + key) in this;
  4295. },
  4296. get: function(key) {
  4297. return this[prefix + key];
  4298. },
  4299. set: function(key, value) {
  4300. this[prefix + key] = value;
  4301. return this;
  4302. },
  4303. remove: function(key) {
  4304. var property = prefix + key;
  4305. return property in this && delete this[property];
  4306. },
  4307. clear: function() {
  4308. for (var property in this) if (property[0] === prefix) delete this[property];
  4309. },
  4310. keys: function() {
  4311. var keys = [];
  4312. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4313. return keys;
  4314. },
  4315. values: function() {
  4316. var values = [];
  4317. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4318. return values;
  4319. },
  4320. entries: function() {
  4321. var entries = [];
  4322. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4323. return entries;
  4324. },
  4325. size: function() {
  4326. var size = 0;
  4327. for (var property in this) if (property[0] === prefix) ++size;
  4328. return size;
  4329. },
  4330. empty: function() {
  4331. for (var property in this) if (property[0] === prefix) return false;
  4332. return true;
  4333. },
  4334. each: function(f) {
  4335. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4336. }
  4337. };
  4338. function map$1(object, f) {
  4339. var map = new Map;
  4340. // Copy constructor.
  4341. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4342. // Index array by numeric index or specified key function.
  4343. else if (Array.isArray(object)) {
  4344. var i = -1,
  4345. n = object.length,
  4346. o;
  4347. if (f == null) while (++i < n) map.set(i, object[i]);
  4348. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4349. }
  4350. // Convert object to map.
  4351. else if (object) for (var key in object) map.set(key, object[key]);
  4352. return map;
  4353. }
  4354. function nest() {
  4355. var keys = [],
  4356. sortKeys = [],
  4357. sortValues,
  4358. rollup,
  4359. nest;
  4360. function apply(array, depth, createResult, setResult) {
  4361. if (depth >= keys.length) {
  4362. if (sortValues != null) array.sort(sortValues);
  4363. return rollup != null ? rollup(array) : array;
  4364. }
  4365. var i = -1,
  4366. n = array.length,
  4367. key = keys[depth++],
  4368. keyValue,
  4369. value,
  4370. valuesByKey = map$1(),
  4371. values,
  4372. result = createResult();
  4373. while (++i < n) {
  4374. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4375. values.push(value);
  4376. } else {
  4377. valuesByKey.set(keyValue, [value]);
  4378. }
  4379. }
  4380. valuesByKey.each(function(values, key) {
  4381. setResult(result, key, apply(values, depth, createResult, setResult));
  4382. });
  4383. return result;
  4384. }
  4385. function entries(map, depth) {
  4386. if (++depth > keys.length) return map;
  4387. var array, sortKey = sortKeys[depth - 1];
  4388. if (rollup != null && depth >= keys.length) array = map.entries();
  4389. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4390. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4391. }
  4392. return nest = {
  4393. object: function(array) { return apply(array, 0, createObject, setObject); },
  4394. map: function(array) { return apply(array, 0, createMap, setMap); },
  4395. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4396. key: function(d) { keys.push(d); return nest; },
  4397. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4398. sortValues: function(order) { sortValues = order; return nest; },
  4399. rollup: function(f) { rollup = f; return nest; }
  4400. };
  4401. }
  4402. function createObject() {
  4403. return {};
  4404. }
  4405. function setObject(object, key, value) {
  4406. object[key] = value;
  4407. }
  4408. function createMap() {
  4409. return map$1();
  4410. }
  4411. function setMap(map, key, value) {
  4412. map.set(key, value);
  4413. }
  4414. function Set() {}
  4415. var proto = map$1.prototype;
  4416. Set.prototype = set$2.prototype = {
  4417. constructor: Set,
  4418. has: proto.has,
  4419. add: function(value) {
  4420. value += "";
  4421. this[prefix + value] = value;
  4422. return this;
  4423. },
  4424. remove: proto.remove,
  4425. clear: proto.clear,
  4426. values: proto.keys,
  4427. size: proto.size,
  4428. empty: proto.empty,
  4429. each: proto.each
  4430. };
  4431. function set$2(object, f) {
  4432. var set = new Set;
  4433. // Copy constructor.
  4434. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4435. // Otherwise, assume it’s an array.
  4436. else if (object) {
  4437. var i = -1, n = object.length;
  4438. if (f == null) while (++i < n) set.add(object[i]);
  4439. else while (++i < n) set.add(f(object[i], i, object));
  4440. }
  4441. return set;
  4442. }
  4443. function keys(map) {
  4444. var keys = [];
  4445. for (var key in map) keys.push(key);
  4446. return keys;
  4447. }
  4448. function values(map) {
  4449. var values = [];
  4450. for (var key in map) values.push(map[key]);
  4451. return values;
  4452. }
  4453. function entries(map) {
  4454. var entries = [];
  4455. for (var key in map) entries.push({key: key, value: map[key]});
  4456. return entries;
  4457. }
  4458. var EOL = {};
  4459. var EOF = {};
  4460. var QUOTE = 34;
  4461. var NEWLINE = 10;
  4462. var RETURN = 13;
  4463. function objectConverter(columns) {
  4464. return new Function("d", "return {" + columns.map(function(name, i) {
  4465. return JSON.stringify(name) + ": d[" + i + "]";
  4466. }).join(",") + "}");
  4467. }
  4468. function customConverter(columns, f) {
  4469. var object = objectConverter(columns);
  4470. return function(row, i) {
  4471. return f(object(row), i, columns);
  4472. };
  4473. }
  4474. // Compute unique columns in order of discovery.
  4475. function inferColumns(rows) {
  4476. var columnSet = Object.create(null),
  4477. columns = [];
  4478. rows.forEach(function(row) {
  4479. for (var column in row) {
  4480. if (!(column in columnSet)) {
  4481. columns.push(columnSet[column] = column);
  4482. }
  4483. }
  4484. });
  4485. return columns;
  4486. }
  4487. function dsv(delimiter) {
  4488. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  4489. DELIMITER = delimiter.charCodeAt(0);
  4490. function parse(text, f) {
  4491. var convert, columns, rows = parseRows(text, function(row, i) {
  4492. if (convert) return convert(row, i - 1);
  4493. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  4494. });
  4495. rows.columns = columns || [];
  4496. return rows;
  4497. }
  4498. function parseRows(text, f) {
  4499. var rows = [], // output rows
  4500. N = text.length,
  4501. I = 0, // current character index
  4502. n = 0, // current line number
  4503. t, // current token
  4504. eof = N <= 0, // current token followed by EOF?
  4505. eol = false; // current token followed by EOL?
  4506. // Strip the trailing newline.
  4507. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  4508. if (text.charCodeAt(N - 1) === RETURN) --N;
  4509. function token() {
  4510. if (eof) return EOF;
  4511. if (eol) return eol = false, EOL;
  4512. // Unescape quotes.
  4513. var i, j = I, c;
  4514. if (text.charCodeAt(j) === QUOTE) {
  4515. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  4516. if ((i = I) >= N) eof = true;
  4517. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  4518. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4519. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  4520. }
  4521. // Find next delimiter or newline.
  4522. while (I < N) {
  4523. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  4524. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  4525. else if (c !== DELIMITER) continue;
  4526. return text.slice(j, i);
  4527. }
  4528. // Return last token before EOF.
  4529. return eof = true, text.slice(j, N);
  4530. }
  4531. while ((t = token()) !== EOF) {
  4532. var row = [];
  4533. while (t !== EOL && t !== EOF) row.push(t), t = token();
  4534. if (f && (row = f(row, n++)) == null) continue;
  4535. rows.push(row);
  4536. }
  4537. return rows;
  4538. }
  4539. function format(rows, columns) {
  4540. if (columns == null) columns = inferColumns(rows);
  4541. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  4542. return columns.map(function(column) {
  4543. return formatValue(row[column]);
  4544. }).join(delimiter);
  4545. })).join("\n");
  4546. }
  4547. function formatRows(rows) {
  4548. return rows.map(formatRow).join("\n");
  4549. }
  4550. function formatRow(row) {
  4551. return row.map(formatValue).join(delimiter);
  4552. }
  4553. function formatValue(text) {
  4554. return text == null ? ""
  4555. : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
  4556. : text;
  4557. }
  4558. return {
  4559. parse: parse,
  4560. parseRows: parseRows,
  4561. format: format,
  4562. formatRows: formatRows
  4563. };
  4564. }
  4565. var csv = dsv(",");
  4566. var csvParse = csv.parse;
  4567. var csvParseRows = csv.parseRows;
  4568. var csvFormat = csv.format;
  4569. var csvFormatRows = csv.formatRows;
  4570. var tsv = dsv("\t");
  4571. var tsvParse = tsv.parse;
  4572. var tsvParseRows = tsv.parseRows;
  4573. var tsvFormat = tsv.format;
  4574. var tsvFormatRows = tsv.formatRows;
  4575. function center$1(x, y) {
  4576. var nodes;
  4577. if (x == null) x = 0;
  4578. if (y == null) y = 0;
  4579. function force() {
  4580. var i,
  4581. n = nodes.length,
  4582. node,
  4583. sx = 0,
  4584. sy = 0;
  4585. for (i = 0; i < n; ++i) {
  4586. node = nodes[i], sx += node.x, sy += node.y;
  4587. }
  4588. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  4589. node = nodes[i], node.x -= sx, node.y -= sy;
  4590. }
  4591. }
  4592. force.initialize = function(_) {
  4593. nodes = _;
  4594. };
  4595. force.x = function(_) {
  4596. return arguments.length ? (x = +_, force) : x;
  4597. };
  4598. force.y = function(_) {
  4599. return arguments.length ? (y = +_, force) : y;
  4600. };
  4601. return force;
  4602. }
  4603. function constant$6(x) {
  4604. return function() {
  4605. return x;
  4606. };
  4607. }
  4608. function jiggle() {
  4609. return (Math.random() - 0.5) * 1e-6;
  4610. }
  4611. function tree_add(d) {
  4612. var x = +this._x.call(null, d),
  4613. y = +this._y.call(null, d);
  4614. return add(this.cover(x, y), x, y, d);
  4615. }
  4616. function add(tree, x, y, d) {
  4617. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  4618. var parent,
  4619. node = tree._root,
  4620. leaf = {data: d},
  4621. x0 = tree._x0,
  4622. y0 = tree._y0,
  4623. x1 = tree._x1,
  4624. y1 = tree._y1,
  4625. xm,
  4626. ym,
  4627. xp,
  4628. yp,
  4629. right,
  4630. bottom,
  4631. i,
  4632. j;
  4633. // If the tree is empty, initialize the root as a leaf.
  4634. if (!node) return tree._root = leaf, tree;
  4635. // Find the existing leaf for the new point, or add it.
  4636. while (node.length) {
  4637. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4638. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4639. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  4640. }
  4641. // Is the new point is exactly coincident with the existing point?
  4642. xp = +tree._x.call(null, node.data);
  4643. yp = +tree._y.call(null, node.data);
  4644. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  4645. // Otherwise, split the leaf node until the old and new point are separated.
  4646. do {
  4647. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  4648. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4649. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4650. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  4651. return parent[j] = node, parent[i] = leaf, tree;
  4652. }
  4653. function addAll(data) {
  4654. var d, i, n = data.length,
  4655. x,
  4656. y,
  4657. xz = new Array(n),
  4658. yz = new Array(n),
  4659. x0 = Infinity,
  4660. y0 = Infinity,
  4661. x1 = -Infinity,
  4662. y1 = -Infinity;
  4663. // Compute the points and their extent.
  4664. for (i = 0; i < n; ++i) {
  4665. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  4666. xz[i] = x;
  4667. yz[i] = y;
  4668. if (x < x0) x0 = x;
  4669. if (x > x1) x1 = x;
  4670. if (y < y0) y0 = y;
  4671. if (y > y1) y1 = y;
  4672. }
  4673. // If there were no (valid) points, inherit the existing extent.
  4674. if (x1 < x0) x0 = this._x0, x1 = this._x1;
  4675. if (y1 < y0) y0 = this._y0, y1 = this._y1;
  4676. // Expand the tree to cover the new points.
  4677. this.cover(x0, y0).cover(x1, y1);
  4678. // Add the new points.
  4679. for (i = 0; i < n; ++i) {
  4680. add(this, xz[i], yz[i], data[i]);
  4681. }
  4682. return this;
  4683. }
  4684. function tree_cover(x, y) {
  4685. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  4686. var x0 = this._x0,
  4687. y0 = this._y0,
  4688. x1 = this._x1,
  4689. y1 = this._y1;
  4690. // If the quadtree has no extent, initialize them.
  4691. // Integer extent are necessary so that if we later double the extent,
  4692. // the existing quadrant boundaries don’t change due to floating point error!
  4693. if (isNaN(x0)) {
  4694. x1 = (x0 = Math.floor(x)) + 1;
  4695. y1 = (y0 = Math.floor(y)) + 1;
  4696. }
  4697. // Otherwise, double repeatedly to cover.
  4698. else if (x0 > x || x > x1 || y0 > y || y > y1) {
  4699. var z = x1 - x0,
  4700. node = this._root,
  4701. parent,
  4702. i;
  4703. switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
  4704. case 0: {
  4705. do parent = new Array(4), parent[i] = node, node = parent;
  4706. while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
  4707. break;
  4708. }
  4709. case 1: {
  4710. do parent = new Array(4), parent[i] = node, node = parent;
  4711. while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
  4712. break;
  4713. }
  4714. case 2: {
  4715. do parent = new Array(4), parent[i] = node, node = parent;
  4716. while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
  4717. break;
  4718. }
  4719. case 3: {
  4720. do parent = new Array(4), parent[i] = node, node = parent;
  4721. while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
  4722. break;
  4723. }
  4724. }
  4725. if (this._root && this._root.length) this._root = node;
  4726. }
  4727. // If the quadtree covers the point already, just return.
  4728. else return this;
  4729. this._x0 = x0;
  4730. this._y0 = y0;
  4731. this._x1 = x1;
  4732. this._y1 = y1;
  4733. return this;
  4734. }
  4735. function tree_data() {
  4736. var data = [];
  4737. this.visit(function(node) {
  4738. if (!node.length) do data.push(node.data); while (node = node.next)
  4739. });
  4740. return data;
  4741. }
  4742. function tree_extent(_) {
  4743. return arguments.length
  4744. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  4745. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  4746. }
  4747. function Quad(node, x0, y0, x1, y1) {
  4748. this.node = node;
  4749. this.x0 = x0;
  4750. this.y0 = y0;
  4751. this.x1 = x1;
  4752. this.y1 = y1;
  4753. }
  4754. function tree_find(x, y, radius) {
  4755. var data,
  4756. x0 = this._x0,
  4757. y0 = this._y0,
  4758. x1,
  4759. y1,
  4760. x2,
  4761. y2,
  4762. x3 = this._x1,
  4763. y3 = this._y1,
  4764. quads = [],
  4765. node = this._root,
  4766. q,
  4767. i;
  4768. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  4769. if (radius == null) radius = Infinity;
  4770. else {
  4771. x0 = x - radius, y0 = y - radius;
  4772. x3 = x + radius, y3 = y + radius;
  4773. radius *= radius;
  4774. }
  4775. while (q = quads.pop()) {
  4776. // Stop searching if this quadrant can’t contain a closer node.
  4777. if (!(node = q.node)
  4778. || (x1 = q.x0) > x3
  4779. || (y1 = q.y0) > y3
  4780. || (x2 = q.x1) < x0
  4781. || (y2 = q.y1) < y0) continue;
  4782. // Bisect the current quadrant.
  4783. if (node.length) {
  4784. var xm = (x1 + x2) / 2,
  4785. ym = (y1 + y2) / 2;
  4786. quads.push(
  4787. new Quad(node[3], xm, ym, x2, y2),
  4788. new Quad(node[2], x1, ym, xm, y2),
  4789. new Quad(node[1], xm, y1, x2, ym),
  4790. new Quad(node[0], x1, y1, xm, ym)
  4791. );
  4792. // Visit the closest quadrant first.
  4793. if (i = (y >= ym) << 1 | (x >= xm)) {
  4794. q = quads[quads.length - 1];
  4795. quads[quads.length - 1] = quads[quads.length - 1 - i];
  4796. quads[quads.length - 1 - i] = q;
  4797. }
  4798. }
  4799. // Visit this point. (Visiting coincident points isn’t necessary!)
  4800. else {
  4801. var dx = x - +this._x.call(null, node.data),
  4802. dy = y - +this._y.call(null, node.data),
  4803. d2 = dx * dx + dy * dy;
  4804. if (d2 < radius) {
  4805. var d = Math.sqrt(radius = d2);
  4806. x0 = x - d, y0 = y - d;
  4807. x3 = x + d, y3 = y + d;
  4808. data = node.data;
  4809. }
  4810. }
  4811. }
  4812. return data;
  4813. }
  4814. function tree_remove(d) {
  4815. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  4816. var parent,
  4817. node = this._root,
  4818. retainer,
  4819. previous,
  4820. next,
  4821. x0 = this._x0,
  4822. y0 = this._y0,
  4823. x1 = this._x1,
  4824. y1 = this._y1,
  4825. x,
  4826. y,
  4827. xm,
  4828. ym,
  4829. right,
  4830. bottom,
  4831. i,
  4832. j;
  4833. // If the tree is empty, initialize the root as a leaf.
  4834. if (!node) return this;
  4835. // Find the leaf node for the point.
  4836. // While descending, also retain the deepest parent with a non-removed sibling.
  4837. if (node.length) while (true) {
  4838. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  4839. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  4840. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  4841. if (!node.length) break;
  4842. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  4843. }
  4844. // Find the point to remove.
  4845. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  4846. if (next = node.next) delete node.next;
  4847. // If there are multiple coincident points, remove just the point.
  4848. if (previous) return next ? previous.next = next : delete previous.next, this;
  4849. // If this is the root point, remove it.
  4850. if (!parent) return this._root = next, this;
  4851. // Remove this leaf.
  4852. next ? parent[i] = next : delete parent[i];
  4853. // If the parent now contains exactly one leaf, collapse superfluous parents.
  4854. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  4855. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  4856. && !node.length) {
  4857. if (retainer) retainer[j] = node;
  4858. else this._root = node;
  4859. }
  4860. return this;
  4861. }
  4862. function removeAll(data) {
  4863. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  4864. return this;
  4865. }
  4866. function tree_root() {
  4867. return this._root;
  4868. }
  4869. function tree_size() {
  4870. var size = 0;
  4871. this.visit(function(node) {
  4872. if (!node.length) do ++size; while (node = node.next)
  4873. });
  4874. return size;
  4875. }
  4876. function tree_visit(callback) {
  4877. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  4878. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  4879. while (q = quads.pop()) {
  4880. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  4881. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  4882. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  4883. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  4884. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  4885. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  4886. }
  4887. }
  4888. return this;
  4889. }
  4890. function tree_visitAfter(callback) {
  4891. var quads = [], next = [], q;
  4892. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  4893. while (q = quads.pop()) {
  4894. var node = q.node;
  4895. if (node.length) {
  4896. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  4897. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  4898. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  4899. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  4900. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  4901. }
  4902. next.push(q);
  4903. }
  4904. while (q = next.pop()) {
  4905. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  4906. }
  4907. return this;
  4908. }
  4909. function defaultX(d) {
  4910. return d[0];
  4911. }
  4912. function tree_x(_) {
  4913. return arguments.length ? (this._x = _, this) : this._x;
  4914. }
  4915. function defaultY(d) {
  4916. return d[1];
  4917. }
  4918. function tree_y(_) {
  4919. return arguments.length ? (this._y = _, this) : this._y;
  4920. }
  4921. function quadtree(nodes, x, y) {
  4922. var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
  4923. return nodes == null ? tree : tree.addAll(nodes);
  4924. }
  4925. function Quadtree(x, y, x0, y0, x1, y1) {
  4926. this._x = x;
  4927. this._y = y;
  4928. this._x0 = x0;
  4929. this._y0 = y0;
  4930. this._x1 = x1;
  4931. this._y1 = y1;
  4932. this._root = undefined;
  4933. }
  4934. function leaf_copy(leaf) {
  4935. var copy = {data: leaf.data}, next = copy;
  4936. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  4937. return copy;
  4938. }
  4939. var treeProto = quadtree.prototype = Quadtree.prototype;
  4940. treeProto.copy = function() {
  4941. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  4942. node = this._root,
  4943. nodes,
  4944. child;
  4945. if (!node) return copy;
  4946. if (!node.length) return copy._root = leaf_copy(node), copy;
  4947. nodes = [{source: node, target: copy._root = new Array(4)}];
  4948. while (node = nodes.pop()) {
  4949. for (var i = 0; i < 4; ++i) {
  4950. if (child = node.source[i]) {
  4951. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  4952. else node.target[i] = leaf_copy(child);
  4953. }
  4954. }
  4955. }
  4956. return copy;
  4957. };
  4958. treeProto.add = tree_add;
  4959. treeProto.addAll = addAll;
  4960. treeProto.cover = tree_cover;
  4961. treeProto.data = tree_data;
  4962. treeProto.extent = tree_extent;
  4963. treeProto.find = tree_find;
  4964. treeProto.remove = tree_remove;
  4965. treeProto.removeAll = removeAll;
  4966. treeProto.root = tree_root;
  4967. treeProto.size = tree_size;
  4968. treeProto.visit = tree_visit;
  4969. treeProto.visitAfter = tree_visitAfter;
  4970. treeProto.x = tree_x;
  4971. treeProto.y = tree_y;
  4972. function x(d) {
  4973. return d.x + d.vx;
  4974. }
  4975. function y(d) {
  4976. return d.y + d.vy;
  4977. }
  4978. function collide(radius) {
  4979. var nodes,
  4980. radii,
  4981. strength = 1,
  4982. iterations = 1;
  4983. if (typeof radius !== "function") radius = constant$6(radius == null ? 1 : +radius);
  4984. function force() {
  4985. var i, n = nodes.length,
  4986. tree,
  4987. node,
  4988. xi,
  4989. yi,
  4990. ri,
  4991. ri2;
  4992. for (var k = 0; k < iterations; ++k) {
  4993. tree = quadtree(nodes, x, y).visitAfter(prepare);
  4994. for (i = 0; i < n; ++i) {
  4995. node = nodes[i];
  4996. ri = radii[node.index], ri2 = ri * ri;
  4997. xi = node.x + node.vx;
  4998. yi = node.y + node.vy;
  4999. tree.visit(apply);
  5000. }
  5001. }
  5002. function apply(quad, x0, y0, x1, y1) {
  5003. var data = quad.data, rj = quad.r, r = ri + rj;
  5004. if (data) {
  5005. if (data.index > node.index) {
  5006. var x = xi - data.x - data.vx,
  5007. y = yi - data.y - data.vy,
  5008. l = x * x + y * y;
  5009. if (l < r * r) {
  5010. if (x === 0) x = jiggle(), l += x * x;
  5011. if (y === 0) y = jiggle(), l += y * y;
  5012. l = (r - (l = Math.sqrt(l))) / l * strength;
  5013. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5014. node.vy += (y *= l) * r;
  5015. data.vx -= x * (r = 1 - r);
  5016. data.vy -= y * r;
  5017. }
  5018. }
  5019. return;
  5020. }
  5021. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5022. }
  5023. }
  5024. function prepare(quad) {
  5025. if (quad.data) return quad.r = radii[quad.data.index];
  5026. for (var i = quad.r = 0; i < 4; ++i) {
  5027. if (quad[i] && quad[i].r > quad.r) {
  5028. quad.r = quad[i].r;
  5029. }
  5030. }
  5031. }
  5032. function initialize() {
  5033. if (!nodes) return;
  5034. var i, n = nodes.length, node;
  5035. radii = new Array(n);
  5036. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5037. }
  5038. force.initialize = function(_) {
  5039. nodes = _;
  5040. initialize();
  5041. };
  5042. force.iterations = function(_) {
  5043. return arguments.length ? (iterations = +_, force) : iterations;
  5044. };
  5045. force.strength = function(_) {
  5046. return arguments.length ? (strength = +_, force) : strength;
  5047. };
  5048. force.radius = function(_) {
  5049. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
  5050. };
  5051. return force;
  5052. }
  5053. function index(d) {
  5054. return d.index;
  5055. }
  5056. function find(nodeById, nodeId) {
  5057. var node = nodeById.get(nodeId);
  5058. if (!node) throw new Error("missing: " + nodeId);
  5059. return node;
  5060. }
  5061. function link(links) {
  5062. var id = index,
  5063. strength = defaultStrength,
  5064. strengths,
  5065. distance = constant$6(30),
  5066. distances,
  5067. nodes,
  5068. count,
  5069. bias,
  5070. iterations = 1;
  5071. if (links == null) links = [];
  5072. function defaultStrength(link) {
  5073. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5074. }
  5075. function force(alpha) {
  5076. for (var k = 0, n = links.length; k < iterations; ++k) {
  5077. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5078. link = links[i], source = link.source, target = link.target;
  5079. x = target.x + target.vx - source.x - source.vx || jiggle();
  5080. y = target.y + target.vy - source.y - source.vy || jiggle();
  5081. l = Math.sqrt(x * x + y * y);
  5082. l = (l - distances[i]) / l * alpha * strengths[i];
  5083. x *= l, y *= l;
  5084. target.vx -= x * (b = bias[i]);
  5085. target.vy -= y * b;
  5086. source.vx += x * (b = 1 - b);
  5087. source.vy += y * b;
  5088. }
  5089. }
  5090. }
  5091. function initialize() {
  5092. if (!nodes) return;
  5093. var i,
  5094. n = nodes.length,
  5095. m = links.length,
  5096. nodeById = map$1(nodes, id),
  5097. link;
  5098. for (i = 0, count = new Array(n); i < m; ++i) {
  5099. link = links[i], link.index = i;
  5100. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5101. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5102. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5103. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5104. }
  5105. for (i = 0, bias = new Array(m); i < m; ++i) {
  5106. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5107. }
  5108. strengths = new Array(m), initializeStrength();
  5109. distances = new Array(m), initializeDistance();
  5110. }
  5111. function initializeStrength() {
  5112. if (!nodes) return;
  5113. for (var i = 0, n = links.length; i < n; ++i) {
  5114. strengths[i] = +strength(links[i], i, links);
  5115. }
  5116. }
  5117. function initializeDistance() {
  5118. if (!nodes) return;
  5119. for (var i = 0, n = links.length; i < n; ++i) {
  5120. distances[i] = +distance(links[i], i, links);
  5121. }
  5122. }
  5123. force.initialize = function(_) {
  5124. nodes = _;
  5125. initialize();
  5126. };
  5127. force.links = function(_) {
  5128. return arguments.length ? (links = _, initialize(), force) : links;
  5129. };
  5130. force.id = function(_) {
  5131. return arguments.length ? (id = _, force) : id;
  5132. };
  5133. force.iterations = function(_) {
  5134. return arguments.length ? (iterations = +_, force) : iterations;
  5135. };
  5136. force.strength = function(_) {
  5137. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initializeStrength(), force) : strength;
  5138. };
  5139. force.distance = function(_) {
  5140. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$6(+_), initializeDistance(), force) : distance;
  5141. };
  5142. return force;
  5143. }
  5144. function x$1(d) {
  5145. return d.x;
  5146. }
  5147. function y$1(d) {
  5148. return d.y;
  5149. }
  5150. var initialRadius = 10;
  5151. var initialAngle = Math.PI * (3 - Math.sqrt(5));
  5152. function simulation(nodes) {
  5153. var simulation,
  5154. alpha = 1,
  5155. alphaMin = 0.001,
  5156. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5157. alphaTarget = 0,
  5158. velocityDecay = 0.6,
  5159. forces = map$1(),
  5160. stepper = timer(step),
  5161. event = dispatch("tick", "end");
  5162. if (nodes == null) nodes = [];
  5163. function step() {
  5164. tick();
  5165. event.call("tick", simulation);
  5166. if (alpha < alphaMin) {
  5167. stepper.stop();
  5168. event.call("end", simulation);
  5169. }
  5170. }
  5171. function tick() {
  5172. var i, n = nodes.length, node;
  5173. alpha += (alphaTarget - alpha) * alphaDecay;
  5174. forces.each(function(force) {
  5175. force(alpha);
  5176. });
  5177. for (i = 0; i < n; ++i) {
  5178. node = nodes[i];
  5179. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5180. else node.x = node.fx, node.vx = 0;
  5181. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5182. else node.y = node.fy, node.vy = 0;
  5183. }
  5184. }
  5185. function initializeNodes() {
  5186. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5187. node = nodes[i], node.index = i;
  5188. if (isNaN(node.x) || isNaN(node.y)) {
  5189. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5190. node.x = radius * Math.cos(angle);
  5191. node.y = radius * Math.sin(angle);
  5192. }
  5193. if (isNaN(node.vx) || isNaN(node.vy)) {
  5194. node.vx = node.vy = 0;
  5195. }
  5196. }
  5197. }
  5198. function initializeForce(force) {
  5199. if (force.initialize) force.initialize(nodes);
  5200. return force;
  5201. }
  5202. initializeNodes();
  5203. return simulation = {
  5204. tick: tick,
  5205. restart: function() {
  5206. return stepper.restart(step), simulation;
  5207. },
  5208. stop: function() {
  5209. return stepper.stop(), simulation;
  5210. },
  5211. nodes: function(_) {
  5212. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5213. },
  5214. alpha: function(_) {
  5215. return arguments.length ? (alpha = +_, simulation) : alpha;
  5216. },
  5217. alphaMin: function(_) {
  5218. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5219. },
  5220. alphaDecay: function(_) {
  5221. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5222. },
  5223. alphaTarget: function(_) {
  5224. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5225. },
  5226. velocityDecay: function(_) {
  5227. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5228. },
  5229. force: function(name, _) {
  5230. return arguments.length > 1 ? (_ == null ? forces.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
  5231. },
  5232. find: function(x, y, radius) {
  5233. var i = 0,
  5234. n = nodes.length,
  5235. dx,
  5236. dy,
  5237. d2,
  5238. node,
  5239. closest;
  5240. if (radius == null) radius = Infinity;
  5241. else radius *= radius;
  5242. for (i = 0; i < n; ++i) {
  5243. node = nodes[i];
  5244. dx = x - node.x;
  5245. dy = y - node.y;
  5246. d2 = dx * dx + dy * dy;
  5247. if (d2 < radius) closest = node, radius = d2;
  5248. }
  5249. return closest;
  5250. },
  5251. on: function(name, _) {
  5252. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5253. }
  5254. };
  5255. }
  5256. function manyBody() {
  5257. var nodes,
  5258. node,
  5259. alpha,
  5260. strength = constant$6(-30),
  5261. strengths,
  5262. distanceMin2 = 1,
  5263. distanceMax2 = Infinity,
  5264. theta2 = 0.81;
  5265. function force(_) {
  5266. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5267. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5268. }
  5269. function initialize() {
  5270. if (!nodes) return;
  5271. var i, n = nodes.length, node;
  5272. strengths = new Array(n);
  5273. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5274. }
  5275. function accumulate(quad) {
  5276. var strength = 0, q, c, weight = 0, x, y, i;
  5277. // For internal nodes, accumulate forces from child quadrants.
  5278. if (quad.length) {
  5279. for (x = y = i = 0; i < 4; ++i) {
  5280. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5281. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5282. }
  5283. }
  5284. quad.x = x / weight;
  5285. quad.y = y / weight;
  5286. }
  5287. // For leaf nodes, accumulate forces from coincident quadrants.
  5288. else {
  5289. q = quad;
  5290. q.x = q.data.x;
  5291. q.y = q.data.y;
  5292. do strength += strengths[q.data.index];
  5293. while (q = q.next);
  5294. }
  5295. quad.value = strength;
  5296. }
  5297. function apply(quad, x1, _, x2) {
  5298. if (!quad.value) return true;
  5299. var x = quad.x - node.x,
  5300. y = quad.y - node.y,
  5301. w = x2 - x1,
  5302. l = x * x + y * y;
  5303. // Apply the Barnes-Hut approximation if possible.
  5304. // Limit forces for very close nodes; randomize direction if coincident.
  5305. if (w * w / theta2 < l) {
  5306. if (l < distanceMax2) {
  5307. if (x === 0) x = jiggle(), l += x * x;
  5308. if (y === 0) y = jiggle(), l += y * y;
  5309. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5310. node.vx += x * quad.value * alpha / l;
  5311. node.vy += y * quad.value * alpha / l;
  5312. }
  5313. return true;
  5314. }
  5315. // Otherwise, process points directly.
  5316. else if (quad.length || l >= distanceMax2) return;
  5317. // Limit forces for very close nodes; randomize direction if coincident.
  5318. if (quad.data !== node || quad.next) {
  5319. if (x === 0) x = jiggle(), l += x * x;
  5320. if (y === 0) y = jiggle(), l += y * y;
  5321. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5322. }
  5323. do if (quad.data !== node) {
  5324. w = strengths[quad.data.index] * alpha / l;
  5325. node.vx += x * w;
  5326. node.vy += y * w;
  5327. } while (quad = quad.next);
  5328. }
  5329. force.initialize = function(_) {
  5330. nodes = _;
  5331. initialize();
  5332. };
  5333. force.strength = function(_) {
  5334. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5335. };
  5336. force.distanceMin = function(_) {
  5337. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5338. };
  5339. force.distanceMax = function(_) {
  5340. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5341. };
  5342. force.theta = function(_) {
  5343. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  5344. };
  5345. return force;
  5346. }
  5347. function radial(radius, x, y) {
  5348. var nodes,
  5349. strength = constant$6(0.1),
  5350. strengths,
  5351. radiuses;
  5352. if (typeof radius !== "function") radius = constant$6(+radius);
  5353. if (x == null) x = 0;
  5354. if (y == null) y = 0;
  5355. function force(alpha) {
  5356. for (var i = 0, n = nodes.length; i < n; ++i) {
  5357. var node = nodes[i],
  5358. dx = node.x - x || 1e-6,
  5359. dy = node.y - y || 1e-6,
  5360. r = Math.sqrt(dx * dx + dy * dy),
  5361. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  5362. node.vx += dx * k;
  5363. node.vy += dy * k;
  5364. }
  5365. }
  5366. function initialize() {
  5367. if (!nodes) return;
  5368. var i, n = nodes.length;
  5369. strengths = new Array(n);
  5370. radiuses = new Array(n);
  5371. for (i = 0; i < n; ++i) {
  5372. radiuses[i] = +radius(nodes[i], i, nodes);
  5373. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  5374. }
  5375. }
  5376. force.initialize = function(_) {
  5377. nodes = _, initialize();
  5378. };
  5379. force.strength = function(_) {
  5380. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5381. };
  5382. force.radius = function(_) {
  5383. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
  5384. };
  5385. force.x = function(_) {
  5386. return arguments.length ? (x = +_, force) : x;
  5387. };
  5388. force.y = function(_) {
  5389. return arguments.length ? (y = +_, force) : y;
  5390. };
  5391. return force;
  5392. }
  5393. function x$2(x) {
  5394. var strength = constant$6(0.1),
  5395. nodes,
  5396. strengths,
  5397. xz;
  5398. if (typeof x !== "function") x = constant$6(x == null ? 0 : +x);
  5399. function force(alpha) {
  5400. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5401. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  5402. }
  5403. }
  5404. function initialize() {
  5405. if (!nodes) return;
  5406. var i, n = nodes.length;
  5407. strengths = new Array(n);
  5408. xz = new Array(n);
  5409. for (i = 0; i < n; ++i) {
  5410. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5411. }
  5412. }
  5413. force.initialize = function(_) {
  5414. nodes = _;
  5415. initialize();
  5416. };
  5417. force.strength = function(_) {
  5418. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5419. };
  5420. force.x = function(_) {
  5421. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : x;
  5422. };
  5423. return force;
  5424. }
  5425. function y$2(y) {
  5426. var strength = constant$6(0.1),
  5427. nodes,
  5428. strengths,
  5429. yz;
  5430. if (typeof y !== "function") y = constant$6(y == null ? 0 : +y);
  5431. function force(alpha) {
  5432. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5433. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  5434. }
  5435. }
  5436. function initialize() {
  5437. if (!nodes) return;
  5438. var i, n = nodes.length;
  5439. strengths = new Array(n);
  5440. yz = new Array(n);
  5441. for (i = 0; i < n; ++i) {
  5442. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  5443. }
  5444. }
  5445. force.initialize = function(_) {
  5446. nodes = _;
  5447. initialize();
  5448. };
  5449. force.strength = function(_) {
  5450. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  5451. };
  5452. force.y = function(_) {
  5453. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : y;
  5454. };
  5455. return force;
  5456. }
  5457. // Computes the decimal coefficient and exponent of the specified number x with
  5458. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  5459. // For example, formatDecimal(1.23) returns ["123", 0].
  5460. function formatDecimal(x, p) {
  5461. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  5462. var i, coefficient = x.slice(0, i);
  5463. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  5464. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  5465. return [
  5466. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  5467. +x.slice(i + 1)
  5468. ];
  5469. }
  5470. function exponent$1(x) {
  5471. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  5472. }
  5473. function formatGroup(grouping, thousands) {
  5474. return function(value, width) {
  5475. var i = value.length,
  5476. t = [],
  5477. j = 0,
  5478. g = grouping[0],
  5479. length = 0;
  5480. while (i > 0 && g > 0) {
  5481. if (length + g + 1 > width) g = Math.max(1, width - length);
  5482. t.push(value.substring(i -= g, i + g));
  5483. if ((length += g + 1) > width) break;
  5484. g = grouping[j = (j + 1) % grouping.length];
  5485. }
  5486. return t.reverse().join(thousands);
  5487. };
  5488. }
  5489. function formatNumerals(numerals) {
  5490. return function(value) {
  5491. return value.replace(/[0-9]/g, function(i) {
  5492. return numerals[+i];
  5493. });
  5494. };
  5495. }
  5496. function formatDefault(x, p) {
  5497. x = x.toPrecision(p);
  5498. out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
  5499. switch (x[i]) {
  5500. case ".": i0 = i1 = i; break;
  5501. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  5502. case "e": break out;
  5503. default: if (i0 > 0) i0 = 0; break;
  5504. }
  5505. }
  5506. return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
  5507. }
  5508. var prefixExponent;
  5509. function formatPrefixAuto(x, p) {
  5510. var d = formatDecimal(x, p);
  5511. if (!d) return x + "";
  5512. var coefficient = d[0],
  5513. exponent = d[1],
  5514. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  5515. n = coefficient.length;
  5516. return i === n ? coefficient
  5517. : i > n ? coefficient + new Array(i - n + 1).join("0")
  5518. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  5519. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  5520. }
  5521. function formatRounded(x, p) {
  5522. var d = formatDecimal(x, p);
  5523. if (!d) return x + "";
  5524. var coefficient = d[0],
  5525. exponent = d[1];
  5526. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  5527. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  5528. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  5529. }
  5530. var formatTypes = {
  5531. "": formatDefault,
  5532. "%": function(x, p) { return (x * 100).toFixed(p); },
  5533. "b": function(x) { return Math.round(x).toString(2); },
  5534. "c": function(x) { return x + ""; },
  5535. "d": function(x) { return Math.round(x).toString(10); },
  5536. "e": function(x, p) { return x.toExponential(p); },
  5537. "f": function(x, p) { return x.toFixed(p); },
  5538. "g": function(x, p) { return x.toPrecision(p); },
  5539. "o": function(x) { return Math.round(x).toString(8); },
  5540. "p": function(x, p) { return formatRounded(x * 100, p); },
  5541. "r": formatRounded,
  5542. "s": formatPrefixAuto,
  5543. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  5544. "x": function(x) { return Math.round(x).toString(16); }
  5545. };
  5546. // [[fill]align][sign][symbol][0][width][,][.precision][type]
  5547. var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
  5548. function formatSpecifier(specifier) {
  5549. return new FormatSpecifier(specifier);
  5550. }
  5551. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  5552. function FormatSpecifier(specifier) {
  5553. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  5554. var match,
  5555. fill = match[1] || " ",
  5556. align = match[2] || ">",
  5557. sign = match[3] || "-",
  5558. symbol = match[4] || "",
  5559. zero = !!match[5],
  5560. width = match[6] && +match[6],
  5561. comma = !!match[7],
  5562. precision = match[8] && +match[8].slice(1),
  5563. type = match[9] || "";
  5564. // The "n" type is an alias for ",g".
  5565. if (type === "n") comma = true, type = "g";
  5566. // Map invalid types to the default format.
  5567. else if (!formatTypes[type]) type = "";
  5568. // If zero fill is specified, padding goes after sign and before digits.
  5569. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  5570. this.fill = fill;
  5571. this.align = align;
  5572. this.sign = sign;
  5573. this.symbol = symbol;
  5574. this.zero = zero;
  5575. this.width = width;
  5576. this.comma = comma;
  5577. this.precision = precision;
  5578. this.type = type;
  5579. }
  5580. FormatSpecifier.prototype.toString = function() {
  5581. return this.fill
  5582. + this.align
  5583. + this.sign
  5584. + this.symbol
  5585. + (this.zero ? "0" : "")
  5586. + (this.width == null ? "" : Math.max(1, this.width | 0))
  5587. + (this.comma ? "," : "")
  5588. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  5589. + this.type;
  5590. };
  5591. function identity$3(x) {
  5592. return x;
  5593. }
  5594. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  5595. function formatLocale(locale) {
  5596. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  5597. currency = locale.currency,
  5598. decimal = locale.decimal,
  5599. numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
  5600. percent = locale.percent || "%";
  5601. function newFormat(specifier) {
  5602. specifier = formatSpecifier(specifier);
  5603. var fill = specifier.fill,
  5604. align = specifier.align,
  5605. sign = specifier.sign,
  5606. symbol = specifier.symbol,
  5607. zero = specifier.zero,
  5608. width = specifier.width,
  5609. comma = specifier.comma,
  5610. precision = specifier.precision,
  5611. type = specifier.type;
  5612. // Compute the prefix and suffix.
  5613. // For SI-prefix, the suffix is lazily computed.
  5614. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  5615. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
  5616. // What format function should we use?
  5617. // Is this an integer type?
  5618. // Can this type generate exponential notation?
  5619. var formatType = formatTypes[type],
  5620. maybeSuffix = !type || /[defgprs%]/.test(type);
  5621. // Set the default precision if not specified,
  5622. // or clamp the specified precision to the supported range.
  5623. // For significant precision, it must be in [1, 21].
  5624. // For fixed precision, it must be in [0, 20].
  5625. precision = precision == null ? (type ? 6 : 12)
  5626. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  5627. : Math.max(0, Math.min(20, precision));
  5628. function format(value) {
  5629. var valuePrefix = prefix,
  5630. valueSuffix = suffix,
  5631. i, n, c;
  5632. if (type === "c") {
  5633. valueSuffix = formatType(value) + valueSuffix;
  5634. value = "";
  5635. } else {
  5636. value = +value;
  5637. // Perform the initial formatting.
  5638. var valueNegative = value < 0;
  5639. value = formatType(Math.abs(value), precision);
  5640. // If a negative value rounds to zero during formatting, treat as positive.
  5641. if (valueNegative && +value === 0) valueNegative = false;
  5642. // Compute the prefix and suffix.
  5643. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  5644. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  5645. // Break the formatted value into the integer “value” part that can be
  5646. // grouped, and fractional or exponential “suffix” part that is not.
  5647. if (maybeSuffix) {
  5648. i = -1, n = value.length;
  5649. while (++i < n) {
  5650. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  5651. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  5652. value = value.slice(0, i);
  5653. break;
  5654. }
  5655. }
  5656. }
  5657. }
  5658. // If the fill character is not "0", grouping is applied before padding.
  5659. if (comma && !zero) value = group(value, Infinity);
  5660. // Compute the padding.
  5661. var length = valuePrefix.length + value.length + valueSuffix.length,
  5662. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  5663. // If the fill character is "0", grouping is applied after padding.
  5664. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  5665. // Reconstruct the final output based on the desired alignment.
  5666. switch (align) {
  5667. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  5668. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  5669. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  5670. default: value = padding + valuePrefix + value + valueSuffix; break;
  5671. }
  5672. return numerals(value);
  5673. }
  5674. format.toString = function() {
  5675. return specifier + "";
  5676. };
  5677. return format;
  5678. }
  5679. function formatPrefix(specifier, value) {
  5680. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  5681. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  5682. k = Math.pow(10, -e),
  5683. prefix = prefixes[8 + e / 3];
  5684. return function(value) {
  5685. return f(k * value) + prefix;
  5686. };
  5687. }
  5688. return {
  5689. format: newFormat,
  5690. formatPrefix: formatPrefix
  5691. };
  5692. }
  5693. var locale;
  5694. defaultLocale({
  5695. decimal: ".",
  5696. thousands: ",",
  5697. grouping: [3],
  5698. currency: ["$", ""]
  5699. });
  5700. function defaultLocale(definition) {
  5701. locale = formatLocale(definition);
  5702. exports.format = locale.format;
  5703. exports.formatPrefix = locale.formatPrefix;
  5704. return locale;
  5705. }
  5706. function precisionFixed(step) {
  5707. return Math.max(0, -exponent$1(Math.abs(step)));
  5708. }
  5709. function precisionPrefix(step, value) {
  5710. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  5711. }
  5712. function precisionRound(step, max) {
  5713. step = Math.abs(step), max = Math.abs(max) - step;
  5714. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  5715. }
  5716. // Adds floating point numbers with twice the normal precision.
  5717. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  5718. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  5719. // 305–363 (1997).
  5720. // Code adapted from GeographicLib by Charles F. F. Karney,
  5721. // http://geographiclib.sourceforge.net/
  5722. function adder() {
  5723. return new Adder;
  5724. }
  5725. function Adder() {
  5726. this.reset();
  5727. }
  5728. Adder.prototype = {
  5729. constructor: Adder,
  5730. reset: function() {
  5731. this.s = // rounded value
  5732. this.t = 0; // exact error
  5733. },
  5734. add: function(y) {
  5735. add$1(temp, y, this.t);
  5736. add$1(this, temp.s, this.s);
  5737. if (this.s) this.t += temp.t;
  5738. else this.s = temp.t;
  5739. },
  5740. valueOf: function() {
  5741. return this.s;
  5742. }
  5743. };
  5744. var temp = new Adder;
  5745. function add$1(adder, a, b) {
  5746. var x = adder.s = a + b,
  5747. bv = x - a,
  5748. av = x - bv;
  5749. adder.t = (a - av) + (b - bv);
  5750. }
  5751. var epsilon$2 = 1e-6;
  5752. var epsilon2$1 = 1e-12;
  5753. var pi$3 = Math.PI;
  5754. var halfPi$2 = pi$3 / 2;
  5755. var quarterPi = pi$3 / 4;
  5756. var tau$3 = pi$3 * 2;
  5757. var degrees$1 = 180 / pi$3;
  5758. var radians = pi$3 / 180;
  5759. var abs = Math.abs;
  5760. var atan = Math.atan;
  5761. var atan2 = Math.atan2;
  5762. var cos$1 = Math.cos;
  5763. var ceil = Math.ceil;
  5764. var exp = Math.exp;
  5765. var log = Math.log;
  5766. var pow = Math.pow;
  5767. var sin$1 = Math.sin;
  5768. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  5769. var sqrt = Math.sqrt;
  5770. var tan = Math.tan;
  5771. function acos(x) {
  5772. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  5773. }
  5774. function asin(x) {
  5775. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  5776. }
  5777. function haversin(x) {
  5778. return (x = sin$1(x / 2)) * x;
  5779. }
  5780. function noop$1() {}
  5781. function streamGeometry(geometry, stream) {
  5782. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  5783. streamGeometryType[geometry.type](geometry, stream);
  5784. }
  5785. }
  5786. var streamObjectType = {
  5787. Feature: function(object, stream) {
  5788. streamGeometry(object.geometry, stream);
  5789. },
  5790. FeatureCollection: function(object, stream) {
  5791. var features = object.features, i = -1, n = features.length;
  5792. while (++i < n) streamGeometry(features[i].geometry, stream);
  5793. }
  5794. };
  5795. var streamGeometryType = {
  5796. Sphere: function(object, stream) {
  5797. stream.sphere();
  5798. },
  5799. Point: function(object, stream) {
  5800. object = object.coordinates;
  5801. stream.point(object[0], object[1], object[2]);
  5802. },
  5803. MultiPoint: function(object, stream) {
  5804. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5805. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  5806. },
  5807. LineString: function(object, stream) {
  5808. streamLine(object.coordinates, stream, 0);
  5809. },
  5810. MultiLineString: function(object, stream) {
  5811. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5812. while (++i < n) streamLine(coordinates[i], stream, 0);
  5813. },
  5814. Polygon: function(object, stream) {
  5815. streamPolygon(object.coordinates, stream);
  5816. },
  5817. MultiPolygon: function(object, stream) {
  5818. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  5819. while (++i < n) streamPolygon(coordinates[i], stream);
  5820. },
  5821. GeometryCollection: function(object, stream) {
  5822. var geometries = object.geometries, i = -1, n = geometries.length;
  5823. while (++i < n) streamGeometry(geometries[i], stream);
  5824. }
  5825. };
  5826. function streamLine(coordinates, stream, closed) {
  5827. var i = -1, n = coordinates.length - closed, coordinate;
  5828. stream.lineStart();
  5829. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  5830. stream.lineEnd();
  5831. }
  5832. function streamPolygon(coordinates, stream) {
  5833. var i = -1, n = coordinates.length;
  5834. stream.polygonStart();
  5835. while (++i < n) streamLine(coordinates[i], stream, 1);
  5836. stream.polygonEnd();
  5837. }
  5838. function geoStream(object, stream) {
  5839. if (object && streamObjectType.hasOwnProperty(object.type)) {
  5840. streamObjectType[object.type](object, stream);
  5841. } else {
  5842. streamGeometry(object, stream);
  5843. }
  5844. }
  5845. var areaRingSum = adder();
  5846. var areaSum = adder();
  5847. var lambda00;
  5848. var phi00;
  5849. var lambda0;
  5850. var cosPhi0;
  5851. var sinPhi0;
  5852. var areaStream = {
  5853. point: noop$1,
  5854. lineStart: noop$1,
  5855. lineEnd: noop$1,
  5856. polygonStart: function() {
  5857. areaRingSum.reset();
  5858. areaStream.lineStart = areaRingStart;
  5859. areaStream.lineEnd = areaRingEnd;
  5860. },
  5861. polygonEnd: function() {
  5862. var areaRing = +areaRingSum;
  5863. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  5864. this.lineStart = this.lineEnd = this.point = noop$1;
  5865. },
  5866. sphere: function() {
  5867. areaSum.add(tau$3);
  5868. }
  5869. };
  5870. function areaRingStart() {
  5871. areaStream.point = areaPointFirst;
  5872. }
  5873. function areaRingEnd() {
  5874. areaPoint(lambda00, phi00);
  5875. }
  5876. function areaPointFirst(lambda, phi) {
  5877. areaStream.point = areaPoint;
  5878. lambda00 = lambda, phi00 = phi;
  5879. lambda *= radians, phi *= radians;
  5880. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  5881. }
  5882. function areaPoint(lambda, phi) {
  5883. lambda *= radians, phi *= radians;
  5884. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  5885. // Spherical excess E for a spherical triangle with vertices: south pole,
  5886. // previous point, current point. Uses a formula derived from Cagnoli’s
  5887. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  5888. var dLambda = lambda - lambda0,
  5889. sdLambda = dLambda >= 0 ? 1 : -1,
  5890. adLambda = sdLambda * dLambda,
  5891. cosPhi = cos$1(phi),
  5892. sinPhi = sin$1(phi),
  5893. k = sinPhi0 * sinPhi,
  5894. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  5895. v = k * sdLambda * sin$1(adLambda);
  5896. areaRingSum.add(atan2(v, u));
  5897. // Advance the previous points.
  5898. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  5899. }
  5900. function area(object) {
  5901. areaSum.reset();
  5902. geoStream(object, areaStream);
  5903. return areaSum * 2;
  5904. }
  5905. function spherical(cartesian) {
  5906. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  5907. }
  5908. function cartesian(spherical) {
  5909. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  5910. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  5911. }
  5912. function cartesianDot(a, b) {
  5913. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  5914. }
  5915. function cartesianCross(a, b) {
  5916. 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]];
  5917. }
  5918. // TODO return a
  5919. function cartesianAddInPlace(a, b) {
  5920. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  5921. }
  5922. function cartesianScale(vector, k) {
  5923. return [vector[0] * k, vector[1] * k, vector[2] * k];
  5924. }
  5925. // TODO return d
  5926. function cartesianNormalizeInPlace(d) {
  5927. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  5928. d[0] /= l, d[1] /= l, d[2] /= l;
  5929. }
  5930. var lambda0$1;
  5931. var phi0;
  5932. var lambda1;
  5933. var phi1;
  5934. var lambda2;
  5935. var lambda00$1;
  5936. var phi00$1;
  5937. var p0;
  5938. var deltaSum = adder();
  5939. var ranges;
  5940. var range;
  5941. var boundsStream = {
  5942. point: boundsPoint,
  5943. lineStart: boundsLineStart,
  5944. lineEnd: boundsLineEnd,
  5945. polygonStart: function() {
  5946. boundsStream.point = boundsRingPoint;
  5947. boundsStream.lineStart = boundsRingStart;
  5948. boundsStream.lineEnd = boundsRingEnd;
  5949. deltaSum.reset();
  5950. areaStream.polygonStart();
  5951. },
  5952. polygonEnd: function() {
  5953. areaStream.polygonEnd();
  5954. boundsStream.point = boundsPoint;
  5955. boundsStream.lineStart = boundsLineStart;
  5956. boundsStream.lineEnd = boundsLineEnd;
  5957. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  5958. else if (deltaSum > epsilon$2) phi1 = 90;
  5959. else if (deltaSum < -epsilon$2) phi0 = -90;
  5960. range[0] = lambda0$1, range[1] = lambda1;
  5961. }
  5962. };
  5963. function boundsPoint(lambda, phi) {
  5964. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  5965. if (phi < phi0) phi0 = phi;
  5966. if (phi > phi1) phi1 = phi;
  5967. }
  5968. function linePoint(lambda, phi) {
  5969. var p = cartesian([lambda * radians, phi * radians]);
  5970. if (p0) {
  5971. var normal = cartesianCross(p0, p),
  5972. equatorial = [normal[1], -normal[0], 0],
  5973. inflection = cartesianCross(equatorial, normal);
  5974. cartesianNormalizeInPlace(inflection);
  5975. inflection = spherical(inflection);
  5976. var delta = lambda - lambda2,
  5977. sign$$1 = delta > 0 ? 1 : -1,
  5978. lambdai = inflection[0] * degrees$1 * sign$$1,
  5979. phii,
  5980. antimeridian = abs(delta) > 180;
  5981. if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  5982. phii = inflection[1] * degrees$1;
  5983. if (phii > phi1) phi1 = phii;
  5984. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  5985. phii = -inflection[1] * degrees$1;
  5986. if (phii < phi0) phi0 = phii;
  5987. } else {
  5988. if (phi < phi0) phi0 = phi;
  5989. if (phi > phi1) phi1 = phi;
  5990. }
  5991. if (antimeridian) {
  5992. if (lambda < lambda2) {
  5993. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  5994. } else {
  5995. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  5996. }
  5997. } else {
  5998. if (lambda1 >= lambda0$1) {
  5999. if (lambda < lambda0$1) lambda0$1 = lambda;
  6000. if (lambda > lambda1) lambda1 = lambda;
  6001. } else {
  6002. if (lambda > lambda2) {
  6003. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6004. } else {
  6005. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6006. }
  6007. }
  6008. }
  6009. } else {
  6010. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6011. }
  6012. if (phi < phi0) phi0 = phi;
  6013. if (phi > phi1) phi1 = phi;
  6014. p0 = p, lambda2 = lambda;
  6015. }
  6016. function boundsLineStart() {
  6017. boundsStream.point = linePoint;
  6018. }
  6019. function boundsLineEnd() {
  6020. range[0] = lambda0$1, range[1] = lambda1;
  6021. boundsStream.point = boundsPoint;
  6022. p0 = null;
  6023. }
  6024. function boundsRingPoint(lambda, phi) {
  6025. if (p0) {
  6026. var delta = lambda - lambda2;
  6027. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6028. } else {
  6029. lambda00$1 = lambda, phi00$1 = phi;
  6030. }
  6031. areaStream.point(lambda, phi);
  6032. linePoint(lambda, phi);
  6033. }
  6034. function boundsRingStart() {
  6035. areaStream.lineStart();
  6036. }
  6037. function boundsRingEnd() {
  6038. boundsRingPoint(lambda00$1, phi00$1);
  6039. areaStream.lineEnd();
  6040. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6041. range[0] = lambda0$1, range[1] = lambda1;
  6042. p0 = null;
  6043. }
  6044. // Finds the left-right distance between two longitudes.
  6045. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6046. // the distance between ±180° to be 360°.
  6047. function angle(lambda0, lambda1) {
  6048. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6049. }
  6050. function rangeCompare(a, b) {
  6051. return a[0] - b[0];
  6052. }
  6053. function rangeContains(range, x) {
  6054. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6055. }
  6056. function bounds(feature) {
  6057. var i, n, a, b, merged, deltaMax, delta;
  6058. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6059. ranges = [];
  6060. geoStream(feature, boundsStream);
  6061. // First, sort ranges by their minimum longitudes.
  6062. if (n = ranges.length) {
  6063. ranges.sort(rangeCompare);
  6064. // Then, merge any ranges that overlap.
  6065. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6066. b = ranges[i];
  6067. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6068. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6069. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6070. } else {
  6071. merged.push(a = b);
  6072. }
  6073. }
  6074. // Finally, find the largest gap between the merged ranges.
  6075. // The final bounding box will be the inverse of this gap.
  6076. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6077. b = merged[i];
  6078. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6079. }
  6080. }
  6081. ranges = range = null;
  6082. return lambda0$1 === Infinity || phi0 === Infinity
  6083. ? [[NaN, NaN], [NaN, NaN]]
  6084. : [[lambda0$1, phi0], [lambda1, phi1]];
  6085. }
  6086. var W0;
  6087. var W1;
  6088. var X0;
  6089. var Y0;
  6090. var Z0;
  6091. var X1;
  6092. var Y1;
  6093. var Z1;
  6094. var X2;
  6095. var Y2;
  6096. var Z2;
  6097. var lambda00$2;
  6098. var phi00$2;
  6099. var x0;
  6100. var y0;
  6101. var z0; // previous point
  6102. var centroidStream = {
  6103. sphere: noop$1,
  6104. point: centroidPoint,
  6105. lineStart: centroidLineStart,
  6106. lineEnd: centroidLineEnd,
  6107. polygonStart: function() {
  6108. centroidStream.lineStart = centroidRingStart;
  6109. centroidStream.lineEnd = centroidRingEnd;
  6110. },
  6111. polygonEnd: function() {
  6112. centroidStream.lineStart = centroidLineStart;
  6113. centroidStream.lineEnd = centroidLineEnd;
  6114. }
  6115. };
  6116. // Arithmetic mean of Cartesian vectors.
  6117. function centroidPoint(lambda, phi) {
  6118. lambda *= radians, phi *= radians;
  6119. var cosPhi = cos$1(phi);
  6120. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6121. }
  6122. function centroidPointCartesian(x, y, z) {
  6123. ++W0;
  6124. X0 += (x - X0) / W0;
  6125. Y0 += (y - Y0) / W0;
  6126. Z0 += (z - Z0) / W0;
  6127. }
  6128. function centroidLineStart() {
  6129. centroidStream.point = centroidLinePointFirst;
  6130. }
  6131. function centroidLinePointFirst(lambda, phi) {
  6132. lambda *= radians, phi *= radians;
  6133. var cosPhi = cos$1(phi);
  6134. x0 = cosPhi * cos$1(lambda);
  6135. y0 = cosPhi * sin$1(lambda);
  6136. z0 = sin$1(phi);
  6137. centroidStream.point = centroidLinePoint;
  6138. centroidPointCartesian(x0, y0, z0);
  6139. }
  6140. function centroidLinePoint(lambda, phi) {
  6141. lambda *= radians, phi *= radians;
  6142. var cosPhi = cos$1(phi),
  6143. x = cosPhi * cos$1(lambda),
  6144. y = cosPhi * sin$1(lambda),
  6145. z = sin$1(phi),
  6146. 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);
  6147. W1 += w;
  6148. X1 += w * (x0 + (x0 = x));
  6149. Y1 += w * (y0 + (y0 = y));
  6150. Z1 += w * (z0 + (z0 = z));
  6151. centroidPointCartesian(x0, y0, z0);
  6152. }
  6153. function centroidLineEnd() {
  6154. centroidStream.point = centroidPoint;
  6155. }
  6156. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6157. // J. Applied Mechanics 42, 239 (1975).
  6158. function centroidRingStart() {
  6159. centroidStream.point = centroidRingPointFirst;
  6160. }
  6161. function centroidRingEnd() {
  6162. centroidRingPoint(lambda00$2, phi00$2);
  6163. centroidStream.point = centroidPoint;
  6164. }
  6165. function centroidRingPointFirst(lambda, phi) {
  6166. lambda00$2 = lambda, phi00$2 = phi;
  6167. lambda *= radians, phi *= radians;
  6168. centroidStream.point = centroidRingPoint;
  6169. var cosPhi = cos$1(phi);
  6170. x0 = cosPhi * cos$1(lambda);
  6171. y0 = cosPhi * sin$1(lambda);
  6172. z0 = sin$1(phi);
  6173. centroidPointCartesian(x0, y0, z0);
  6174. }
  6175. function centroidRingPoint(lambda, phi) {
  6176. lambda *= radians, phi *= radians;
  6177. var cosPhi = cos$1(phi),
  6178. x = cosPhi * cos$1(lambda),
  6179. y = cosPhi * sin$1(lambda),
  6180. z = sin$1(phi),
  6181. cx = y0 * z - z0 * y,
  6182. cy = z0 * x - x0 * z,
  6183. cz = x0 * y - y0 * x,
  6184. m = sqrt(cx * cx + cy * cy + cz * cz),
  6185. w = asin(m), // line weight = angle
  6186. v = m && -w / m; // area weight multiplier
  6187. X2 += v * cx;
  6188. Y2 += v * cy;
  6189. Z2 += v * cz;
  6190. W1 += w;
  6191. X1 += w * (x0 + (x0 = x));
  6192. Y1 += w * (y0 + (y0 = y));
  6193. Z1 += w * (z0 + (z0 = z));
  6194. centroidPointCartesian(x0, y0, z0);
  6195. }
  6196. function centroid(object) {
  6197. W0 = W1 =
  6198. X0 = Y0 = Z0 =
  6199. X1 = Y1 = Z1 =
  6200. X2 = Y2 = Z2 = 0;
  6201. geoStream(object, centroidStream);
  6202. var x = X2,
  6203. y = Y2,
  6204. z = Z2,
  6205. m = x * x + y * y + z * z;
  6206. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6207. if (m < epsilon2$1) {
  6208. x = X1, y = Y1, z = Z1;
  6209. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6210. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6211. m = x * x + y * y + z * z;
  6212. // If the feature still has an undefined ccentroid, then return.
  6213. if (m < epsilon2$1) return [NaN, NaN];
  6214. }
  6215. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6216. }
  6217. function constant$7(x) {
  6218. return function() {
  6219. return x;
  6220. };
  6221. }
  6222. function compose(a, b) {
  6223. function compose(x, y) {
  6224. return x = a(x, y), b(x[0], x[1]);
  6225. }
  6226. if (a.invert && b.invert) compose.invert = function(x, y) {
  6227. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6228. };
  6229. return compose;
  6230. }
  6231. function rotationIdentity(lambda, phi) {
  6232. return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6233. }
  6234. rotationIdentity.invert = rotationIdentity;
  6235. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6236. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6237. : rotationLambda(deltaLambda))
  6238. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6239. : rotationIdentity);
  6240. }
  6241. function forwardRotationLambda(deltaLambda) {
  6242. return function(lambda, phi) {
  6243. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6244. };
  6245. }
  6246. function rotationLambda(deltaLambda) {
  6247. var rotation = forwardRotationLambda(deltaLambda);
  6248. rotation.invert = forwardRotationLambda(-deltaLambda);
  6249. return rotation;
  6250. }
  6251. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6252. var cosDeltaPhi = cos$1(deltaPhi),
  6253. sinDeltaPhi = sin$1(deltaPhi),
  6254. cosDeltaGamma = cos$1(deltaGamma),
  6255. sinDeltaGamma = sin$1(deltaGamma);
  6256. function rotation(lambda, phi) {
  6257. var cosPhi = cos$1(phi),
  6258. x = cos$1(lambda) * cosPhi,
  6259. y = sin$1(lambda) * cosPhi,
  6260. z = sin$1(phi),
  6261. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6262. return [
  6263. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6264. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6265. ];
  6266. }
  6267. rotation.invert = function(lambda, phi) {
  6268. var cosPhi = cos$1(phi),
  6269. x = cos$1(lambda) * cosPhi,
  6270. y = sin$1(lambda) * cosPhi,
  6271. z = sin$1(phi),
  6272. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6273. return [
  6274. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6275. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6276. ];
  6277. };
  6278. return rotation;
  6279. }
  6280. function rotation(rotate) {
  6281. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6282. function forward(coordinates) {
  6283. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6284. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6285. }
  6286. forward.invert = function(coordinates) {
  6287. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6288. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6289. };
  6290. return forward;
  6291. }
  6292. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6293. function circleStream(stream, radius, delta, direction, t0, t1) {
  6294. if (!delta) return;
  6295. var cosRadius = cos$1(radius),
  6296. sinRadius = sin$1(radius),
  6297. step = direction * delta;
  6298. if (t0 == null) {
  6299. t0 = radius + direction * tau$3;
  6300. t1 = radius - step / 2;
  6301. } else {
  6302. t0 = circleRadius(cosRadius, t0);
  6303. t1 = circleRadius(cosRadius, t1);
  6304. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6305. }
  6306. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6307. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6308. stream.point(point[0], point[1]);
  6309. }
  6310. }
  6311. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6312. function circleRadius(cosRadius, point) {
  6313. point = cartesian(point), point[0] -= cosRadius;
  6314. cartesianNormalizeInPlace(point);
  6315. var radius = acos(-point[1]);
  6316. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6317. }
  6318. function circle() {
  6319. var center = constant$7([0, 0]),
  6320. radius = constant$7(90),
  6321. precision = constant$7(6),
  6322. ring,
  6323. rotate,
  6324. stream = {point: point};
  6325. function point(x, y) {
  6326. ring.push(x = rotate(x, y));
  6327. x[0] *= degrees$1, x[1] *= degrees$1;
  6328. }
  6329. function circle() {
  6330. var c = center.apply(this, arguments),
  6331. r = radius.apply(this, arguments) * radians,
  6332. p = precision.apply(this, arguments) * radians;
  6333. ring = [];
  6334. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6335. circleStream(stream, r, p, 1);
  6336. c = {type: "Polygon", coordinates: [ring]};
  6337. ring = rotate = null;
  6338. return c;
  6339. }
  6340. circle.center = function(_) {
  6341. return arguments.length ? (center = typeof _ === "function" ? _ : constant$7([+_[0], +_[1]]), circle) : center;
  6342. };
  6343. circle.radius = function(_) {
  6344. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), circle) : radius;
  6345. };
  6346. circle.precision = function(_) {
  6347. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$7(+_), circle) : precision;
  6348. };
  6349. return circle;
  6350. }
  6351. function clipBuffer() {
  6352. var lines = [],
  6353. line;
  6354. return {
  6355. point: function(x, y) {
  6356. line.push([x, y]);
  6357. },
  6358. lineStart: function() {
  6359. lines.push(line = []);
  6360. },
  6361. lineEnd: noop$1,
  6362. rejoin: function() {
  6363. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  6364. },
  6365. result: function() {
  6366. var result = lines;
  6367. lines = [];
  6368. line = null;
  6369. return result;
  6370. }
  6371. };
  6372. }
  6373. function pointEqual(a, b) {
  6374. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  6375. }
  6376. function Intersection(point, points, other, entry) {
  6377. this.x = point;
  6378. this.z = points;
  6379. this.o = other; // another intersection
  6380. this.e = entry; // is an entry?
  6381. this.v = false; // visited
  6382. this.n = this.p = null; // next & previous
  6383. }
  6384. // A generalized polygon clipping algorithm: given a polygon that has been cut
  6385. // into its visible line segments, and rejoins the segments by interpolating
  6386. // along the clip edge.
  6387. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  6388. var subject = [],
  6389. clip = [],
  6390. i,
  6391. n;
  6392. segments.forEach(function(segment) {
  6393. if ((n = segment.length - 1) <= 0) return;
  6394. var n, p0 = segment[0], p1 = segment[n], x;
  6395. // If the first and last points of a segment are coincident, then treat as a
  6396. // closed ring. TODO if all rings are closed, then the winding order of the
  6397. // exterior ring should be checked.
  6398. if (pointEqual(p0, p1)) {
  6399. stream.lineStart();
  6400. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  6401. stream.lineEnd();
  6402. return;
  6403. }
  6404. subject.push(x = new Intersection(p0, segment, null, true));
  6405. clip.push(x.o = new Intersection(p0, null, x, false));
  6406. subject.push(x = new Intersection(p1, segment, null, false));
  6407. clip.push(x.o = new Intersection(p1, null, x, true));
  6408. });
  6409. if (!subject.length) return;
  6410. clip.sort(compareIntersection);
  6411. link$1(subject);
  6412. link$1(clip);
  6413. for (i = 0, n = clip.length; i < n; ++i) {
  6414. clip[i].e = startInside = !startInside;
  6415. }
  6416. var start = subject[0],
  6417. points,
  6418. point;
  6419. while (1) {
  6420. // Find first unvisited intersection.
  6421. var current = start,
  6422. isSubject = true;
  6423. while (current.v) if ((current = current.n) === start) return;
  6424. points = current.z;
  6425. stream.lineStart();
  6426. do {
  6427. current.v = current.o.v = true;
  6428. if (current.e) {
  6429. if (isSubject) {
  6430. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  6431. } else {
  6432. interpolate(current.x, current.n.x, 1, stream);
  6433. }
  6434. current = current.n;
  6435. } else {
  6436. if (isSubject) {
  6437. points = current.p.z;
  6438. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  6439. } else {
  6440. interpolate(current.x, current.p.x, -1, stream);
  6441. }
  6442. current = current.p;
  6443. }
  6444. current = current.o;
  6445. points = current.z;
  6446. isSubject = !isSubject;
  6447. } while (!current.v);
  6448. stream.lineEnd();
  6449. }
  6450. }
  6451. function link$1(array) {
  6452. if (!(n = array.length)) return;
  6453. var n,
  6454. i = 0,
  6455. a = array[0],
  6456. b;
  6457. while (++i < n) {
  6458. a.n = b = array[i];
  6459. b.p = a;
  6460. a = b;
  6461. }
  6462. a.n = b = array[0];
  6463. b.p = a;
  6464. }
  6465. var sum$1 = adder();
  6466. function polygonContains(polygon, point) {
  6467. var lambda = point[0],
  6468. phi = point[1],
  6469. normal = [sin$1(lambda), -cos$1(lambda), 0],
  6470. angle = 0,
  6471. winding = 0;
  6472. sum$1.reset();
  6473. for (var i = 0, n = polygon.length; i < n; ++i) {
  6474. if (!(m = (ring = polygon[i]).length)) continue;
  6475. var ring,
  6476. m,
  6477. point0 = ring[m - 1],
  6478. lambda0 = point0[0],
  6479. phi0 = point0[1] / 2 + quarterPi,
  6480. sinPhi0 = sin$1(phi0),
  6481. cosPhi0 = cos$1(phi0);
  6482. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  6483. var point1 = ring[j],
  6484. lambda1 = point1[0],
  6485. phi1 = point1[1] / 2 + quarterPi,
  6486. sinPhi1 = sin$1(phi1),
  6487. cosPhi1 = cos$1(phi1),
  6488. delta = lambda1 - lambda0,
  6489. sign$$1 = delta >= 0 ? 1 : -1,
  6490. absDelta = sign$$1 * delta,
  6491. antimeridian = absDelta > pi$3,
  6492. k = sinPhi0 * sinPhi1;
  6493. sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  6494. angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
  6495. // Are the longitudes either side of the point’s meridian (lambda),
  6496. // and are the latitudes smaller than the parallel (phi)?
  6497. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  6498. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  6499. cartesianNormalizeInPlace(arc);
  6500. var intersection = cartesianCross(normal, arc);
  6501. cartesianNormalizeInPlace(intersection);
  6502. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  6503. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  6504. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  6505. }
  6506. }
  6507. }
  6508. }
  6509. // First, determine whether the South pole is inside or outside:
  6510. //
  6511. // It is inside if:
  6512. // * the polygon winds around it in a clockwise direction.
  6513. // * the polygon does not (cumulatively) wind around it, but has a negative
  6514. // (counter-clockwise) area.
  6515. //
  6516. // Second, count the (signed) number of times a segment crosses a lambda
  6517. // from the point to the South pole. If it is zero, then the point is the
  6518. // same side as the South pole.
  6519. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  6520. }
  6521. function clip(pointVisible, clipLine, interpolate, start) {
  6522. return function(sink) {
  6523. var line = clipLine(sink),
  6524. ringBuffer = clipBuffer(),
  6525. ringSink = clipLine(ringBuffer),
  6526. polygonStarted = false,
  6527. polygon,
  6528. segments,
  6529. ring;
  6530. var clip = {
  6531. point: point,
  6532. lineStart: lineStart,
  6533. lineEnd: lineEnd,
  6534. polygonStart: function() {
  6535. clip.point = pointRing;
  6536. clip.lineStart = ringStart;
  6537. clip.lineEnd = ringEnd;
  6538. segments = [];
  6539. polygon = [];
  6540. },
  6541. polygonEnd: function() {
  6542. clip.point = point;
  6543. clip.lineStart = lineStart;
  6544. clip.lineEnd = lineEnd;
  6545. segments = merge(segments);
  6546. var startInside = polygonContains(polygon, start);
  6547. if (segments.length) {
  6548. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6549. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  6550. } else if (startInside) {
  6551. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6552. sink.lineStart();
  6553. interpolate(null, null, 1, sink);
  6554. sink.lineEnd();
  6555. }
  6556. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  6557. segments = polygon = null;
  6558. },
  6559. sphere: function() {
  6560. sink.polygonStart();
  6561. sink.lineStart();
  6562. interpolate(null, null, 1, sink);
  6563. sink.lineEnd();
  6564. sink.polygonEnd();
  6565. }
  6566. };
  6567. function point(lambda, phi) {
  6568. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  6569. }
  6570. function pointLine(lambda, phi) {
  6571. line.point(lambda, phi);
  6572. }
  6573. function lineStart() {
  6574. clip.point = pointLine;
  6575. line.lineStart();
  6576. }
  6577. function lineEnd() {
  6578. clip.point = point;
  6579. line.lineEnd();
  6580. }
  6581. function pointRing(lambda, phi) {
  6582. ring.push([lambda, phi]);
  6583. ringSink.point(lambda, phi);
  6584. }
  6585. function ringStart() {
  6586. ringSink.lineStart();
  6587. ring = [];
  6588. }
  6589. function ringEnd() {
  6590. pointRing(ring[0][0], ring[0][1]);
  6591. ringSink.lineEnd();
  6592. var clean = ringSink.clean(),
  6593. ringSegments = ringBuffer.result(),
  6594. i, n = ringSegments.length, m,
  6595. segment,
  6596. point;
  6597. ring.pop();
  6598. polygon.push(ring);
  6599. ring = null;
  6600. if (!n) return;
  6601. // No intersections.
  6602. if (clean & 1) {
  6603. segment = ringSegments[0];
  6604. if ((m = segment.length - 1) > 0) {
  6605. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  6606. sink.lineStart();
  6607. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  6608. sink.lineEnd();
  6609. }
  6610. return;
  6611. }
  6612. // Rejoin connected segments.
  6613. // TODO reuse ringBuffer.rejoin()?
  6614. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  6615. segments.push(ringSegments.filter(validSegment));
  6616. }
  6617. return clip;
  6618. };
  6619. }
  6620. function validSegment(segment) {
  6621. return segment.length > 1;
  6622. }
  6623. // Intersections are sorted along the clip edge. For both antimeridian cutting
  6624. // and circle clipping, the same comparison is used.
  6625. function compareIntersection(a, b) {
  6626. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  6627. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  6628. }
  6629. var clipAntimeridian = clip(
  6630. function() { return true; },
  6631. clipAntimeridianLine,
  6632. clipAntimeridianInterpolate,
  6633. [-pi$3, -halfPi$2]
  6634. );
  6635. // Takes a line and cuts into visible segments. Return values: 0 - there were
  6636. // intersections or the line was empty; 1 - no intersections; 2 - there were
  6637. // intersections, and the first and last segments should be rejoined.
  6638. function clipAntimeridianLine(stream) {
  6639. var lambda0 = NaN,
  6640. phi0 = NaN,
  6641. sign0 = NaN,
  6642. clean; // no intersections
  6643. return {
  6644. lineStart: function() {
  6645. stream.lineStart();
  6646. clean = 1;
  6647. },
  6648. point: function(lambda1, phi1) {
  6649. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  6650. delta = abs(lambda1 - lambda0);
  6651. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  6652. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  6653. stream.point(sign0, phi0);
  6654. stream.lineEnd();
  6655. stream.lineStart();
  6656. stream.point(sign1, phi0);
  6657. stream.point(lambda1, phi0);
  6658. clean = 0;
  6659. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  6660. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  6661. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  6662. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  6663. stream.point(sign0, phi0);
  6664. stream.lineEnd();
  6665. stream.lineStart();
  6666. stream.point(sign1, phi0);
  6667. clean = 0;
  6668. }
  6669. stream.point(lambda0 = lambda1, phi0 = phi1);
  6670. sign0 = sign1;
  6671. },
  6672. lineEnd: function() {
  6673. stream.lineEnd();
  6674. lambda0 = phi0 = NaN;
  6675. },
  6676. clean: function() {
  6677. return 2 - clean; // if intersections, rejoin first and last segments
  6678. }
  6679. };
  6680. }
  6681. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  6682. var cosPhi0,
  6683. cosPhi1,
  6684. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  6685. return abs(sinLambda0Lambda1) > epsilon$2
  6686. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  6687. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  6688. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  6689. : (phi0 + phi1) / 2;
  6690. }
  6691. function clipAntimeridianInterpolate(from, to, direction, stream) {
  6692. var phi;
  6693. if (from == null) {
  6694. phi = direction * halfPi$2;
  6695. stream.point(-pi$3, phi);
  6696. stream.point(0, phi);
  6697. stream.point(pi$3, phi);
  6698. stream.point(pi$3, 0);
  6699. stream.point(pi$3, -phi);
  6700. stream.point(0, -phi);
  6701. stream.point(-pi$3, -phi);
  6702. stream.point(-pi$3, 0);
  6703. stream.point(-pi$3, phi);
  6704. } else if (abs(from[0] - to[0]) > epsilon$2) {
  6705. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  6706. phi = direction * lambda / 2;
  6707. stream.point(-lambda, phi);
  6708. stream.point(0, phi);
  6709. stream.point(lambda, phi);
  6710. } else {
  6711. stream.point(to[0], to[1]);
  6712. }
  6713. }
  6714. function clipCircle(radius) {
  6715. var cr = cos$1(radius),
  6716. delta = 6 * radians,
  6717. smallRadius = cr > 0,
  6718. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  6719. function interpolate(from, to, direction, stream) {
  6720. circleStream(stream, radius, delta, direction, from, to);
  6721. }
  6722. function visible(lambda, phi) {
  6723. return cos$1(lambda) * cos$1(phi) > cr;
  6724. }
  6725. // Takes a line and cuts into visible segments. Return values used for polygon
  6726. // clipping: 0 - there were intersections or the line was empty; 1 - no
  6727. // intersections 2 - there were intersections, and the first and last segments
  6728. // should be rejoined.
  6729. function clipLine(stream) {
  6730. var point0, // previous point
  6731. c0, // code for previous point
  6732. v0, // visibility of previous point
  6733. v00, // visibility of first point
  6734. clean; // no intersections
  6735. return {
  6736. lineStart: function() {
  6737. v00 = v0 = false;
  6738. clean = 1;
  6739. },
  6740. point: function(lambda, phi) {
  6741. var point1 = [lambda, phi],
  6742. point2,
  6743. v = visible(lambda, phi),
  6744. c = smallRadius
  6745. ? v ? 0 : code(lambda, phi)
  6746. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  6747. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  6748. // Handle degeneracies.
  6749. // TODO ignore if not clipping polygons.
  6750. if (v !== v0) {
  6751. point2 = intersect(point0, point1);
  6752. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  6753. point1[0] += epsilon$2;
  6754. point1[1] += epsilon$2;
  6755. v = visible(point1[0], point1[1]);
  6756. }
  6757. }
  6758. if (v !== v0) {
  6759. clean = 0;
  6760. if (v) {
  6761. // outside going in
  6762. stream.lineStart();
  6763. point2 = intersect(point1, point0);
  6764. stream.point(point2[0], point2[1]);
  6765. } else {
  6766. // inside going out
  6767. point2 = intersect(point0, point1);
  6768. stream.point(point2[0], point2[1]);
  6769. stream.lineEnd();
  6770. }
  6771. point0 = point2;
  6772. } else if (notHemisphere && point0 && smallRadius ^ v) {
  6773. var t;
  6774. // If the codes for two points are different, or are both zero,
  6775. // and there this segment intersects with the small circle.
  6776. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  6777. clean = 0;
  6778. if (smallRadius) {
  6779. stream.lineStart();
  6780. stream.point(t[0][0], t[0][1]);
  6781. stream.point(t[1][0], t[1][1]);
  6782. stream.lineEnd();
  6783. } else {
  6784. stream.point(t[1][0], t[1][1]);
  6785. stream.lineEnd();
  6786. stream.lineStart();
  6787. stream.point(t[0][0], t[0][1]);
  6788. }
  6789. }
  6790. }
  6791. if (v && (!point0 || !pointEqual(point0, point1))) {
  6792. stream.point(point1[0], point1[1]);
  6793. }
  6794. point0 = point1, v0 = v, c0 = c;
  6795. },
  6796. lineEnd: function() {
  6797. if (v0) stream.lineEnd();
  6798. point0 = null;
  6799. },
  6800. // Rejoin first and last segments if there were intersections and the first
  6801. // and last points were visible.
  6802. clean: function() {
  6803. return clean | ((v00 && v0) << 1);
  6804. }
  6805. };
  6806. }
  6807. // Intersects the great circle between a and b with the clip circle.
  6808. function intersect(a, b, two) {
  6809. var pa = cartesian(a),
  6810. pb = cartesian(b);
  6811. // We have two planes, n1.p = d1 and n2.p = d2.
  6812. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  6813. var n1 = [1, 0, 0], // normal
  6814. n2 = cartesianCross(pa, pb),
  6815. n2n2 = cartesianDot(n2, n2),
  6816. n1n2 = n2[0], // cartesianDot(n1, n2),
  6817. determinant = n2n2 - n1n2 * n1n2;
  6818. // Two polar points.
  6819. if (!determinant) return !two && a;
  6820. var c1 = cr * n2n2 / determinant,
  6821. c2 = -cr * n1n2 / determinant,
  6822. n1xn2 = cartesianCross(n1, n2),
  6823. A = cartesianScale(n1, c1),
  6824. B = cartesianScale(n2, c2);
  6825. cartesianAddInPlace(A, B);
  6826. // Solve |p(t)|^2 = 1.
  6827. var u = n1xn2,
  6828. w = cartesianDot(A, u),
  6829. uu = cartesianDot(u, u),
  6830. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  6831. if (t2 < 0) return;
  6832. var t = sqrt(t2),
  6833. q = cartesianScale(u, (-w - t) / uu);
  6834. cartesianAddInPlace(q, A);
  6835. q = spherical(q);
  6836. if (!two) return q;
  6837. // Two intersection points.
  6838. var lambda0 = a[0],
  6839. lambda1 = b[0],
  6840. phi0 = a[1],
  6841. phi1 = b[1],
  6842. z;
  6843. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  6844. var delta = lambda1 - lambda0,
  6845. polar = abs(delta - pi$3) < epsilon$2,
  6846. meridian = polar || delta < epsilon$2;
  6847. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  6848. // Check that the first point is between a and b.
  6849. if (meridian
  6850. ? polar
  6851. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  6852. : phi0 <= q[1] && q[1] <= phi1
  6853. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  6854. var q1 = cartesianScale(u, (-w + t) / uu);
  6855. cartesianAddInPlace(q1, A);
  6856. return [q, spherical(q1)];
  6857. }
  6858. }
  6859. // Generates a 4-bit vector representing the location of a point relative to
  6860. // the small circle's bounding box.
  6861. function code(lambda, phi) {
  6862. var r = smallRadius ? radius : pi$3 - radius,
  6863. code = 0;
  6864. if (lambda < -r) code |= 1; // left
  6865. else if (lambda > r) code |= 2; // right
  6866. if (phi < -r) code |= 4; // below
  6867. else if (phi > r) code |= 8; // above
  6868. return code;
  6869. }
  6870. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  6871. }
  6872. function clipLine(a, b, x0, y0, x1, y1) {
  6873. var ax = a[0],
  6874. ay = a[1],
  6875. bx = b[0],
  6876. by = b[1],
  6877. t0 = 0,
  6878. t1 = 1,
  6879. dx = bx - ax,
  6880. dy = by - ay,
  6881. r;
  6882. r = x0 - ax;
  6883. if (!dx && r > 0) return;
  6884. r /= dx;
  6885. if (dx < 0) {
  6886. if (r < t0) return;
  6887. if (r < t1) t1 = r;
  6888. } else if (dx > 0) {
  6889. if (r > t1) return;
  6890. if (r > t0) t0 = r;
  6891. }
  6892. r = x1 - ax;
  6893. if (!dx && r < 0) return;
  6894. r /= dx;
  6895. if (dx < 0) {
  6896. if (r > t1) return;
  6897. if (r > t0) t0 = r;
  6898. } else if (dx > 0) {
  6899. if (r < t0) return;
  6900. if (r < t1) t1 = r;
  6901. }
  6902. r = y0 - ay;
  6903. if (!dy && r > 0) return;
  6904. r /= dy;
  6905. if (dy < 0) {
  6906. if (r < t0) return;
  6907. if (r < t1) t1 = r;
  6908. } else if (dy > 0) {
  6909. if (r > t1) return;
  6910. if (r > t0) t0 = r;
  6911. }
  6912. r = y1 - ay;
  6913. if (!dy && r < 0) return;
  6914. r /= dy;
  6915. if (dy < 0) {
  6916. if (r > t1) return;
  6917. if (r > t0) t0 = r;
  6918. } else if (dy > 0) {
  6919. if (r < t0) return;
  6920. if (r < t1) t1 = r;
  6921. }
  6922. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  6923. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  6924. return true;
  6925. }
  6926. var clipMax = 1e9;
  6927. var clipMin = -clipMax;
  6928. // TODO Use d3-polygon’s polygonContains here for the ring check?
  6929. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  6930. function clipRectangle(x0, y0, x1, y1) {
  6931. function visible(x, y) {
  6932. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  6933. }
  6934. function interpolate(from, to, direction, stream) {
  6935. var a = 0, a1 = 0;
  6936. if (from == null
  6937. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  6938. || comparePoint(from, to) < 0 ^ direction > 0) {
  6939. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  6940. while ((a = (a + direction + 4) % 4) !== a1);
  6941. } else {
  6942. stream.point(to[0], to[1]);
  6943. }
  6944. }
  6945. function corner(p, direction) {
  6946. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  6947. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  6948. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  6949. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  6950. }
  6951. function compareIntersection(a, b) {
  6952. return comparePoint(a.x, b.x);
  6953. }
  6954. function comparePoint(a, b) {
  6955. var ca = corner(a, 1),
  6956. cb = corner(b, 1);
  6957. return ca !== cb ? ca - cb
  6958. : ca === 0 ? b[1] - a[1]
  6959. : ca === 1 ? a[0] - b[0]
  6960. : ca === 2 ? a[1] - b[1]
  6961. : b[0] - a[0];
  6962. }
  6963. return function(stream) {
  6964. var activeStream = stream,
  6965. bufferStream = clipBuffer(),
  6966. segments,
  6967. polygon,
  6968. ring,
  6969. x__, y__, v__, // first point
  6970. x_, y_, v_, // previous point
  6971. first,
  6972. clean;
  6973. var clipStream = {
  6974. point: point,
  6975. lineStart: lineStart,
  6976. lineEnd: lineEnd,
  6977. polygonStart: polygonStart,
  6978. polygonEnd: polygonEnd
  6979. };
  6980. function point(x, y) {
  6981. if (visible(x, y)) activeStream.point(x, y);
  6982. }
  6983. function polygonInside() {
  6984. var winding = 0;
  6985. for (var i = 0, n = polygon.length; i < n; ++i) {
  6986. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  6987. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  6988. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  6989. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  6990. }
  6991. }
  6992. return winding;
  6993. }
  6994. // Buffer geometry within a polygon and then clip it en masse.
  6995. function polygonStart() {
  6996. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  6997. }
  6998. function polygonEnd() {
  6999. var startInside = polygonInside(),
  7000. cleanInside = clean && startInside,
  7001. visible = (segments = merge(segments)).length;
  7002. if (cleanInside || visible) {
  7003. stream.polygonStart();
  7004. if (cleanInside) {
  7005. stream.lineStart();
  7006. interpolate(null, null, 1, stream);
  7007. stream.lineEnd();
  7008. }
  7009. if (visible) {
  7010. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  7011. }
  7012. stream.polygonEnd();
  7013. }
  7014. activeStream = stream, segments = polygon = ring = null;
  7015. }
  7016. function lineStart() {
  7017. clipStream.point = linePoint;
  7018. if (polygon) polygon.push(ring = []);
  7019. first = true;
  7020. v_ = false;
  7021. x_ = y_ = NaN;
  7022. }
  7023. // TODO rather than special-case polygons, simply handle them separately.
  7024. // Ideally, coincident intersection points should be jittered to avoid
  7025. // clipping issues.
  7026. function lineEnd() {
  7027. if (segments) {
  7028. linePoint(x__, y__);
  7029. if (v__ && v_) bufferStream.rejoin();
  7030. segments.push(bufferStream.result());
  7031. }
  7032. clipStream.point = point;
  7033. if (v_) activeStream.lineEnd();
  7034. }
  7035. function linePoint(x, y) {
  7036. var v = visible(x, y);
  7037. if (polygon) ring.push([x, y]);
  7038. if (first) {
  7039. x__ = x, y__ = y, v__ = v;
  7040. first = false;
  7041. if (v) {
  7042. activeStream.lineStart();
  7043. activeStream.point(x, y);
  7044. }
  7045. } else {
  7046. if (v && v_) activeStream.point(x, y);
  7047. else {
  7048. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7049. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7050. if (clipLine(a, b, x0, y0, x1, y1)) {
  7051. if (!v_) {
  7052. activeStream.lineStart();
  7053. activeStream.point(a[0], a[1]);
  7054. }
  7055. activeStream.point(b[0], b[1]);
  7056. if (!v) activeStream.lineEnd();
  7057. clean = false;
  7058. } else if (v) {
  7059. activeStream.lineStart();
  7060. activeStream.point(x, y);
  7061. clean = false;
  7062. }
  7063. }
  7064. }
  7065. x_ = x, y_ = y, v_ = v;
  7066. }
  7067. return clipStream;
  7068. };
  7069. }
  7070. function extent$1() {
  7071. var x0 = 0,
  7072. y0 = 0,
  7073. x1 = 960,
  7074. y1 = 500,
  7075. cache,
  7076. cacheStream,
  7077. clip;
  7078. return clip = {
  7079. stream: function(stream) {
  7080. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7081. },
  7082. extent: function(_) {
  7083. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7084. }
  7085. };
  7086. }
  7087. var lengthSum = adder();
  7088. var lambda0$2;
  7089. var sinPhi0$1;
  7090. var cosPhi0$1;
  7091. var lengthStream = {
  7092. sphere: noop$1,
  7093. point: noop$1,
  7094. lineStart: lengthLineStart,
  7095. lineEnd: noop$1,
  7096. polygonStart: noop$1,
  7097. polygonEnd: noop$1
  7098. };
  7099. function lengthLineStart() {
  7100. lengthStream.point = lengthPointFirst;
  7101. lengthStream.lineEnd = lengthLineEnd;
  7102. }
  7103. function lengthLineEnd() {
  7104. lengthStream.point = lengthStream.lineEnd = noop$1;
  7105. }
  7106. function lengthPointFirst(lambda, phi) {
  7107. lambda *= radians, phi *= radians;
  7108. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7109. lengthStream.point = lengthPoint;
  7110. }
  7111. function lengthPoint(lambda, phi) {
  7112. lambda *= radians, phi *= radians;
  7113. var sinPhi = sin$1(phi),
  7114. cosPhi = cos$1(phi),
  7115. delta = abs(lambda - lambda0$2),
  7116. cosDelta = cos$1(delta),
  7117. sinDelta = sin$1(delta),
  7118. x = cosPhi * sinDelta,
  7119. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7120. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7121. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7122. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7123. }
  7124. function length$1(object) {
  7125. lengthSum.reset();
  7126. geoStream(object, lengthStream);
  7127. return +lengthSum;
  7128. }
  7129. var coordinates = [null, null];
  7130. var object$1 = {type: "LineString", coordinates: coordinates};
  7131. function distance(a, b) {
  7132. coordinates[0] = a;
  7133. coordinates[1] = b;
  7134. return length$1(object$1);
  7135. }
  7136. var containsObjectType = {
  7137. Feature: function(object, point) {
  7138. return containsGeometry(object.geometry, point);
  7139. },
  7140. FeatureCollection: function(object, point) {
  7141. var features = object.features, i = -1, n = features.length;
  7142. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7143. return false;
  7144. }
  7145. };
  7146. var containsGeometryType = {
  7147. Sphere: function() {
  7148. return true;
  7149. },
  7150. Point: function(object, point) {
  7151. return containsPoint(object.coordinates, point);
  7152. },
  7153. MultiPoint: function(object, point) {
  7154. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7155. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7156. return false;
  7157. },
  7158. LineString: function(object, point) {
  7159. return containsLine(object.coordinates, point);
  7160. },
  7161. MultiLineString: function(object, point) {
  7162. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7163. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7164. return false;
  7165. },
  7166. Polygon: function(object, point) {
  7167. return containsPolygon(object.coordinates, point);
  7168. },
  7169. MultiPolygon: function(object, point) {
  7170. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7171. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7172. return false;
  7173. },
  7174. GeometryCollection: function(object, point) {
  7175. var geometries = object.geometries, i = -1, n = geometries.length;
  7176. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7177. return false;
  7178. }
  7179. };
  7180. function containsGeometry(geometry, point) {
  7181. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7182. ? containsGeometryType[geometry.type](geometry, point)
  7183. : false;
  7184. }
  7185. function containsPoint(coordinates, point) {
  7186. return distance(coordinates, point) === 0;
  7187. }
  7188. function containsLine(coordinates, point) {
  7189. var ab = distance(coordinates[0], coordinates[1]),
  7190. ao = distance(coordinates[0], point),
  7191. ob = distance(point, coordinates[1]);
  7192. return ao + ob <= ab + epsilon$2;
  7193. }
  7194. function containsPolygon(coordinates, point) {
  7195. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7196. }
  7197. function ringRadians(ring) {
  7198. return ring = ring.map(pointRadians), ring.pop(), ring;
  7199. }
  7200. function pointRadians(point) {
  7201. return [point[0] * radians, point[1] * radians];
  7202. }
  7203. function contains(object, point) {
  7204. return (object && containsObjectType.hasOwnProperty(object.type)
  7205. ? containsObjectType[object.type]
  7206. : containsGeometry)(object, point);
  7207. }
  7208. function graticuleX(y0, y1, dy) {
  7209. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7210. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7211. }
  7212. function graticuleY(x0, x1, dx) {
  7213. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7214. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7215. }
  7216. function graticule() {
  7217. var x1, x0, X1, X0,
  7218. y1, y0, Y1, Y0,
  7219. dx = 10, dy = dx, DX = 90, DY = 360,
  7220. x, y, X, Y,
  7221. precision = 2.5;
  7222. function graticule() {
  7223. return {type: "MultiLineString", coordinates: lines()};
  7224. }
  7225. function lines() {
  7226. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7227. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7228. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7229. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7230. }
  7231. graticule.lines = function() {
  7232. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7233. };
  7234. graticule.outline = function() {
  7235. return {
  7236. type: "Polygon",
  7237. coordinates: [
  7238. X(X0).concat(
  7239. Y(Y1).slice(1),
  7240. X(X1).reverse().slice(1),
  7241. Y(Y0).reverse().slice(1))
  7242. ]
  7243. };
  7244. };
  7245. graticule.extent = function(_) {
  7246. if (!arguments.length) return graticule.extentMinor();
  7247. return graticule.extentMajor(_).extentMinor(_);
  7248. };
  7249. graticule.extentMajor = function(_) {
  7250. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7251. X0 = +_[0][0], X1 = +_[1][0];
  7252. Y0 = +_[0][1], Y1 = +_[1][1];
  7253. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7254. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7255. return graticule.precision(precision);
  7256. };
  7257. graticule.extentMinor = function(_) {
  7258. if (!arguments.length) return [[x0, y0], [x1, y1]];
  7259. x0 = +_[0][0], x1 = +_[1][0];
  7260. y0 = +_[0][1], y1 = +_[1][1];
  7261. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  7262. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  7263. return graticule.precision(precision);
  7264. };
  7265. graticule.step = function(_) {
  7266. if (!arguments.length) return graticule.stepMinor();
  7267. return graticule.stepMajor(_).stepMinor(_);
  7268. };
  7269. graticule.stepMajor = function(_) {
  7270. if (!arguments.length) return [DX, DY];
  7271. DX = +_[0], DY = +_[1];
  7272. return graticule;
  7273. };
  7274. graticule.stepMinor = function(_) {
  7275. if (!arguments.length) return [dx, dy];
  7276. dx = +_[0], dy = +_[1];
  7277. return graticule;
  7278. };
  7279. graticule.precision = function(_) {
  7280. if (!arguments.length) return precision;
  7281. precision = +_;
  7282. x = graticuleX(y0, y1, 90);
  7283. y = graticuleY(x0, x1, precision);
  7284. X = graticuleX(Y0, Y1, 90);
  7285. Y = graticuleY(X0, X1, precision);
  7286. return graticule;
  7287. };
  7288. return graticule
  7289. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7290. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7291. }
  7292. function graticule10() {
  7293. return graticule()();
  7294. }
  7295. function interpolate$1(a, b) {
  7296. var x0 = a[0] * radians,
  7297. y0 = a[1] * radians,
  7298. x1 = b[0] * radians,
  7299. y1 = b[1] * radians,
  7300. cy0 = cos$1(y0),
  7301. sy0 = sin$1(y0),
  7302. cy1 = cos$1(y1),
  7303. sy1 = sin$1(y1),
  7304. kx0 = cy0 * cos$1(x0),
  7305. ky0 = cy0 * sin$1(x0),
  7306. kx1 = cy1 * cos$1(x1),
  7307. ky1 = cy1 * sin$1(x1),
  7308. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  7309. k = sin$1(d);
  7310. var interpolate = d ? function(t) {
  7311. var B = sin$1(t *= d) / k,
  7312. A = sin$1(d - t) / k,
  7313. x = A * kx0 + B * kx1,
  7314. y = A * ky0 + B * ky1,
  7315. z = A * sy0 + B * sy1;
  7316. return [
  7317. atan2(y, x) * degrees$1,
  7318. atan2(z, sqrt(x * x + y * y)) * degrees$1
  7319. ];
  7320. } : function() {
  7321. return [x0 * degrees$1, y0 * degrees$1];
  7322. };
  7323. interpolate.distance = d;
  7324. return interpolate;
  7325. }
  7326. function identity$4(x) {
  7327. return x;
  7328. }
  7329. var areaSum$1 = adder();
  7330. var areaRingSum$1 = adder();
  7331. var x00;
  7332. var y00;
  7333. var x0$1;
  7334. var y0$1;
  7335. var areaStream$1 = {
  7336. point: noop$1,
  7337. lineStart: noop$1,
  7338. lineEnd: noop$1,
  7339. polygonStart: function() {
  7340. areaStream$1.lineStart = areaRingStart$1;
  7341. areaStream$1.lineEnd = areaRingEnd$1;
  7342. },
  7343. polygonEnd: function() {
  7344. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$1;
  7345. areaSum$1.add(abs(areaRingSum$1));
  7346. areaRingSum$1.reset();
  7347. },
  7348. result: function() {
  7349. var area = areaSum$1 / 2;
  7350. areaSum$1.reset();
  7351. return area;
  7352. }
  7353. };
  7354. function areaRingStart$1() {
  7355. areaStream$1.point = areaPointFirst$1;
  7356. }
  7357. function areaPointFirst$1(x, y) {
  7358. areaStream$1.point = areaPoint$1;
  7359. x00 = x0$1 = x, y00 = y0$1 = y;
  7360. }
  7361. function areaPoint$1(x, y) {
  7362. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  7363. x0$1 = x, y0$1 = y;
  7364. }
  7365. function areaRingEnd$1() {
  7366. areaPoint$1(x00, y00);
  7367. }
  7368. var x0$2 = Infinity;
  7369. var y0$2 = x0$2;
  7370. var x1 = -x0$2;
  7371. var y1 = x1;
  7372. var boundsStream$1 = {
  7373. point: boundsPoint$1,
  7374. lineStart: noop$1,
  7375. lineEnd: noop$1,
  7376. polygonStart: noop$1,
  7377. polygonEnd: noop$1,
  7378. result: function() {
  7379. var bounds = [[x0$2, y0$2], [x1, y1]];
  7380. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  7381. return bounds;
  7382. }
  7383. };
  7384. function boundsPoint$1(x, y) {
  7385. if (x < x0$2) x0$2 = x;
  7386. if (x > x1) x1 = x;
  7387. if (y < y0$2) y0$2 = y;
  7388. if (y > y1) y1 = y;
  7389. }
  7390. // TODO Enforce positive area for exterior, negative area for interior?
  7391. var X0$1 = 0;
  7392. var Y0$1 = 0;
  7393. var Z0$1 = 0;
  7394. var X1$1 = 0;
  7395. var Y1$1 = 0;
  7396. var Z1$1 = 0;
  7397. var X2$1 = 0;
  7398. var Y2$1 = 0;
  7399. var Z2$1 = 0;
  7400. var x00$1;
  7401. var y00$1;
  7402. var x0$3;
  7403. var y0$3;
  7404. var centroidStream$1 = {
  7405. point: centroidPoint$1,
  7406. lineStart: centroidLineStart$1,
  7407. lineEnd: centroidLineEnd$1,
  7408. polygonStart: function() {
  7409. centroidStream$1.lineStart = centroidRingStart$1;
  7410. centroidStream$1.lineEnd = centroidRingEnd$1;
  7411. },
  7412. polygonEnd: function() {
  7413. centroidStream$1.point = centroidPoint$1;
  7414. centroidStream$1.lineStart = centroidLineStart$1;
  7415. centroidStream$1.lineEnd = centroidLineEnd$1;
  7416. },
  7417. result: function() {
  7418. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  7419. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  7420. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  7421. : [NaN, NaN];
  7422. X0$1 = Y0$1 = Z0$1 =
  7423. X1$1 = Y1$1 = Z1$1 =
  7424. X2$1 = Y2$1 = Z2$1 = 0;
  7425. return centroid;
  7426. }
  7427. };
  7428. function centroidPoint$1(x, y) {
  7429. X0$1 += x;
  7430. Y0$1 += y;
  7431. ++Z0$1;
  7432. }
  7433. function centroidLineStart$1() {
  7434. centroidStream$1.point = centroidPointFirstLine;
  7435. }
  7436. function centroidPointFirstLine(x, y) {
  7437. centroidStream$1.point = centroidPointLine;
  7438. centroidPoint$1(x0$3 = x, y0$3 = y);
  7439. }
  7440. function centroidPointLine(x, y) {
  7441. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  7442. X1$1 += z * (x0$3 + x) / 2;
  7443. Y1$1 += z * (y0$3 + y) / 2;
  7444. Z1$1 += z;
  7445. centroidPoint$1(x0$3 = x, y0$3 = y);
  7446. }
  7447. function centroidLineEnd$1() {
  7448. centroidStream$1.point = centroidPoint$1;
  7449. }
  7450. function centroidRingStart$1() {
  7451. centroidStream$1.point = centroidPointFirstRing;
  7452. }
  7453. function centroidRingEnd$1() {
  7454. centroidPointRing(x00$1, y00$1);
  7455. }
  7456. function centroidPointFirstRing(x, y) {
  7457. centroidStream$1.point = centroidPointRing;
  7458. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  7459. }
  7460. function centroidPointRing(x, y) {
  7461. var dx = x - x0$3,
  7462. dy = y - y0$3,
  7463. z = sqrt(dx * dx + dy * dy);
  7464. X1$1 += z * (x0$3 + x) / 2;
  7465. Y1$1 += z * (y0$3 + y) / 2;
  7466. Z1$1 += z;
  7467. z = y0$3 * x - x0$3 * y;
  7468. X2$1 += z * (x0$3 + x);
  7469. Y2$1 += z * (y0$3 + y);
  7470. Z2$1 += z * 3;
  7471. centroidPoint$1(x0$3 = x, y0$3 = y);
  7472. }
  7473. function PathContext(context) {
  7474. this._context = context;
  7475. }
  7476. PathContext.prototype = {
  7477. _radius: 4.5,
  7478. pointRadius: function(_) {
  7479. return this._radius = _, this;
  7480. },
  7481. polygonStart: function() {
  7482. this._line = 0;
  7483. },
  7484. polygonEnd: function() {
  7485. this._line = NaN;
  7486. },
  7487. lineStart: function() {
  7488. this._point = 0;
  7489. },
  7490. lineEnd: function() {
  7491. if (this._line === 0) this._context.closePath();
  7492. this._point = NaN;
  7493. },
  7494. point: function(x, y) {
  7495. switch (this._point) {
  7496. case 0: {
  7497. this._context.moveTo(x, y);
  7498. this._point = 1;
  7499. break;
  7500. }
  7501. case 1: {
  7502. this._context.lineTo(x, y);
  7503. break;
  7504. }
  7505. default: {
  7506. this._context.moveTo(x + this._radius, y);
  7507. this._context.arc(x, y, this._radius, 0, tau$3);
  7508. break;
  7509. }
  7510. }
  7511. },
  7512. result: noop$1
  7513. };
  7514. var lengthSum$1 = adder();
  7515. var lengthRing;
  7516. var x00$2;
  7517. var y00$2;
  7518. var x0$4;
  7519. var y0$4;
  7520. var lengthStream$1 = {
  7521. point: noop$1,
  7522. lineStart: function() {
  7523. lengthStream$1.point = lengthPointFirst$1;
  7524. },
  7525. lineEnd: function() {
  7526. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  7527. lengthStream$1.point = noop$1;
  7528. },
  7529. polygonStart: function() {
  7530. lengthRing = true;
  7531. },
  7532. polygonEnd: function() {
  7533. lengthRing = null;
  7534. },
  7535. result: function() {
  7536. var length = +lengthSum$1;
  7537. lengthSum$1.reset();
  7538. return length;
  7539. }
  7540. };
  7541. function lengthPointFirst$1(x, y) {
  7542. lengthStream$1.point = lengthPoint$1;
  7543. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  7544. }
  7545. function lengthPoint$1(x, y) {
  7546. x0$4 -= x, y0$4 -= y;
  7547. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  7548. x0$4 = x, y0$4 = y;
  7549. }
  7550. function PathString() {
  7551. this._string = [];
  7552. }
  7553. PathString.prototype = {
  7554. _radius: 4.5,
  7555. _circle: circle$1(4.5),
  7556. pointRadius: function(_) {
  7557. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  7558. return this;
  7559. },
  7560. polygonStart: function() {
  7561. this._line = 0;
  7562. },
  7563. polygonEnd: function() {
  7564. this._line = NaN;
  7565. },
  7566. lineStart: function() {
  7567. this._point = 0;
  7568. },
  7569. lineEnd: function() {
  7570. if (this._line === 0) this._string.push("Z");
  7571. this._point = NaN;
  7572. },
  7573. point: function(x, y) {
  7574. switch (this._point) {
  7575. case 0: {
  7576. this._string.push("M", x, ",", y);
  7577. this._point = 1;
  7578. break;
  7579. }
  7580. case 1: {
  7581. this._string.push("L", x, ",", y);
  7582. break;
  7583. }
  7584. default: {
  7585. if (this._circle == null) this._circle = circle$1(this._radius);
  7586. this._string.push("M", x, ",", y, this._circle);
  7587. break;
  7588. }
  7589. }
  7590. },
  7591. result: function() {
  7592. if (this._string.length) {
  7593. var result = this._string.join("");
  7594. this._string = [];
  7595. return result;
  7596. } else {
  7597. return null;
  7598. }
  7599. }
  7600. };
  7601. function circle$1(radius) {
  7602. return "m0," + radius
  7603. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  7604. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  7605. + "z";
  7606. }
  7607. function index$1(projection, context) {
  7608. var pointRadius = 4.5,
  7609. projectionStream,
  7610. contextStream;
  7611. function path(object) {
  7612. if (object) {
  7613. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  7614. geoStream(object, projectionStream(contextStream));
  7615. }
  7616. return contextStream.result();
  7617. }
  7618. path.area = function(object) {
  7619. geoStream(object, projectionStream(areaStream$1));
  7620. return areaStream$1.result();
  7621. };
  7622. path.measure = function(object) {
  7623. geoStream(object, projectionStream(lengthStream$1));
  7624. return lengthStream$1.result();
  7625. };
  7626. path.bounds = function(object) {
  7627. geoStream(object, projectionStream(boundsStream$1));
  7628. return boundsStream$1.result();
  7629. };
  7630. path.centroid = function(object) {
  7631. geoStream(object, projectionStream(centroidStream$1));
  7632. return centroidStream$1.result();
  7633. };
  7634. path.projection = function(_) {
  7635. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  7636. };
  7637. path.context = function(_) {
  7638. if (!arguments.length) return context;
  7639. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  7640. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  7641. return path;
  7642. };
  7643. path.pointRadius = function(_) {
  7644. if (!arguments.length) return pointRadius;
  7645. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  7646. return path;
  7647. };
  7648. return path.projection(projection).context(context);
  7649. }
  7650. function transform(methods) {
  7651. return {
  7652. stream: transformer(methods)
  7653. };
  7654. }
  7655. function transformer(methods) {
  7656. return function(stream) {
  7657. var s = new TransformStream;
  7658. for (var key in methods) s[key] = methods[key];
  7659. s.stream = stream;
  7660. return s;
  7661. };
  7662. }
  7663. function TransformStream() {}
  7664. TransformStream.prototype = {
  7665. constructor: TransformStream,
  7666. point: function(x, y) { this.stream.point(x, y); },
  7667. sphere: function() { this.stream.sphere(); },
  7668. lineStart: function() { this.stream.lineStart(); },
  7669. lineEnd: function() { this.stream.lineEnd(); },
  7670. polygonStart: function() { this.stream.polygonStart(); },
  7671. polygonEnd: function() { this.stream.polygonEnd(); }
  7672. };
  7673. function fit(projection, fitBounds, object) {
  7674. var clip = projection.clipExtent && projection.clipExtent();
  7675. projection.scale(150).translate([0, 0]);
  7676. if (clip != null) projection.clipExtent(null);
  7677. geoStream(object, projection.stream(boundsStream$1));
  7678. fitBounds(boundsStream$1.result());
  7679. if (clip != null) projection.clipExtent(clip);
  7680. return projection;
  7681. }
  7682. function fitExtent(projection, extent, object) {
  7683. return fit(projection, function(b) {
  7684. var w = extent[1][0] - extent[0][0],
  7685. h = extent[1][1] - extent[0][1],
  7686. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  7687. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  7688. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  7689. projection.scale(150 * k).translate([x, y]);
  7690. }, object);
  7691. }
  7692. function fitSize(projection, size, object) {
  7693. return fitExtent(projection, [[0, 0], size], object);
  7694. }
  7695. function fitWidth(projection, width, object) {
  7696. return fit(projection, function(b) {
  7697. var w = +width,
  7698. k = w / (b[1][0] - b[0][0]),
  7699. x = (w - k * (b[1][0] + b[0][0])) / 2,
  7700. y = -k * b[0][1];
  7701. projection.scale(150 * k).translate([x, y]);
  7702. }, object);
  7703. }
  7704. function fitHeight(projection, height, object) {
  7705. return fit(projection, function(b) {
  7706. var h = +height,
  7707. k = h / (b[1][1] - b[0][1]),
  7708. x = -k * b[0][0],
  7709. y = (h - k * (b[1][1] + b[0][1])) / 2;
  7710. projection.scale(150 * k).translate([x, y]);
  7711. }, object);
  7712. }
  7713. var maxDepth = 16;
  7714. var cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  7715. function resample(project, delta2) {
  7716. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  7717. }
  7718. function resampleNone(project) {
  7719. return transformer({
  7720. point: function(x, y) {
  7721. x = project(x, y);
  7722. this.stream.point(x[0], x[1]);
  7723. }
  7724. });
  7725. }
  7726. function resample$1(project, delta2) {
  7727. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  7728. var dx = x1 - x0,
  7729. dy = y1 - y0,
  7730. d2 = dx * dx + dy * dy;
  7731. if (d2 > 4 * delta2 && depth--) {
  7732. var a = a0 + a1,
  7733. b = b0 + b1,
  7734. c = c0 + c1,
  7735. m = sqrt(a * a + b * b + c * c),
  7736. phi2 = asin(c /= m),
  7737. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  7738. p = project(lambda2, phi2),
  7739. x2 = p[0],
  7740. y2 = p[1],
  7741. dx2 = x2 - x0,
  7742. dy2 = y2 - y0,
  7743. dz = dy * dx2 - dx * dy2;
  7744. if (dz * dz / d2 > delta2 // perpendicular projected distance
  7745. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  7746. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  7747. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  7748. stream.point(x2, y2);
  7749. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  7750. }
  7751. }
  7752. }
  7753. return function(stream) {
  7754. var lambda00, x00, y00, a00, b00, c00, // first point
  7755. lambda0, x0, y0, a0, b0, c0; // previous point
  7756. var resampleStream = {
  7757. point: point,
  7758. lineStart: lineStart,
  7759. lineEnd: lineEnd,
  7760. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  7761. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  7762. };
  7763. function point(x, y) {
  7764. x = project(x, y);
  7765. stream.point(x[0], x[1]);
  7766. }
  7767. function lineStart() {
  7768. x0 = NaN;
  7769. resampleStream.point = linePoint;
  7770. stream.lineStart();
  7771. }
  7772. function linePoint(lambda, phi) {
  7773. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  7774. 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);
  7775. stream.point(x0, y0);
  7776. }
  7777. function lineEnd() {
  7778. resampleStream.point = point;
  7779. stream.lineEnd();
  7780. }
  7781. function ringStart() {
  7782. lineStart();
  7783. resampleStream.point = ringPoint;
  7784. resampleStream.lineEnd = ringEnd;
  7785. }
  7786. function ringPoint(lambda, phi) {
  7787. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  7788. resampleStream.point = linePoint;
  7789. }
  7790. function ringEnd() {
  7791. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  7792. resampleStream.lineEnd = lineEnd;
  7793. lineEnd();
  7794. }
  7795. return resampleStream;
  7796. };
  7797. }
  7798. var transformRadians = transformer({
  7799. point: function(x, y) {
  7800. this.stream.point(x * radians, y * radians);
  7801. }
  7802. });
  7803. function transformRotate(rotate) {
  7804. return transformer({
  7805. point: function(x, y) {
  7806. var r = rotate(x, y);
  7807. return this.stream.point(r[0], r[1]);
  7808. }
  7809. });
  7810. }
  7811. function projection(project) {
  7812. return projectionMutator(function() { return project; })();
  7813. }
  7814. function projectionMutator(projectAt) {
  7815. var project,
  7816. k = 150, // scale
  7817. x = 480, y = 250, // translate
  7818. dx, dy, lambda = 0, phi = 0, // center
  7819. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
  7820. theta = null, preclip = clipAntimeridian, // clip angle
  7821. x0 = null, y0, x1, y1, postclip = identity$4, // clip extent
  7822. delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
  7823. cache,
  7824. cacheStream;
  7825. function projection(point) {
  7826. point = projectRotate(point[0] * radians, point[1] * radians);
  7827. return [point[0] * k + dx, dy - point[1] * k];
  7828. }
  7829. function invert(point) {
  7830. point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
  7831. return point && [point[0] * degrees$1, point[1] * degrees$1];
  7832. }
  7833. function projectTransform(x, y) {
  7834. return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
  7835. }
  7836. projection.stream = function(stream) {
  7837. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  7838. };
  7839. projection.preclip = function(_) {
  7840. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  7841. };
  7842. projection.postclip = function(_) {
  7843. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  7844. };
  7845. projection.clipAngle = function(_) {
  7846. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  7847. };
  7848. projection.clipExtent = function(_) {
  7849. 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]];
  7850. };
  7851. projection.scale = function(_) {
  7852. return arguments.length ? (k = +_, recenter()) : k;
  7853. };
  7854. projection.translate = function(_) {
  7855. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  7856. };
  7857. projection.center = function(_) {
  7858. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  7859. };
  7860. projection.rotate = function(_) {
  7861. 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];
  7862. };
  7863. projection.precision = function(_) {
  7864. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  7865. };
  7866. projection.fitExtent = function(extent, object) {
  7867. return fitExtent(projection, extent, object);
  7868. };
  7869. projection.fitSize = function(size, object) {
  7870. return fitSize(projection, size, object);
  7871. };
  7872. projection.fitWidth = function(width, object) {
  7873. return fitWidth(projection, width, object);
  7874. };
  7875. projection.fitHeight = function(height, object) {
  7876. return fitHeight(projection, height, object);
  7877. };
  7878. function recenter() {
  7879. projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
  7880. var center = project(lambda, phi);
  7881. dx = x - center[0] * k;
  7882. dy = y + center[1] * k;
  7883. return reset();
  7884. }
  7885. function reset() {
  7886. cache = cacheStream = null;
  7887. return projection;
  7888. }
  7889. return function() {
  7890. project = projectAt.apply(this, arguments);
  7891. projection.invert = project.invert && invert;
  7892. return recenter();
  7893. };
  7894. }
  7895. function conicProjection(projectAt) {
  7896. var phi0 = 0,
  7897. phi1 = pi$3 / 3,
  7898. m = projectionMutator(projectAt),
  7899. p = m(phi0, phi1);
  7900. p.parallels = function(_) {
  7901. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  7902. };
  7903. return p;
  7904. }
  7905. function cylindricalEqualAreaRaw(phi0) {
  7906. var cosPhi0 = cos$1(phi0);
  7907. function forward(lambda, phi) {
  7908. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  7909. }
  7910. forward.invert = function(x, y) {
  7911. return [x / cosPhi0, asin(y * cosPhi0)];
  7912. };
  7913. return forward;
  7914. }
  7915. function conicEqualAreaRaw(y0, y1) {
  7916. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  7917. // Are the parallels symmetrical around the Equator?
  7918. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  7919. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  7920. function project(x, y) {
  7921. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  7922. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  7923. }
  7924. project.invert = function(x, y) {
  7925. var r0y = r0 - y;
  7926. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  7927. };
  7928. return project;
  7929. }
  7930. function conicEqualArea() {
  7931. return conicProjection(conicEqualAreaRaw)
  7932. .scale(155.424)
  7933. .center([0, 33.6442]);
  7934. }
  7935. function albers() {
  7936. return conicEqualArea()
  7937. .parallels([29.5, 45.5])
  7938. .scale(1070)
  7939. .translate([480, 250])
  7940. .rotate([96, 0])
  7941. .center([-0.6, 38.7]);
  7942. }
  7943. // The projections must have mutually exclusive clip regions on the sphere,
  7944. // as this will avoid emitting interleaving lines and polygons.
  7945. function multiplex(streams) {
  7946. var n = streams.length;
  7947. return {
  7948. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  7949. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  7950. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  7951. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  7952. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  7953. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  7954. };
  7955. }
  7956. // A composite projection for the United States, configured by default for
  7957. // 960×500. The projection also works quite well at 960×600 if you change the
  7958. // scale to 1285 and adjust the translate accordingly. The set of standard
  7959. // parallels for each region comes from USGS, which is published here:
  7960. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  7961. function albersUsa() {
  7962. var cache,
  7963. cacheStream,
  7964. lower48 = albers(), lower48Point,
  7965. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  7966. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  7967. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  7968. function albersUsa(coordinates) {
  7969. var x = coordinates[0], y = coordinates[1];
  7970. return point = null, (lower48Point.point(x, y), point)
  7971. || (alaskaPoint.point(x, y), point)
  7972. || (hawaiiPoint.point(x, y), point);
  7973. }
  7974. albersUsa.invert = function(coordinates) {
  7975. var k = lower48.scale(),
  7976. t = lower48.translate(),
  7977. x = (coordinates[0] - t[0]) / k,
  7978. y = (coordinates[1] - t[1]) / k;
  7979. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  7980. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  7981. : lower48).invert(coordinates);
  7982. };
  7983. albersUsa.stream = function(stream) {
  7984. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  7985. };
  7986. albersUsa.precision = function(_) {
  7987. if (!arguments.length) return lower48.precision();
  7988. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  7989. return reset();
  7990. };
  7991. albersUsa.scale = function(_) {
  7992. if (!arguments.length) return lower48.scale();
  7993. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  7994. return albersUsa.translate(lower48.translate());
  7995. };
  7996. albersUsa.translate = function(_) {
  7997. if (!arguments.length) return lower48.translate();
  7998. var k = lower48.scale(), x = +_[0], y = +_[1];
  7999. lower48Point = lower48
  8000. .translate(_)
  8001. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  8002. .stream(pointStream);
  8003. alaskaPoint = alaska
  8004. .translate([x - 0.307 * k, y + 0.201 * k])
  8005. .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]])
  8006. .stream(pointStream);
  8007. hawaiiPoint = hawaii
  8008. .translate([x - 0.205 * k, y + 0.212 * k])
  8009. .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]])
  8010. .stream(pointStream);
  8011. return reset();
  8012. };
  8013. albersUsa.fitExtent = function(extent, object) {
  8014. return fitExtent(albersUsa, extent, object);
  8015. };
  8016. albersUsa.fitSize = function(size, object) {
  8017. return fitSize(albersUsa, size, object);
  8018. };
  8019. albersUsa.fitWidth = function(width, object) {
  8020. return fitWidth(albersUsa, width, object);
  8021. };
  8022. albersUsa.fitHeight = function(height, object) {
  8023. return fitHeight(albersUsa, height, object);
  8024. };
  8025. function reset() {
  8026. cache = cacheStream = null;
  8027. return albersUsa;
  8028. }
  8029. return albersUsa.scale(1070);
  8030. }
  8031. function azimuthalRaw(scale) {
  8032. return function(x, y) {
  8033. var cx = cos$1(x),
  8034. cy = cos$1(y),
  8035. k = scale(cx * cy);
  8036. return [
  8037. k * cy * sin$1(x),
  8038. k * sin$1(y)
  8039. ];
  8040. }
  8041. }
  8042. function azimuthalInvert(angle) {
  8043. return function(x, y) {
  8044. var z = sqrt(x * x + y * y),
  8045. c = angle(z),
  8046. sc = sin$1(c),
  8047. cc = cos$1(c);
  8048. return [
  8049. atan2(x * sc, z * cc),
  8050. asin(z && y * sc / z)
  8051. ];
  8052. }
  8053. }
  8054. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8055. return sqrt(2 / (1 + cxcy));
  8056. });
  8057. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8058. return 2 * asin(z / 2);
  8059. });
  8060. function azimuthalEqualArea() {
  8061. return projection(azimuthalEqualAreaRaw)
  8062. .scale(124.75)
  8063. .clipAngle(180 - 1e-3);
  8064. }
  8065. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8066. return (c = acos(c)) && c / sin$1(c);
  8067. });
  8068. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8069. return z;
  8070. });
  8071. function azimuthalEquidistant() {
  8072. return projection(azimuthalEquidistantRaw)
  8073. .scale(79.4188)
  8074. .clipAngle(180 - 1e-3);
  8075. }
  8076. function mercatorRaw(lambda, phi) {
  8077. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8078. }
  8079. mercatorRaw.invert = function(x, y) {
  8080. return [x, 2 * atan(exp(y)) - halfPi$2];
  8081. };
  8082. function mercator() {
  8083. return mercatorProjection(mercatorRaw)
  8084. .scale(961 / tau$3);
  8085. }
  8086. function mercatorProjection(project) {
  8087. var m = projection(project),
  8088. center = m.center,
  8089. scale = m.scale,
  8090. translate = m.translate,
  8091. clipExtent = m.clipExtent,
  8092. x0 = null, y0, x1, y1; // clip extent
  8093. m.scale = function(_) {
  8094. return arguments.length ? (scale(_), reclip()) : scale();
  8095. };
  8096. m.translate = function(_) {
  8097. return arguments.length ? (translate(_), reclip()) : translate();
  8098. };
  8099. m.center = function(_) {
  8100. return arguments.length ? (center(_), reclip()) : center();
  8101. };
  8102. m.clipExtent = function(_) {
  8103. 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]];
  8104. };
  8105. function reclip() {
  8106. var k = pi$3 * scale(),
  8107. t = m(rotation(m.rotate()).invert([0, 0]));
  8108. return clipExtent(x0 == null
  8109. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8110. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8111. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8112. }
  8113. return reclip();
  8114. }
  8115. function tany(y) {
  8116. return tan((halfPi$2 + y) / 2);
  8117. }
  8118. function conicConformalRaw(y0, y1) {
  8119. var cy0 = cos$1(y0),
  8120. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8121. f = cy0 * pow(tany(y0), n) / n;
  8122. if (!n) return mercatorRaw;
  8123. function project(x, y) {
  8124. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8125. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8126. var r = f / pow(tany(y), n);
  8127. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8128. }
  8129. project.invert = function(x, y) {
  8130. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8131. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8132. };
  8133. return project;
  8134. }
  8135. function conicConformal() {
  8136. return conicProjection(conicConformalRaw)
  8137. .scale(109.5)
  8138. .parallels([30, 30]);
  8139. }
  8140. function equirectangularRaw(lambda, phi) {
  8141. return [lambda, phi];
  8142. }
  8143. equirectangularRaw.invert = equirectangularRaw;
  8144. function equirectangular() {
  8145. return projection(equirectangularRaw)
  8146. .scale(152.63);
  8147. }
  8148. function conicEquidistantRaw(y0, y1) {
  8149. var cy0 = cos$1(y0),
  8150. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8151. g = cy0 / n + y0;
  8152. if (abs(n) < epsilon$2) return equirectangularRaw;
  8153. function project(x, y) {
  8154. var gy = g - y, nx = n * x;
  8155. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8156. }
  8157. project.invert = function(x, y) {
  8158. var gy = g - y;
  8159. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8160. };
  8161. return project;
  8162. }
  8163. function conicEquidistant() {
  8164. return conicProjection(conicEquidistantRaw)
  8165. .scale(131.154)
  8166. .center([0, 13.9389]);
  8167. }
  8168. function gnomonicRaw(x, y) {
  8169. var cy = cos$1(y), k = cos$1(x) * cy;
  8170. return [cy * sin$1(x) / k, sin$1(y) / k];
  8171. }
  8172. gnomonicRaw.invert = azimuthalInvert(atan);
  8173. function gnomonic() {
  8174. return projection(gnomonicRaw)
  8175. .scale(144.049)
  8176. .clipAngle(60);
  8177. }
  8178. function scaleTranslate(kx, ky, tx, ty) {
  8179. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8180. point: function(x, y) {
  8181. this.stream.point(x * kx + tx, y * ky + ty);
  8182. }
  8183. });
  8184. }
  8185. function identity$5() {
  8186. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
  8187. x0 = null, y0, x1, y1, // clip extent
  8188. postclip = identity$4,
  8189. cache,
  8190. cacheStream,
  8191. projection;
  8192. function reset() {
  8193. cache = cacheStream = null;
  8194. return projection;
  8195. }
  8196. return projection = {
  8197. stream: function(stream) {
  8198. return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
  8199. },
  8200. postclip: function(_) {
  8201. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8202. },
  8203. clipExtent: function(_) {
  8204. 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]];
  8205. },
  8206. scale: function(_) {
  8207. return arguments.length ? (transform$$1 = scaleTranslate((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8208. },
  8209. translate: function(_) {
  8210. return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8211. },
  8212. reflectX: function(_) {
  8213. return arguments.length ? (transform$$1 = scaleTranslate(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8214. },
  8215. reflectY: function(_) {
  8216. return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8217. },
  8218. fitExtent: function(extent, object) {
  8219. return fitExtent(projection, extent, object);
  8220. },
  8221. fitSize: function(size, object) {
  8222. return fitSize(projection, size, object);
  8223. },
  8224. fitWidth: function(width, object) {
  8225. return fitWidth(projection, width, object);
  8226. },
  8227. fitHeight: function(height, object) {
  8228. return fitHeight(projection, height, object);
  8229. }
  8230. };
  8231. }
  8232. function naturalEarth1Raw(lambda, phi) {
  8233. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8234. return [
  8235. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  8236. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  8237. ];
  8238. }
  8239. naturalEarth1Raw.invert = function(x, y) {
  8240. var phi = y, i = 25, delta;
  8241. do {
  8242. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8243. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  8244. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  8245. } while (abs(delta) > epsilon$2 && --i > 0);
  8246. return [
  8247. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  8248. phi
  8249. ];
  8250. };
  8251. function naturalEarth1() {
  8252. return projection(naturalEarth1Raw)
  8253. .scale(175.295);
  8254. }
  8255. function orthographicRaw(x, y) {
  8256. return [cos$1(y) * sin$1(x), sin$1(y)];
  8257. }
  8258. orthographicRaw.invert = azimuthalInvert(asin);
  8259. function orthographic() {
  8260. return projection(orthographicRaw)
  8261. .scale(249.5)
  8262. .clipAngle(90 + epsilon$2);
  8263. }
  8264. function stereographicRaw(x, y) {
  8265. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  8266. return [cy * sin$1(x) / k, sin$1(y) / k];
  8267. }
  8268. stereographicRaw.invert = azimuthalInvert(function(z) {
  8269. return 2 * atan(z);
  8270. });
  8271. function stereographic() {
  8272. return projection(stereographicRaw)
  8273. .scale(250)
  8274. .clipAngle(142);
  8275. }
  8276. function transverseMercatorRaw(lambda, phi) {
  8277. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  8278. }
  8279. transverseMercatorRaw.invert = function(x, y) {
  8280. return [-y, 2 * atan(exp(x)) - halfPi$2];
  8281. };
  8282. function transverseMercator() {
  8283. var m = mercatorProjection(transverseMercatorRaw),
  8284. center = m.center,
  8285. rotate = m.rotate;
  8286. m.center = function(_) {
  8287. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  8288. };
  8289. m.rotate = function(_) {
  8290. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  8291. };
  8292. return rotate([0, 0, 90])
  8293. .scale(159.155);
  8294. }
  8295. function defaultSeparation(a, b) {
  8296. return a.parent === b.parent ? 1 : 2;
  8297. }
  8298. function meanX(children) {
  8299. return children.reduce(meanXReduce, 0) / children.length;
  8300. }
  8301. function meanXReduce(x, c) {
  8302. return x + c.x;
  8303. }
  8304. function maxY(children) {
  8305. return 1 + children.reduce(maxYReduce, 0);
  8306. }
  8307. function maxYReduce(y, c) {
  8308. return Math.max(y, c.y);
  8309. }
  8310. function leafLeft(node) {
  8311. var children;
  8312. while (children = node.children) node = children[0];
  8313. return node;
  8314. }
  8315. function leafRight(node) {
  8316. var children;
  8317. while (children = node.children) node = children[children.length - 1];
  8318. return node;
  8319. }
  8320. function cluster() {
  8321. var separation = defaultSeparation,
  8322. dx = 1,
  8323. dy = 1,
  8324. nodeSize = false;
  8325. function cluster(root) {
  8326. var previousNode,
  8327. x = 0;
  8328. // First walk, computing the initial x & y values.
  8329. root.eachAfter(function(node) {
  8330. var children = node.children;
  8331. if (children) {
  8332. node.x = meanX(children);
  8333. node.y = maxY(children);
  8334. } else {
  8335. node.x = previousNode ? x += separation(node, previousNode) : 0;
  8336. node.y = 0;
  8337. previousNode = node;
  8338. }
  8339. });
  8340. var left = leafLeft(root),
  8341. right = leafRight(root),
  8342. x0 = left.x - separation(left, right) / 2,
  8343. x1 = right.x + separation(right, left) / 2;
  8344. // Second walk, normalizing x & y to the desired size.
  8345. return root.eachAfter(nodeSize ? function(node) {
  8346. node.x = (node.x - root.x) * dx;
  8347. node.y = (root.y - node.y) * dy;
  8348. } : function(node) {
  8349. node.x = (node.x - x0) / (x1 - x0) * dx;
  8350. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  8351. });
  8352. }
  8353. cluster.separation = function(x) {
  8354. return arguments.length ? (separation = x, cluster) : separation;
  8355. };
  8356. cluster.size = function(x) {
  8357. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  8358. };
  8359. cluster.nodeSize = function(x) {
  8360. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  8361. };
  8362. return cluster;
  8363. }
  8364. function count(node) {
  8365. var sum = 0,
  8366. children = node.children,
  8367. i = children && children.length;
  8368. if (!i) sum = 1;
  8369. else while (--i >= 0) sum += children[i].value;
  8370. node.value = sum;
  8371. }
  8372. function node_count() {
  8373. return this.eachAfter(count);
  8374. }
  8375. function node_each(callback) {
  8376. var node = this, current, next = [node], children, i, n;
  8377. do {
  8378. current = next.reverse(), next = [];
  8379. while (node = current.pop()) {
  8380. callback(node), children = node.children;
  8381. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8382. next.push(children[i]);
  8383. }
  8384. }
  8385. } while (next.length);
  8386. return this;
  8387. }
  8388. function node_eachBefore(callback) {
  8389. var node = this, nodes = [node], children, i;
  8390. while (node = nodes.pop()) {
  8391. callback(node), children = node.children;
  8392. if (children) for (i = children.length - 1; i >= 0; --i) {
  8393. nodes.push(children[i]);
  8394. }
  8395. }
  8396. return this;
  8397. }
  8398. function node_eachAfter(callback) {
  8399. var node = this, nodes = [node], next = [], children, i, n;
  8400. while (node = nodes.pop()) {
  8401. next.push(node), children = node.children;
  8402. if (children) for (i = 0, n = children.length; i < n; ++i) {
  8403. nodes.push(children[i]);
  8404. }
  8405. }
  8406. while (node = next.pop()) {
  8407. callback(node);
  8408. }
  8409. return this;
  8410. }
  8411. function node_sum(value) {
  8412. return this.eachAfter(function(node) {
  8413. var sum = +value(node.data) || 0,
  8414. children = node.children,
  8415. i = children && children.length;
  8416. while (--i >= 0) sum += children[i].value;
  8417. node.value = sum;
  8418. });
  8419. }
  8420. function node_sort(compare) {
  8421. return this.eachBefore(function(node) {
  8422. if (node.children) {
  8423. node.children.sort(compare);
  8424. }
  8425. });
  8426. }
  8427. function node_path(end) {
  8428. var start = this,
  8429. ancestor = leastCommonAncestor(start, end),
  8430. nodes = [start];
  8431. while (start !== ancestor) {
  8432. start = start.parent;
  8433. nodes.push(start);
  8434. }
  8435. var k = nodes.length;
  8436. while (end !== ancestor) {
  8437. nodes.splice(k, 0, end);
  8438. end = end.parent;
  8439. }
  8440. return nodes;
  8441. }
  8442. function leastCommonAncestor(a, b) {
  8443. if (a === b) return a;
  8444. var aNodes = a.ancestors(),
  8445. bNodes = b.ancestors(),
  8446. c = null;
  8447. a = aNodes.pop();
  8448. b = bNodes.pop();
  8449. while (a === b) {
  8450. c = a;
  8451. a = aNodes.pop();
  8452. b = bNodes.pop();
  8453. }
  8454. return c;
  8455. }
  8456. function node_ancestors() {
  8457. var node = this, nodes = [node];
  8458. while (node = node.parent) {
  8459. nodes.push(node);
  8460. }
  8461. return nodes;
  8462. }
  8463. function node_descendants() {
  8464. var nodes = [];
  8465. this.each(function(node) {
  8466. nodes.push(node);
  8467. });
  8468. return nodes;
  8469. }
  8470. function node_leaves() {
  8471. var leaves = [];
  8472. this.eachBefore(function(node) {
  8473. if (!node.children) {
  8474. leaves.push(node);
  8475. }
  8476. });
  8477. return leaves;
  8478. }
  8479. function node_links() {
  8480. var root = this, links = [];
  8481. root.each(function(node) {
  8482. if (node !== root) { // Don’t include the root’s parent, if any.
  8483. links.push({source: node.parent, target: node});
  8484. }
  8485. });
  8486. return links;
  8487. }
  8488. function hierarchy(data, children) {
  8489. var root = new Node(data),
  8490. valued = +data.value && (root.value = data.value),
  8491. node,
  8492. nodes = [root],
  8493. child,
  8494. childs,
  8495. i,
  8496. n;
  8497. if (children == null) children = defaultChildren;
  8498. while (node = nodes.pop()) {
  8499. if (valued) node.value = +node.data.value;
  8500. if ((childs = children(node.data)) && (n = childs.length)) {
  8501. node.children = new Array(n);
  8502. for (i = n - 1; i >= 0; --i) {
  8503. nodes.push(child = node.children[i] = new Node(childs[i]));
  8504. child.parent = node;
  8505. child.depth = node.depth + 1;
  8506. }
  8507. }
  8508. }
  8509. return root.eachBefore(computeHeight);
  8510. }
  8511. function node_copy() {
  8512. return hierarchy(this).eachBefore(copyData);
  8513. }
  8514. function defaultChildren(d) {
  8515. return d.children;
  8516. }
  8517. function copyData(node) {
  8518. node.data = node.data.data;
  8519. }
  8520. function computeHeight(node) {
  8521. var height = 0;
  8522. do node.height = height;
  8523. while ((node = node.parent) && (node.height < ++height));
  8524. }
  8525. function Node(data) {
  8526. this.data = data;
  8527. this.depth =
  8528. this.height = 0;
  8529. this.parent = null;
  8530. }
  8531. Node.prototype = hierarchy.prototype = {
  8532. constructor: Node,
  8533. count: node_count,
  8534. each: node_each,
  8535. eachAfter: node_eachAfter,
  8536. eachBefore: node_eachBefore,
  8537. sum: node_sum,
  8538. sort: node_sort,
  8539. path: node_path,
  8540. ancestors: node_ancestors,
  8541. descendants: node_descendants,
  8542. leaves: node_leaves,
  8543. links: node_links,
  8544. copy: node_copy
  8545. };
  8546. var slice$3 = Array.prototype.slice;
  8547. function shuffle$1(array) {
  8548. var m = array.length,
  8549. t,
  8550. i;
  8551. while (m) {
  8552. i = Math.random() * m-- | 0;
  8553. t = array[m];
  8554. array[m] = array[i];
  8555. array[i] = t;
  8556. }
  8557. return array;
  8558. }
  8559. function enclose(circles) {
  8560. var i = 0, n = (circles = shuffle$1(slice$3.call(circles))).length, B = [], p, e;
  8561. while (i < n) {
  8562. p = circles[i];
  8563. if (e && enclosesWeak(e, p)) ++i;
  8564. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  8565. }
  8566. return e;
  8567. }
  8568. function extendBasis(B, p) {
  8569. var i, j;
  8570. if (enclosesWeakAll(p, B)) return [p];
  8571. // If we get here then B must have at least one element.
  8572. for (i = 0; i < B.length; ++i) {
  8573. if (enclosesNot(p, B[i])
  8574. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  8575. return [B[i], p];
  8576. }
  8577. }
  8578. // If we get here then B must have at least two elements.
  8579. for (i = 0; i < B.length - 1; ++i) {
  8580. for (j = i + 1; j < B.length; ++j) {
  8581. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  8582. && enclosesNot(encloseBasis2(B[i], p), B[j])
  8583. && enclosesNot(encloseBasis2(B[j], p), B[i])
  8584. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  8585. return [B[i], B[j], p];
  8586. }
  8587. }
  8588. }
  8589. // If we get here then something is very wrong.
  8590. throw new Error;
  8591. }
  8592. function enclosesNot(a, b) {
  8593. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  8594. return dr < 0 || dr * dr < dx * dx + dy * dy;
  8595. }
  8596. function enclosesWeak(a, b) {
  8597. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  8598. return dr > 0 && dr * dr > dx * dx + dy * dy;
  8599. }
  8600. function enclosesWeakAll(a, B) {
  8601. for (var i = 0; i < B.length; ++i) {
  8602. if (!enclosesWeak(a, B[i])) {
  8603. return false;
  8604. }
  8605. }
  8606. return true;
  8607. }
  8608. function encloseBasis(B) {
  8609. switch (B.length) {
  8610. case 1: return encloseBasis1(B[0]);
  8611. case 2: return encloseBasis2(B[0], B[1]);
  8612. case 3: return encloseBasis3(B[0], B[1], B[2]);
  8613. }
  8614. }
  8615. function encloseBasis1(a) {
  8616. return {
  8617. x: a.x,
  8618. y: a.y,
  8619. r: a.r
  8620. };
  8621. }
  8622. function encloseBasis2(a, b) {
  8623. var x1 = a.x, y1 = a.y, r1 = a.r,
  8624. x2 = b.x, y2 = b.y, r2 = b.r,
  8625. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  8626. l = Math.sqrt(x21 * x21 + y21 * y21);
  8627. return {
  8628. x: (x1 + x2 + x21 / l * r21) / 2,
  8629. y: (y1 + y2 + y21 / l * r21) / 2,
  8630. r: (l + r1 + r2) / 2
  8631. };
  8632. }
  8633. function encloseBasis3(a, b, c) {
  8634. var x1 = a.x, y1 = a.y, r1 = a.r,
  8635. x2 = b.x, y2 = b.y, r2 = b.r,
  8636. x3 = c.x, y3 = c.y, r3 = c.r,
  8637. a2 = x1 - x2,
  8638. a3 = x1 - x3,
  8639. b2 = y1 - y2,
  8640. b3 = y1 - y3,
  8641. c2 = r2 - r1,
  8642. c3 = r3 - r1,
  8643. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  8644. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  8645. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  8646. ab = a3 * b2 - a2 * b3,
  8647. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  8648. xb = (b3 * c2 - b2 * c3) / ab,
  8649. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  8650. yb = (a2 * c3 - a3 * c2) / ab,
  8651. A = xb * xb + yb * yb - 1,
  8652. B = 2 * (r1 + xa * xb + ya * yb),
  8653. C = xa * xa + ya * ya - r1 * r1,
  8654. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  8655. return {
  8656. x: x1 + xa + xb * r,
  8657. y: y1 + ya + yb * r,
  8658. r: r
  8659. };
  8660. }
  8661. function place(a, b, c) {
  8662. var ax = a.x,
  8663. ay = a.y,
  8664. da = b.r + c.r,
  8665. db = a.r + c.r,
  8666. dx = b.x - ax,
  8667. dy = b.y - ay,
  8668. dc = dx * dx + dy * dy;
  8669. if (dc) {
  8670. var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
  8671. y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  8672. c.x = ax + x * dx + y * dy;
  8673. c.y = ay + x * dy - y * dx;
  8674. } else {
  8675. c.x = ax + db;
  8676. c.y = ay;
  8677. }
  8678. }
  8679. function intersects(a, b) {
  8680. var dx = b.x - a.x,
  8681. dy = b.y - a.y,
  8682. dr = a.r + b.r;
  8683. return dr * dr - 1e-6 > dx * dx + dy * dy;
  8684. }
  8685. function score(node) {
  8686. var a = node._,
  8687. b = node.next._,
  8688. ab = a.r + b.r,
  8689. dx = (a.x * b.r + b.x * a.r) / ab,
  8690. dy = (a.y * b.r + b.y * a.r) / ab;
  8691. return dx * dx + dy * dy;
  8692. }
  8693. function Node$1(circle) {
  8694. this._ = circle;
  8695. this.next = null;
  8696. this.previous = null;
  8697. }
  8698. function packEnclose(circles) {
  8699. if (!(n = circles.length)) return 0;
  8700. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  8701. // Place the first circle.
  8702. a = circles[0], a.x = 0, a.y = 0;
  8703. if (!(n > 1)) return a.r;
  8704. // Place the second circle.
  8705. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  8706. if (!(n > 2)) return a.r + b.r;
  8707. // Place the third circle.
  8708. place(b, a, c = circles[2]);
  8709. // Initialize the front-chain using the first three circles a, b and c.
  8710. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  8711. a.next = c.previous = b;
  8712. b.next = a.previous = c;
  8713. c.next = b.previous = a;
  8714. // Attempt to place each remaining circle…
  8715. pack: for (i = 3; i < n; ++i) {
  8716. place(a._, b._, c = circles[i]), c = new Node$1(c);
  8717. // Find the closest intersecting circle on the front-chain, if any.
  8718. // “Closeness” is determined by linear distance along the front-chain.
  8719. // “Ahead” or “behind” is likewise determined by linear distance.
  8720. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  8721. do {
  8722. if (sj <= sk) {
  8723. if (intersects(j._, c._)) {
  8724. b = j, a.next = b, b.previous = a, --i;
  8725. continue pack;
  8726. }
  8727. sj += j._.r, j = j.next;
  8728. } else {
  8729. if (intersects(k._, c._)) {
  8730. a = k, a.next = b, b.previous = a, --i;
  8731. continue pack;
  8732. }
  8733. sk += k._.r, k = k.previous;
  8734. }
  8735. } while (j !== k.next);
  8736. // Success! Insert the new circle c between a and b.
  8737. c.previous = a, c.next = b, a.next = b.previous = b = c;
  8738. // Compute the new closest circle pair to the centroid.
  8739. aa = score(a);
  8740. while ((c = c.next) !== b) {
  8741. if ((ca = score(c)) < aa) {
  8742. a = c, aa = ca;
  8743. }
  8744. }
  8745. b = a.next;
  8746. }
  8747. // Compute the enclosing circle of the front chain.
  8748. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  8749. // Translate the circles to put the enclosing circle around the origin.
  8750. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  8751. return c.r;
  8752. }
  8753. function siblings(circles) {
  8754. packEnclose(circles);
  8755. return circles;
  8756. }
  8757. function optional(f) {
  8758. return f == null ? null : required(f);
  8759. }
  8760. function required(f) {
  8761. if (typeof f !== "function") throw new Error;
  8762. return f;
  8763. }
  8764. function constantZero() {
  8765. return 0;
  8766. }
  8767. function constant$8(x) {
  8768. return function() {
  8769. return x;
  8770. };
  8771. }
  8772. function defaultRadius$1(d) {
  8773. return Math.sqrt(d.value);
  8774. }
  8775. function index$2() {
  8776. var radius = null,
  8777. dx = 1,
  8778. dy = 1,
  8779. padding = constantZero;
  8780. function pack(root) {
  8781. root.x = dx / 2, root.y = dy / 2;
  8782. if (radius) {
  8783. root.eachBefore(radiusLeaf(radius))
  8784. .eachAfter(packChildren(padding, 0.5))
  8785. .eachBefore(translateChild(1));
  8786. } else {
  8787. root.eachBefore(radiusLeaf(defaultRadius$1))
  8788. .eachAfter(packChildren(constantZero, 1))
  8789. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  8790. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  8791. }
  8792. return root;
  8793. }
  8794. pack.radius = function(x) {
  8795. return arguments.length ? (radius = optional(x), pack) : radius;
  8796. };
  8797. pack.size = function(x) {
  8798. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  8799. };
  8800. pack.padding = function(x) {
  8801. return arguments.length ? (padding = typeof x === "function" ? x : constant$8(+x), pack) : padding;
  8802. };
  8803. return pack;
  8804. }
  8805. function radiusLeaf(radius) {
  8806. return function(node) {
  8807. if (!node.children) {
  8808. node.r = Math.max(0, +radius(node) || 0);
  8809. }
  8810. };
  8811. }
  8812. function packChildren(padding, k) {
  8813. return function(node) {
  8814. if (children = node.children) {
  8815. var children,
  8816. i,
  8817. n = children.length,
  8818. r = padding(node) * k || 0,
  8819. e;
  8820. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  8821. e = packEnclose(children);
  8822. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  8823. node.r = e + r;
  8824. }
  8825. };
  8826. }
  8827. function translateChild(k) {
  8828. return function(node) {
  8829. var parent = node.parent;
  8830. node.r *= k;
  8831. if (parent) {
  8832. node.x = parent.x + k * node.x;
  8833. node.y = parent.y + k * node.y;
  8834. }
  8835. };
  8836. }
  8837. function roundNode(node) {
  8838. node.x0 = Math.round(node.x0);
  8839. node.y0 = Math.round(node.y0);
  8840. node.x1 = Math.round(node.x1);
  8841. node.y1 = Math.round(node.y1);
  8842. }
  8843. function treemapDice(parent, x0, y0, x1, y1) {
  8844. var nodes = parent.children,
  8845. node,
  8846. i = -1,
  8847. n = nodes.length,
  8848. k = parent.value && (x1 - x0) / parent.value;
  8849. while (++i < n) {
  8850. node = nodes[i], node.y0 = y0, node.y1 = y1;
  8851. node.x0 = x0, node.x1 = x0 += node.value * k;
  8852. }
  8853. }
  8854. function partition() {
  8855. var dx = 1,
  8856. dy = 1,
  8857. padding = 0,
  8858. round = false;
  8859. function partition(root) {
  8860. var n = root.height + 1;
  8861. root.x0 =
  8862. root.y0 = padding;
  8863. root.x1 = dx;
  8864. root.y1 = dy / n;
  8865. root.eachBefore(positionNode(dy, n));
  8866. if (round) root.eachBefore(roundNode);
  8867. return root;
  8868. }
  8869. function positionNode(dy, n) {
  8870. return function(node) {
  8871. if (node.children) {
  8872. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  8873. }
  8874. var x0 = node.x0,
  8875. y0 = node.y0,
  8876. x1 = node.x1 - padding,
  8877. y1 = node.y1 - padding;
  8878. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  8879. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  8880. node.x0 = x0;
  8881. node.y0 = y0;
  8882. node.x1 = x1;
  8883. node.y1 = y1;
  8884. };
  8885. }
  8886. partition.round = function(x) {
  8887. return arguments.length ? (round = !!x, partition) : round;
  8888. };
  8889. partition.size = function(x) {
  8890. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  8891. };
  8892. partition.padding = function(x) {
  8893. return arguments.length ? (padding = +x, partition) : padding;
  8894. };
  8895. return partition;
  8896. }
  8897. var keyPrefix$1 = "$";
  8898. var preroot = {depth: -1};
  8899. var ambiguous = {};
  8900. function defaultId(d) {
  8901. return d.id;
  8902. }
  8903. function defaultParentId(d) {
  8904. return d.parentId;
  8905. }
  8906. function stratify() {
  8907. var id = defaultId,
  8908. parentId = defaultParentId;
  8909. function stratify(data) {
  8910. var d,
  8911. i,
  8912. n = data.length,
  8913. root,
  8914. parent,
  8915. node,
  8916. nodes = new Array(n),
  8917. nodeId,
  8918. nodeKey,
  8919. nodeByKey = {};
  8920. for (i = 0; i < n; ++i) {
  8921. d = data[i], node = nodes[i] = new Node(d);
  8922. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  8923. nodeKey = keyPrefix$1 + (node.id = nodeId);
  8924. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  8925. }
  8926. }
  8927. for (i = 0; i < n; ++i) {
  8928. node = nodes[i], nodeId = parentId(data[i], i, data);
  8929. if (nodeId == null || !(nodeId += "")) {
  8930. if (root) throw new Error("multiple roots");
  8931. root = node;
  8932. } else {
  8933. parent = nodeByKey[keyPrefix$1 + nodeId];
  8934. if (!parent) throw new Error("missing: " + nodeId);
  8935. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  8936. if (parent.children) parent.children.push(node);
  8937. else parent.children = [node];
  8938. node.parent = parent;
  8939. }
  8940. }
  8941. if (!root) throw new Error("no root");
  8942. root.parent = preroot;
  8943. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  8944. root.parent = null;
  8945. if (n > 0) throw new Error("cycle");
  8946. return root;
  8947. }
  8948. stratify.id = function(x) {
  8949. return arguments.length ? (id = required(x), stratify) : id;
  8950. };
  8951. stratify.parentId = function(x) {
  8952. return arguments.length ? (parentId = required(x), stratify) : parentId;
  8953. };
  8954. return stratify;
  8955. }
  8956. function defaultSeparation$1(a, b) {
  8957. return a.parent === b.parent ? 1 : 2;
  8958. }
  8959. // function radialSeparation(a, b) {
  8960. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  8961. // }
  8962. // This function is used to traverse the left contour of a subtree (or
  8963. // subforest). It returns the successor of v on this contour. This successor is
  8964. // either given by the leftmost child of v or by the thread of v. The function
  8965. // returns null if and only if v is on the highest level of its subtree.
  8966. function nextLeft(v) {
  8967. var children = v.children;
  8968. return children ? children[0] : v.t;
  8969. }
  8970. // This function works analogously to nextLeft.
  8971. function nextRight(v) {
  8972. var children = v.children;
  8973. return children ? children[children.length - 1] : v.t;
  8974. }
  8975. // Shifts the current subtree rooted at w+. This is done by increasing
  8976. // prelim(w+) and mod(w+) by shift.
  8977. function moveSubtree(wm, wp, shift) {
  8978. var change = shift / (wp.i - wm.i);
  8979. wp.c -= change;
  8980. wp.s += shift;
  8981. wm.c += change;
  8982. wp.z += shift;
  8983. wp.m += shift;
  8984. }
  8985. // All other shifts, applied to the smaller subtrees between w- and w+, are
  8986. // performed by this function. To prepare the shifts, we have to adjust
  8987. // change(w+), shift(w+), and change(w-).
  8988. function executeShifts(v) {
  8989. var shift = 0,
  8990. change = 0,
  8991. children = v.children,
  8992. i = children.length,
  8993. w;
  8994. while (--i >= 0) {
  8995. w = children[i];
  8996. w.z += shift;
  8997. w.m += shift;
  8998. shift += w.s + (change += w.c);
  8999. }
  9000. }
  9001. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  9002. // returns the specified (default) ancestor.
  9003. function nextAncestor(vim, v, ancestor) {
  9004. return vim.a.parent === v.parent ? vim.a : ancestor;
  9005. }
  9006. function TreeNode(node, i) {
  9007. this._ = node;
  9008. this.parent = null;
  9009. this.children = null;
  9010. this.A = null; // default ancestor
  9011. this.a = this; // ancestor
  9012. this.z = 0; // prelim
  9013. this.m = 0; // mod
  9014. this.c = 0; // change
  9015. this.s = 0; // shift
  9016. this.t = null; // thread
  9017. this.i = i; // number
  9018. }
  9019. TreeNode.prototype = Object.create(Node.prototype);
  9020. function treeRoot(root) {
  9021. var tree = new TreeNode(root, 0),
  9022. node,
  9023. nodes = [tree],
  9024. child,
  9025. children,
  9026. i,
  9027. n;
  9028. while (node = nodes.pop()) {
  9029. if (children = node._.children) {
  9030. node.children = new Array(n = children.length);
  9031. for (i = n - 1; i >= 0; --i) {
  9032. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  9033. child.parent = node;
  9034. }
  9035. }
  9036. }
  9037. (tree.parent = new TreeNode(null, 0)).children = [tree];
  9038. return tree;
  9039. }
  9040. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  9041. function tree() {
  9042. var separation = defaultSeparation$1,
  9043. dx = 1,
  9044. dy = 1,
  9045. nodeSize = null;
  9046. function tree(root) {
  9047. var t = treeRoot(root);
  9048. // Compute the layout using Buchheim et al.’s algorithm.
  9049. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9050. t.eachBefore(secondWalk);
  9051. // If a fixed node size is specified, scale x and y.
  9052. if (nodeSize) root.eachBefore(sizeNode);
  9053. // If a fixed tree size is specified, scale x and y based on the extent.
  9054. // Compute the left-most, right-most, and depth-most nodes for extents.
  9055. else {
  9056. var left = root,
  9057. right = root,
  9058. bottom = root;
  9059. root.eachBefore(function(node) {
  9060. if (node.x < left.x) left = node;
  9061. if (node.x > right.x) right = node;
  9062. if (node.depth > bottom.depth) bottom = node;
  9063. });
  9064. var s = left === right ? 1 : separation(left, right) / 2,
  9065. tx = s - left.x,
  9066. kx = dx / (right.x + s + tx),
  9067. ky = dy / (bottom.depth || 1);
  9068. root.eachBefore(function(node) {
  9069. node.x = (node.x + tx) * kx;
  9070. node.y = node.depth * ky;
  9071. });
  9072. }
  9073. return root;
  9074. }
  9075. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9076. // applied recursively to the children of v, as well as the function
  9077. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9078. // node v is placed to the midpoint of its outermost children.
  9079. function firstWalk(v) {
  9080. var children = v.children,
  9081. siblings = v.parent.children,
  9082. w = v.i ? siblings[v.i - 1] : null;
  9083. if (children) {
  9084. executeShifts(v);
  9085. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9086. if (w) {
  9087. v.z = w.z + separation(v._, w._);
  9088. v.m = v.z - midpoint;
  9089. } else {
  9090. v.z = midpoint;
  9091. }
  9092. } else if (w) {
  9093. v.z = w.z + separation(v._, w._);
  9094. }
  9095. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9096. }
  9097. // Computes all real x-coordinates by summing up the modifiers recursively.
  9098. function secondWalk(v) {
  9099. v._.x = v.z + v.parent.m;
  9100. v.m += v.parent.m;
  9101. }
  9102. // The core of the algorithm. Here, a new subtree is combined with the
  9103. // previous subtrees. Threads are used to traverse the inside and outside
  9104. // contours of the left and right subtree up to the highest common level. The
  9105. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9106. // superscript o means outside and i means inside, the subscript - means left
  9107. // subtree and + means right subtree. For summing up the modifiers along the
  9108. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9109. // nodes of the inside contours conflict, we compute the left one of the
  9110. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9111. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9112. // Finally, we add a new thread (if necessary).
  9113. function apportion(v, w, ancestor) {
  9114. if (w) {
  9115. var vip = v,
  9116. vop = v,
  9117. vim = w,
  9118. vom = vip.parent.children[0],
  9119. sip = vip.m,
  9120. sop = vop.m,
  9121. sim = vim.m,
  9122. som = vom.m,
  9123. shift;
  9124. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9125. vom = nextLeft(vom);
  9126. vop = nextRight(vop);
  9127. vop.a = v;
  9128. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9129. if (shift > 0) {
  9130. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9131. sip += shift;
  9132. sop += shift;
  9133. }
  9134. sim += vim.m;
  9135. sip += vip.m;
  9136. som += vom.m;
  9137. sop += vop.m;
  9138. }
  9139. if (vim && !nextRight(vop)) {
  9140. vop.t = vim;
  9141. vop.m += sim - sop;
  9142. }
  9143. if (vip && !nextLeft(vom)) {
  9144. vom.t = vip;
  9145. vom.m += sip - som;
  9146. ancestor = v;
  9147. }
  9148. }
  9149. return ancestor;
  9150. }
  9151. function sizeNode(node) {
  9152. node.x *= dx;
  9153. node.y = node.depth * dy;
  9154. }
  9155. tree.separation = function(x) {
  9156. return arguments.length ? (separation = x, tree) : separation;
  9157. };
  9158. tree.size = function(x) {
  9159. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9160. };
  9161. tree.nodeSize = function(x) {
  9162. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9163. };
  9164. return tree;
  9165. }
  9166. function treemapSlice(parent, x0, y0, x1, y1) {
  9167. var nodes = parent.children,
  9168. node,
  9169. i = -1,
  9170. n = nodes.length,
  9171. k = parent.value && (y1 - y0) / parent.value;
  9172. while (++i < n) {
  9173. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9174. node.y0 = y0, node.y1 = y0 += node.value * k;
  9175. }
  9176. }
  9177. var phi = (1 + Math.sqrt(5)) / 2;
  9178. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9179. var rows = [],
  9180. nodes = parent.children,
  9181. row,
  9182. nodeValue,
  9183. i0 = 0,
  9184. i1 = 0,
  9185. n = nodes.length,
  9186. dx, dy,
  9187. value = parent.value,
  9188. sumValue,
  9189. minValue,
  9190. maxValue,
  9191. newRatio,
  9192. minRatio,
  9193. alpha,
  9194. beta;
  9195. while (i0 < n) {
  9196. dx = x1 - x0, dy = y1 - y0;
  9197. // Find the next non-empty node.
  9198. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9199. minValue = maxValue = sumValue;
  9200. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9201. beta = sumValue * sumValue * alpha;
  9202. minRatio = Math.max(maxValue / beta, beta / minValue);
  9203. // Keep adding nodes while the aspect ratio maintains or improves.
  9204. for (; i1 < n; ++i1) {
  9205. sumValue += nodeValue = nodes[i1].value;
  9206. if (nodeValue < minValue) minValue = nodeValue;
  9207. if (nodeValue > maxValue) maxValue = nodeValue;
  9208. beta = sumValue * sumValue * alpha;
  9209. newRatio = Math.max(maxValue / beta, beta / minValue);
  9210. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9211. minRatio = newRatio;
  9212. }
  9213. // Position and record the row orientation.
  9214. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9215. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9216. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9217. value -= sumValue, i0 = i1;
  9218. }
  9219. return rows;
  9220. }
  9221. var squarify = (function custom(ratio) {
  9222. function squarify(parent, x0, y0, x1, y1) {
  9223. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9224. }
  9225. squarify.ratio = function(x) {
  9226. return custom((x = +x) > 1 ? x : 1);
  9227. };
  9228. return squarify;
  9229. })(phi);
  9230. function index$3() {
  9231. var tile = squarify,
  9232. round = false,
  9233. dx = 1,
  9234. dy = 1,
  9235. paddingStack = [0],
  9236. paddingInner = constantZero,
  9237. paddingTop = constantZero,
  9238. paddingRight = constantZero,
  9239. paddingBottom = constantZero,
  9240. paddingLeft = constantZero;
  9241. function treemap(root) {
  9242. root.x0 =
  9243. root.y0 = 0;
  9244. root.x1 = dx;
  9245. root.y1 = dy;
  9246. root.eachBefore(positionNode);
  9247. paddingStack = [0];
  9248. if (round) root.eachBefore(roundNode);
  9249. return root;
  9250. }
  9251. function positionNode(node) {
  9252. var p = paddingStack[node.depth],
  9253. x0 = node.x0 + p,
  9254. y0 = node.y0 + p,
  9255. x1 = node.x1 - p,
  9256. y1 = node.y1 - p;
  9257. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9258. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9259. node.x0 = x0;
  9260. node.y0 = y0;
  9261. node.x1 = x1;
  9262. node.y1 = y1;
  9263. if (node.children) {
  9264. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  9265. x0 += paddingLeft(node) - p;
  9266. y0 += paddingTop(node) - p;
  9267. x1 -= paddingRight(node) - p;
  9268. y1 -= paddingBottom(node) - p;
  9269. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9270. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9271. tile(node, x0, y0, x1, y1);
  9272. }
  9273. }
  9274. treemap.round = function(x) {
  9275. return arguments.length ? (round = !!x, treemap) : round;
  9276. };
  9277. treemap.size = function(x) {
  9278. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  9279. };
  9280. treemap.tile = function(x) {
  9281. return arguments.length ? (tile = required(x), treemap) : tile;
  9282. };
  9283. treemap.padding = function(x) {
  9284. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  9285. };
  9286. treemap.paddingInner = function(x) {
  9287. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$8(+x), treemap) : paddingInner;
  9288. };
  9289. treemap.paddingOuter = function(x) {
  9290. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  9291. };
  9292. treemap.paddingTop = function(x) {
  9293. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$8(+x), treemap) : paddingTop;
  9294. };
  9295. treemap.paddingRight = function(x) {
  9296. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$8(+x), treemap) : paddingRight;
  9297. };
  9298. treemap.paddingBottom = function(x) {
  9299. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$8(+x), treemap) : paddingBottom;
  9300. };
  9301. treemap.paddingLeft = function(x) {
  9302. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$8(+x), treemap) : paddingLeft;
  9303. };
  9304. return treemap;
  9305. }
  9306. function binary(parent, x0, y0, x1, y1) {
  9307. var nodes = parent.children,
  9308. i, n = nodes.length,
  9309. sum, sums = new Array(n + 1);
  9310. for (sums[0] = sum = i = 0; i < n; ++i) {
  9311. sums[i + 1] = sum += nodes[i].value;
  9312. }
  9313. partition(0, n, parent.value, x0, y0, x1, y1);
  9314. function partition(i, j, value, x0, y0, x1, y1) {
  9315. if (i >= j - 1) {
  9316. var node = nodes[i];
  9317. node.x0 = x0, node.y0 = y0;
  9318. node.x1 = x1, node.y1 = y1;
  9319. return;
  9320. }
  9321. var valueOffset = sums[i],
  9322. valueTarget = (value / 2) + valueOffset,
  9323. k = i + 1,
  9324. hi = j - 1;
  9325. while (k < hi) {
  9326. var mid = k + hi >>> 1;
  9327. if (sums[mid] < valueTarget) k = mid + 1;
  9328. else hi = mid;
  9329. }
  9330. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  9331. var valueLeft = sums[k] - valueOffset,
  9332. valueRight = value - valueLeft;
  9333. if ((x1 - x0) > (y1 - y0)) {
  9334. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  9335. partition(i, k, valueLeft, x0, y0, xk, y1);
  9336. partition(k, j, valueRight, xk, y0, x1, y1);
  9337. } else {
  9338. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  9339. partition(i, k, valueLeft, x0, y0, x1, yk);
  9340. partition(k, j, valueRight, x0, yk, x1, y1);
  9341. }
  9342. }
  9343. }
  9344. function sliceDice(parent, x0, y0, x1, y1) {
  9345. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  9346. }
  9347. var resquarify = (function custom(ratio) {
  9348. function resquarify(parent, x0, y0, x1, y1) {
  9349. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  9350. var rows,
  9351. row,
  9352. nodes,
  9353. i,
  9354. j = -1,
  9355. n,
  9356. m = rows.length,
  9357. value = parent.value;
  9358. while (++j < m) {
  9359. row = rows[j], nodes = row.children;
  9360. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  9361. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  9362. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  9363. value -= row.value;
  9364. }
  9365. } else {
  9366. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9367. rows.ratio = ratio;
  9368. }
  9369. }
  9370. resquarify.ratio = function(x) {
  9371. return custom((x = +x) > 1 ? x : 1);
  9372. };
  9373. return resquarify;
  9374. })(phi);
  9375. function area$1(polygon) {
  9376. var i = -1,
  9377. n = polygon.length,
  9378. a,
  9379. b = polygon[n - 1],
  9380. area = 0;
  9381. while (++i < n) {
  9382. a = b;
  9383. b = polygon[i];
  9384. area += a[1] * b[0] - a[0] * b[1];
  9385. }
  9386. return area / 2;
  9387. }
  9388. function centroid$1(polygon) {
  9389. var i = -1,
  9390. n = polygon.length,
  9391. x = 0,
  9392. y = 0,
  9393. a,
  9394. b = polygon[n - 1],
  9395. c,
  9396. k = 0;
  9397. while (++i < n) {
  9398. a = b;
  9399. b = polygon[i];
  9400. k += c = a[0] * b[1] - b[0] * a[1];
  9401. x += (a[0] + b[0]) * c;
  9402. y += (a[1] + b[1]) * c;
  9403. }
  9404. return k *= 3, [x / k, y / k];
  9405. }
  9406. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  9407. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  9408. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  9409. // negative if clockwise, and zero if the points are collinear.
  9410. function cross$1(a, b, c) {
  9411. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  9412. }
  9413. function lexicographicOrder(a, b) {
  9414. return a[0] - b[0] || a[1] - b[1];
  9415. }
  9416. // Computes the upper convex hull per the monotone chain algorithm.
  9417. // Assumes points.length >= 3, is sorted by x, unique in y.
  9418. // Returns an array of indices into points in left-to-right order.
  9419. function computeUpperHullIndexes(points) {
  9420. var n = points.length,
  9421. indexes = [0, 1],
  9422. size = 2;
  9423. for (var i = 2; i < n; ++i) {
  9424. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  9425. indexes[size++] = i;
  9426. }
  9427. return indexes.slice(0, size); // remove popped points
  9428. }
  9429. function hull(points) {
  9430. if ((n = points.length) < 3) return null;
  9431. var i,
  9432. n,
  9433. sortedPoints = new Array(n),
  9434. flippedPoints = new Array(n);
  9435. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  9436. sortedPoints.sort(lexicographicOrder);
  9437. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  9438. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  9439. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  9440. // Construct the hull polygon, removing possible duplicate endpoints.
  9441. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  9442. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  9443. hull = [];
  9444. // Add upper hull in right-to-l order.
  9445. // Then add lower hull in left-to-right order.
  9446. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  9447. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  9448. return hull;
  9449. }
  9450. function contains$1(polygon, point) {
  9451. var n = polygon.length,
  9452. p = polygon[n - 1],
  9453. x = point[0], y = point[1],
  9454. x0 = p[0], y0 = p[1],
  9455. x1, y1,
  9456. inside = false;
  9457. for (var i = 0; i < n; ++i) {
  9458. p = polygon[i], x1 = p[0], y1 = p[1];
  9459. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  9460. x0 = x1, y0 = y1;
  9461. }
  9462. return inside;
  9463. }
  9464. function length$2(polygon) {
  9465. var i = -1,
  9466. n = polygon.length,
  9467. b = polygon[n - 1],
  9468. xa,
  9469. ya,
  9470. xb = b[0],
  9471. yb = b[1],
  9472. perimeter = 0;
  9473. while (++i < n) {
  9474. xa = xb;
  9475. ya = yb;
  9476. b = polygon[i];
  9477. xb = b[0];
  9478. yb = b[1];
  9479. xa -= xb;
  9480. ya -= yb;
  9481. perimeter += Math.sqrt(xa * xa + ya * ya);
  9482. }
  9483. return perimeter;
  9484. }
  9485. var slice$4 = [].slice;
  9486. var noabort = {};
  9487. function Queue(size) {
  9488. this._size = size;
  9489. this._call =
  9490. this._error = null;
  9491. this._tasks = [];
  9492. this._data = [];
  9493. this._waiting =
  9494. this._active =
  9495. this._ended =
  9496. this._start = 0; // inside a synchronous task callback?
  9497. }
  9498. Queue.prototype = queue.prototype = {
  9499. constructor: Queue,
  9500. defer: function(callback) {
  9501. if (typeof callback !== "function") throw new Error("invalid callback");
  9502. if (this._call) throw new Error("defer after await");
  9503. if (this._error != null) return this;
  9504. var t = slice$4.call(arguments, 1);
  9505. t.push(callback);
  9506. ++this._waiting, this._tasks.push(t);
  9507. poke$1(this);
  9508. return this;
  9509. },
  9510. abort: function() {
  9511. if (this._error == null) abort(this, new Error("abort"));
  9512. return this;
  9513. },
  9514. await: function(callback) {
  9515. if (typeof callback !== "function") throw new Error("invalid callback");
  9516. if (this._call) throw new Error("multiple await");
  9517. this._call = function(error, results) { callback.apply(null, [error].concat(results)); };
  9518. maybeNotify(this);
  9519. return this;
  9520. },
  9521. awaitAll: function(callback) {
  9522. if (typeof callback !== "function") throw new Error("invalid callback");
  9523. if (this._call) throw new Error("multiple await");
  9524. this._call = callback;
  9525. maybeNotify(this);
  9526. return this;
  9527. }
  9528. };
  9529. function poke$1(q) {
  9530. if (!q._start) {
  9531. try { start$1(q); } // let the current task complete
  9532. catch (e) {
  9533. if (q._tasks[q._ended + q._active - 1]) abort(q, e); // task errored synchronously
  9534. else if (!q._data) throw e; // await callback errored synchronously
  9535. }
  9536. }
  9537. }
  9538. function start$1(q) {
  9539. while (q._start = q._waiting && q._active < q._size) {
  9540. var i = q._ended + q._active,
  9541. t = q._tasks[i],
  9542. j = t.length - 1,
  9543. c = t[j];
  9544. t[j] = end(q, i);
  9545. --q._waiting, ++q._active;
  9546. t = c.apply(null, t);
  9547. if (!q._tasks[i]) continue; // task finished synchronously
  9548. q._tasks[i] = t || noabort;
  9549. }
  9550. }
  9551. function end(q, i) {
  9552. return function(e, r) {
  9553. if (!q._tasks[i]) return; // ignore multiple callbacks
  9554. --q._active, ++q._ended;
  9555. q._tasks[i] = null;
  9556. if (q._error != null) return; // ignore secondary errors
  9557. if (e != null) {
  9558. abort(q, e);
  9559. } else {
  9560. q._data[i] = r;
  9561. if (q._waiting) poke$1(q);
  9562. else maybeNotify(q);
  9563. }
  9564. };
  9565. }
  9566. function abort(q, e) {
  9567. var i = q._tasks.length, t;
  9568. q._error = e; // ignore active callbacks
  9569. q._data = undefined; // allow gc
  9570. q._waiting = NaN; // prevent starting
  9571. while (--i >= 0) {
  9572. if (t = q._tasks[i]) {
  9573. q._tasks[i] = null;
  9574. if (t.abort) {
  9575. try { t.abort(); }
  9576. catch (e) { /* ignore */ }
  9577. }
  9578. }
  9579. }
  9580. q._active = NaN; // allow notification
  9581. maybeNotify(q);
  9582. }
  9583. function maybeNotify(q) {
  9584. if (!q._active && q._call) {
  9585. var d = q._data;
  9586. q._data = undefined; // allow gc
  9587. q._call(q._error, d);
  9588. }
  9589. }
  9590. function queue(concurrency) {
  9591. if (concurrency == null) concurrency = Infinity;
  9592. else if (!((concurrency = +concurrency) >= 1)) throw new Error("invalid concurrency");
  9593. return new Queue(concurrency);
  9594. }
  9595. function defaultSource$1() {
  9596. return Math.random();
  9597. }
  9598. var uniform = (function sourceRandomUniform(source) {
  9599. function randomUniform(min, max) {
  9600. min = min == null ? 0 : +min;
  9601. max = max == null ? 1 : +max;
  9602. if (arguments.length === 1) max = min, min = 0;
  9603. else max -= min;
  9604. return function() {
  9605. return source() * max + min;
  9606. };
  9607. }
  9608. randomUniform.source = sourceRandomUniform;
  9609. return randomUniform;
  9610. })(defaultSource$1);
  9611. var normal = (function sourceRandomNormal(source) {
  9612. function randomNormal(mu, sigma) {
  9613. var x, r;
  9614. mu = mu == null ? 0 : +mu;
  9615. sigma = sigma == null ? 1 : +sigma;
  9616. return function() {
  9617. var y;
  9618. // If available, use the second previously-generated uniform random.
  9619. if (x != null) y = x, x = null;
  9620. // Otherwise, generate a new x and y.
  9621. else do {
  9622. x = source() * 2 - 1;
  9623. y = source() * 2 - 1;
  9624. r = x * x + y * y;
  9625. } while (!r || r > 1);
  9626. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  9627. };
  9628. }
  9629. randomNormal.source = sourceRandomNormal;
  9630. return randomNormal;
  9631. })(defaultSource$1);
  9632. var logNormal = (function sourceRandomLogNormal(source) {
  9633. function randomLogNormal() {
  9634. var randomNormal = normal.source(source).apply(this, arguments);
  9635. return function() {
  9636. return Math.exp(randomNormal());
  9637. };
  9638. }
  9639. randomLogNormal.source = sourceRandomLogNormal;
  9640. return randomLogNormal;
  9641. })(defaultSource$1);
  9642. var irwinHall = (function sourceRandomIrwinHall(source) {
  9643. function randomIrwinHall(n) {
  9644. return function() {
  9645. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  9646. return sum;
  9647. };
  9648. }
  9649. randomIrwinHall.source = sourceRandomIrwinHall;
  9650. return randomIrwinHall;
  9651. })(defaultSource$1);
  9652. var bates = (function sourceRandomBates(source) {
  9653. function randomBates(n) {
  9654. var randomIrwinHall = irwinHall.source(source)(n);
  9655. return function() {
  9656. return randomIrwinHall() / n;
  9657. };
  9658. }
  9659. randomBates.source = sourceRandomBates;
  9660. return randomBates;
  9661. })(defaultSource$1);
  9662. var exponential$1 = (function sourceRandomExponential(source) {
  9663. function randomExponential(lambda) {
  9664. return function() {
  9665. return -Math.log(1 - source()) / lambda;
  9666. };
  9667. }
  9668. randomExponential.source = sourceRandomExponential;
  9669. return randomExponential;
  9670. })(defaultSource$1);
  9671. function request(url, callback) {
  9672. var request,
  9673. event = dispatch("beforesend", "progress", "load", "error"),
  9674. mimeType,
  9675. headers = map$1(),
  9676. xhr = new XMLHttpRequest,
  9677. user = null,
  9678. password = null,
  9679. response,
  9680. responseType,
  9681. timeout = 0;
  9682. // If IE does not support CORS, use XDomainRequest.
  9683. if (typeof XDomainRequest !== "undefined"
  9684. && !("withCredentials" in xhr)
  9685. && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
  9686. "onload" in xhr
  9687. ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
  9688. : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
  9689. function respond(o) {
  9690. var status = xhr.status, result;
  9691. if (!status && hasResponse(xhr)
  9692. || status >= 200 && status < 300
  9693. || status === 304) {
  9694. if (response) {
  9695. try {
  9696. result = response.call(request, xhr);
  9697. } catch (e) {
  9698. event.call("error", request, e);
  9699. return;
  9700. }
  9701. } else {
  9702. result = xhr;
  9703. }
  9704. event.call("load", request, result);
  9705. } else {
  9706. event.call("error", request, o);
  9707. }
  9708. }
  9709. xhr.onprogress = function(e) {
  9710. event.call("progress", request, e);
  9711. };
  9712. request = {
  9713. header: function(name, value) {
  9714. name = (name + "").toLowerCase();
  9715. if (arguments.length < 2) return headers.get(name);
  9716. if (value == null) headers.remove(name);
  9717. else headers.set(name, value + "");
  9718. return request;
  9719. },
  9720. // If mimeType is non-null and no Accept header is set, a default is used.
  9721. mimeType: function(value) {
  9722. if (!arguments.length) return mimeType;
  9723. mimeType = value == null ? null : value + "";
  9724. return request;
  9725. },
  9726. // Specifies what type the response value should take;
  9727. // for instance, arraybuffer, blob, document, or text.
  9728. responseType: function(value) {
  9729. if (!arguments.length) return responseType;
  9730. responseType = value;
  9731. return request;
  9732. },
  9733. timeout: function(value) {
  9734. if (!arguments.length) return timeout;
  9735. timeout = +value;
  9736. return request;
  9737. },
  9738. user: function(value) {
  9739. return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
  9740. },
  9741. password: function(value) {
  9742. return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
  9743. },
  9744. // Specify how to convert the response content to a specific type;
  9745. // changes the callback value on "load" events.
  9746. response: function(value) {
  9747. response = value;
  9748. return request;
  9749. },
  9750. // Alias for send("GET", …).
  9751. get: function(data, callback) {
  9752. return request.send("GET", data, callback);
  9753. },
  9754. // Alias for send("POST", …).
  9755. post: function(data, callback) {
  9756. return request.send("POST", data, callback);
  9757. },
  9758. // If callback is non-null, it will be used for error and load events.
  9759. send: function(method, data, callback) {
  9760. xhr.open(method, url, true, user, password);
  9761. if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
  9762. if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
  9763. if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
  9764. if (responseType != null) xhr.responseType = responseType;
  9765. if (timeout > 0) xhr.timeout = timeout;
  9766. if (callback == null && typeof data === "function") callback = data, data = null;
  9767. if (callback != null && callback.length === 1) callback = fixCallback(callback);
  9768. if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
  9769. event.call("beforesend", request, xhr);
  9770. xhr.send(data == null ? null : data);
  9771. return request;
  9772. },
  9773. abort: function() {
  9774. xhr.abort();
  9775. return request;
  9776. },
  9777. on: function() {
  9778. var value = event.on.apply(event, arguments);
  9779. return value === event ? request : value;
  9780. }
  9781. };
  9782. if (callback != null) {
  9783. if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
  9784. return request.get(callback);
  9785. }
  9786. return request;
  9787. }
  9788. function fixCallback(callback) {
  9789. return function(error, xhr) {
  9790. callback(error == null ? xhr : null);
  9791. };
  9792. }
  9793. function hasResponse(xhr) {
  9794. var type = xhr.responseType;
  9795. return type && type !== "text"
  9796. ? xhr.response // null on error
  9797. : xhr.responseText; // "" on error
  9798. }
  9799. function type$1(defaultMimeType, response) {
  9800. return function(url, callback) {
  9801. var r = request(url).mimeType(defaultMimeType).response(response);
  9802. if (callback != null) {
  9803. if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
  9804. return r.get(callback);
  9805. }
  9806. return r;
  9807. };
  9808. }
  9809. var html = type$1("text/html", function(xhr) {
  9810. return document.createRange().createContextualFragment(xhr.responseText);
  9811. });
  9812. var json = type$1("application/json", function(xhr) {
  9813. return JSON.parse(xhr.responseText);
  9814. });
  9815. var text = type$1("text/plain", function(xhr) {
  9816. return xhr.responseText;
  9817. });
  9818. var xml = type$1("application/xml", function(xhr) {
  9819. var xml = xhr.responseXML;
  9820. if (!xml) throw new Error("parse error");
  9821. return xml;
  9822. });
  9823. function dsv$1(defaultMimeType, parse) {
  9824. return function(url, row, callback) {
  9825. if (arguments.length < 3) callback = row, row = null;
  9826. var r = request(url).mimeType(defaultMimeType);
  9827. r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
  9828. r.row(row);
  9829. return callback ? r.get(callback) : r;
  9830. };
  9831. }
  9832. function responseOf(parse, row) {
  9833. return function(request$$1) {
  9834. return parse(request$$1.responseText, row);
  9835. };
  9836. }
  9837. var csv$1 = dsv$1("text/csv", csvParse);
  9838. var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
  9839. var array$2 = Array.prototype;
  9840. var map$3 = array$2.map;
  9841. var slice$5 = array$2.slice;
  9842. var implicit = {name: "implicit"};
  9843. function ordinal(range) {
  9844. var index = map$1(),
  9845. domain = [],
  9846. unknown = implicit;
  9847. range = range == null ? [] : slice$5.call(range);
  9848. function scale(d) {
  9849. var key = d + "", i = index.get(key);
  9850. if (!i) {
  9851. if (unknown !== implicit) return unknown;
  9852. index.set(key, i = domain.push(d));
  9853. }
  9854. return range[(i - 1) % range.length];
  9855. }
  9856. scale.domain = function(_) {
  9857. if (!arguments.length) return domain.slice();
  9858. domain = [], index = map$1();
  9859. var i = -1, n = _.length, d, key;
  9860. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  9861. return scale;
  9862. };
  9863. scale.range = function(_) {
  9864. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  9865. };
  9866. scale.unknown = function(_) {
  9867. return arguments.length ? (unknown = _, scale) : unknown;
  9868. };
  9869. scale.copy = function() {
  9870. return ordinal()
  9871. .domain(domain)
  9872. .range(range)
  9873. .unknown(unknown);
  9874. };
  9875. return scale;
  9876. }
  9877. function band() {
  9878. var scale = ordinal().unknown(undefined),
  9879. domain = scale.domain,
  9880. ordinalRange = scale.range,
  9881. range$$1 = [0, 1],
  9882. step,
  9883. bandwidth,
  9884. round = false,
  9885. paddingInner = 0,
  9886. paddingOuter = 0,
  9887. align = 0.5;
  9888. delete scale.unknown;
  9889. function rescale() {
  9890. var n = domain().length,
  9891. reverse = range$$1[1] < range$$1[0],
  9892. start = range$$1[reverse - 0],
  9893. stop = range$$1[1 - reverse];
  9894. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  9895. if (round) step = Math.floor(step);
  9896. start += (stop - start - step * (n - paddingInner)) * align;
  9897. bandwidth = step * (1 - paddingInner);
  9898. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  9899. var values = sequence(n).map(function(i) { return start + step * i; });
  9900. return ordinalRange(reverse ? values.reverse() : values);
  9901. }
  9902. scale.domain = function(_) {
  9903. return arguments.length ? (domain(_), rescale()) : domain();
  9904. };
  9905. scale.range = function(_) {
  9906. return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
  9907. };
  9908. scale.rangeRound = function(_) {
  9909. return range$$1 = [+_[0], +_[1]], round = true, rescale();
  9910. };
  9911. scale.bandwidth = function() {
  9912. return bandwidth;
  9913. };
  9914. scale.step = function() {
  9915. return step;
  9916. };
  9917. scale.round = function(_) {
  9918. return arguments.length ? (round = !!_, rescale()) : round;
  9919. };
  9920. scale.padding = function(_) {
  9921. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  9922. };
  9923. scale.paddingInner = function(_) {
  9924. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  9925. };
  9926. scale.paddingOuter = function(_) {
  9927. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  9928. };
  9929. scale.align = function(_) {
  9930. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  9931. };
  9932. scale.copy = function() {
  9933. return band()
  9934. .domain(domain())
  9935. .range(range$$1)
  9936. .round(round)
  9937. .paddingInner(paddingInner)
  9938. .paddingOuter(paddingOuter)
  9939. .align(align);
  9940. };
  9941. return rescale();
  9942. }
  9943. function pointish(scale) {
  9944. var copy = scale.copy;
  9945. scale.padding = scale.paddingOuter;
  9946. delete scale.paddingInner;
  9947. delete scale.paddingOuter;
  9948. scale.copy = function() {
  9949. return pointish(copy());
  9950. };
  9951. return scale;
  9952. }
  9953. function point$1() {
  9954. return pointish(band().paddingInner(1));
  9955. }
  9956. function constant$9(x) {
  9957. return function() {
  9958. return x;
  9959. };
  9960. }
  9961. function number$2(x) {
  9962. return +x;
  9963. }
  9964. var unit = [0, 1];
  9965. function deinterpolateLinear(a, b) {
  9966. return (b -= (a = +a))
  9967. ? function(x) { return (x - a) / b; }
  9968. : constant$9(b);
  9969. }
  9970. function deinterpolateClamp(deinterpolate) {
  9971. return function(a, b) {
  9972. var d = deinterpolate(a = +a, b = +b);
  9973. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  9974. };
  9975. }
  9976. function reinterpolateClamp(reinterpolate) {
  9977. return function(a, b) {
  9978. var r = reinterpolate(a = +a, b = +b);
  9979. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  9980. };
  9981. }
  9982. function bimap(domain, range, deinterpolate, reinterpolate) {
  9983. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  9984. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
  9985. else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
  9986. return function(x) { return r0(d0(x)); };
  9987. }
  9988. function polymap(domain, range, deinterpolate, reinterpolate) {
  9989. var j = Math.min(domain.length, range.length) - 1,
  9990. d = new Array(j),
  9991. r = new Array(j),
  9992. i = -1;
  9993. // Reverse descending domains.
  9994. if (domain[j] < domain[0]) {
  9995. domain = domain.slice().reverse();
  9996. range = range.slice().reverse();
  9997. }
  9998. while (++i < j) {
  9999. d[i] = deinterpolate(domain[i], domain[i + 1]);
  10000. r[i] = reinterpolate(range[i], range[i + 1]);
  10001. }
  10002. return function(x) {
  10003. var i = bisectRight(domain, x, 1, j) - 1;
  10004. return r[i](d[i](x));
  10005. };
  10006. }
  10007. function copy(source, target) {
  10008. return target
  10009. .domain(source.domain())
  10010. .range(source.range())
  10011. .interpolate(source.interpolate())
  10012. .clamp(source.clamp());
  10013. }
  10014. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  10015. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  10016. function continuous(deinterpolate, reinterpolate) {
  10017. var domain = unit,
  10018. range = unit,
  10019. interpolate$$1 = interpolateValue,
  10020. clamp = false,
  10021. piecewise,
  10022. output,
  10023. input;
  10024. function rescale() {
  10025. piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  10026. output = input = null;
  10027. return scale;
  10028. }
  10029. function scale(x) {
  10030. return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  10031. }
  10032. scale.invert = function(y) {
  10033. return (input || (input = piecewise(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
  10034. };
  10035. scale.domain = function(_) {
  10036. return arguments.length ? (domain = map$3.call(_, number$2), rescale()) : domain.slice();
  10037. };
  10038. scale.range = function(_) {
  10039. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10040. };
  10041. scale.rangeRound = function(_) {
  10042. return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
  10043. };
  10044. scale.clamp = function(_) {
  10045. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  10046. };
  10047. scale.interpolate = function(_) {
  10048. return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
  10049. };
  10050. return rescale();
  10051. }
  10052. function tickFormat(domain, count, specifier) {
  10053. var start = domain[0],
  10054. stop = domain[domain.length - 1],
  10055. step = tickStep(start, stop, count == null ? 10 : count),
  10056. precision;
  10057. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10058. switch (specifier.type) {
  10059. case "s": {
  10060. var value = Math.max(Math.abs(start), Math.abs(stop));
  10061. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10062. return exports.formatPrefix(specifier, value);
  10063. }
  10064. case "":
  10065. case "e":
  10066. case "g":
  10067. case "p":
  10068. case "r": {
  10069. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10070. break;
  10071. }
  10072. case "f":
  10073. case "%": {
  10074. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10075. break;
  10076. }
  10077. }
  10078. return exports.format(specifier);
  10079. }
  10080. function linearish(scale) {
  10081. var domain = scale.domain;
  10082. scale.ticks = function(count) {
  10083. var d = domain();
  10084. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10085. };
  10086. scale.tickFormat = function(count, specifier) {
  10087. return tickFormat(domain(), count, specifier);
  10088. };
  10089. scale.nice = function(count) {
  10090. if (count == null) count = 10;
  10091. var d = domain(),
  10092. i0 = 0,
  10093. i1 = d.length - 1,
  10094. start = d[i0],
  10095. stop = d[i1],
  10096. step;
  10097. if (stop < start) {
  10098. step = start, start = stop, stop = step;
  10099. step = i0, i0 = i1, i1 = step;
  10100. }
  10101. step = tickIncrement(start, stop, count);
  10102. if (step > 0) {
  10103. start = Math.floor(start / step) * step;
  10104. stop = Math.ceil(stop / step) * step;
  10105. step = tickIncrement(start, stop, count);
  10106. } else if (step < 0) {
  10107. start = Math.ceil(start * step) / step;
  10108. stop = Math.floor(stop * step) / step;
  10109. step = tickIncrement(start, stop, count);
  10110. }
  10111. if (step > 0) {
  10112. d[i0] = Math.floor(start / step) * step;
  10113. d[i1] = Math.ceil(stop / step) * step;
  10114. domain(d);
  10115. } else if (step < 0) {
  10116. d[i0] = Math.ceil(start * step) / step;
  10117. d[i1] = Math.floor(stop * step) / step;
  10118. domain(d);
  10119. }
  10120. return scale;
  10121. };
  10122. return scale;
  10123. }
  10124. function linear$2() {
  10125. var scale = continuous(deinterpolateLinear, reinterpolate);
  10126. scale.copy = function() {
  10127. return copy(scale, linear$2());
  10128. };
  10129. return linearish(scale);
  10130. }
  10131. function identity$6() {
  10132. var domain = [0, 1];
  10133. function scale(x) {
  10134. return +x;
  10135. }
  10136. scale.invert = scale;
  10137. scale.domain = scale.range = function(_) {
  10138. return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
  10139. };
  10140. scale.copy = function() {
  10141. return identity$6().domain(domain);
  10142. };
  10143. return linearish(scale);
  10144. }
  10145. function nice(domain, interval) {
  10146. domain = domain.slice();
  10147. var i0 = 0,
  10148. i1 = domain.length - 1,
  10149. x0 = domain[i0],
  10150. x1 = domain[i1],
  10151. t;
  10152. if (x1 < x0) {
  10153. t = i0, i0 = i1, i1 = t;
  10154. t = x0, x0 = x1, x1 = t;
  10155. }
  10156. domain[i0] = interval.floor(x0);
  10157. domain[i1] = interval.ceil(x1);
  10158. return domain;
  10159. }
  10160. function deinterpolate(a, b) {
  10161. return (b = Math.log(b / a))
  10162. ? function(x) { return Math.log(x / a) / b; }
  10163. : constant$9(b);
  10164. }
  10165. function reinterpolate$1(a, b) {
  10166. return a < 0
  10167. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  10168. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  10169. }
  10170. function pow10(x) {
  10171. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10172. }
  10173. function powp(base) {
  10174. return base === 10 ? pow10
  10175. : base === Math.E ? Math.exp
  10176. : function(x) { return Math.pow(base, x); };
  10177. }
  10178. function logp(base) {
  10179. return base === Math.E ? Math.log
  10180. : base === 10 && Math.log10
  10181. || base === 2 && Math.log2
  10182. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10183. }
  10184. function reflect(f) {
  10185. return function(x) {
  10186. return -f(-x);
  10187. };
  10188. }
  10189. function log$1() {
  10190. var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
  10191. domain = scale.domain,
  10192. base = 10,
  10193. logs = logp(10),
  10194. pows = powp(10);
  10195. function rescale() {
  10196. logs = logp(base), pows = powp(base);
  10197. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  10198. return scale;
  10199. }
  10200. scale.base = function(_) {
  10201. return arguments.length ? (base = +_, rescale()) : base;
  10202. };
  10203. scale.domain = function(_) {
  10204. return arguments.length ? (domain(_), rescale()) : domain();
  10205. };
  10206. scale.ticks = function(count) {
  10207. var d = domain(),
  10208. u = d[0],
  10209. v = d[d.length - 1],
  10210. r;
  10211. if (r = v < u) i = u, u = v, v = i;
  10212. var i = logs(u),
  10213. j = logs(v),
  10214. p,
  10215. k,
  10216. t,
  10217. n = count == null ? 10 : +count,
  10218. z = [];
  10219. if (!(base % 1) && j - i < n) {
  10220. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10221. if (u > 0) for (; i < j; ++i) {
  10222. for (k = 1, p = pows(i); k < base; ++k) {
  10223. t = p * k;
  10224. if (t < u) continue;
  10225. if (t > v) break;
  10226. z.push(t);
  10227. }
  10228. } else for (; i < j; ++i) {
  10229. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10230. t = p * k;
  10231. if (t < u) continue;
  10232. if (t > v) break;
  10233. z.push(t);
  10234. }
  10235. }
  10236. } else {
  10237. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10238. }
  10239. return r ? z.reverse() : z;
  10240. };
  10241. scale.tickFormat = function(count, specifier) {
  10242. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10243. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10244. if (count === Infinity) return specifier;
  10245. if (count == null) count = 10;
  10246. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10247. return function(d) {
  10248. var i = d / pows(Math.round(logs(d)));
  10249. if (i * base < base - 0.5) i *= base;
  10250. return i <= k ? specifier(d) : "";
  10251. };
  10252. };
  10253. scale.nice = function() {
  10254. return domain(nice(domain(), {
  10255. floor: function(x) { return pows(Math.floor(logs(x))); },
  10256. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10257. }));
  10258. };
  10259. scale.copy = function() {
  10260. return copy(scale, log$1().base(base));
  10261. };
  10262. return scale;
  10263. }
  10264. function raise$1(x, exponent) {
  10265. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10266. }
  10267. function pow$1() {
  10268. var exponent = 1,
  10269. scale = continuous(deinterpolate, reinterpolate),
  10270. domain = scale.domain;
  10271. function deinterpolate(a, b) {
  10272. return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
  10273. ? function(x) { return (raise$1(x, exponent) - a) / b; }
  10274. : constant$9(b);
  10275. }
  10276. function reinterpolate(a, b) {
  10277. b = raise$1(b, exponent) - (a = raise$1(a, exponent));
  10278. return function(t) { return raise$1(a + b * t, 1 / exponent); };
  10279. }
  10280. scale.exponent = function(_) {
  10281. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  10282. };
  10283. scale.copy = function() {
  10284. return copy(scale, pow$1().exponent(exponent));
  10285. };
  10286. return linearish(scale);
  10287. }
  10288. function sqrt$1() {
  10289. return pow$1().exponent(0.5);
  10290. }
  10291. function quantile$$1() {
  10292. var domain = [],
  10293. range = [],
  10294. thresholds = [];
  10295. function rescale() {
  10296. var i = 0, n = Math.max(1, range.length);
  10297. thresholds = new Array(n - 1);
  10298. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10299. return scale;
  10300. }
  10301. function scale(x) {
  10302. if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
  10303. }
  10304. scale.invertExtent = function(y) {
  10305. var i = range.indexOf(y);
  10306. return i < 0 ? [NaN, NaN] : [
  10307. i > 0 ? thresholds[i - 1] : domain[0],
  10308. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10309. ];
  10310. };
  10311. scale.domain = function(_) {
  10312. if (!arguments.length) return domain.slice();
  10313. domain = [];
  10314. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10315. domain.sort(ascending);
  10316. return rescale();
  10317. };
  10318. scale.range = function(_) {
  10319. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10320. };
  10321. scale.quantiles = function() {
  10322. return thresholds.slice();
  10323. };
  10324. scale.copy = function() {
  10325. return quantile$$1()
  10326. .domain(domain)
  10327. .range(range);
  10328. };
  10329. return scale;
  10330. }
  10331. function quantize$1() {
  10332. var x0 = 0,
  10333. x1 = 1,
  10334. n = 1,
  10335. domain = [0.5],
  10336. range = [0, 1];
  10337. function scale(x) {
  10338. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10339. }
  10340. function rescale() {
  10341. var i = -1;
  10342. domain = new Array(n);
  10343. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10344. return scale;
  10345. }
  10346. scale.domain = function(_) {
  10347. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10348. };
  10349. scale.range = function(_) {
  10350. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10351. };
  10352. scale.invertExtent = function(y) {
  10353. var i = range.indexOf(y);
  10354. return i < 0 ? [NaN, NaN]
  10355. : i < 1 ? [x0, domain[0]]
  10356. : i >= n ? [domain[n - 1], x1]
  10357. : [domain[i - 1], domain[i]];
  10358. };
  10359. scale.copy = function() {
  10360. return quantize$1()
  10361. .domain([x0, x1])
  10362. .range(range);
  10363. };
  10364. return linearish(scale);
  10365. }
  10366. function threshold$1() {
  10367. var domain = [0.5],
  10368. range = [0, 1],
  10369. n = 1;
  10370. function scale(x) {
  10371. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  10372. }
  10373. scale.domain = function(_) {
  10374. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10375. };
  10376. scale.range = function(_) {
  10377. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10378. };
  10379. scale.invertExtent = function(y) {
  10380. var i = range.indexOf(y);
  10381. return [domain[i - 1], domain[i]];
  10382. };
  10383. scale.copy = function() {
  10384. return threshold$1()
  10385. .domain(domain)
  10386. .range(range);
  10387. };
  10388. return scale;
  10389. }
  10390. var t0$1 = new Date;
  10391. var t1$1 = new Date;
  10392. function newInterval(floori, offseti, count, field) {
  10393. function interval(date) {
  10394. return floori(date = new Date(+date)), date;
  10395. }
  10396. interval.floor = interval;
  10397. interval.ceil = function(date) {
  10398. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10399. };
  10400. interval.round = function(date) {
  10401. var d0 = interval(date),
  10402. d1 = interval.ceil(date);
  10403. return date - d0 < d1 - date ? d0 : d1;
  10404. };
  10405. interval.offset = function(date, step) {
  10406. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10407. };
  10408. interval.range = function(start, stop, step) {
  10409. var range = [], previous;
  10410. start = interval.ceil(start);
  10411. step = step == null ? 1 : Math.floor(step);
  10412. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10413. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  10414. while (previous < start && start < stop);
  10415. return range;
  10416. };
  10417. interval.filter = function(test) {
  10418. return newInterval(function(date) {
  10419. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10420. }, function(date, step) {
  10421. if (date >= date) {
  10422. if (step < 0) while (++step <= 0) {
  10423. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10424. } else while (--step >= 0) {
  10425. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10426. }
  10427. }
  10428. });
  10429. };
  10430. if (count) {
  10431. interval.count = function(start, end) {
  10432. t0$1.setTime(+start), t1$1.setTime(+end);
  10433. floori(t0$1), floori(t1$1);
  10434. return Math.floor(count(t0$1, t1$1));
  10435. };
  10436. interval.every = function(step) {
  10437. step = Math.floor(step);
  10438. return !isFinite(step) || !(step > 0) ? null
  10439. : !(step > 1) ? interval
  10440. : interval.filter(field
  10441. ? function(d) { return field(d) % step === 0; }
  10442. : function(d) { return interval.count(0, d) % step === 0; });
  10443. };
  10444. }
  10445. return interval;
  10446. }
  10447. var millisecond = newInterval(function() {
  10448. // noop
  10449. }, function(date, step) {
  10450. date.setTime(+date + step);
  10451. }, function(start, end) {
  10452. return end - start;
  10453. });
  10454. // An optimized implementation for this simple case.
  10455. millisecond.every = function(k) {
  10456. k = Math.floor(k);
  10457. if (!isFinite(k) || !(k > 0)) return null;
  10458. if (!(k > 1)) return millisecond;
  10459. return newInterval(function(date) {
  10460. date.setTime(Math.floor(date / k) * k);
  10461. }, function(date, step) {
  10462. date.setTime(+date + step * k);
  10463. }, function(start, end) {
  10464. return (end - start) / k;
  10465. });
  10466. };
  10467. var milliseconds = millisecond.range;
  10468. var durationSecond$1 = 1e3;
  10469. var durationMinute$1 = 6e4;
  10470. var durationHour$1 = 36e5;
  10471. var durationDay$1 = 864e5;
  10472. var durationWeek$1 = 6048e5;
  10473. var second = newInterval(function(date) {
  10474. date.setTime(Math.floor(date / durationSecond$1) * durationSecond$1);
  10475. }, function(date, step) {
  10476. date.setTime(+date + step * durationSecond$1);
  10477. }, function(start, end) {
  10478. return (end - start) / durationSecond$1;
  10479. }, function(date) {
  10480. return date.getUTCSeconds();
  10481. });
  10482. var seconds = second.range;
  10483. var minute = newInterval(function(date) {
  10484. date.setTime(Math.floor(date / durationMinute$1) * durationMinute$1);
  10485. }, function(date, step) {
  10486. date.setTime(+date + step * durationMinute$1);
  10487. }, function(start, end) {
  10488. return (end - start) / durationMinute$1;
  10489. }, function(date) {
  10490. return date.getMinutes();
  10491. });
  10492. var minutes = minute.range;
  10493. var hour = newInterval(function(date) {
  10494. var offset = date.getTimezoneOffset() * durationMinute$1 % durationHour$1;
  10495. if (offset < 0) offset += durationHour$1;
  10496. date.setTime(Math.floor((+date - offset) / durationHour$1) * durationHour$1 + offset);
  10497. }, function(date, step) {
  10498. date.setTime(+date + step * durationHour$1);
  10499. }, function(start, end) {
  10500. return (end - start) / durationHour$1;
  10501. }, function(date) {
  10502. return date.getHours();
  10503. });
  10504. var hours = hour.range;
  10505. var day = newInterval(function(date) {
  10506. date.setHours(0, 0, 0, 0);
  10507. }, function(date, step) {
  10508. date.setDate(date.getDate() + step);
  10509. }, function(start, end) {
  10510. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationDay$1;
  10511. }, function(date) {
  10512. return date.getDate() - 1;
  10513. });
  10514. var days = day.range;
  10515. function weekday(i) {
  10516. return newInterval(function(date) {
  10517. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  10518. date.setHours(0, 0, 0, 0);
  10519. }, function(date, step) {
  10520. date.setDate(date.getDate() + step * 7);
  10521. }, function(start, end) {
  10522. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationWeek$1;
  10523. });
  10524. }
  10525. var sunday = weekday(0);
  10526. var monday = weekday(1);
  10527. var tuesday = weekday(2);
  10528. var wednesday = weekday(3);
  10529. var thursday = weekday(4);
  10530. var friday = weekday(5);
  10531. var saturday = weekday(6);
  10532. var sundays = sunday.range;
  10533. var mondays = monday.range;
  10534. var tuesdays = tuesday.range;
  10535. var wednesdays = wednesday.range;
  10536. var thursdays = thursday.range;
  10537. var fridays = friday.range;
  10538. var saturdays = saturday.range;
  10539. var month = newInterval(function(date) {
  10540. date.setDate(1);
  10541. date.setHours(0, 0, 0, 0);
  10542. }, function(date, step) {
  10543. date.setMonth(date.getMonth() + step);
  10544. }, function(start, end) {
  10545. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  10546. }, function(date) {
  10547. return date.getMonth();
  10548. });
  10549. var months = month.range;
  10550. var year = newInterval(function(date) {
  10551. date.setMonth(0, 1);
  10552. date.setHours(0, 0, 0, 0);
  10553. }, function(date, step) {
  10554. date.setFullYear(date.getFullYear() + step);
  10555. }, function(start, end) {
  10556. return end.getFullYear() - start.getFullYear();
  10557. }, function(date) {
  10558. return date.getFullYear();
  10559. });
  10560. // An optimized implementation for this simple case.
  10561. year.every = function(k) {
  10562. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10563. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  10564. date.setMonth(0, 1);
  10565. date.setHours(0, 0, 0, 0);
  10566. }, function(date, step) {
  10567. date.setFullYear(date.getFullYear() + step * k);
  10568. });
  10569. };
  10570. var years = year.range;
  10571. var utcMinute = newInterval(function(date) {
  10572. date.setUTCSeconds(0, 0);
  10573. }, function(date, step) {
  10574. date.setTime(+date + step * durationMinute$1);
  10575. }, function(start, end) {
  10576. return (end - start) / durationMinute$1;
  10577. }, function(date) {
  10578. return date.getUTCMinutes();
  10579. });
  10580. var utcMinutes = utcMinute.range;
  10581. var utcHour = newInterval(function(date) {
  10582. date.setUTCMinutes(0, 0, 0);
  10583. }, function(date, step) {
  10584. date.setTime(+date + step * durationHour$1);
  10585. }, function(start, end) {
  10586. return (end - start) / durationHour$1;
  10587. }, function(date) {
  10588. return date.getUTCHours();
  10589. });
  10590. var utcHours = utcHour.range;
  10591. var utcDay = newInterval(function(date) {
  10592. date.setUTCHours(0, 0, 0, 0);
  10593. }, function(date, step) {
  10594. date.setUTCDate(date.getUTCDate() + step);
  10595. }, function(start, end) {
  10596. return (end - start) / durationDay$1;
  10597. }, function(date) {
  10598. return date.getUTCDate() - 1;
  10599. });
  10600. var utcDays = utcDay.range;
  10601. function utcWeekday(i) {
  10602. return newInterval(function(date) {
  10603. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  10604. date.setUTCHours(0, 0, 0, 0);
  10605. }, function(date, step) {
  10606. date.setUTCDate(date.getUTCDate() + step * 7);
  10607. }, function(start, end) {
  10608. return (end - start) / durationWeek$1;
  10609. });
  10610. }
  10611. var utcSunday = utcWeekday(0);
  10612. var utcMonday = utcWeekday(1);
  10613. var utcTuesday = utcWeekday(2);
  10614. var utcWednesday = utcWeekday(3);
  10615. var utcThursday = utcWeekday(4);
  10616. var utcFriday = utcWeekday(5);
  10617. var utcSaturday = utcWeekday(6);
  10618. var utcSundays = utcSunday.range;
  10619. var utcMondays = utcMonday.range;
  10620. var utcTuesdays = utcTuesday.range;
  10621. var utcWednesdays = utcWednesday.range;
  10622. var utcThursdays = utcThursday.range;
  10623. var utcFridays = utcFriday.range;
  10624. var utcSaturdays = utcSaturday.range;
  10625. var utcMonth = newInterval(function(date) {
  10626. date.setUTCDate(1);
  10627. date.setUTCHours(0, 0, 0, 0);
  10628. }, function(date, step) {
  10629. date.setUTCMonth(date.getUTCMonth() + step);
  10630. }, function(start, end) {
  10631. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  10632. }, function(date) {
  10633. return date.getUTCMonth();
  10634. });
  10635. var utcMonths = utcMonth.range;
  10636. var utcYear = newInterval(function(date) {
  10637. date.setUTCMonth(0, 1);
  10638. date.setUTCHours(0, 0, 0, 0);
  10639. }, function(date, step) {
  10640. date.setUTCFullYear(date.getUTCFullYear() + step);
  10641. }, function(start, end) {
  10642. return end.getUTCFullYear() - start.getUTCFullYear();
  10643. }, function(date) {
  10644. return date.getUTCFullYear();
  10645. });
  10646. // An optimized implementation for this simple case.
  10647. utcYear.every = function(k) {
  10648. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  10649. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  10650. date.setUTCMonth(0, 1);
  10651. date.setUTCHours(0, 0, 0, 0);
  10652. }, function(date, step) {
  10653. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  10654. });
  10655. };
  10656. var utcYears = utcYear.range;
  10657. function localDate(d) {
  10658. if (0 <= d.y && d.y < 100) {
  10659. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  10660. date.setFullYear(d.y);
  10661. return date;
  10662. }
  10663. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  10664. }
  10665. function utcDate(d) {
  10666. if (0 <= d.y && d.y < 100) {
  10667. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  10668. date.setUTCFullYear(d.y);
  10669. return date;
  10670. }
  10671. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  10672. }
  10673. function newYear(y) {
  10674. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  10675. }
  10676. function formatLocale$1(locale) {
  10677. var locale_dateTime = locale.dateTime,
  10678. locale_date = locale.date,
  10679. locale_time = locale.time,
  10680. locale_periods = locale.periods,
  10681. locale_weekdays = locale.days,
  10682. locale_shortWeekdays = locale.shortDays,
  10683. locale_months = locale.months,
  10684. locale_shortMonths = locale.shortMonths;
  10685. var periodRe = formatRe(locale_periods),
  10686. periodLookup = formatLookup(locale_periods),
  10687. weekdayRe = formatRe(locale_weekdays),
  10688. weekdayLookup = formatLookup(locale_weekdays),
  10689. shortWeekdayRe = formatRe(locale_shortWeekdays),
  10690. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  10691. monthRe = formatRe(locale_months),
  10692. monthLookup = formatLookup(locale_months),
  10693. shortMonthRe = formatRe(locale_shortMonths),
  10694. shortMonthLookup = formatLookup(locale_shortMonths);
  10695. var formats = {
  10696. "a": formatShortWeekday,
  10697. "A": formatWeekday,
  10698. "b": formatShortMonth,
  10699. "B": formatMonth,
  10700. "c": null,
  10701. "d": formatDayOfMonth,
  10702. "e": formatDayOfMonth,
  10703. "f": formatMicroseconds,
  10704. "H": formatHour24,
  10705. "I": formatHour12,
  10706. "j": formatDayOfYear,
  10707. "L": formatMilliseconds,
  10708. "m": formatMonthNumber,
  10709. "M": formatMinutes,
  10710. "p": formatPeriod,
  10711. "Q": formatUnixTimestamp,
  10712. "s": formatUnixTimestampSeconds,
  10713. "S": formatSeconds,
  10714. "u": formatWeekdayNumberMonday,
  10715. "U": formatWeekNumberSunday,
  10716. "V": formatWeekNumberISO,
  10717. "w": formatWeekdayNumberSunday,
  10718. "W": formatWeekNumberMonday,
  10719. "x": null,
  10720. "X": null,
  10721. "y": formatYear,
  10722. "Y": formatFullYear,
  10723. "Z": formatZone,
  10724. "%": formatLiteralPercent
  10725. };
  10726. var utcFormats = {
  10727. "a": formatUTCShortWeekday,
  10728. "A": formatUTCWeekday,
  10729. "b": formatUTCShortMonth,
  10730. "B": formatUTCMonth,
  10731. "c": null,
  10732. "d": formatUTCDayOfMonth,
  10733. "e": formatUTCDayOfMonth,
  10734. "f": formatUTCMicroseconds,
  10735. "H": formatUTCHour24,
  10736. "I": formatUTCHour12,
  10737. "j": formatUTCDayOfYear,
  10738. "L": formatUTCMilliseconds,
  10739. "m": formatUTCMonthNumber,
  10740. "M": formatUTCMinutes,
  10741. "p": formatUTCPeriod,
  10742. "Q": formatUnixTimestamp,
  10743. "s": formatUnixTimestampSeconds,
  10744. "S": formatUTCSeconds,
  10745. "u": formatUTCWeekdayNumberMonday,
  10746. "U": formatUTCWeekNumberSunday,
  10747. "V": formatUTCWeekNumberISO,
  10748. "w": formatUTCWeekdayNumberSunday,
  10749. "W": formatUTCWeekNumberMonday,
  10750. "x": null,
  10751. "X": null,
  10752. "y": formatUTCYear,
  10753. "Y": formatUTCFullYear,
  10754. "Z": formatUTCZone,
  10755. "%": formatLiteralPercent
  10756. };
  10757. var parses = {
  10758. "a": parseShortWeekday,
  10759. "A": parseWeekday,
  10760. "b": parseShortMonth,
  10761. "B": parseMonth,
  10762. "c": parseLocaleDateTime,
  10763. "d": parseDayOfMonth,
  10764. "e": parseDayOfMonth,
  10765. "f": parseMicroseconds,
  10766. "H": parseHour24,
  10767. "I": parseHour24,
  10768. "j": parseDayOfYear,
  10769. "L": parseMilliseconds,
  10770. "m": parseMonthNumber,
  10771. "M": parseMinutes,
  10772. "p": parsePeriod,
  10773. "Q": parseUnixTimestamp,
  10774. "s": parseUnixTimestampSeconds,
  10775. "S": parseSeconds,
  10776. "u": parseWeekdayNumberMonday,
  10777. "U": parseWeekNumberSunday,
  10778. "V": parseWeekNumberISO,
  10779. "w": parseWeekdayNumberSunday,
  10780. "W": parseWeekNumberMonday,
  10781. "x": parseLocaleDate,
  10782. "X": parseLocaleTime,
  10783. "y": parseYear,
  10784. "Y": parseFullYear,
  10785. "Z": parseZone,
  10786. "%": parseLiteralPercent
  10787. };
  10788. // These recursive directive definitions must be deferred.
  10789. formats.x = newFormat(locale_date, formats);
  10790. formats.X = newFormat(locale_time, formats);
  10791. formats.c = newFormat(locale_dateTime, formats);
  10792. utcFormats.x = newFormat(locale_date, utcFormats);
  10793. utcFormats.X = newFormat(locale_time, utcFormats);
  10794. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  10795. function newFormat(specifier, formats) {
  10796. return function(date) {
  10797. var string = [],
  10798. i = -1,
  10799. j = 0,
  10800. n = specifier.length,
  10801. c,
  10802. pad,
  10803. format;
  10804. if (!(date instanceof Date)) date = new Date(+date);
  10805. while (++i < n) {
  10806. if (specifier.charCodeAt(i) === 37) {
  10807. string.push(specifier.slice(j, i));
  10808. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  10809. else pad = c === "e" ? " " : "0";
  10810. if (format = formats[c]) c = format(date, pad);
  10811. string.push(c);
  10812. j = i + 1;
  10813. }
  10814. }
  10815. string.push(specifier.slice(j, i));
  10816. return string.join("");
  10817. };
  10818. }
  10819. function newParse(specifier, newDate) {
  10820. return function(string) {
  10821. var d = newYear(1900),
  10822. i = parseSpecifier(d, specifier, string += "", 0),
  10823. week, day$$1;
  10824. if (i != string.length) return null;
  10825. // If a UNIX timestamp is specified, return it.
  10826. if ("Q" in d) return new Date(d.Q);
  10827. // The am-pm flag is 0 for AM, and 1 for PM.
  10828. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  10829. // Convert day-of-week and week-of-year to day-of-year.
  10830. if ("V" in d) {
  10831. if (d.V < 1 || d.V > 53) return null;
  10832. if (!("w" in d)) d.w = 1;
  10833. if ("Z" in d) {
  10834. week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
  10835. week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  10836. week = utcDay.offset(week, (d.V - 1) * 7);
  10837. d.y = week.getUTCFullYear();
  10838. d.m = week.getUTCMonth();
  10839. d.d = week.getUTCDate() + (d.w + 6) % 7;
  10840. } else {
  10841. week = newDate(newYear(d.y)), day$$1 = week.getDay();
  10842. week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
  10843. week = day.offset(week, (d.V - 1) * 7);
  10844. d.y = week.getFullYear();
  10845. d.m = week.getMonth();
  10846. d.d = week.getDate() + (d.w + 6) % 7;
  10847. }
  10848. } else if ("W" in d || "U" in d) {
  10849. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  10850. day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  10851. d.m = 0;
  10852. 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;
  10853. }
  10854. // If a time zone is specified, all fields are interpreted as UTC and then
  10855. // offset according to the specified time zone.
  10856. if ("Z" in d) {
  10857. d.H += d.Z / 100 | 0;
  10858. d.M += d.Z % 100;
  10859. return utcDate(d);
  10860. }
  10861. // Otherwise, all fields are in local time.
  10862. return newDate(d);
  10863. };
  10864. }
  10865. function parseSpecifier(d, specifier, string, j) {
  10866. var i = 0,
  10867. n = specifier.length,
  10868. m = string.length,
  10869. c,
  10870. parse;
  10871. while (i < n) {
  10872. if (j >= m) return -1;
  10873. c = specifier.charCodeAt(i++);
  10874. if (c === 37) {
  10875. c = specifier.charAt(i++);
  10876. parse = parses[c in pads ? specifier.charAt(i++) : c];
  10877. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  10878. } else if (c != string.charCodeAt(j++)) {
  10879. return -1;
  10880. }
  10881. }
  10882. return j;
  10883. }
  10884. function parsePeriod(d, string, i) {
  10885. var n = periodRe.exec(string.slice(i));
  10886. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10887. }
  10888. function parseShortWeekday(d, string, i) {
  10889. var n = shortWeekdayRe.exec(string.slice(i));
  10890. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10891. }
  10892. function parseWeekday(d, string, i) {
  10893. var n = weekdayRe.exec(string.slice(i));
  10894. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10895. }
  10896. function parseShortMonth(d, string, i) {
  10897. var n = shortMonthRe.exec(string.slice(i));
  10898. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10899. }
  10900. function parseMonth(d, string, i) {
  10901. var n = monthRe.exec(string.slice(i));
  10902. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  10903. }
  10904. function parseLocaleDateTime(d, string, i) {
  10905. return parseSpecifier(d, locale_dateTime, string, i);
  10906. }
  10907. function parseLocaleDate(d, string, i) {
  10908. return parseSpecifier(d, locale_date, string, i);
  10909. }
  10910. function parseLocaleTime(d, string, i) {
  10911. return parseSpecifier(d, locale_time, string, i);
  10912. }
  10913. function formatShortWeekday(d) {
  10914. return locale_shortWeekdays[d.getDay()];
  10915. }
  10916. function formatWeekday(d) {
  10917. return locale_weekdays[d.getDay()];
  10918. }
  10919. function formatShortMonth(d) {
  10920. return locale_shortMonths[d.getMonth()];
  10921. }
  10922. function formatMonth(d) {
  10923. return locale_months[d.getMonth()];
  10924. }
  10925. function formatPeriod(d) {
  10926. return locale_periods[+(d.getHours() >= 12)];
  10927. }
  10928. function formatUTCShortWeekday(d) {
  10929. return locale_shortWeekdays[d.getUTCDay()];
  10930. }
  10931. function formatUTCWeekday(d) {
  10932. return locale_weekdays[d.getUTCDay()];
  10933. }
  10934. function formatUTCShortMonth(d) {
  10935. return locale_shortMonths[d.getUTCMonth()];
  10936. }
  10937. function formatUTCMonth(d) {
  10938. return locale_months[d.getUTCMonth()];
  10939. }
  10940. function formatUTCPeriod(d) {
  10941. return locale_periods[+(d.getUTCHours() >= 12)];
  10942. }
  10943. return {
  10944. format: function(specifier) {
  10945. var f = newFormat(specifier += "", formats);
  10946. f.toString = function() { return specifier; };
  10947. return f;
  10948. },
  10949. parse: function(specifier) {
  10950. var p = newParse(specifier += "", localDate);
  10951. p.toString = function() { return specifier; };
  10952. return p;
  10953. },
  10954. utcFormat: function(specifier) {
  10955. var f = newFormat(specifier += "", utcFormats);
  10956. f.toString = function() { return specifier; };
  10957. return f;
  10958. },
  10959. utcParse: function(specifier) {
  10960. var p = newParse(specifier, utcDate);
  10961. p.toString = function() { return specifier; };
  10962. return p;
  10963. }
  10964. };
  10965. }
  10966. var pads = {"-": "", "_": " ", "0": "0"};
  10967. var numberRe = /^\s*\d+/;
  10968. var percentRe = /^%/;
  10969. var requoteRe = /[\\^$*+?|[\]().{}]/g;
  10970. function pad(value, fill, width) {
  10971. var sign = value < 0 ? "-" : "",
  10972. string = (sign ? -value : value) + "",
  10973. length = string.length;
  10974. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  10975. }
  10976. function requote(s) {
  10977. return s.replace(requoteRe, "\\$&");
  10978. }
  10979. function formatRe(names) {
  10980. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  10981. }
  10982. function formatLookup(names) {
  10983. var map = {}, i = -1, n = names.length;
  10984. while (++i < n) map[names[i].toLowerCase()] = i;
  10985. return map;
  10986. }
  10987. function parseWeekdayNumberSunday(d, string, i) {
  10988. var n = numberRe.exec(string.slice(i, i + 1));
  10989. return n ? (d.w = +n[0], i + n[0].length) : -1;
  10990. }
  10991. function parseWeekdayNumberMonday(d, string, i) {
  10992. var n = numberRe.exec(string.slice(i, i + 1));
  10993. return n ? (d.u = +n[0], i + n[0].length) : -1;
  10994. }
  10995. function parseWeekNumberSunday(d, string, i) {
  10996. var n = numberRe.exec(string.slice(i, i + 2));
  10997. return n ? (d.U = +n[0], i + n[0].length) : -1;
  10998. }
  10999. function parseWeekNumberISO(d, string, i) {
  11000. var n = numberRe.exec(string.slice(i, i + 2));
  11001. return n ? (d.V = +n[0], i + n[0].length) : -1;
  11002. }
  11003. function parseWeekNumberMonday(d, string, i) {
  11004. var n = numberRe.exec(string.slice(i, i + 2));
  11005. return n ? (d.W = +n[0], i + n[0].length) : -1;
  11006. }
  11007. function parseFullYear(d, string, i) {
  11008. var n = numberRe.exec(string.slice(i, i + 4));
  11009. return n ? (d.y = +n[0], i + n[0].length) : -1;
  11010. }
  11011. function parseYear(d, string, i) {
  11012. var n = numberRe.exec(string.slice(i, i + 2));
  11013. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  11014. }
  11015. function parseZone(d, string, i) {
  11016. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  11017. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  11018. }
  11019. function parseMonthNumber(d, string, i) {
  11020. var n = numberRe.exec(string.slice(i, i + 2));
  11021. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  11022. }
  11023. function parseDayOfMonth(d, string, i) {
  11024. var n = numberRe.exec(string.slice(i, i + 2));
  11025. return n ? (d.d = +n[0], i + n[0].length) : -1;
  11026. }
  11027. function parseDayOfYear(d, string, i) {
  11028. var n = numberRe.exec(string.slice(i, i + 3));
  11029. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  11030. }
  11031. function parseHour24(d, string, i) {
  11032. var n = numberRe.exec(string.slice(i, i + 2));
  11033. return n ? (d.H = +n[0], i + n[0].length) : -1;
  11034. }
  11035. function parseMinutes(d, string, i) {
  11036. var n = numberRe.exec(string.slice(i, i + 2));
  11037. return n ? (d.M = +n[0], i + n[0].length) : -1;
  11038. }
  11039. function parseSeconds(d, string, i) {
  11040. var n = numberRe.exec(string.slice(i, i + 2));
  11041. return n ? (d.S = +n[0], i + n[0].length) : -1;
  11042. }
  11043. function parseMilliseconds(d, string, i) {
  11044. var n = numberRe.exec(string.slice(i, i + 3));
  11045. return n ? (d.L = +n[0], i + n[0].length) : -1;
  11046. }
  11047. function parseMicroseconds(d, string, i) {
  11048. var n = numberRe.exec(string.slice(i, i + 6));
  11049. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  11050. }
  11051. function parseLiteralPercent(d, string, i) {
  11052. var n = percentRe.exec(string.slice(i, i + 1));
  11053. return n ? i + n[0].length : -1;
  11054. }
  11055. function parseUnixTimestamp(d, string, i) {
  11056. var n = numberRe.exec(string.slice(i));
  11057. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  11058. }
  11059. function parseUnixTimestampSeconds(d, string, i) {
  11060. var n = numberRe.exec(string.slice(i));
  11061. return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
  11062. }
  11063. function formatDayOfMonth(d, p) {
  11064. return pad(d.getDate(), p, 2);
  11065. }
  11066. function formatHour24(d, p) {
  11067. return pad(d.getHours(), p, 2);
  11068. }
  11069. function formatHour12(d, p) {
  11070. return pad(d.getHours() % 12 || 12, p, 2);
  11071. }
  11072. function formatDayOfYear(d, p) {
  11073. return pad(1 + day.count(year(d), d), p, 3);
  11074. }
  11075. function formatMilliseconds(d, p) {
  11076. return pad(d.getMilliseconds(), p, 3);
  11077. }
  11078. function formatMicroseconds(d, p) {
  11079. return formatMilliseconds(d, p) + "000";
  11080. }
  11081. function formatMonthNumber(d, p) {
  11082. return pad(d.getMonth() + 1, p, 2);
  11083. }
  11084. function formatMinutes(d, p) {
  11085. return pad(d.getMinutes(), p, 2);
  11086. }
  11087. function formatSeconds(d, p) {
  11088. return pad(d.getSeconds(), p, 2);
  11089. }
  11090. function formatWeekdayNumberMonday(d) {
  11091. var day$$1 = d.getDay();
  11092. return day$$1 === 0 ? 7 : day$$1;
  11093. }
  11094. function formatWeekNumberSunday(d, p) {
  11095. return pad(sunday.count(year(d), d), p, 2);
  11096. }
  11097. function formatWeekNumberISO(d, p) {
  11098. var day$$1 = d.getDay();
  11099. d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
  11100. return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  11101. }
  11102. function formatWeekdayNumberSunday(d) {
  11103. return d.getDay();
  11104. }
  11105. function formatWeekNumberMonday(d, p) {
  11106. return pad(monday.count(year(d), d), p, 2);
  11107. }
  11108. function formatYear(d, p) {
  11109. return pad(d.getFullYear() % 100, p, 2);
  11110. }
  11111. function formatFullYear(d, p) {
  11112. return pad(d.getFullYear() % 10000, p, 4);
  11113. }
  11114. function formatZone(d) {
  11115. var z = d.getTimezoneOffset();
  11116. return (z > 0 ? "-" : (z *= -1, "+"))
  11117. + pad(z / 60 | 0, "0", 2)
  11118. + pad(z % 60, "0", 2);
  11119. }
  11120. function formatUTCDayOfMonth(d, p) {
  11121. return pad(d.getUTCDate(), p, 2);
  11122. }
  11123. function formatUTCHour24(d, p) {
  11124. return pad(d.getUTCHours(), p, 2);
  11125. }
  11126. function formatUTCHour12(d, p) {
  11127. return pad(d.getUTCHours() % 12 || 12, p, 2);
  11128. }
  11129. function formatUTCDayOfYear(d, p) {
  11130. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  11131. }
  11132. function formatUTCMilliseconds(d, p) {
  11133. return pad(d.getUTCMilliseconds(), p, 3);
  11134. }
  11135. function formatUTCMicroseconds(d, p) {
  11136. return formatUTCMilliseconds(d, p) + "000";
  11137. }
  11138. function formatUTCMonthNumber(d, p) {
  11139. return pad(d.getUTCMonth() + 1, p, 2);
  11140. }
  11141. function formatUTCMinutes(d, p) {
  11142. return pad(d.getUTCMinutes(), p, 2);
  11143. }
  11144. function formatUTCSeconds(d, p) {
  11145. return pad(d.getUTCSeconds(), p, 2);
  11146. }
  11147. function formatUTCWeekdayNumberMonday(d) {
  11148. var dow = d.getUTCDay();
  11149. return dow === 0 ? 7 : dow;
  11150. }
  11151. function formatUTCWeekNumberSunday(d, p) {
  11152. return pad(utcSunday.count(utcYear(d), d), p, 2);
  11153. }
  11154. function formatUTCWeekNumberISO(d, p) {
  11155. var day$$1 = d.getUTCDay();
  11156. d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
  11157. return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  11158. }
  11159. function formatUTCWeekdayNumberSunday(d) {
  11160. return d.getUTCDay();
  11161. }
  11162. function formatUTCWeekNumberMonday(d, p) {
  11163. return pad(utcMonday.count(utcYear(d), d), p, 2);
  11164. }
  11165. function formatUTCYear(d, p) {
  11166. return pad(d.getUTCFullYear() % 100, p, 2);
  11167. }
  11168. function formatUTCFullYear(d, p) {
  11169. return pad(d.getUTCFullYear() % 10000, p, 4);
  11170. }
  11171. function formatUTCZone() {
  11172. return "+0000";
  11173. }
  11174. function formatLiteralPercent() {
  11175. return "%";
  11176. }
  11177. function formatUnixTimestamp(d) {
  11178. return +d;
  11179. }
  11180. function formatUnixTimestampSeconds(d) {
  11181. return Math.floor(+d / 1000);
  11182. }
  11183. var locale$1;
  11184. defaultLocale$1({
  11185. dateTime: "%x, %X",
  11186. date: "%-m/%-d/%Y",
  11187. time: "%-I:%M:%S %p",
  11188. periods: ["AM", "PM"],
  11189. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11190. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11191. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11192. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11193. });
  11194. function defaultLocale$1(definition) {
  11195. locale$1 = formatLocale$1(definition);
  11196. exports.timeFormat = locale$1.format;
  11197. exports.timeParse = locale$1.parse;
  11198. exports.utcFormat = locale$1.utcFormat;
  11199. exports.utcParse = locale$1.utcParse;
  11200. return locale$1;
  11201. }
  11202. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11203. function formatIsoNative(date) {
  11204. return date.toISOString();
  11205. }
  11206. var formatIso = Date.prototype.toISOString
  11207. ? formatIsoNative
  11208. : exports.utcFormat(isoSpecifier);
  11209. function parseIsoNative(string) {
  11210. var date = new Date(string);
  11211. return isNaN(date) ? null : date;
  11212. }
  11213. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11214. ? parseIsoNative
  11215. : exports.utcParse(isoSpecifier);
  11216. var durationSecond = 1000;
  11217. var durationMinute = durationSecond * 60;
  11218. var durationHour = durationMinute * 60;
  11219. var durationDay = durationHour * 24;
  11220. var durationWeek = durationDay * 7;
  11221. var durationMonth = durationDay * 30;
  11222. var durationYear = durationDay * 365;
  11223. function date$1(t) {
  11224. return new Date(t);
  11225. }
  11226. function number$3(t) {
  11227. return t instanceof Date ? +t : +new Date(+t);
  11228. }
  11229. function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
  11230. var scale = continuous(deinterpolateLinear, reinterpolate),
  11231. invert = scale.invert,
  11232. domain = scale.domain;
  11233. var formatMillisecond = format(".%L"),
  11234. formatSecond = format(":%S"),
  11235. formatMinute = format("%I:%M"),
  11236. formatHour = format("%I %p"),
  11237. formatDay = format("%a %d"),
  11238. formatWeek = format("%b %d"),
  11239. formatMonth = format("%B"),
  11240. formatYear = format("%Y");
  11241. var tickIntervals = [
  11242. [second$$1, 1, durationSecond],
  11243. [second$$1, 5, 5 * durationSecond],
  11244. [second$$1, 15, 15 * durationSecond],
  11245. [second$$1, 30, 30 * durationSecond],
  11246. [minute$$1, 1, durationMinute],
  11247. [minute$$1, 5, 5 * durationMinute],
  11248. [minute$$1, 15, 15 * durationMinute],
  11249. [minute$$1, 30, 30 * durationMinute],
  11250. [ hour$$1, 1, durationHour ],
  11251. [ hour$$1, 3, 3 * durationHour ],
  11252. [ hour$$1, 6, 6 * durationHour ],
  11253. [ hour$$1, 12, 12 * durationHour ],
  11254. [ day$$1, 1, durationDay ],
  11255. [ day$$1, 2, 2 * durationDay ],
  11256. [ week, 1, durationWeek ],
  11257. [ month$$1, 1, durationMonth ],
  11258. [ month$$1, 3, 3 * durationMonth ],
  11259. [ year$$1, 1, durationYear ]
  11260. ];
  11261. function tickFormat(date) {
  11262. return (second$$1(date) < date ? formatMillisecond
  11263. : minute$$1(date) < date ? formatSecond
  11264. : hour$$1(date) < date ? formatMinute
  11265. : day$$1(date) < date ? formatHour
  11266. : month$$1(date) < date ? (week(date) < date ? formatDay : formatWeek)
  11267. : year$$1(date) < date ? formatMonth
  11268. : formatYear)(date);
  11269. }
  11270. function tickInterval(interval, start, stop, step) {
  11271. if (interval == null) interval = 10;
  11272. // If a desired tick count is specified, pick a reasonable tick interval
  11273. // based on the extent of the domain and a rough estimate of tick size.
  11274. // Otherwise, assume interval is already a time interval and use it.
  11275. if (typeof interval === "number") {
  11276. var target = Math.abs(stop - start) / interval,
  11277. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11278. if (i === tickIntervals.length) {
  11279. step = tickStep(start / durationYear, stop / durationYear, interval);
  11280. interval = year$$1;
  11281. } else if (i) {
  11282. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11283. step = i[1];
  11284. interval = i[0];
  11285. } else {
  11286. step = Math.max(tickStep(start, stop, interval), 1);
  11287. interval = millisecond$$1;
  11288. }
  11289. }
  11290. return step == null ? interval : interval.every(step);
  11291. }
  11292. scale.invert = function(y) {
  11293. return new Date(invert(y));
  11294. };
  11295. scale.domain = function(_) {
  11296. return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
  11297. };
  11298. scale.ticks = function(interval, step) {
  11299. var d = domain(),
  11300. t0 = d[0],
  11301. t1 = d[d.length - 1],
  11302. r = t1 < t0,
  11303. t;
  11304. if (r) t = t0, t0 = t1, t1 = t;
  11305. t = tickInterval(interval, t0, t1, step);
  11306. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11307. return r ? t.reverse() : t;
  11308. };
  11309. scale.tickFormat = function(count, specifier) {
  11310. return specifier == null ? tickFormat : format(specifier);
  11311. };
  11312. scale.nice = function(interval, step) {
  11313. var d = domain();
  11314. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11315. ? domain(nice(d, interval))
  11316. : scale;
  11317. };
  11318. scale.copy = function() {
  11319. return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
  11320. };
  11321. return scale;
  11322. }
  11323. function time() {
  11324. return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  11325. }
  11326. function utcTime() {
  11327. return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  11328. }
  11329. function colors(s) {
  11330. return s.match(/.{6}/g).map(function(x) {
  11331. return "#" + x;
  11332. });
  11333. }
  11334. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  11335. var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
  11336. var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
  11337. var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
  11338. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  11339. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11340. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  11341. var rainbow = cubehelix();
  11342. function rainbow$1(t) {
  11343. if (t < 0 || t > 1) t -= Math.floor(t);
  11344. var ts = Math.abs(t - 0.5);
  11345. rainbow.h = 360 * t - 100;
  11346. rainbow.s = 1.5 - 1.5 * ts;
  11347. rainbow.l = 0.8 - 0.9 * ts;
  11348. return rainbow + "";
  11349. }
  11350. function ramp(range) {
  11351. var n = range.length;
  11352. return function(t) {
  11353. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  11354. };
  11355. }
  11356. var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  11357. var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  11358. var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  11359. var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  11360. function sequential(interpolator) {
  11361. var x0 = 0,
  11362. x1 = 1,
  11363. clamp = false;
  11364. function scale(x) {
  11365. var t = (x - x0) / (x1 - x0);
  11366. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  11367. }
  11368. scale.domain = function(_) {
  11369. return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
  11370. };
  11371. scale.clamp = function(_) {
  11372. return arguments.length ? (clamp = !!_, scale) : clamp;
  11373. };
  11374. scale.interpolator = function(_) {
  11375. return arguments.length ? (interpolator = _, scale) : interpolator;
  11376. };
  11377. scale.copy = function() {
  11378. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  11379. };
  11380. return linearish(scale);
  11381. }
  11382. function constant$10(x) {
  11383. return function constant() {
  11384. return x;
  11385. };
  11386. }
  11387. var abs$1 = Math.abs;
  11388. var atan2$1 = Math.atan2;
  11389. var cos$2 = Math.cos;
  11390. var max$2 = Math.max;
  11391. var min$1 = Math.min;
  11392. var sin$2 = Math.sin;
  11393. var sqrt$2 = Math.sqrt;
  11394. var epsilon$3 = 1e-12;
  11395. var pi$4 = Math.PI;
  11396. var halfPi$3 = pi$4 / 2;
  11397. var tau$4 = 2 * pi$4;
  11398. function acos$1(x) {
  11399. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  11400. }
  11401. function asin$1(x) {
  11402. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  11403. }
  11404. function arcInnerRadius(d) {
  11405. return d.innerRadius;
  11406. }
  11407. function arcOuterRadius(d) {
  11408. return d.outerRadius;
  11409. }
  11410. function arcStartAngle(d) {
  11411. return d.startAngle;
  11412. }
  11413. function arcEndAngle(d) {
  11414. return d.endAngle;
  11415. }
  11416. function arcPadAngle(d) {
  11417. return d && d.padAngle; // Note: optional!
  11418. }
  11419. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  11420. var x10 = x1 - x0, y10 = y1 - y0,
  11421. x32 = x3 - x2, y32 = y3 - y2,
  11422. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  11423. return [x0 + t * x10, y0 + t * y10];
  11424. }
  11425. // Compute perpendicular offset line of length rc.
  11426. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  11427. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  11428. var x01 = x0 - x1,
  11429. y01 = y0 - y1,
  11430. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  11431. ox = lo * y01,
  11432. oy = -lo * x01,
  11433. x11 = x0 + ox,
  11434. y11 = y0 + oy,
  11435. x10 = x1 + ox,
  11436. y10 = y1 + oy,
  11437. x00 = (x11 + x10) / 2,
  11438. y00 = (y11 + y10) / 2,
  11439. dx = x10 - x11,
  11440. dy = y10 - y11,
  11441. d2 = dx * dx + dy * dy,
  11442. r = r1 - rc,
  11443. D = x11 * y10 - x10 * y11,
  11444. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  11445. cx0 = (D * dy - dx * d) / d2,
  11446. cy0 = (-D * dx - dy * d) / d2,
  11447. cx1 = (D * dy + dx * d) / d2,
  11448. cy1 = (-D * dx + dy * d) / d2,
  11449. dx0 = cx0 - x00,
  11450. dy0 = cy0 - y00,
  11451. dx1 = cx1 - x00,
  11452. dy1 = cy1 - y00;
  11453. // Pick the closer of the two intersection points.
  11454. // TODO Is there a faster way to determine which intersection to use?
  11455. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  11456. return {
  11457. cx: cx0,
  11458. cy: cy0,
  11459. x01: -ox,
  11460. y01: -oy,
  11461. x11: cx0 * (r1 / r - 1),
  11462. y11: cy0 * (r1 / r - 1)
  11463. };
  11464. }
  11465. function arc() {
  11466. var innerRadius = arcInnerRadius,
  11467. outerRadius = arcOuterRadius,
  11468. cornerRadius = constant$10(0),
  11469. padRadius = null,
  11470. startAngle = arcStartAngle,
  11471. endAngle = arcEndAngle,
  11472. padAngle = arcPadAngle,
  11473. context = null;
  11474. function arc() {
  11475. var buffer,
  11476. r,
  11477. r0 = +innerRadius.apply(this, arguments),
  11478. r1 = +outerRadius.apply(this, arguments),
  11479. a0 = startAngle.apply(this, arguments) - halfPi$3,
  11480. a1 = endAngle.apply(this, arguments) - halfPi$3,
  11481. da = abs$1(a1 - a0),
  11482. cw = a1 > a0;
  11483. if (!context) context = buffer = path();
  11484. // Ensure that the outer radius is always larger than the inner radius.
  11485. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  11486. // Is it a point?
  11487. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  11488. // Or is it a circle or annulus?
  11489. else if (da > tau$4 - epsilon$3) {
  11490. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  11491. context.arc(0, 0, r1, a0, a1, !cw);
  11492. if (r0 > epsilon$3) {
  11493. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  11494. context.arc(0, 0, r0, a1, a0, cw);
  11495. }
  11496. }
  11497. // Or is it a circular or annular sector?
  11498. else {
  11499. var a01 = a0,
  11500. a11 = a1,
  11501. a00 = a0,
  11502. a10 = a1,
  11503. da0 = da,
  11504. da1 = da,
  11505. ap = padAngle.apply(this, arguments) / 2,
  11506. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  11507. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  11508. rc0 = rc,
  11509. rc1 = rc,
  11510. t0,
  11511. t1;
  11512. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  11513. if (rp > epsilon$3) {
  11514. var p0 = asin$1(rp / r0 * sin$2(ap)),
  11515. p1 = asin$1(rp / r1 * sin$2(ap));
  11516. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  11517. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  11518. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  11519. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  11520. }
  11521. var x01 = r1 * cos$2(a01),
  11522. y01 = r1 * sin$2(a01),
  11523. x10 = r0 * cos$2(a10),
  11524. y10 = r0 * sin$2(a10);
  11525. // Apply rounded corners?
  11526. if (rc > epsilon$3) {
  11527. var x11 = r1 * cos$2(a11),
  11528. y11 = r1 * sin$2(a11),
  11529. x00 = r0 * cos$2(a00),
  11530. y00 = r0 * sin$2(a00);
  11531. // Restrict the corner radius according to the sector angle.
  11532. if (da < pi$4) {
  11533. var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  11534. ax = x01 - oc[0],
  11535. ay = y01 - oc[1],
  11536. bx = x11 - oc[0],
  11537. by = y11 - oc[1],
  11538. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  11539. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  11540. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  11541. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  11542. }
  11543. }
  11544. // Is the sector collapsed to a line?
  11545. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  11546. // Does the sector’s outer ring have rounded corners?
  11547. else if (rc1 > epsilon$3) {
  11548. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  11549. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  11550. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  11551. // Have the corners merged?
  11552. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  11553. // Otherwise, draw the two corners and the ring.
  11554. else {
  11555. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  11556. 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);
  11557. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  11558. }
  11559. }
  11560. // Or is the outer ring just a circular arc?
  11561. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  11562. // Is there no inner ring, and it’s a circular sector?
  11563. // Or perhaps it’s an annular sector collapsed due to padding?
  11564. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  11565. // Does the sector’s inner ring (or point) have rounded corners?
  11566. else if (rc0 > epsilon$3) {
  11567. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  11568. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  11569. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  11570. // Have the corners merged?
  11571. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  11572. // Otherwise, draw the two corners and the ring.
  11573. else {
  11574. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  11575. 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);
  11576. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  11577. }
  11578. }
  11579. // Or is the inner ring just a circular arc?
  11580. else context.arc(0, 0, r0, a10, a00, cw);
  11581. }
  11582. context.closePath();
  11583. if (buffer) return context = null, buffer + "" || null;
  11584. }
  11585. arc.centroid = function() {
  11586. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  11587. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  11588. return [cos$2(a) * r, sin$2(a) * r];
  11589. };
  11590. arc.innerRadius = function(_) {
  11591. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : innerRadius;
  11592. };
  11593. arc.outerRadius = function(_) {
  11594. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : outerRadius;
  11595. };
  11596. arc.cornerRadius = function(_) {
  11597. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : cornerRadius;
  11598. };
  11599. arc.padRadius = function(_) {
  11600. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), arc) : padRadius;
  11601. };
  11602. arc.startAngle = function(_) {
  11603. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : startAngle;
  11604. };
  11605. arc.endAngle = function(_) {
  11606. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : endAngle;
  11607. };
  11608. arc.padAngle = function(_) {
  11609. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : padAngle;
  11610. };
  11611. arc.context = function(_) {
  11612. return arguments.length ? (context = _ == null ? null : _, arc) : context;
  11613. };
  11614. return arc;
  11615. }
  11616. function Linear(context) {
  11617. this._context = context;
  11618. }
  11619. Linear.prototype = {
  11620. areaStart: function() {
  11621. this._line = 0;
  11622. },
  11623. areaEnd: function() {
  11624. this._line = NaN;
  11625. },
  11626. lineStart: function() {
  11627. this._point = 0;
  11628. },
  11629. lineEnd: function() {
  11630. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  11631. this._line = 1 - this._line;
  11632. },
  11633. point: function(x, y) {
  11634. x = +x, y = +y;
  11635. switch (this._point) {
  11636. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  11637. case 1: this._point = 2; // proceed
  11638. default: this._context.lineTo(x, y); break;
  11639. }
  11640. }
  11641. };
  11642. function curveLinear(context) {
  11643. return new Linear(context);
  11644. }
  11645. function x$3(p) {
  11646. return p[0];
  11647. }
  11648. function y$3(p) {
  11649. return p[1];
  11650. }
  11651. function line() {
  11652. var x$$1 = x$3,
  11653. y$$1 = y$3,
  11654. defined = constant$10(true),
  11655. context = null,
  11656. curve = curveLinear,
  11657. output = null;
  11658. function line(data) {
  11659. var i,
  11660. n = data.length,
  11661. d,
  11662. defined0 = false,
  11663. buffer;
  11664. if (context == null) output = curve(buffer = path());
  11665. for (i = 0; i <= n; ++i) {
  11666. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  11667. if (defined0 = !defined0) output.lineStart();
  11668. else output.lineEnd();
  11669. }
  11670. if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
  11671. }
  11672. if (buffer) return output = null, buffer + "" || null;
  11673. }
  11674. line.x = function(_) {
  11675. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : x$$1;
  11676. };
  11677. line.y = function(_) {
  11678. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : y$$1;
  11679. };
  11680. line.defined = function(_) {
  11681. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), line) : defined;
  11682. };
  11683. line.curve = function(_) {
  11684. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  11685. };
  11686. line.context = function(_) {
  11687. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  11688. };
  11689. return line;
  11690. }
  11691. function area$2() {
  11692. var x0 = x$3,
  11693. x1 = null,
  11694. y0 = constant$10(0),
  11695. y1 = y$3,
  11696. defined = constant$10(true),
  11697. context = null,
  11698. curve = curveLinear,
  11699. output = null;
  11700. function area(data) {
  11701. var i,
  11702. j,
  11703. k,
  11704. n = data.length,
  11705. d,
  11706. defined0 = false,
  11707. buffer,
  11708. x0z = new Array(n),
  11709. y0z = new Array(n);
  11710. if (context == null) output = curve(buffer = path());
  11711. for (i = 0; i <= n; ++i) {
  11712. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  11713. if (defined0 = !defined0) {
  11714. j = i;
  11715. output.areaStart();
  11716. output.lineStart();
  11717. } else {
  11718. output.lineEnd();
  11719. output.lineStart();
  11720. for (k = i - 1; k >= j; --k) {
  11721. output.point(x0z[k], y0z[k]);
  11722. }
  11723. output.lineEnd();
  11724. output.areaEnd();
  11725. }
  11726. }
  11727. if (defined0) {
  11728. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  11729. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  11730. }
  11731. }
  11732. if (buffer) return output = null, buffer + "" || null;
  11733. }
  11734. function arealine() {
  11735. return line().defined(defined).curve(curve).context(context);
  11736. }
  11737. area.x = function(_) {
  11738. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), x1 = null, area) : x0;
  11739. };
  11740. area.x0 = function(_) {
  11741. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), area) : x0;
  11742. };
  11743. area.x1 = function(_) {
  11744. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : x1;
  11745. };
  11746. area.y = function(_) {
  11747. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), y1 = null, area) : y0;
  11748. };
  11749. area.y0 = function(_) {
  11750. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), area) : y0;
  11751. };
  11752. area.y1 = function(_) {
  11753. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : y1;
  11754. };
  11755. area.lineX0 =
  11756. area.lineY0 = function() {
  11757. return arealine().x(x0).y(y0);
  11758. };
  11759. area.lineY1 = function() {
  11760. return arealine().x(x0).y(y1);
  11761. };
  11762. area.lineX1 = function() {
  11763. return arealine().x(x1).y(y0);
  11764. };
  11765. area.defined = function(_) {
  11766. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), area) : defined;
  11767. };
  11768. area.curve = function(_) {
  11769. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  11770. };
  11771. area.context = function(_) {
  11772. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  11773. };
  11774. return area;
  11775. }
  11776. function descending$1(a, b) {
  11777. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  11778. }
  11779. function identity$7(d) {
  11780. return d;
  11781. }
  11782. function pie() {
  11783. var value = identity$7,
  11784. sortValues = descending$1,
  11785. sort = null,
  11786. startAngle = constant$10(0),
  11787. endAngle = constant$10(tau$4),
  11788. padAngle = constant$10(0);
  11789. function pie(data) {
  11790. var i,
  11791. n = data.length,
  11792. j,
  11793. k,
  11794. sum = 0,
  11795. index = new Array(n),
  11796. arcs = new Array(n),
  11797. a0 = +startAngle.apply(this, arguments),
  11798. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  11799. a1,
  11800. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  11801. pa = p * (da < 0 ? -1 : 1),
  11802. v;
  11803. for (i = 0; i < n; ++i) {
  11804. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  11805. sum += v;
  11806. }
  11807. }
  11808. // Optionally sort the arcs by previously-computed values or by data.
  11809. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  11810. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  11811. // Compute the arcs! They are stored in the original data's order.
  11812. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  11813. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  11814. data: data[j],
  11815. index: i,
  11816. value: v,
  11817. startAngle: a0,
  11818. endAngle: a1,
  11819. padAngle: p
  11820. };
  11821. }
  11822. return arcs;
  11823. }
  11824. pie.value = function(_) {
  11825. return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), pie) : value;
  11826. };
  11827. pie.sortValues = function(_) {
  11828. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  11829. };
  11830. pie.sort = function(_) {
  11831. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  11832. };
  11833. pie.startAngle = function(_) {
  11834. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : startAngle;
  11835. };
  11836. pie.endAngle = function(_) {
  11837. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : endAngle;
  11838. };
  11839. pie.padAngle = function(_) {
  11840. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : padAngle;
  11841. };
  11842. return pie;
  11843. }
  11844. var curveRadialLinear = curveRadial(curveLinear);
  11845. function Radial(curve) {
  11846. this._curve = curve;
  11847. }
  11848. Radial.prototype = {
  11849. areaStart: function() {
  11850. this._curve.areaStart();
  11851. },
  11852. areaEnd: function() {
  11853. this._curve.areaEnd();
  11854. },
  11855. lineStart: function() {
  11856. this._curve.lineStart();
  11857. },
  11858. lineEnd: function() {
  11859. this._curve.lineEnd();
  11860. },
  11861. point: function(a, r) {
  11862. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  11863. }
  11864. };
  11865. function curveRadial(curve) {
  11866. function radial(context) {
  11867. return new Radial(curve(context));
  11868. }
  11869. radial._curve = curve;
  11870. return radial;
  11871. }
  11872. function lineRadial(l) {
  11873. var c = l.curve;
  11874. l.angle = l.x, delete l.x;
  11875. l.radius = l.y, delete l.y;
  11876. l.curve = function(_) {
  11877. return arguments.length ? c(curveRadial(_)) : c()._curve;
  11878. };
  11879. return l;
  11880. }
  11881. function lineRadial$1() {
  11882. return lineRadial(line().curve(curveRadialLinear));
  11883. }
  11884. function areaRadial() {
  11885. var a = area$2().curve(curveRadialLinear),
  11886. c = a.curve,
  11887. x0 = a.lineX0,
  11888. x1 = a.lineX1,
  11889. y0 = a.lineY0,
  11890. y1 = a.lineY1;
  11891. a.angle = a.x, delete a.x;
  11892. a.startAngle = a.x0, delete a.x0;
  11893. a.endAngle = a.x1, delete a.x1;
  11894. a.radius = a.y, delete a.y;
  11895. a.innerRadius = a.y0, delete a.y0;
  11896. a.outerRadius = a.y1, delete a.y1;
  11897. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  11898. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  11899. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  11900. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  11901. a.curve = function(_) {
  11902. return arguments.length ? c(curveRadial(_)) : c()._curve;
  11903. };
  11904. return a;
  11905. }
  11906. function pointRadial(x, y) {
  11907. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  11908. }
  11909. var slice$6 = Array.prototype.slice;
  11910. function linkSource(d) {
  11911. return d.source;
  11912. }
  11913. function linkTarget(d) {
  11914. return d.target;
  11915. }
  11916. function link$2(curve) {
  11917. var source = linkSource,
  11918. target = linkTarget,
  11919. x$$1 = x$3,
  11920. y$$1 = y$3,
  11921. context = null;
  11922. function link() {
  11923. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  11924. if (!context) context = buffer = path();
  11925. 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));
  11926. if (buffer) return context = null, buffer + "" || null;
  11927. }
  11928. link.source = function(_) {
  11929. return arguments.length ? (source = _, link) : source;
  11930. };
  11931. link.target = function(_) {
  11932. return arguments.length ? (target = _, link) : target;
  11933. };
  11934. link.x = function(_) {
  11935. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : x$$1;
  11936. };
  11937. link.y = function(_) {
  11938. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : y$$1;
  11939. };
  11940. link.context = function(_) {
  11941. return arguments.length ? (context = _ == null ? null : _, link) : context;
  11942. };
  11943. return link;
  11944. }
  11945. function curveHorizontal(context, x0, y0, x1, y1) {
  11946. context.moveTo(x0, y0);
  11947. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  11948. }
  11949. function curveVertical(context, x0, y0, x1, y1) {
  11950. context.moveTo(x0, y0);
  11951. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  11952. }
  11953. function curveRadial$1(context, x0, y0, x1, y1) {
  11954. var p0 = pointRadial(x0, y0),
  11955. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  11956. p2 = pointRadial(x1, y0),
  11957. p3 = pointRadial(x1, y1);
  11958. context.moveTo(p0[0], p0[1]);
  11959. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  11960. }
  11961. function linkHorizontal() {
  11962. return link$2(curveHorizontal);
  11963. }
  11964. function linkVertical() {
  11965. return link$2(curveVertical);
  11966. }
  11967. function linkRadial() {
  11968. var l = link$2(curveRadial$1);
  11969. l.angle = l.x, delete l.x;
  11970. l.radius = l.y, delete l.y;
  11971. return l;
  11972. }
  11973. var circle$2 = {
  11974. draw: function(context, size) {
  11975. var r = Math.sqrt(size / pi$4);
  11976. context.moveTo(r, 0);
  11977. context.arc(0, 0, r, 0, tau$4);
  11978. }
  11979. };
  11980. var cross$2 = {
  11981. draw: function(context, size) {
  11982. var r = Math.sqrt(size / 5) / 2;
  11983. context.moveTo(-3 * r, -r);
  11984. context.lineTo(-r, -r);
  11985. context.lineTo(-r, -3 * r);
  11986. context.lineTo(r, -3 * r);
  11987. context.lineTo(r, -r);
  11988. context.lineTo(3 * r, -r);
  11989. context.lineTo(3 * r, r);
  11990. context.lineTo(r, r);
  11991. context.lineTo(r, 3 * r);
  11992. context.lineTo(-r, 3 * r);
  11993. context.lineTo(-r, r);
  11994. context.lineTo(-3 * r, r);
  11995. context.closePath();
  11996. }
  11997. };
  11998. var tan30 = Math.sqrt(1 / 3);
  11999. var tan30_2 = tan30 * 2;
  12000. var diamond = {
  12001. draw: function(context, size) {
  12002. var y = Math.sqrt(size / tan30_2),
  12003. x = y * tan30;
  12004. context.moveTo(0, -y);
  12005. context.lineTo(x, 0);
  12006. context.lineTo(0, y);
  12007. context.lineTo(-x, 0);
  12008. context.closePath();
  12009. }
  12010. };
  12011. var ka = 0.89081309152928522810;
  12012. var kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10);
  12013. var kx = Math.sin(tau$4 / 10) * kr;
  12014. var ky = -Math.cos(tau$4 / 10) * kr;
  12015. var star = {
  12016. draw: function(context, size) {
  12017. var r = Math.sqrt(size * ka),
  12018. x = kx * r,
  12019. y = ky * r;
  12020. context.moveTo(0, -r);
  12021. context.lineTo(x, y);
  12022. for (var i = 1; i < 5; ++i) {
  12023. var a = tau$4 * i / 5,
  12024. c = Math.cos(a),
  12025. s = Math.sin(a);
  12026. context.lineTo(s * r, -c * r);
  12027. context.lineTo(c * x - s * y, s * x + c * y);
  12028. }
  12029. context.closePath();
  12030. }
  12031. };
  12032. var square = {
  12033. draw: function(context, size) {
  12034. var w = Math.sqrt(size),
  12035. x = -w / 2;
  12036. context.rect(x, x, w, w);
  12037. }
  12038. };
  12039. var sqrt3 = Math.sqrt(3);
  12040. var triangle = {
  12041. draw: function(context, size) {
  12042. var y = -Math.sqrt(size / (sqrt3 * 3));
  12043. context.moveTo(0, y * 2);
  12044. context.lineTo(-sqrt3 * y, -y);
  12045. context.lineTo(sqrt3 * y, -y);
  12046. context.closePath();
  12047. }
  12048. };
  12049. var c = -0.5;
  12050. var s = Math.sqrt(3) / 2;
  12051. var k = 1 / Math.sqrt(12);
  12052. var a = (k / 2 + 1) * 3;
  12053. var wye = {
  12054. draw: function(context, size) {
  12055. var r = Math.sqrt(size / a),
  12056. x0 = r / 2,
  12057. y0 = r * k,
  12058. x1 = x0,
  12059. y1 = r * k + r,
  12060. x2 = -x1,
  12061. y2 = y1;
  12062. context.moveTo(x0, y0);
  12063. context.lineTo(x1, y1);
  12064. context.lineTo(x2, y2);
  12065. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  12066. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  12067. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  12068. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  12069. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  12070. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  12071. context.closePath();
  12072. }
  12073. };
  12074. var symbols = [
  12075. circle$2,
  12076. cross$2,
  12077. diamond,
  12078. square,
  12079. star,
  12080. triangle,
  12081. wye
  12082. ];
  12083. function symbol() {
  12084. var type = constant$10(circle$2),
  12085. size = constant$10(64),
  12086. context = null;
  12087. function symbol() {
  12088. var buffer;
  12089. if (!context) context = buffer = path();
  12090. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  12091. if (buffer) return context = null, buffer + "" || null;
  12092. }
  12093. symbol.type = function(_) {
  12094. return arguments.length ? (type = typeof _ === "function" ? _ : constant$10(_), symbol) : type;
  12095. };
  12096. symbol.size = function(_) {
  12097. return arguments.length ? (size = typeof _ === "function" ? _ : constant$10(+_), symbol) : size;
  12098. };
  12099. symbol.context = function(_) {
  12100. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  12101. };
  12102. return symbol;
  12103. }
  12104. function noop$2() {}
  12105. function point$2(that, x, y) {
  12106. that._context.bezierCurveTo(
  12107. (2 * that._x0 + that._x1) / 3,
  12108. (2 * that._y0 + that._y1) / 3,
  12109. (that._x0 + 2 * that._x1) / 3,
  12110. (that._y0 + 2 * that._y1) / 3,
  12111. (that._x0 + 4 * that._x1 + x) / 6,
  12112. (that._y0 + 4 * that._y1 + y) / 6
  12113. );
  12114. }
  12115. function Basis(context) {
  12116. this._context = context;
  12117. }
  12118. Basis.prototype = {
  12119. areaStart: function() {
  12120. this._line = 0;
  12121. },
  12122. areaEnd: function() {
  12123. this._line = NaN;
  12124. },
  12125. lineStart: function() {
  12126. this._x0 = this._x1 =
  12127. this._y0 = this._y1 = NaN;
  12128. this._point = 0;
  12129. },
  12130. lineEnd: function() {
  12131. switch (this._point) {
  12132. case 3: point$2(this, this._x1, this._y1); // proceed
  12133. case 2: this._context.lineTo(this._x1, this._y1); break;
  12134. }
  12135. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12136. this._line = 1 - this._line;
  12137. },
  12138. point: function(x, y) {
  12139. x = +x, y = +y;
  12140. switch (this._point) {
  12141. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12142. case 1: this._point = 2; break;
  12143. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  12144. default: point$2(this, x, y); break;
  12145. }
  12146. this._x0 = this._x1, this._x1 = x;
  12147. this._y0 = this._y1, this._y1 = y;
  12148. }
  12149. };
  12150. function basis$2(context) {
  12151. return new Basis(context);
  12152. }
  12153. function BasisClosed(context) {
  12154. this._context = context;
  12155. }
  12156. BasisClosed.prototype = {
  12157. areaStart: noop$2,
  12158. areaEnd: noop$2,
  12159. lineStart: function() {
  12160. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  12161. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  12162. this._point = 0;
  12163. },
  12164. lineEnd: function() {
  12165. switch (this._point) {
  12166. case 1: {
  12167. this._context.moveTo(this._x2, this._y2);
  12168. this._context.closePath();
  12169. break;
  12170. }
  12171. case 2: {
  12172. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  12173. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  12174. this._context.closePath();
  12175. break;
  12176. }
  12177. case 3: {
  12178. this.point(this._x2, this._y2);
  12179. this.point(this._x3, this._y3);
  12180. this.point(this._x4, this._y4);
  12181. break;
  12182. }
  12183. }
  12184. },
  12185. point: function(x, y) {
  12186. x = +x, y = +y;
  12187. switch (this._point) {
  12188. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  12189. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  12190. 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;
  12191. default: point$2(this, x, y); break;
  12192. }
  12193. this._x0 = this._x1, this._x1 = x;
  12194. this._y0 = this._y1, this._y1 = y;
  12195. }
  12196. };
  12197. function basisClosed$1(context) {
  12198. return new BasisClosed(context);
  12199. }
  12200. function BasisOpen(context) {
  12201. this._context = context;
  12202. }
  12203. BasisOpen.prototype = {
  12204. areaStart: function() {
  12205. this._line = 0;
  12206. },
  12207. areaEnd: function() {
  12208. this._line = NaN;
  12209. },
  12210. lineStart: function() {
  12211. this._x0 = this._x1 =
  12212. this._y0 = this._y1 = NaN;
  12213. this._point = 0;
  12214. },
  12215. lineEnd: function() {
  12216. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12217. this._line = 1 - this._line;
  12218. },
  12219. point: function(x, y) {
  12220. x = +x, y = +y;
  12221. switch (this._point) {
  12222. case 0: this._point = 1; break;
  12223. case 1: this._point = 2; break;
  12224. 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;
  12225. case 3: this._point = 4; // proceed
  12226. default: point$2(this, x, y); break;
  12227. }
  12228. this._x0 = this._x1, this._x1 = x;
  12229. this._y0 = this._y1, this._y1 = y;
  12230. }
  12231. };
  12232. function basisOpen(context) {
  12233. return new BasisOpen(context);
  12234. }
  12235. function Bundle(context, beta) {
  12236. this._basis = new Basis(context);
  12237. this._beta = beta;
  12238. }
  12239. Bundle.prototype = {
  12240. lineStart: function() {
  12241. this._x = [];
  12242. this._y = [];
  12243. this._basis.lineStart();
  12244. },
  12245. lineEnd: function() {
  12246. var x = this._x,
  12247. y = this._y,
  12248. j = x.length - 1;
  12249. if (j > 0) {
  12250. var x0 = x[0],
  12251. y0 = y[0],
  12252. dx = x[j] - x0,
  12253. dy = y[j] - y0,
  12254. i = -1,
  12255. t;
  12256. while (++i <= j) {
  12257. t = i / j;
  12258. this._basis.point(
  12259. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  12260. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  12261. );
  12262. }
  12263. }
  12264. this._x = this._y = null;
  12265. this._basis.lineEnd();
  12266. },
  12267. point: function(x, y) {
  12268. this._x.push(+x);
  12269. this._y.push(+y);
  12270. }
  12271. };
  12272. var bundle = (function custom(beta) {
  12273. function bundle(context) {
  12274. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  12275. }
  12276. bundle.beta = function(beta) {
  12277. return custom(+beta);
  12278. };
  12279. return bundle;
  12280. })(0.85);
  12281. function point$3(that, x, y) {
  12282. that._context.bezierCurveTo(
  12283. that._x1 + that._k * (that._x2 - that._x0),
  12284. that._y1 + that._k * (that._y2 - that._y0),
  12285. that._x2 + that._k * (that._x1 - x),
  12286. that._y2 + that._k * (that._y1 - y),
  12287. that._x2,
  12288. that._y2
  12289. );
  12290. }
  12291. function Cardinal(context, tension) {
  12292. this._context = context;
  12293. this._k = (1 - tension) / 6;
  12294. }
  12295. Cardinal.prototype = {
  12296. areaStart: function() {
  12297. this._line = 0;
  12298. },
  12299. areaEnd: function() {
  12300. this._line = NaN;
  12301. },
  12302. lineStart: function() {
  12303. this._x0 = this._x1 = this._x2 =
  12304. this._y0 = this._y1 = this._y2 = NaN;
  12305. this._point = 0;
  12306. },
  12307. lineEnd: function() {
  12308. switch (this._point) {
  12309. case 2: this._context.lineTo(this._x2, this._y2); break;
  12310. case 3: point$3(this, this._x1, this._y1); break;
  12311. }
  12312. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12313. this._line = 1 - this._line;
  12314. },
  12315. point: function(x, y) {
  12316. x = +x, y = +y;
  12317. switch (this._point) {
  12318. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12319. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  12320. case 2: this._point = 3; // proceed
  12321. default: point$3(this, x, y); break;
  12322. }
  12323. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12324. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12325. }
  12326. };
  12327. var cardinal = (function custom(tension) {
  12328. function cardinal(context) {
  12329. return new Cardinal(context, tension);
  12330. }
  12331. cardinal.tension = function(tension) {
  12332. return custom(+tension);
  12333. };
  12334. return cardinal;
  12335. })(0);
  12336. function CardinalClosed(context, tension) {
  12337. this._context = context;
  12338. this._k = (1 - tension) / 6;
  12339. }
  12340. CardinalClosed.prototype = {
  12341. areaStart: noop$2,
  12342. areaEnd: noop$2,
  12343. lineStart: function() {
  12344. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12345. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12346. this._point = 0;
  12347. },
  12348. lineEnd: function() {
  12349. switch (this._point) {
  12350. case 1: {
  12351. this._context.moveTo(this._x3, this._y3);
  12352. this._context.closePath();
  12353. break;
  12354. }
  12355. case 2: {
  12356. this._context.lineTo(this._x3, this._y3);
  12357. this._context.closePath();
  12358. break;
  12359. }
  12360. case 3: {
  12361. this.point(this._x3, this._y3);
  12362. this.point(this._x4, this._y4);
  12363. this.point(this._x5, this._y5);
  12364. break;
  12365. }
  12366. }
  12367. },
  12368. point: function(x, y) {
  12369. x = +x, y = +y;
  12370. switch (this._point) {
  12371. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12372. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12373. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12374. default: point$3(this, x, y); break;
  12375. }
  12376. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12377. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12378. }
  12379. };
  12380. var cardinalClosed = (function custom(tension) {
  12381. function cardinal$$1(context) {
  12382. return new CardinalClosed(context, tension);
  12383. }
  12384. cardinal$$1.tension = function(tension) {
  12385. return custom(+tension);
  12386. };
  12387. return cardinal$$1;
  12388. })(0);
  12389. function CardinalOpen(context, tension) {
  12390. this._context = context;
  12391. this._k = (1 - tension) / 6;
  12392. }
  12393. CardinalOpen.prototype = {
  12394. areaStart: function() {
  12395. this._line = 0;
  12396. },
  12397. areaEnd: function() {
  12398. this._line = NaN;
  12399. },
  12400. lineStart: function() {
  12401. this._x0 = this._x1 = this._x2 =
  12402. this._y0 = this._y1 = this._y2 = NaN;
  12403. this._point = 0;
  12404. },
  12405. lineEnd: function() {
  12406. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12407. this._line = 1 - this._line;
  12408. },
  12409. point: function(x, y) {
  12410. x = +x, y = +y;
  12411. switch (this._point) {
  12412. case 0: this._point = 1; break;
  12413. case 1: this._point = 2; break;
  12414. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12415. case 3: this._point = 4; // proceed
  12416. default: point$3(this, x, y); break;
  12417. }
  12418. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12419. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12420. }
  12421. };
  12422. var cardinalOpen = (function custom(tension) {
  12423. function cardinal$$1(context) {
  12424. return new CardinalOpen(context, tension);
  12425. }
  12426. cardinal$$1.tension = function(tension) {
  12427. return custom(+tension);
  12428. };
  12429. return cardinal$$1;
  12430. })(0);
  12431. function point$4(that, x, y) {
  12432. var x1 = that._x1,
  12433. y1 = that._y1,
  12434. x2 = that._x2,
  12435. y2 = that._y2;
  12436. if (that._l01_a > epsilon$3) {
  12437. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  12438. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  12439. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  12440. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  12441. }
  12442. if (that._l23_a > epsilon$3) {
  12443. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  12444. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  12445. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  12446. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  12447. }
  12448. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  12449. }
  12450. function CatmullRom(context, alpha) {
  12451. this._context = context;
  12452. this._alpha = alpha;
  12453. }
  12454. CatmullRom.prototype = {
  12455. areaStart: function() {
  12456. this._line = 0;
  12457. },
  12458. areaEnd: function() {
  12459. this._line = NaN;
  12460. },
  12461. lineStart: function() {
  12462. this._x0 = this._x1 = this._x2 =
  12463. this._y0 = this._y1 = this._y2 = NaN;
  12464. this._l01_a = this._l12_a = this._l23_a =
  12465. this._l01_2a = this._l12_2a = this._l23_2a =
  12466. this._point = 0;
  12467. },
  12468. lineEnd: function() {
  12469. switch (this._point) {
  12470. case 2: this._context.lineTo(this._x2, this._y2); break;
  12471. case 3: this.point(this._x2, this._y2); break;
  12472. }
  12473. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12474. this._line = 1 - this._line;
  12475. },
  12476. point: function(x, y) {
  12477. x = +x, y = +y;
  12478. if (this._point) {
  12479. var x23 = this._x2 - x,
  12480. y23 = this._y2 - y;
  12481. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12482. }
  12483. switch (this._point) {
  12484. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12485. case 1: this._point = 2; break;
  12486. case 2: this._point = 3; // proceed
  12487. default: point$4(this, x, y); break;
  12488. }
  12489. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12490. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12491. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12492. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12493. }
  12494. };
  12495. var catmullRom = (function custom(alpha) {
  12496. function catmullRom(context) {
  12497. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  12498. }
  12499. catmullRom.alpha = function(alpha) {
  12500. return custom(+alpha);
  12501. };
  12502. return catmullRom;
  12503. })(0.5);
  12504. function CatmullRomClosed(context, alpha) {
  12505. this._context = context;
  12506. this._alpha = alpha;
  12507. }
  12508. CatmullRomClosed.prototype = {
  12509. areaStart: noop$2,
  12510. areaEnd: noop$2,
  12511. lineStart: function() {
  12512. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  12513. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  12514. this._l01_a = this._l12_a = this._l23_a =
  12515. this._l01_2a = this._l12_2a = this._l23_2a =
  12516. this._point = 0;
  12517. },
  12518. lineEnd: function() {
  12519. switch (this._point) {
  12520. case 1: {
  12521. this._context.moveTo(this._x3, this._y3);
  12522. this._context.closePath();
  12523. break;
  12524. }
  12525. case 2: {
  12526. this._context.lineTo(this._x3, this._y3);
  12527. this._context.closePath();
  12528. break;
  12529. }
  12530. case 3: {
  12531. this.point(this._x3, this._y3);
  12532. this.point(this._x4, this._y4);
  12533. this.point(this._x5, this._y5);
  12534. break;
  12535. }
  12536. }
  12537. },
  12538. point: function(x, y) {
  12539. x = +x, y = +y;
  12540. if (this._point) {
  12541. var x23 = this._x2 - x,
  12542. y23 = this._y2 - y;
  12543. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12544. }
  12545. switch (this._point) {
  12546. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  12547. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  12548. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  12549. default: point$4(this, x, y); break;
  12550. }
  12551. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12552. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12553. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12554. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12555. }
  12556. };
  12557. var catmullRomClosed = (function custom(alpha) {
  12558. function catmullRom$$1(context) {
  12559. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  12560. }
  12561. catmullRom$$1.alpha = function(alpha) {
  12562. return custom(+alpha);
  12563. };
  12564. return catmullRom$$1;
  12565. })(0.5);
  12566. function CatmullRomOpen(context, alpha) {
  12567. this._context = context;
  12568. this._alpha = alpha;
  12569. }
  12570. CatmullRomOpen.prototype = {
  12571. areaStart: function() {
  12572. this._line = 0;
  12573. },
  12574. areaEnd: function() {
  12575. this._line = NaN;
  12576. },
  12577. lineStart: function() {
  12578. this._x0 = this._x1 = this._x2 =
  12579. this._y0 = this._y1 = this._y2 = NaN;
  12580. this._l01_a = this._l12_a = this._l23_a =
  12581. this._l01_2a = this._l12_2a = this._l23_2a =
  12582. this._point = 0;
  12583. },
  12584. lineEnd: function() {
  12585. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  12586. this._line = 1 - this._line;
  12587. },
  12588. point: function(x, y) {
  12589. x = +x, y = +y;
  12590. if (this._point) {
  12591. var x23 = this._x2 - x,
  12592. y23 = this._y2 - y;
  12593. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  12594. }
  12595. switch (this._point) {
  12596. case 0: this._point = 1; break;
  12597. case 1: this._point = 2; break;
  12598. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  12599. case 3: this._point = 4; // proceed
  12600. default: point$4(this, x, y); break;
  12601. }
  12602. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  12603. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  12604. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  12605. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  12606. }
  12607. };
  12608. var catmullRomOpen = (function custom(alpha) {
  12609. function catmullRom$$1(context) {
  12610. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  12611. }
  12612. catmullRom$$1.alpha = function(alpha) {
  12613. return custom(+alpha);
  12614. };
  12615. return catmullRom$$1;
  12616. })(0.5);
  12617. function LinearClosed(context) {
  12618. this._context = context;
  12619. }
  12620. LinearClosed.prototype = {
  12621. areaStart: noop$2,
  12622. areaEnd: noop$2,
  12623. lineStart: function() {
  12624. this._point = 0;
  12625. },
  12626. lineEnd: function() {
  12627. if (this._point) this._context.closePath();
  12628. },
  12629. point: function(x, y) {
  12630. x = +x, y = +y;
  12631. if (this._point) this._context.lineTo(x, y);
  12632. else this._point = 1, this._context.moveTo(x, y);
  12633. }
  12634. };
  12635. function linearClosed(context) {
  12636. return new LinearClosed(context);
  12637. }
  12638. function sign$1(x) {
  12639. return x < 0 ? -1 : 1;
  12640. }
  12641. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  12642. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  12643. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  12644. // NOV(II), P. 443, 1990.
  12645. function slope3(that, x2, y2) {
  12646. var h0 = that._x1 - that._x0,
  12647. h1 = x2 - that._x1,
  12648. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  12649. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  12650. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  12651. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  12652. }
  12653. // Calculate a one-sided slope.
  12654. function slope2(that, t) {
  12655. var h = that._x1 - that._x0;
  12656. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  12657. }
  12658. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  12659. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  12660. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  12661. function point$5(that, t0, t1) {
  12662. var x0 = that._x0,
  12663. y0 = that._y0,
  12664. x1 = that._x1,
  12665. y1 = that._y1,
  12666. dx = (x1 - x0) / 3;
  12667. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  12668. }
  12669. function MonotoneX(context) {
  12670. this._context = context;
  12671. }
  12672. MonotoneX.prototype = {
  12673. areaStart: function() {
  12674. this._line = 0;
  12675. },
  12676. areaEnd: function() {
  12677. this._line = NaN;
  12678. },
  12679. lineStart: function() {
  12680. this._x0 = this._x1 =
  12681. this._y0 = this._y1 =
  12682. this._t0 = NaN;
  12683. this._point = 0;
  12684. },
  12685. lineEnd: function() {
  12686. switch (this._point) {
  12687. case 2: this._context.lineTo(this._x1, this._y1); break;
  12688. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  12689. }
  12690. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12691. this._line = 1 - this._line;
  12692. },
  12693. point: function(x, y) {
  12694. var t1 = NaN;
  12695. x = +x, y = +y;
  12696. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  12697. switch (this._point) {
  12698. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12699. case 1: this._point = 2; break;
  12700. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  12701. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  12702. }
  12703. this._x0 = this._x1, this._x1 = x;
  12704. this._y0 = this._y1, this._y1 = y;
  12705. this._t0 = t1;
  12706. }
  12707. };
  12708. function MonotoneY(context) {
  12709. this._context = new ReflectContext(context);
  12710. }
  12711. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  12712. MonotoneX.prototype.point.call(this, y, x);
  12713. };
  12714. function ReflectContext(context) {
  12715. this._context = context;
  12716. }
  12717. ReflectContext.prototype = {
  12718. moveTo: function(x, y) { this._context.moveTo(y, x); },
  12719. closePath: function() { this._context.closePath(); },
  12720. lineTo: function(x, y) { this._context.lineTo(y, x); },
  12721. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  12722. };
  12723. function monotoneX(context) {
  12724. return new MonotoneX(context);
  12725. }
  12726. function monotoneY(context) {
  12727. return new MonotoneY(context);
  12728. }
  12729. function Natural(context) {
  12730. this._context = context;
  12731. }
  12732. Natural.prototype = {
  12733. areaStart: function() {
  12734. this._line = 0;
  12735. },
  12736. areaEnd: function() {
  12737. this._line = NaN;
  12738. },
  12739. lineStart: function() {
  12740. this._x = [];
  12741. this._y = [];
  12742. },
  12743. lineEnd: function() {
  12744. var x = this._x,
  12745. y = this._y,
  12746. n = x.length;
  12747. if (n) {
  12748. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  12749. if (n === 2) {
  12750. this._context.lineTo(x[1], y[1]);
  12751. } else {
  12752. var px = controlPoints(x),
  12753. py = controlPoints(y);
  12754. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  12755. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  12756. }
  12757. }
  12758. }
  12759. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  12760. this._line = 1 - this._line;
  12761. this._x = this._y = null;
  12762. },
  12763. point: function(x, y) {
  12764. this._x.push(+x);
  12765. this._y.push(+y);
  12766. }
  12767. };
  12768. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  12769. function controlPoints(x) {
  12770. var i,
  12771. n = x.length - 1,
  12772. m,
  12773. a = new Array(n),
  12774. b = new Array(n),
  12775. r = new Array(n);
  12776. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  12777. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  12778. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  12779. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  12780. a[n - 1] = r[n - 1] / b[n - 1];
  12781. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  12782. b[n - 1] = (x[n] + a[n - 1]) / 2;
  12783. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  12784. return [a, b];
  12785. }
  12786. function natural(context) {
  12787. return new Natural(context);
  12788. }
  12789. function Step(context, t) {
  12790. this._context = context;
  12791. this._t = t;
  12792. }
  12793. Step.prototype = {
  12794. areaStart: function() {
  12795. this._line = 0;
  12796. },
  12797. areaEnd: function() {
  12798. this._line = NaN;
  12799. },
  12800. lineStart: function() {
  12801. this._x = this._y = NaN;
  12802. this._point = 0;
  12803. },
  12804. lineEnd: function() {
  12805. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  12806. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12807. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  12808. },
  12809. point: function(x, y) {
  12810. x = +x, y = +y;
  12811. switch (this._point) {
  12812. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12813. case 1: this._point = 2; // proceed
  12814. default: {
  12815. if (this._t <= 0) {
  12816. this._context.lineTo(this._x, y);
  12817. this._context.lineTo(x, y);
  12818. } else {
  12819. var x1 = this._x * (1 - this._t) + x * this._t;
  12820. this._context.lineTo(x1, this._y);
  12821. this._context.lineTo(x1, y);
  12822. }
  12823. break;
  12824. }
  12825. }
  12826. this._x = x, this._y = y;
  12827. }
  12828. };
  12829. function step(context) {
  12830. return new Step(context, 0.5);
  12831. }
  12832. function stepBefore(context) {
  12833. return new Step(context, 0);
  12834. }
  12835. function stepAfter(context) {
  12836. return new Step(context, 1);
  12837. }
  12838. function none$1(series, order) {
  12839. if (!((n = series.length) > 1)) return;
  12840. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  12841. s0 = s1, s1 = series[order[i]];
  12842. for (j = 0; j < m; ++j) {
  12843. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  12844. }
  12845. }
  12846. }
  12847. function none$2(series) {
  12848. var n = series.length, o = new Array(n);
  12849. while (--n >= 0) o[n] = n;
  12850. return o;
  12851. }
  12852. function stackValue(d, key) {
  12853. return d[key];
  12854. }
  12855. function stack() {
  12856. var keys = constant$10([]),
  12857. order = none$2,
  12858. offset = none$1,
  12859. value = stackValue;
  12860. function stack(data) {
  12861. var kz = keys.apply(this, arguments),
  12862. i,
  12863. m = data.length,
  12864. n = kz.length,
  12865. sz = new Array(n),
  12866. oz;
  12867. for (i = 0; i < n; ++i) {
  12868. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  12869. si[j] = sij = [0, +value(data[j], ki, j, data)];
  12870. sij.data = data[j];
  12871. }
  12872. si.key = ki;
  12873. }
  12874. for (i = 0, oz = order(sz); i < n; ++i) {
  12875. sz[oz[i]].index = i;
  12876. }
  12877. offset(sz, oz);
  12878. return sz;
  12879. }
  12880. stack.keys = function(_) {
  12881. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : keys;
  12882. };
  12883. stack.value = function(_) {
  12884. return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), stack) : value;
  12885. };
  12886. stack.order = function(_) {
  12887. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : order;
  12888. };
  12889. stack.offset = function(_) {
  12890. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  12891. };
  12892. return stack;
  12893. }
  12894. function expand(series, order) {
  12895. if (!((n = series.length) > 0)) return;
  12896. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  12897. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  12898. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  12899. }
  12900. none$1(series, order);
  12901. }
  12902. function diverging(series, order) {
  12903. if (!((n = series.length) > 1)) return;
  12904. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  12905. for (yp = yn = 0, i = 0; i < n; ++i) {
  12906. if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
  12907. d[0] = yp, d[1] = yp += dy;
  12908. } else if (dy < 0) {
  12909. d[1] = yn, d[0] = yn += dy;
  12910. } else {
  12911. d[0] = yp;
  12912. }
  12913. }
  12914. }
  12915. }
  12916. function silhouette(series, order) {
  12917. if (!((n = series.length) > 0)) return;
  12918. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  12919. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  12920. s0[j][1] += s0[j][0] = -y / 2;
  12921. }
  12922. none$1(series, order);
  12923. }
  12924. function wiggle(series, order) {
  12925. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  12926. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  12927. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  12928. var si = series[order[i]],
  12929. sij0 = si[j][1] || 0,
  12930. sij1 = si[j - 1][1] || 0,
  12931. s3 = (sij0 - sij1) / 2;
  12932. for (var k = 0; k < i; ++k) {
  12933. var sk = series[order[k]],
  12934. skj0 = sk[j][1] || 0,
  12935. skj1 = sk[j - 1][1] || 0;
  12936. s3 += skj0 - skj1;
  12937. }
  12938. s1 += sij0, s2 += s3 * sij0;
  12939. }
  12940. s0[j - 1][1] += s0[j - 1][0] = y;
  12941. if (s1) y -= s2 / s1;
  12942. }
  12943. s0[j - 1][1] += s0[j - 1][0] = y;
  12944. none$1(series, order);
  12945. }
  12946. function ascending$2(series) {
  12947. var sums = series.map(sum$2);
  12948. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  12949. }
  12950. function sum$2(series) {
  12951. var s = 0, i = -1, n = series.length, v;
  12952. while (++i < n) if (v = +series[i][1]) s += v;
  12953. return s;
  12954. }
  12955. function descending$2(series) {
  12956. return ascending$2(series).reverse();
  12957. }
  12958. function insideOut(series) {
  12959. var n = series.length,
  12960. i,
  12961. j,
  12962. sums = series.map(sum$2),
  12963. order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  12964. top = 0,
  12965. bottom = 0,
  12966. tops = [],
  12967. bottoms = [];
  12968. for (i = 0; i < n; ++i) {
  12969. j = order[i];
  12970. if (top < bottom) {
  12971. top += sums[j];
  12972. tops.push(j);
  12973. } else {
  12974. bottom += sums[j];
  12975. bottoms.push(j);
  12976. }
  12977. }
  12978. return bottoms.reverse().concat(tops);
  12979. }
  12980. function reverse(series) {
  12981. return none$2(series).reverse();
  12982. }
  12983. function constant$11(x) {
  12984. return function() {
  12985. return x;
  12986. };
  12987. }
  12988. function x$4(d) {
  12989. return d[0];
  12990. }
  12991. function y$4(d) {
  12992. return d[1];
  12993. }
  12994. function RedBlackTree() {
  12995. this._ = null; // root node
  12996. }
  12997. function RedBlackNode(node) {
  12998. node.U = // parent node
  12999. node.C = // color - true for red, false for black
  13000. node.L = // left node
  13001. node.R = // right node
  13002. node.P = // previous node
  13003. node.N = null; // next node
  13004. }
  13005. RedBlackTree.prototype = {
  13006. constructor: RedBlackTree,
  13007. insert: function(after, node) {
  13008. var parent, grandpa, uncle;
  13009. if (after) {
  13010. node.P = after;
  13011. node.N = after.N;
  13012. if (after.N) after.N.P = node;
  13013. after.N = node;
  13014. if (after.R) {
  13015. after = after.R;
  13016. while (after.L) after = after.L;
  13017. after.L = node;
  13018. } else {
  13019. after.R = node;
  13020. }
  13021. parent = after;
  13022. } else if (this._) {
  13023. after = RedBlackFirst(this._);
  13024. node.P = null;
  13025. node.N = after;
  13026. after.P = after.L = node;
  13027. parent = after;
  13028. } else {
  13029. node.P = node.N = null;
  13030. this._ = node;
  13031. parent = null;
  13032. }
  13033. node.L = node.R = null;
  13034. node.U = parent;
  13035. node.C = true;
  13036. after = node;
  13037. while (parent && parent.C) {
  13038. grandpa = parent.U;
  13039. if (parent === grandpa.L) {
  13040. uncle = grandpa.R;
  13041. if (uncle && uncle.C) {
  13042. parent.C = uncle.C = false;
  13043. grandpa.C = true;
  13044. after = grandpa;
  13045. } else {
  13046. if (after === parent.R) {
  13047. RedBlackRotateLeft(this, parent);
  13048. after = parent;
  13049. parent = after.U;
  13050. }
  13051. parent.C = false;
  13052. grandpa.C = true;
  13053. RedBlackRotateRight(this, grandpa);
  13054. }
  13055. } else {
  13056. uncle = grandpa.L;
  13057. if (uncle && uncle.C) {
  13058. parent.C = uncle.C = false;
  13059. grandpa.C = true;
  13060. after = grandpa;
  13061. } else {
  13062. if (after === parent.L) {
  13063. RedBlackRotateRight(this, parent);
  13064. after = parent;
  13065. parent = after.U;
  13066. }
  13067. parent.C = false;
  13068. grandpa.C = true;
  13069. RedBlackRotateLeft(this, grandpa);
  13070. }
  13071. }
  13072. parent = after.U;
  13073. }
  13074. this._.C = false;
  13075. },
  13076. remove: function(node) {
  13077. if (node.N) node.N.P = node.P;
  13078. if (node.P) node.P.N = node.N;
  13079. node.N = node.P = null;
  13080. var parent = node.U,
  13081. sibling,
  13082. left = node.L,
  13083. right = node.R,
  13084. next,
  13085. red;
  13086. if (!left) next = right;
  13087. else if (!right) next = left;
  13088. else next = RedBlackFirst(right);
  13089. if (parent) {
  13090. if (parent.L === node) parent.L = next;
  13091. else parent.R = next;
  13092. } else {
  13093. this._ = next;
  13094. }
  13095. if (left && right) {
  13096. red = next.C;
  13097. next.C = node.C;
  13098. next.L = left;
  13099. left.U = next;
  13100. if (next !== right) {
  13101. parent = next.U;
  13102. next.U = node.U;
  13103. node = next.R;
  13104. parent.L = node;
  13105. next.R = right;
  13106. right.U = next;
  13107. } else {
  13108. next.U = parent;
  13109. parent = next;
  13110. node = next.R;
  13111. }
  13112. } else {
  13113. red = node.C;
  13114. node = next;
  13115. }
  13116. if (node) node.U = parent;
  13117. if (red) return;
  13118. if (node && node.C) { node.C = false; return; }
  13119. do {
  13120. if (node === this._) break;
  13121. if (node === parent.L) {
  13122. sibling = parent.R;
  13123. if (sibling.C) {
  13124. sibling.C = false;
  13125. parent.C = true;
  13126. RedBlackRotateLeft(this, parent);
  13127. sibling = parent.R;
  13128. }
  13129. if ((sibling.L && sibling.L.C)
  13130. || (sibling.R && sibling.R.C)) {
  13131. if (!sibling.R || !sibling.R.C) {
  13132. sibling.L.C = false;
  13133. sibling.C = true;
  13134. RedBlackRotateRight(this, sibling);
  13135. sibling = parent.R;
  13136. }
  13137. sibling.C = parent.C;
  13138. parent.C = sibling.R.C = false;
  13139. RedBlackRotateLeft(this, parent);
  13140. node = this._;
  13141. break;
  13142. }
  13143. } else {
  13144. sibling = parent.L;
  13145. if (sibling.C) {
  13146. sibling.C = false;
  13147. parent.C = true;
  13148. RedBlackRotateRight(this, parent);
  13149. sibling = parent.L;
  13150. }
  13151. if ((sibling.L && sibling.L.C)
  13152. || (sibling.R && sibling.R.C)) {
  13153. if (!sibling.L || !sibling.L.C) {
  13154. sibling.R.C = false;
  13155. sibling.C = true;
  13156. RedBlackRotateLeft(this, sibling);
  13157. sibling = parent.L;
  13158. }
  13159. sibling.C = parent.C;
  13160. parent.C = sibling.L.C = false;
  13161. RedBlackRotateRight(this, parent);
  13162. node = this._;
  13163. break;
  13164. }
  13165. }
  13166. sibling.C = true;
  13167. node = parent;
  13168. parent = parent.U;
  13169. } while (!node.C);
  13170. if (node) node.C = false;
  13171. }
  13172. };
  13173. function RedBlackRotateLeft(tree, node) {
  13174. var p = node,
  13175. q = node.R,
  13176. parent = p.U;
  13177. if (parent) {
  13178. if (parent.L === p) parent.L = q;
  13179. else parent.R = q;
  13180. } else {
  13181. tree._ = q;
  13182. }
  13183. q.U = parent;
  13184. p.U = q;
  13185. p.R = q.L;
  13186. if (p.R) p.R.U = p;
  13187. q.L = p;
  13188. }
  13189. function RedBlackRotateRight(tree, node) {
  13190. var p = node,
  13191. q = node.L,
  13192. parent = p.U;
  13193. if (parent) {
  13194. if (parent.L === p) parent.L = q;
  13195. else parent.R = q;
  13196. } else {
  13197. tree._ = q;
  13198. }
  13199. q.U = parent;
  13200. p.U = q;
  13201. p.L = q.R;
  13202. if (p.L) p.L.U = p;
  13203. q.R = p;
  13204. }
  13205. function RedBlackFirst(node) {
  13206. while (node.L) node = node.L;
  13207. return node;
  13208. }
  13209. function createEdge(left, right, v0, v1) {
  13210. var edge = [null, null],
  13211. index = edges.push(edge) - 1;
  13212. edge.left = left;
  13213. edge.right = right;
  13214. if (v0) setEdgeEnd(edge, left, right, v0);
  13215. if (v1) setEdgeEnd(edge, right, left, v1);
  13216. cells[left.index].halfedges.push(index);
  13217. cells[right.index].halfedges.push(index);
  13218. return edge;
  13219. }
  13220. function createBorderEdge(left, v0, v1) {
  13221. var edge = [v0, v1];
  13222. edge.left = left;
  13223. return edge;
  13224. }
  13225. function setEdgeEnd(edge, left, right, vertex) {
  13226. if (!edge[0] && !edge[1]) {
  13227. edge[0] = vertex;
  13228. edge.left = left;
  13229. edge.right = right;
  13230. } else if (edge.left === right) {
  13231. edge[1] = vertex;
  13232. } else {
  13233. edge[0] = vertex;
  13234. }
  13235. }
  13236. // Liang–Barsky line clipping.
  13237. function clipEdge(edge, x0, y0, x1, y1) {
  13238. var a = edge[0],
  13239. b = edge[1],
  13240. ax = a[0],
  13241. ay = a[1],
  13242. bx = b[0],
  13243. by = b[1],
  13244. t0 = 0,
  13245. t1 = 1,
  13246. dx = bx - ax,
  13247. dy = by - ay,
  13248. r;
  13249. r = x0 - ax;
  13250. if (!dx && r > 0) return;
  13251. r /= dx;
  13252. if (dx < 0) {
  13253. if (r < t0) return;
  13254. if (r < t1) t1 = r;
  13255. } else if (dx > 0) {
  13256. if (r > t1) return;
  13257. if (r > t0) t0 = r;
  13258. }
  13259. r = x1 - ax;
  13260. if (!dx && r < 0) return;
  13261. r /= dx;
  13262. if (dx < 0) {
  13263. if (r > t1) return;
  13264. if (r > t0) t0 = r;
  13265. } else if (dx > 0) {
  13266. if (r < t0) return;
  13267. if (r < t1) t1 = r;
  13268. }
  13269. r = y0 - ay;
  13270. if (!dy && r > 0) return;
  13271. r /= dy;
  13272. if (dy < 0) {
  13273. if (r < t0) return;
  13274. if (r < t1) t1 = r;
  13275. } else if (dy > 0) {
  13276. if (r > t1) return;
  13277. if (r > t0) t0 = r;
  13278. }
  13279. r = y1 - ay;
  13280. if (!dy && r < 0) return;
  13281. r /= dy;
  13282. if (dy < 0) {
  13283. if (r > t1) return;
  13284. if (r > t0) t0 = r;
  13285. } else if (dy > 0) {
  13286. if (r < t0) return;
  13287. if (r < t1) t1 = r;
  13288. }
  13289. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  13290. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  13291. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  13292. return true;
  13293. }
  13294. function connectEdge(edge, x0, y0, x1, y1) {
  13295. var v1 = edge[1];
  13296. if (v1) return true;
  13297. var v0 = edge[0],
  13298. left = edge.left,
  13299. right = edge.right,
  13300. lx = left[0],
  13301. ly = left[1],
  13302. rx = right[0],
  13303. ry = right[1],
  13304. fx = (lx + rx) / 2,
  13305. fy = (ly + ry) / 2,
  13306. fm,
  13307. fb;
  13308. if (ry === ly) {
  13309. if (fx < x0 || fx >= x1) return;
  13310. if (lx > rx) {
  13311. if (!v0) v0 = [fx, y0];
  13312. else if (v0[1] >= y1) return;
  13313. v1 = [fx, y1];
  13314. } else {
  13315. if (!v0) v0 = [fx, y1];
  13316. else if (v0[1] < y0) return;
  13317. v1 = [fx, y0];
  13318. }
  13319. } else {
  13320. fm = (lx - rx) / (ry - ly);
  13321. fb = fy - fm * fx;
  13322. if (fm < -1 || fm > 1) {
  13323. if (lx > rx) {
  13324. if (!v0) v0 = [(y0 - fb) / fm, y0];
  13325. else if (v0[1] >= y1) return;
  13326. v1 = [(y1 - fb) / fm, y1];
  13327. } else {
  13328. if (!v0) v0 = [(y1 - fb) / fm, y1];
  13329. else if (v0[1] < y0) return;
  13330. v1 = [(y0 - fb) / fm, y0];
  13331. }
  13332. } else {
  13333. if (ly < ry) {
  13334. if (!v0) v0 = [x0, fm * x0 + fb];
  13335. else if (v0[0] >= x1) return;
  13336. v1 = [x1, fm * x1 + fb];
  13337. } else {
  13338. if (!v0) v0 = [x1, fm * x1 + fb];
  13339. else if (v0[0] < x0) return;
  13340. v1 = [x0, fm * x0 + fb];
  13341. }
  13342. }
  13343. }
  13344. edge[0] = v0;
  13345. edge[1] = v1;
  13346. return true;
  13347. }
  13348. function clipEdges(x0, y0, x1, y1) {
  13349. var i = edges.length,
  13350. edge;
  13351. while (i--) {
  13352. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  13353. || !clipEdge(edge, x0, y0, x1, y1)
  13354. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  13355. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  13356. delete edges[i];
  13357. }
  13358. }
  13359. }
  13360. function createCell(site) {
  13361. return cells[site.index] = {
  13362. site: site,
  13363. halfedges: []
  13364. };
  13365. }
  13366. function cellHalfedgeAngle(cell, edge) {
  13367. var site = cell.site,
  13368. va = edge.left,
  13369. vb = edge.right;
  13370. if (site === vb) vb = va, va = site;
  13371. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  13372. if (site === va) va = edge[1], vb = edge[0];
  13373. else va = edge[0], vb = edge[1];
  13374. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  13375. }
  13376. function cellHalfedgeStart(cell, edge) {
  13377. return edge[+(edge.left !== cell.site)];
  13378. }
  13379. function cellHalfedgeEnd(cell, edge) {
  13380. return edge[+(edge.left === cell.site)];
  13381. }
  13382. function sortCellHalfedges() {
  13383. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  13384. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  13385. var index = new Array(m),
  13386. array = new Array(m);
  13387. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  13388. index.sort(function(i, j) { return array[j] - array[i]; });
  13389. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  13390. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  13391. }
  13392. }
  13393. }
  13394. function clipCells(x0, y0, x1, y1) {
  13395. var nCells = cells.length,
  13396. iCell,
  13397. cell,
  13398. site,
  13399. iHalfedge,
  13400. halfedges,
  13401. nHalfedges,
  13402. start,
  13403. startX,
  13404. startY,
  13405. end,
  13406. endX,
  13407. endY,
  13408. cover = true;
  13409. for (iCell = 0; iCell < nCells; ++iCell) {
  13410. if (cell = cells[iCell]) {
  13411. site = cell.site;
  13412. halfedges = cell.halfedges;
  13413. iHalfedge = halfedges.length;
  13414. // Remove any dangling clipped edges.
  13415. while (iHalfedge--) {
  13416. if (!edges[halfedges[iHalfedge]]) {
  13417. halfedges.splice(iHalfedge, 1);
  13418. }
  13419. }
  13420. // Insert any border edges as necessary.
  13421. iHalfedge = 0, nHalfedges = halfedges.length;
  13422. while (iHalfedge < nHalfedges) {
  13423. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  13424. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  13425. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  13426. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  13427. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  13428. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  13429. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  13430. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  13431. : null)) - 1);
  13432. ++nHalfedges;
  13433. }
  13434. }
  13435. if (nHalfedges) cover = false;
  13436. }
  13437. }
  13438. // If there weren’t any edges, have the closest site cover the extent.
  13439. // It doesn’t matter which corner of the extent we measure!
  13440. if (cover) {
  13441. var dx, dy, d2, dc = Infinity;
  13442. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  13443. if (cell = cells[iCell]) {
  13444. site = cell.site;
  13445. dx = site[0] - x0;
  13446. dy = site[1] - y0;
  13447. d2 = dx * dx + dy * dy;
  13448. if (d2 < dc) dc = d2, cover = cell;
  13449. }
  13450. }
  13451. if (cover) {
  13452. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  13453. cover.halfedges.push(
  13454. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  13455. edges.push(createBorderEdge(site, v01, v11)) - 1,
  13456. edges.push(createBorderEdge(site, v11, v10)) - 1,
  13457. edges.push(createBorderEdge(site, v10, v00)) - 1
  13458. );
  13459. }
  13460. }
  13461. // Lastly delete any cells with no edges; these were entirely clipped.
  13462. for (iCell = 0; iCell < nCells; ++iCell) {
  13463. if (cell = cells[iCell]) {
  13464. if (!cell.halfedges.length) {
  13465. delete cells[iCell];
  13466. }
  13467. }
  13468. }
  13469. }
  13470. var circlePool = [];
  13471. var firstCircle;
  13472. function Circle() {
  13473. RedBlackNode(this);
  13474. this.x =
  13475. this.y =
  13476. this.arc =
  13477. this.site =
  13478. this.cy = null;
  13479. }
  13480. function attachCircle(arc) {
  13481. var lArc = arc.P,
  13482. rArc = arc.N;
  13483. if (!lArc || !rArc) return;
  13484. var lSite = lArc.site,
  13485. cSite = arc.site,
  13486. rSite = rArc.site;
  13487. if (lSite === rSite) return;
  13488. var bx = cSite[0],
  13489. by = cSite[1],
  13490. ax = lSite[0] - bx,
  13491. ay = lSite[1] - by,
  13492. cx = rSite[0] - bx,
  13493. cy = rSite[1] - by;
  13494. var d = 2 * (ax * cy - ay * cx);
  13495. if (d >= -epsilon2$2) return;
  13496. var ha = ax * ax + ay * ay,
  13497. hc = cx * cx + cy * cy,
  13498. x = (cy * ha - ay * hc) / d,
  13499. y = (ax * hc - cx * ha) / d;
  13500. var circle = circlePool.pop() || new Circle;
  13501. circle.arc = arc;
  13502. circle.site = cSite;
  13503. circle.x = x + bx;
  13504. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  13505. arc.circle = circle;
  13506. var before = null,
  13507. node = circles._;
  13508. while (node) {
  13509. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  13510. if (node.L) node = node.L;
  13511. else { before = node.P; break; }
  13512. } else {
  13513. if (node.R) node = node.R;
  13514. else { before = node; break; }
  13515. }
  13516. }
  13517. circles.insert(before, circle);
  13518. if (!before) firstCircle = circle;
  13519. }
  13520. function detachCircle(arc) {
  13521. var circle = arc.circle;
  13522. if (circle) {
  13523. if (!circle.P) firstCircle = circle.N;
  13524. circles.remove(circle);
  13525. circlePool.push(circle);
  13526. RedBlackNode(circle);
  13527. arc.circle = null;
  13528. }
  13529. }
  13530. var beachPool = [];
  13531. function Beach() {
  13532. RedBlackNode(this);
  13533. this.edge =
  13534. this.site =
  13535. this.circle = null;
  13536. }
  13537. function createBeach(site) {
  13538. var beach = beachPool.pop() || new Beach;
  13539. beach.site = site;
  13540. return beach;
  13541. }
  13542. function detachBeach(beach) {
  13543. detachCircle(beach);
  13544. beaches.remove(beach);
  13545. beachPool.push(beach);
  13546. RedBlackNode(beach);
  13547. }
  13548. function removeBeach(beach) {
  13549. var circle = beach.circle,
  13550. x = circle.x,
  13551. y = circle.cy,
  13552. vertex = [x, y],
  13553. previous = beach.P,
  13554. next = beach.N,
  13555. disappearing = [beach];
  13556. detachBeach(beach);
  13557. var lArc = previous;
  13558. while (lArc.circle
  13559. && Math.abs(x - lArc.circle.x) < epsilon$4
  13560. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  13561. previous = lArc.P;
  13562. disappearing.unshift(lArc);
  13563. detachBeach(lArc);
  13564. lArc = previous;
  13565. }
  13566. disappearing.unshift(lArc);
  13567. detachCircle(lArc);
  13568. var rArc = next;
  13569. while (rArc.circle
  13570. && Math.abs(x - rArc.circle.x) < epsilon$4
  13571. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  13572. next = rArc.N;
  13573. disappearing.push(rArc);
  13574. detachBeach(rArc);
  13575. rArc = next;
  13576. }
  13577. disappearing.push(rArc);
  13578. detachCircle(rArc);
  13579. var nArcs = disappearing.length,
  13580. iArc;
  13581. for (iArc = 1; iArc < nArcs; ++iArc) {
  13582. rArc = disappearing[iArc];
  13583. lArc = disappearing[iArc - 1];
  13584. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  13585. }
  13586. lArc = disappearing[0];
  13587. rArc = disappearing[nArcs - 1];
  13588. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  13589. attachCircle(lArc);
  13590. attachCircle(rArc);
  13591. }
  13592. function addBeach(site) {
  13593. var x = site[0],
  13594. directrix = site[1],
  13595. lArc,
  13596. rArc,
  13597. dxl,
  13598. dxr,
  13599. node = beaches._;
  13600. while (node) {
  13601. dxl = leftBreakPoint(node, directrix) - x;
  13602. if (dxl > epsilon$4) node = node.L; else {
  13603. dxr = x - rightBreakPoint(node, directrix);
  13604. if (dxr > epsilon$4) {
  13605. if (!node.R) {
  13606. lArc = node;
  13607. break;
  13608. }
  13609. node = node.R;
  13610. } else {
  13611. if (dxl > -epsilon$4) {
  13612. lArc = node.P;
  13613. rArc = node;
  13614. } else if (dxr > -epsilon$4) {
  13615. lArc = node;
  13616. rArc = node.N;
  13617. } else {
  13618. lArc = rArc = node;
  13619. }
  13620. break;
  13621. }
  13622. }
  13623. }
  13624. createCell(site);
  13625. var newArc = createBeach(site);
  13626. beaches.insert(lArc, newArc);
  13627. if (!lArc && !rArc) return;
  13628. if (lArc === rArc) {
  13629. detachCircle(lArc);
  13630. rArc = createBeach(lArc.site);
  13631. beaches.insert(newArc, rArc);
  13632. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  13633. attachCircle(lArc);
  13634. attachCircle(rArc);
  13635. return;
  13636. }
  13637. if (!rArc) { // && lArc
  13638. newArc.edge = createEdge(lArc.site, newArc.site);
  13639. return;
  13640. }
  13641. // else lArc !== rArc
  13642. detachCircle(lArc);
  13643. detachCircle(rArc);
  13644. var lSite = lArc.site,
  13645. ax = lSite[0],
  13646. ay = lSite[1],
  13647. bx = site[0] - ax,
  13648. by = site[1] - ay,
  13649. rSite = rArc.site,
  13650. cx = rSite[0] - ax,
  13651. cy = rSite[1] - ay,
  13652. d = 2 * (bx * cy - by * cx),
  13653. hb = bx * bx + by * by,
  13654. hc = cx * cx + cy * cy,
  13655. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  13656. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  13657. newArc.edge = createEdge(lSite, site, null, vertex);
  13658. rArc.edge = createEdge(site, rSite, null, vertex);
  13659. attachCircle(lArc);
  13660. attachCircle(rArc);
  13661. }
  13662. function leftBreakPoint(arc, directrix) {
  13663. var site = arc.site,
  13664. rfocx = site[0],
  13665. rfocy = site[1],
  13666. pby2 = rfocy - directrix;
  13667. if (!pby2) return rfocx;
  13668. var lArc = arc.P;
  13669. if (!lArc) return -Infinity;
  13670. site = lArc.site;
  13671. var lfocx = site[0],
  13672. lfocy = site[1],
  13673. plby2 = lfocy - directrix;
  13674. if (!plby2) return lfocx;
  13675. var hl = lfocx - rfocx,
  13676. aby2 = 1 / pby2 - 1 / plby2,
  13677. b = hl / plby2;
  13678. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  13679. return (rfocx + lfocx) / 2;
  13680. }
  13681. function rightBreakPoint(arc, directrix) {
  13682. var rArc = arc.N;
  13683. if (rArc) return leftBreakPoint(rArc, directrix);
  13684. var site = arc.site;
  13685. return site[1] === directrix ? site[0] : Infinity;
  13686. }
  13687. var epsilon$4 = 1e-6;
  13688. var epsilon2$2 = 1e-12;
  13689. var beaches;
  13690. var cells;
  13691. var circles;
  13692. var edges;
  13693. function triangleArea(a, b, c) {
  13694. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  13695. }
  13696. function lexicographic(a, b) {
  13697. return b[1] - a[1]
  13698. || b[0] - a[0];
  13699. }
  13700. function Diagram(sites, extent) {
  13701. var site = sites.sort(lexicographic).pop(),
  13702. x,
  13703. y,
  13704. circle;
  13705. edges = [];
  13706. cells = new Array(sites.length);
  13707. beaches = new RedBlackTree;
  13708. circles = new RedBlackTree;
  13709. while (true) {
  13710. circle = firstCircle;
  13711. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  13712. if (site[0] !== x || site[1] !== y) {
  13713. addBeach(site);
  13714. x = site[0], y = site[1];
  13715. }
  13716. site = sites.pop();
  13717. } else if (circle) {
  13718. removeBeach(circle.arc);
  13719. } else {
  13720. break;
  13721. }
  13722. }
  13723. sortCellHalfedges();
  13724. if (extent) {
  13725. var x0 = +extent[0][0],
  13726. y0 = +extent[0][1],
  13727. x1 = +extent[1][0],
  13728. y1 = +extent[1][1];
  13729. clipEdges(x0, y0, x1, y1);
  13730. clipCells(x0, y0, x1, y1);
  13731. }
  13732. this.edges = edges;
  13733. this.cells = cells;
  13734. beaches =
  13735. circles =
  13736. edges =
  13737. cells = null;
  13738. }
  13739. Diagram.prototype = {
  13740. constructor: Diagram,
  13741. polygons: function() {
  13742. var edges = this.edges;
  13743. return this.cells.map(function(cell) {
  13744. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  13745. polygon.data = cell.site.data;
  13746. return polygon;
  13747. });
  13748. },
  13749. triangles: function() {
  13750. var triangles = [],
  13751. edges = this.edges;
  13752. this.cells.forEach(function(cell, i) {
  13753. if (!(m = (halfedges = cell.halfedges).length)) return;
  13754. var site = cell.site,
  13755. halfedges,
  13756. j = -1,
  13757. m,
  13758. s0,
  13759. e1 = edges[halfedges[m - 1]],
  13760. s1 = e1.left === site ? e1.right : e1.left;
  13761. while (++j < m) {
  13762. s0 = s1;
  13763. e1 = edges[halfedges[j]];
  13764. s1 = e1.left === site ? e1.right : e1.left;
  13765. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  13766. triangles.push([site.data, s0.data, s1.data]);
  13767. }
  13768. }
  13769. });
  13770. return triangles;
  13771. },
  13772. links: function() {
  13773. return this.edges.filter(function(edge) {
  13774. return edge.right;
  13775. }).map(function(edge) {
  13776. return {
  13777. source: edge.left.data,
  13778. target: edge.right.data
  13779. };
  13780. });
  13781. },
  13782. find: function(x, y, radius) {
  13783. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  13784. // Use the previously-found cell, or start with an arbitrary one.
  13785. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  13786. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  13787. // Traverse the half-edges to find a closer cell, if any.
  13788. do {
  13789. cell = that.cells[i0 = i1], i1 = null;
  13790. cell.halfedges.forEach(function(e) {
  13791. var edge = that.edges[e], v = edge.left;
  13792. if ((v === cell.site || !v) && !(v = edge.right)) return;
  13793. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  13794. if (v2 < d2) d2 = v2, i1 = v.index;
  13795. });
  13796. } while (i1 !== null);
  13797. that._found = i0;
  13798. return radius == null || d2 <= radius * radius ? cell.site : null;
  13799. }
  13800. };
  13801. function voronoi() {
  13802. var x$$1 = x$4,
  13803. y$$1 = y$4,
  13804. extent = null;
  13805. function voronoi(data) {
  13806. return new Diagram(data.map(function(d, i) {
  13807. var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
  13808. s.index = i;
  13809. s.data = d;
  13810. return s;
  13811. }), extent);
  13812. }
  13813. voronoi.polygons = function(data) {
  13814. return voronoi(data).polygons();
  13815. };
  13816. voronoi.links = function(data) {
  13817. return voronoi(data).links();
  13818. };
  13819. voronoi.triangles = function(data) {
  13820. return voronoi(data).triangles();
  13821. };
  13822. voronoi.x = function(_) {
  13823. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : x$$1;
  13824. };
  13825. voronoi.y = function(_) {
  13826. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : y$$1;
  13827. };
  13828. voronoi.extent = function(_) {
  13829. 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]]];
  13830. };
  13831. voronoi.size = function(_) {
  13832. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  13833. };
  13834. return voronoi;
  13835. }
  13836. function constant$12(x) {
  13837. return function() {
  13838. return x;
  13839. };
  13840. }
  13841. function ZoomEvent(target, type, transform) {
  13842. this.target = target;
  13843. this.type = type;
  13844. this.transform = transform;
  13845. }
  13846. function Transform(k, x, y) {
  13847. this.k = k;
  13848. this.x = x;
  13849. this.y = y;
  13850. }
  13851. Transform.prototype = {
  13852. constructor: Transform,
  13853. scale: function(k) {
  13854. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  13855. },
  13856. translate: function(x, y) {
  13857. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  13858. },
  13859. apply: function(point) {
  13860. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  13861. },
  13862. applyX: function(x) {
  13863. return x * this.k + this.x;
  13864. },
  13865. applyY: function(y) {
  13866. return y * this.k + this.y;
  13867. },
  13868. invert: function(location) {
  13869. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  13870. },
  13871. invertX: function(x) {
  13872. return (x - this.x) / this.k;
  13873. },
  13874. invertY: function(y) {
  13875. return (y - this.y) / this.k;
  13876. },
  13877. rescaleX: function(x) {
  13878. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  13879. },
  13880. rescaleY: function(y) {
  13881. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  13882. },
  13883. toString: function() {
  13884. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  13885. }
  13886. };
  13887. var identity$8 = new Transform(1, 0, 0);
  13888. transform$1.prototype = Transform.prototype;
  13889. function transform$1(node) {
  13890. return node.__zoom || identity$8;
  13891. }
  13892. function nopropagation$2() {
  13893. exports.event.stopImmediatePropagation();
  13894. }
  13895. function noevent$2() {
  13896. exports.event.preventDefault();
  13897. exports.event.stopImmediatePropagation();
  13898. }
  13899. // Ignore right-click, since that should open the context menu.
  13900. function defaultFilter$2() {
  13901. return !exports.event.button;
  13902. }
  13903. function defaultExtent$1() {
  13904. var e = this, w, h;
  13905. if (e instanceof SVGElement) {
  13906. e = e.ownerSVGElement || e;
  13907. w = e.width.baseVal.value;
  13908. h = e.height.baseVal.value;
  13909. } else {
  13910. w = e.clientWidth;
  13911. h = e.clientHeight;
  13912. }
  13913. return [[0, 0], [w, h]];
  13914. }
  13915. function defaultTransform() {
  13916. return this.__zoom || identity$8;
  13917. }
  13918. function defaultWheelDelta() {
  13919. return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
  13920. }
  13921. function defaultTouchable$1() {
  13922. return "ontouchstart" in this;
  13923. }
  13924. function defaultConstrain(transform$$1, extent, translateExtent) {
  13925. var dx0 = transform$$1.invertX(extent[0][0]) - translateExtent[0][0],
  13926. dx1 = transform$$1.invertX(extent[1][0]) - translateExtent[1][0],
  13927. dy0 = transform$$1.invertY(extent[0][1]) - translateExtent[0][1],
  13928. dy1 = transform$$1.invertY(extent[1][1]) - translateExtent[1][1];
  13929. return transform$$1.translate(
  13930. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  13931. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  13932. );
  13933. }
  13934. function zoom() {
  13935. var filter = defaultFilter$2,
  13936. extent = defaultExtent$1,
  13937. constrain = defaultConstrain,
  13938. wheelDelta = defaultWheelDelta,
  13939. touchable = defaultTouchable$1,
  13940. scaleExtent = [0, Infinity],
  13941. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  13942. duration = 250,
  13943. interpolate = interpolateZoom,
  13944. gestures = [],
  13945. listeners = dispatch("start", "zoom", "end"),
  13946. touchstarting,
  13947. touchending,
  13948. touchDelay = 500,
  13949. wheelDelay = 150,
  13950. clickDistance2 = 0;
  13951. function zoom(selection) {
  13952. selection
  13953. .property("__zoom", defaultTransform)
  13954. .on("wheel.zoom", wheeled)
  13955. .on("mousedown.zoom", mousedowned)
  13956. .on("dblclick.zoom", dblclicked)
  13957. .filter(touchable)
  13958. .on("touchstart.zoom", touchstarted)
  13959. .on("touchmove.zoom", touchmoved)
  13960. .on("touchend.zoom touchcancel.zoom", touchended)
  13961. .style("touch-action", "none")
  13962. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  13963. }
  13964. zoom.transform = function(collection, transform$$1) {
  13965. var selection = collection.selection ? collection.selection() : collection;
  13966. selection.property("__zoom", defaultTransform);
  13967. if (collection !== selection) {
  13968. schedule(collection, transform$$1);
  13969. } else {
  13970. selection.interrupt().each(function() {
  13971. gesture(this, arguments)
  13972. .start()
  13973. .zoom(null, typeof transform$$1 === "function" ? transform$$1.apply(this, arguments) : transform$$1)
  13974. .end();
  13975. });
  13976. }
  13977. };
  13978. zoom.scaleBy = function(selection, k) {
  13979. zoom.scaleTo(selection, function() {
  13980. var k0 = this.__zoom.k,
  13981. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  13982. return k0 * k1;
  13983. });
  13984. };
  13985. zoom.scaleTo = function(selection, k) {
  13986. zoom.transform(selection, function() {
  13987. var e = extent.apply(this, arguments),
  13988. t0 = this.__zoom,
  13989. p0 = centroid(e),
  13990. p1 = t0.invert(p0),
  13991. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  13992. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  13993. });
  13994. };
  13995. zoom.translateBy = function(selection, x, y) {
  13996. zoom.transform(selection, function() {
  13997. return constrain(this.__zoom.translate(
  13998. typeof x === "function" ? x.apply(this, arguments) : x,
  13999. typeof y === "function" ? y.apply(this, arguments) : y
  14000. ), extent.apply(this, arguments), translateExtent);
  14001. });
  14002. };
  14003. zoom.translateTo = function(selection, x, y) {
  14004. zoom.transform(selection, function() {
  14005. var e = extent.apply(this, arguments),
  14006. t = this.__zoom,
  14007. p = centroid(e);
  14008. return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
  14009. typeof x === "function" ? -x.apply(this, arguments) : -x,
  14010. typeof y === "function" ? -y.apply(this, arguments) : -y
  14011. ), e, translateExtent);
  14012. });
  14013. };
  14014. function scale(transform$$1, k) {
  14015. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  14016. return k === transform$$1.k ? transform$$1 : new Transform(k, transform$$1.x, transform$$1.y);
  14017. }
  14018. function translate(transform$$1, p0, p1) {
  14019. var x = p0[0] - p1[0] * transform$$1.k, y = p0[1] - p1[1] * transform$$1.k;
  14020. return x === transform$$1.x && y === transform$$1.y ? transform$$1 : new Transform(transform$$1.k, x, y);
  14021. }
  14022. function centroid(extent) {
  14023. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  14024. }
  14025. function schedule(transition, transform$$1, center) {
  14026. transition
  14027. .on("start.zoom", function() { gesture(this, arguments).start(); })
  14028. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  14029. .tween("zoom", function() {
  14030. var that = this,
  14031. args = arguments,
  14032. g = gesture(that, args),
  14033. e = extent.apply(that, args),
  14034. p = center || centroid(e),
  14035. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  14036. a = that.__zoom,
  14037. b = typeof transform$$1 === "function" ? transform$$1.apply(that, args) : transform$$1,
  14038. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  14039. return function(t) {
  14040. if (t === 1) t = b; // Avoid rounding error on end.
  14041. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  14042. g.zoom(null, t);
  14043. };
  14044. });
  14045. }
  14046. function gesture(that, args) {
  14047. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  14048. if ((g = gestures[i]).that === that) {
  14049. return g;
  14050. }
  14051. }
  14052. return new Gesture(that, args);
  14053. }
  14054. function Gesture(that, args) {
  14055. this.that = that;
  14056. this.args = args;
  14057. this.index = -1;
  14058. this.active = 0;
  14059. this.extent = extent.apply(that, args);
  14060. }
  14061. Gesture.prototype = {
  14062. start: function() {
  14063. if (++this.active === 1) {
  14064. this.index = gestures.push(this) - 1;
  14065. this.emit("start");
  14066. }
  14067. return this;
  14068. },
  14069. zoom: function(key, transform$$1) {
  14070. if (this.mouse && key !== "mouse") this.mouse[1] = transform$$1.invert(this.mouse[0]);
  14071. if (this.touch0 && key !== "touch") this.touch0[1] = transform$$1.invert(this.touch0[0]);
  14072. if (this.touch1 && key !== "touch") this.touch1[1] = transform$$1.invert(this.touch1[0]);
  14073. this.that.__zoom = transform$$1;
  14074. this.emit("zoom");
  14075. return this;
  14076. },
  14077. end: function() {
  14078. if (--this.active === 0) {
  14079. gestures.splice(this.index, 1);
  14080. this.index = -1;
  14081. this.emit("end");
  14082. }
  14083. return this;
  14084. },
  14085. emit: function(type) {
  14086. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  14087. }
  14088. };
  14089. function wheeled() {
  14090. if (!filter.apply(this, arguments)) return;
  14091. var g = gesture(this, arguments),
  14092. t = this.__zoom,
  14093. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  14094. p = mouse(this);
  14095. // If the mouse is in the same location as before, reuse it.
  14096. // If there were recent wheel events, reset the wheel idle timeout.
  14097. if (g.wheel) {
  14098. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  14099. g.mouse[1] = t.invert(g.mouse[0] = p);
  14100. }
  14101. clearTimeout(g.wheel);
  14102. }
  14103. // If this wheel event won’t trigger a transform change, ignore it.
  14104. else if (t.k === k) return;
  14105. // Otherwise, capture the mouse point and location at the start.
  14106. else {
  14107. g.mouse = [p, t.invert(p)];
  14108. interrupt(this);
  14109. g.start();
  14110. }
  14111. noevent$2();
  14112. g.wheel = setTimeout(wheelidled, wheelDelay);
  14113. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  14114. function wheelidled() {
  14115. g.wheel = null;
  14116. g.end();
  14117. }
  14118. }
  14119. function mousedowned() {
  14120. if (touchending || !filter.apply(this, arguments)) return;
  14121. var g = gesture(this, arguments),
  14122. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  14123. p = mouse(this),
  14124. x0 = exports.event.clientX,
  14125. y0 = exports.event.clientY;
  14126. dragDisable(exports.event.view);
  14127. nopropagation$2();
  14128. g.mouse = [p, this.__zoom.invert(p)];
  14129. interrupt(this);
  14130. g.start();
  14131. function mousemoved() {
  14132. noevent$2();
  14133. if (!g.moved) {
  14134. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  14135. g.moved = dx * dx + dy * dy > clickDistance2;
  14136. }
  14137. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  14138. }
  14139. function mouseupped() {
  14140. v.on("mousemove.zoom mouseup.zoom", null);
  14141. yesdrag(exports.event.view, g.moved);
  14142. noevent$2();
  14143. g.end();
  14144. }
  14145. }
  14146. function dblclicked() {
  14147. if (!filter.apply(this, arguments)) return;
  14148. var t0 = this.__zoom,
  14149. p0 = mouse(this),
  14150. p1 = t0.invert(p0),
  14151. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  14152. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  14153. noevent$2();
  14154. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  14155. else select(this).call(zoom.transform, t1);
  14156. }
  14157. function touchstarted() {
  14158. if (!filter.apply(this, arguments)) return;
  14159. var g = gesture(this, arguments),
  14160. touches = exports.event.changedTouches,
  14161. started,
  14162. n = touches.length, i, t, p;
  14163. nopropagation$2();
  14164. for (i = 0; i < n; ++i) {
  14165. t = touches[i], p = touch(this, touches, t.identifier);
  14166. p = [p, this.__zoom.invert(p), t.identifier];
  14167. if (!g.touch0) g.touch0 = p, started = true;
  14168. else if (!g.touch1) g.touch1 = p;
  14169. }
  14170. // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
  14171. if (touchstarting) {
  14172. touchstarting = clearTimeout(touchstarting);
  14173. if (!g.touch1) {
  14174. g.end();
  14175. p = select(this).on("dblclick.zoom");
  14176. if (p) p.apply(this, arguments);
  14177. return;
  14178. }
  14179. }
  14180. if (started) {
  14181. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  14182. interrupt(this);
  14183. g.start();
  14184. }
  14185. }
  14186. function touchmoved() {
  14187. var g = gesture(this, arguments),
  14188. touches = exports.event.changedTouches,
  14189. n = touches.length, i, t, p, l;
  14190. noevent$2();
  14191. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  14192. for (i = 0; i < n; ++i) {
  14193. t = touches[i], p = touch(this, touches, t.identifier);
  14194. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  14195. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  14196. }
  14197. t = g.that.__zoom;
  14198. if (g.touch1) {
  14199. var p0 = g.touch0[0], l0 = g.touch0[1],
  14200. p1 = g.touch1[0], l1 = g.touch1[1],
  14201. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  14202. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  14203. t = scale(t, Math.sqrt(dp / dl));
  14204. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  14205. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  14206. }
  14207. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  14208. else return;
  14209. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  14210. }
  14211. function touchended() {
  14212. var g = gesture(this, arguments),
  14213. touches = exports.event.changedTouches,
  14214. n = touches.length, i, t;
  14215. nopropagation$2();
  14216. if (touchending) clearTimeout(touchending);
  14217. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  14218. for (i = 0; i < n; ++i) {
  14219. t = touches[i];
  14220. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  14221. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  14222. }
  14223. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  14224. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  14225. else g.end();
  14226. }
  14227. zoom.wheelDelta = function(_) {
  14228. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$12(+_), zoom) : wheelDelta;
  14229. };
  14230. zoom.filter = function(_) {
  14231. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$12(!!_), zoom) : filter;
  14232. };
  14233. zoom.touchable = function(_) {
  14234. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$12(!!_), zoom) : touchable;
  14235. };
  14236. zoom.extent = function(_) {
  14237. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$12([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  14238. };
  14239. zoom.scaleExtent = function(_) {
  14240. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  14241. };
  14242. zoom.translateExtent = function(_) {
  14243. return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
  14244. };
  14245. zoom.constrain = function(_) {
  14246. return arguments.length ? (constrain = _, zoom) : constrain;
  14247. };
  14248. zoom.duration = function(_) {
  14249. return arguments.length ? (duration = +_, zoom) : duration;
  14250. };
  14251. zoom.interpolate = function(_) {
  14252. return arguments.length ? (interpolate = _, zoom) : interpolate;
  14253. };
  14254. zoom.on = function() {
  14255. var value = listeners.on.apply(listeners, arguments);
  14256. return value === listeners ? zoom : value;
  14257. };
  14258. zoom.clickDistance = function(_) {
  14259. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  14260. };
  14261. return zoom;
  14262. }
  14263. exports.version = version;
  14264. exports.bisect = bisectRight;
  14265. exports.bisectRight = bisectRight;
  14266. exports.bisectLeft = bisectLeft;
  14267. exports.ascending = ascending;
  14268. exports.bisector = bisector;
  14269. exports.cross = cross;
  14270. exports.descending = descending;
  14271. exports.deviation = deviation;
  14272. exports.extent = extent;
  14273. exports.histogram = histogram;
  14274. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  14275. exports.thresholdScott = scott;
  14276. exports.thresholdSturges = sturges;
  14277. exports.max = max;
  14278. exports.mean = mean;
  14279. exports.median = median;
  14280. exports.merge = merge;
  14281. exports.min = min;
  14282. exports.pairs = pairs;
  14283. exports.permute = permute;
  14284. exports.quantile = threshold;
  14285. exports.range = sequence;
  14286. exports.scan = scan;
  14287. exports.shuffle = shuffle;
  14288. exports.sum = sum;
  14289. exports.ticks = ticks;
  14290. exports.tickIncrement = tickIncrement;
  14291. exports.tickStep = tickStep;
  14292. exports.transpose = transpose;
  14293. exports.variance = variance;
  14294. exports.zip = zip;
  14295. exports.axisTop = axisTop;
  14296. exports.axisRight = axisRight;
  14297. exports.axisBottom = axisBottom;
  14298. exports.axisLeft = axisLeft;
  14299. exports.brush = brush;
  14300. exports.brushX = brushX;
  14301. exports.brushY = brushY;
  14302. exports.brushSelection = brushSelection;
  14303. exports.chord = chord;
  14304. exports.ribbon = ribbon;
  14305. exports.nest = nest;
  14306. exports.set = set$2;
  14307. exports.map = map$1;
  14308. exports.keys = keys;
  14309. exports.values = values;
  14310. exports.entries = entries;
  14311. exports.color = color;
  14312. exports.rgb = rgb;
  14313. exports.hsl = hsl;
  14314. exports.lab = lab;
  14315. exports.hcl = hcl;
  14316. exports.cubehelix = cubehelix;
  14317. exports.dispatch = dispatch;
  14318. exports.drag = drag;
  14319. exports.dragDisable = dragDisable;
  14320. exports.dragEnable = yesdrag;
  14321. exports.dsvFormat = dsv;
  14322. exports.csvParse = csvParse;
  14323. exports.csvParseRows = csvParseRows;
  14324. exports.csvFormat = csvFormat;
  14325. exports.csvFormatRows = csvFormatRows;
  14326. exports.tsvParse = tsvParse;
  14327. exports.tsvParseRows = tsvParseRows;
  14328. exports.tsvFormat = tsvFormat;
  14329. exports.tsvFormatRows = tsvFormatRows;
  14330. exports.easeLinear = linear$1;
  14331. exports.easeQuad = quadInOut;
  14332. exports.easeQuadIn = quadIn;
  14333. exports.easeQuadOut = quadOut;
  14334. exports.easeQuadInOut = quadInOut;
  14335. exports.easeCubic = cubicInOut;
  14336. exports.easeCubicIn = cubicIn;
  14337. exports.easeCubicOut = cubicOut;
  14338. exports.easeCubicInOut = cubicInOut;
  14339. exports.easePoly = polyInOut;
  14340. exports.easePolyIn = polyIn;
  14341. exports.easePolyOut = polyOut;
  14342. exports.easePolyInOut = polyInOut;
  14343. exports.easeSin = sinInOut;
  14344. exports.easeSinIn = sinIn;
  14345. exports.easeSinOut = sinOut;
  14346. exports.easeSinInOut = sinInOut;
  14347. exports.easeExp = expInOut;
  14348. exports.easeExpIn = expIn;
  14349. exports.easeExpOut = expOut;
  14350. exports.easeExpInOut = expInOut;
  14351. exports.easeCircle = circleInOut;
  14352. exports.easeCircleIn = circleIn;
  14353. exports.easeCircleOut = circleOut;
  14354. exports.easeCircleInOut = circleInOut;
  14355. exports.easeBounce = bounceOut;
  14356. exports.easeBounceIn = bounceIn;
  14357. exports.easeBounceOut = bounceOut;
  14358. exports.easeBounceInOut = bounceInOut;
  14359. exports.easeBack = backInOut;
  14360. exports.easeBackIn = backIn;
  14361. exports.easeBackOut = backOut;
  14362. exports.easeBackInOut = backInOut;
  14363. exports.easeElastic = elasticOut;
  14364. exports.easeElasticIn = elasticIn;
  14365. exports.easeElasticOut = elasticOut;
  14366. exports.easeElasticInOut = elasticInOut;
  14367. exports.forceCenter = center$1;
  14368. exports.forceCollide = collide;
  14369. exports.forceLink = link;
  14370. exports.forceManyBody = manyBody;
  14371. exports.forceRadial = radial;
  14372. exports.forceSimulation = simulation;
  14373. exports.forceX = x$2;
  14374. exports.forceY = y$2;
  14375. exports.formatDefaultLocale = defaultLocale;
  14376. exports.formatLocale = formatLocale;
  14377. exports.formatSpecifier = formatSpecifier;
  14378. exports.precisionFixed = precisionFixed;
  14379. exports.precisionPrefix = precisionPrefix;
  14380. exports.precisionRound = precisionRound;
  14381. exports.geoArea = area;
  14382. exports.geoBounds = bounds;
  14383. exports.geoCentroid = centroid;
  14384. exports.geoCircle = circle;
  14385. exports.geoClipAntimeridian = clipAntimeridian;
  14386. exports.geoClipCircle = clipCircle;
  14387. exports.geoClipExtent = extent$1;
  14388. exports.geoClipRectangle = clipRectangle;
  14389. exports.geoContains = contains;
  14390. exports.geoDistance = distance;
  14391. exports.geoGraticule = graticule;
  14392. exports.geoGraticule10 = graticule10;
  14393. exports.geoInterpolate = interpolate$1;
  14394. exports.geoLength = length$1;
  14395. exports.geoPath = index$1;
  14396. exports.geoAlbers = albers;
  14397. exports.geoAlbersUsa = albersUsa;
  14398. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  14399. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  14400. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  14401. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  14402. exports.geoConicConformal = conicConformal;
  14403. exports.geoConicConformalRaw = conicConformalRaw;
  14404. exports.geoConicEqualArea = conicEqualArea;
  14405. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  14406. exports.geoConicEquidistant = conicEquidistant;
  14407. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  14408. exports.geoEquirectangular = equirectangular;
  14409. exports.geoEquirectangularRaw = equirectangularRaw;
  14410. exports.geoGnomonic = gnomonic;
  14411. exports.geoGnomonicRaw = gnomonicRaw;
  14412. exports.geoIdentity = identity$5;
  14413. exports.geoProjection = projection;
  14414. exports.geoProjectionMutator = projectionMutator;
  14415. exports.geoMercator = mercator;
  14416. exports.geoMercatorRaw = mercatorRaw;
  14417. exports.geoNaturalEarth1 = naturalEarth1;
  14418. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  14419. exports.geoOrthographic = orthographic;
  14420. exports.geoOrthographicRaw = orthographicRaw;
  14421. exports.geoStereographic = stereographic;
  14422. exports.geoStereographicRaw = stereographicRaw;
  14423. exports.geoTransverseMercator = transverseMercator;
  14424. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  14425. exports.geoRotation = rotation;
  14426. exports.geoStream = geoStream;
  14427. exports.geoTransform = transform;
  14428. exports.cluster = cluster;
  14429. exports.hierarchy = hierarchy;
  14430. exports.pack = index$2;
  14431. exports.packSiblings = siblings;
  14432. exports.packEnclose = enclose;
  14433. exports.partition = partition;
  14434. exports.stratify = stratify;
  14435. exports.tree = tree;
  14436. exports.treemap = index$3;
  14437. exports.treemapBinary = binary;
  14438. exports.treemapDice = treemapDice;
  14439. exports.treemapSlice = treemapSlice;
  14440. exports.treemapSliceDice = sliceDice;
  14441. exports.treemapSquarify = squarify;
  14442. exports.treemapResquarify = resquarify;
  14443. exports.interpolate = interpolateValue;
  14444. exports.interpolateArray = array$1;
  14445. exports.interpolateBasis = basis$1;
  14446. exports.interpolateBasisClosed = basisClosed;
  14447. exports.interpolateDate = date;
  14448. exports.interpolateNumber = reinterpolate;
  14449. exports.interpolateObject = object;
  14450. exports.interpolateRound = interpolateRound;
  14451. exports.interpolateString = interpolateString;
  14452. exports.interpolateTransformCss = interpolateTransformCss;
  14453. exports.interpolateTransformSvg = interpolateTransformSvg;
  14454. exports.interpolateZoom = interpolateZoom;
  14455. exports.interpolateRgb = interpolateRgb;
  14456. exports.interpolateRgbBasis = rgbBasis;
  14457. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  14458. exports.interpolateHsl = hsl$2;
  14459. exports.interpolateHslLong = hslLong;
  14460. exports.interpolateLab = lab$1;
  14461. exports.interpolateHcl = hcl$2;
  14462. exports.interpolateHclLong = hclLong;
  14463. exports.interpolateCubehelix = cubehelix$2;
  14464. exports.interpolateCubehelixLong = cubehelixLong;
  14465. exports.quantize = quantize;
  14466. exports.path = path;
  14467. exports.polygonArea = area$1;
  14468. exports.polygonCentroid = centroid$1;
  14469. exports.polygonHull = hull;
  14470. exports.polygonContains = contains$1;
  14471. exports.polygonLength = length$2;
  14472. exports.quadtree = quadtree;
  14473. exports.queue = queue;
  14474. exports.randomUniform = uniform;
  14475. exports.randomNormal = normal;
  14476. exports.randomLogNormal = logNormal;
  14477. exports.randomBates = bates;
  14478. exports.randomIrwinHall = irwinHall;
  14479. exports.randomExponential = exponential$1;
  14480. exports.request = request;
  14481. exports.html = html;
  14482. exports.json = json;
  14483. exports.text = text;
  14484. exports.xml = xml;
  14485. exports.csv = csv$1;
  14486. exports.tsv = tsv$1;
  14487. exports.scaleBand = band;
  14488. exports.scalePoint = point$1;
  14489. exports.scaleIdentity = identity$6;
  14490. exports.scaleLinear = linear$2;
  14491. exports.scaleLog = log$1;
  14492. exports.scaleOrdinal = ordinal;
  14493. exports.scaleImplicit = implicit;
  14494. exports.scalePow = pow$1;
  14495. exports.scaleSqrt = sqrt$1;
  14496. exports.scaleQuantile = quantile$$1;
  14497. exports.scaleQuantize = quantize$1;
  14498. exports.scaleThreshold = threshold$1;
  14499. exports.scaleTime = time;
  14500. exports.scaleUtc = utcTime;
  14501. exports.schemeCategory10 = category10;
  14502. exports.schemeCategory20b = category20b;
  14503. exports.schemeCategory20c = category20c;
  14504. exports.schemeCategory20 = category20;
  14505. exports.interpolateCubehelixDefault = cubehelix$3;
  14506. exports.interpolateRainbow = rainbow$1;
  14507. exports.interpolateWarm = warm;
  14508. exports.interpolateCool = cool;
  14509. exports.interpolateViridis = viridis;
  14510. exports.interpolateMagma = magma;
  14511. exports.interpolateInferno = inferno;
  14512. exports.interpolatePlasma = plasma;
  14513. exports.scaleSequential = sequential;
  14514. exports.create = create;
  14515. exports.creator = creator;
  14516. exports.local = local$1;
  14517. exports.matcher = matcher$1;
  14518. exports.mouse = mouse;
  14519. exports.namespace = namespace;
  14520. exports.namespaces = namespaces;
  14521. exports.clientPoint = point;
  14522. exports.select = select;
  14523. exports.selectAll = selectAll;
  14524. exports.selection = selection;
  14525. exports.selector = selector;
  14526. exports.selectorAll = selectorAll;
  14527. exports.style = styleValue;
  14528. exports.touch = touch;
  14529. exports.touches = touches;
  14530. exports.window = defaultView;
  14531. exports.customEvent = customEvent;
  14532. exports.arc = arc;
  14533. exports.area = area$2;
  14534. exports.line = line;
  14535. exports.pie = pie;
  14536. exports.areaRadial = areaRadial;
  14537. exports.radialArea = areaRadial;
  14538. exports.lineRadial = lineRadial$1;
  14539. exports.radialLine = lineRadial$1;
  14540. exports.pointRadial = pointRadial;
  14541. exports.linkHorizontal = linkHorizontal;
  14542. exports.linkVertical = linkVertical;
  14543. exports.linkRadial = linkRadial;
  14544. exports.symbol = symbol;
  14545. exports.symbols = symbols;
  14546. exports.symbolCircle = circle$2;
  14547. exports.symbolCross = cross$2;
  14548. exports.symbolDiamond = diamond;
  14549. exports.symbolSquare = square;
  14550. exports.symbolStar = star;
  14551. exports.symbolTriangle = triangle;
  14552. exports.symbolWye = wye;
  14553. exports.curveBasisClosed = basisClosed$1;
  14554. exports.curveBasisOpen = basisOpen;
  14555. exports.curveBasis = basis$2;
  14556. exports.curveBundle = bundle;
  14557. exports.curveCardinalClosed = cardinalClosed;
  14558. exports.curveCardinalOpen = cardinalOpen;
  14559. exports.curveCardinal = cardinal;
  14560. exports.curveCatmullRomClosed = catmullRomClosed;
  14561. exports.curveCatmullRomOpen = catmullRomOpen;
  14562. exports.curveCatmullRom = catmullRom;
  14563. exports.curveLinearClosed = linearClosed;
  14564. exports.curveLinear = curveLinear;
  14565. exports.curveMonotoneX = monotoneX;
  14566. exports.curveMonotoneY = monotoneY;
  14567. exports.curveNatural = natural;
  14568. exports.curveStep = step;
  14569. exports.curveStepAfter = stepAfter;
  14570. exports.curveStepBefore = stepBefore;
  14571. exports.stack = stack;
  14572. exports.stackOffsetExpand = expand;
  14573. exports.stackOffsetDiverging = diverging;
  14574. exports.stackOffsetNone = none$1;
  14575. exports.stackOffsetSilhouette = silhouette;
  14576. exports.stackOffsetWiggle = wiggle;
  14577. exports.stackOrderAscending = ascending$2;
  14578. exports.stackOrderDescending = descending$2;
  14579. exports.stackOrderInsideOut = insideOut;
  14580. exports.stackOrderNone = none$2;
  14581. exports.stackOrderReverse = reverse;
  14582. exports.timeInterval = newInterval;
  14583. exports.timeMillisecond = millisecond;
  14584. exports.timeMilliseconds = milliseconds;
  14585. exports.utcMillisecond = millisecond;
  14586. exports.utcMilliseconds = milliseconds;
  14587. exports.timeSecond = second;
  14588. exports.timeSeconds = seconds;
  14589. exports.utcSecond = second;
  14590. exports.utcSeconds = seconds;
  14591. exports.timeMinute = minute;
  14592. exports.timeMinutes = minutes;
  14593. exports.timeHour = hour;
  14594. exports.timeHours = hours;
  14595. exports.timeDay = day;
  14596. exports.timeDays = days;
  14597. exports.timeWeek = sunday;
  14598. exports.timeWeeks = sundays;
  14599. exports.timeSunday = sunday;
  14600. exports.timeSundays = sundays;
  14601. exports.timeMonday = monday;
  14602. exports.timeMondays = mondays;
  14603. exports.timeTuesday = tuesday;
  14604. exports.timeTuesdays = tuesdays;
  14605. exports.timeWednesday = wednesday;
  14606. exports.timeWednesdays = wednesdays;
  14607. exports.timeThursday = thursday;
  14608. exports.timeThursdays = thursdays;
  14609. exports.timeFriday = friday;
  14610. exports.timeFridays = fridays;
  14611. exports.timeSaturday = saturday;
  14612. exports.timeSaturdays = saturdays;
  14613. exports.timeMonth = month;
  14614. exports.timeMonths = months;
  14615. exports.timeYear = year;
  14616. exports.timeYears = years;
  14617. exports.utcMinute = utcMinute;
  14618. exports.utcMinutes = utcMinutes;
  14619. exports.utcHour = utcHour;
  14620. exports.utcHours = utcHours;
  14621. exports.utcDay = utcDay;
  14622. exports.utcDays = utcDays;
  14623. exports.utcWeek = utcSunday;
  14624. exports.utcWeeks = utcSundays;
  14625. exports.utcSunday = utcSunday;
  14626. exports.utcSundays = utcSundays;
  14627. exports.utcMonday = utcMonday;
  14628. exports.utcMondays = utcMondays;
  14629. exports.utcTuesday = utcTuesday;
  14630. exports.utcTuesdays = utcTuesdays;
  14631. exports.utcWednesday = utcWednesday;
  14632. exports.utcWednesdays = utcWednesdays;
  14633. exports.utcThursday = utcThursday;
  14634. exports.utcThursdays = utcThursdays;
  14635. exports.utcFriday = utcFriday;
  14636. exports.utcFridays = utcFridays;
  14637. exports.utcSaturday = utcSaturday;
  14638. exports.utcSaturdays = utcSaturdays;
  14639. exports.utcMonth = utcMonth;
  14640. exports.utcMonths = utcMonths;
  14641. exports.utcYear = utcYear;
  14642. exports.utcYears = utcYears;
  14643. exports.timeFormatDefaultLocale = defaultLocale$1;
  14644. exports.timeFormatLocale = formatLocale$1;
  14645. exports.isoFormat = formatIso;
  14646. exports.isoParse = parseIso;
  14647. exports.now = now;
  14648. exports.timer = timer;
  14649. exports.timerFlush = timerFlush;
  14650. exports.timeout = timeout$1;
  14651. exports.interval = interval$1;
  14652. exports.transition = transition;
  14653. exports.active = active;
  14654. exports.interrupt = interrupt;
  14655. exports.voronoi = voronoi;
  14656. exports.zoom = zoom;
  14657. exports.zoomTransform = transform$1;
  14658. exports.zoomIdentity = identity$8;
  14659. Object.defineProperty(exports, '__esModule', { value: true });
  14660. })));