d3.js 452 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945
  1. // https://d3js.org Version 4.0.0. Copyright 2016 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.0.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 descending(a, b) {
  45. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  46. }
  47. function number(x) {
  48. return x === null ? NaN : +x;
  49. }
  50. function variance(array, f) {
  51. var n = array.length,
  52. m = 0,
  53. a,
  54. d,
  55. s = 0,
  56. i = -1,
  57. j = 0;
  58. if (f == null) {
  59. while (++i < n) {
  60. if (!isNaN(a = number(array[i]))) {
  61. d = a - m;
  62. m += d / ++j;
  63. s += d * (a - m);
  64. }
  65. }
  66. }
  67. else {
  68. while (++i < n) {
  69. if (!isNaN(a = number(f(array[i], i, array)))) {
  70. d = a - m;
  71. m += d / ++j;
  72. s += d * (a - m);
  73. }
  74. }
  75. }
  76. if (j > 1) return s / (j - 1);
  77. }
  78. function deviation(array, f) {
  79. var v = variance(array, f);
  80. return v ? Math.sqrt(v) : v;
  81. }
  82. function extent(array, f) {
  83. var i = -1,
  84. n = array.length,
  85. a,
  86. b,
  87. c;
  88. if (f == null) {
  89. while (++i < n) if ((b = array[i]) != null && b >= b) { a = c = b; break; }
  90. while (++i < n) if ((b = array[i]) != null) {
  91. if (a > b) a = b;
  92. if (c < b) c = b;
  93. }
  94. }
  95. else {
  96. while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = c = b; break; }
  97. while (++i < n) if ((b = f(array[i], i, array)) != null) {
  98. if (a > b) a = b;
  99. if (c < b) c = b;
  100. }
  101. }
  102. return [a, c];
  103. }
  104. var array = Array.prototype;
  105. var slice = array.slice;
  106. var map = array.map;
  107. function constant(x) {
  108. return function() {
  109. return x;
  110. };
  111. }
  112. function identity(x) {
  113. return x;
  114. }
  115. function range(start, stop, step) {
  116. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  117. var i = -1,
  118. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  119. range = new Array(n);
  120. while (++i < n) {
  121. range[i] = start + i * step;
  122. }
  123. return range;
  124. }
  125. var e10 = Math.sqrt(50);
  126. var e5 = Math.sqrt(10);
  127. var e2 = Math.sqrt(2);
  128. function ticks(start, stop, count) {
  129. var step = tickStep(start, stop, count);
  130. return range(
  131. Math.ceil(start / step) * step,
  132. Math.floor(stop / step) * step + step / 2, // inclusive
  133. step
  134. );
  135. }
  136. function tickStep(start, stop, count) {
  137. var step0 = Math.abs(stop - start) / Math.max(0, count),
  138. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  139. error = step0 / step1;
  140. if (error >= e10) step1 *= 10;
  141. else if (error >= e5) step1 *= 5;
  142. else if (error >= e2) step1 *= 2;
  143. return stop < start ? -step1 : step1;
  144. }
  145. function sturges(values) {
  146. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  147. }
  148. function histogram() {
  149. var value = identity,
  150. domain = extent,
  151. threshold = sturges;
  152. function histogram(data) {
  153. var i,
  154. n = data.length,
  155. x,
  156. values = new Array(n);
  157. for (i = 0; i < n; ++i) {
  158. values[i] = value(data[i], i, data);
  159. }
  160. var xz = domain(values),
  161. x0 = xz[0],
  162. x1 = xz[1],
  163. tz = threshold(values, x0, x1);
  164. // Convert number of thresholds into uniform thresholds.
  165. if (!Array.isArray(tz)) tz = ticks(x0, x1, tz);
  166. // Remove any thresholds outside the domain.
  167. var m = tz.length;
  168. while (tz[0] <= x0) tz.shift(), --m;
  169. while (tz[m - 1] >= x1) tz.pop(), --m;
  170. var bins = new Array(m + 1),
  171. bin;
  172. // Initialize bins.
  173. for (i = 0; i <= m; ++i) {
  174. bin = bins[i] = [];
  175. bin.x0 = i > 0 ? tz[i - 1] : x0;
  176. bin.x1 = i < m ? tz[i] : x1;
  177. }
  178. // Assign data to bins by value, ignoring any outside the domain.
  179. for (i = 0; i < n; ++i) {
  180. x = values[i];
  181. if (x0 <= x && x <= x1) {
  182. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  183. }
  184. }
  185. return bins;
  186. }
  187. histogram.value = function(_) {
  188. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  189. };
  190. histogram.domain = function(_) {
  191. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  192. };
  193. histogram.thresholds = function(_) {
  194. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  195. };
  196. return histogram;
  197. }
  198. function threshold(array, p, f) {
  199. if (f == null) f = number;
  200. if (!(n = array.length)) return;
  201. if ((p = +p) <= 0 || n < 2) return +f(array[0], 0, array);
  202. if (p >= 1) return +f(array[n - 1], n - 1, array);
  203. var n,
  204. h = (n - 1) * p,
  205. i = Math.floor(h),
  206. a = +f(array[i], i, array),
  207. b = +f(array[i + 1], i + 1, array);
  208. return a + (b - a) * (h - i);
  209. }
  210. function freedmanDiaconis(values, min, max) {
  211. values = map.call(values, number).sort(ascending);
  212. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  213. }
  214. function scott(values, min, max) {
  215. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  216. }
  217. function max(array, f) {
  218. var i = -1,
  219. n = array.length,
  220. a,
  221. b;
  222. if (f == null) {
  223. while (++i < n) if ((b = array[i]) != null && b >= b) { a = b; break; }
  224. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  225. }
  226. else {
  227. while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = b; break; }
  228. while (++i < n) if ((b = f(array[i], i, array)) != null && b > a) a = b;
  229. }
  230. return a;
  231. }
  232. function mean(array, f) {
  233. var s = 0,
  234. n = array.length,
  235. a,
  236. i = -1,
  237. j = n;
  238. if (f == null) {
  239. while (++i < n) if (!isNaN(a = number(array[i]))) s += a; else --j;
  240. }
  241. else {
  242. while (++i < n) if (!isNaN(a = number(f(array[i], i, array)))) s += a; else --j;
  243. }
  244. if (j) return s / j;
  245. }
  246. function median(array, f) {
  247. var numbers = [],
  248. n = array.length,
  249. a,
  250. i = -1;
  251. if (f == null) {
  252. while (++i < n) if (!isNaN(a = number(array[i]))) numbers.push(a);
  253. }
  254. else {
  255. while (++i < n) if (!isNaN(a = number(f(array[i], i, array)))) numbers.push(a);
  256. }
  257. return threshold(numbers.sort(ascending), 0.5);
  258. }
  259. function merge(arrays) {
  260. var n = arrays.length,
  261. m,
  262. i = -1,
  263. j = 0,
  264. merged,
  265. array;
  266. while (++i < n) j += arrays[i].length;
  267. merged = new Array(j);
  268. while (--n >= 0) {
  269. array = arrays[n];
  270. m = array.length;
  271. while (--m >= 0) {
  272. merged[--j] = array[m];
  273. }
  274. }
  275. return merged;
  276. }
  277. function min(array, f) {
  278. var i = -1,
  279. n = array.length,
  280. a,
  281. b;
  282. if (f == null) {
  283. while (++i < n) if ((b = array[i]) != null && b >= b) { a = b; break; }
  284. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  285. }
  286. else {
  287. while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = b; break; }
  288. while (++i < n) if ((b = f(array[i], i, array)) != null && a > b) a = b;
  289. }
  290. return a;
  291. }
  292. function pairs(array) {
  293. var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
  294. while (i < n) pairs[i] = [p, p = array[++i]];
  295. return pairs;
  296. }
  297. function permute(array, indexes) {
  298. var i = indexes.length, permutes = new Array(i);
  299. while (i--) permutes[i] = array[indexes[i]];
  300. return permutes;
  301. }
  302. function scan(array, compare) {
  303. if (!(n = array.length)) return;
  304. var i = 0,
  305. n,
  306. j = 0,
  307. xi,
  308. xj = array[j];
  309. if (!compare) compare = ascending;
  310. while (++i < n) if (compare(xi = array[i], xj) < 0 || compare(xj, xj) !== 0) xj = xi, j = i;
  311. if (compare(xj, xj) === 0) return j;
  312. }
  313. function shuffle(array, i0, i1) {
  314. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  315. t,
  316. i;
  317. while (m) {
  318. i = Math.random() * m-- | 0;
  319. t = array[m + i0];
  320. array[m + i0] = array[i + i0];
  321. array[i + i0] = t;
  322. }
  323. return array;
  324. }
  325. function sum(array, f) {
  326. var s = 0,
  327. n = array.length,
  328. a,
  329. i = -1;
  330. if (f == null) {
  331. while (++i < n) if (a = +array[i]) s += a; // Note: zero and null are equivalent.
  332. }
  333. else {
  334. while (++i < n) if (a = +f(array[i], i, array)) s += a;
  335. }
  336. return s;
  337. }
  338. function transpose(matrix) {
  339. if (!(n = matrix.length)) return [];
  340. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  341. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  342. row[j] = matrix[j][i];
  343. }
  344. }
  345. return transpose;
  346. }
  347. function length(d) {
  348. return d.length;
  349. }
  350. function zip() {
  351. return transpose(arguments);
  352. }
  353. var prefix = "$";
  354. function Map() {}
  355. Map.prototype = map$1.prototype = {
  356. constructor: Map,
  357. has: function(key) {
  358. return (prefix + key) in this;
  359. },
  360. get: function(key) {
  361. return this[prefix + key];
  362. },
  363. set: function(key, value) {
  364. this[prefix + key] = value;
  365. return this;
  366. },
  367. remove: function(key) {
  368. var property = prefix + key;
  369. return property in this && delete this[property];
  370. },
  371. clear: function() {
  372. for (var property in this) if (property[0] === prefix) delete this[property];
  373. },
  374. keys: function() {
  375. var keys = [];
  376. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  377. return keys;
  378. },
  379. values: function() {
  380. var values = [];
  381. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  382. return values;
  383. },
  384. entries: function() {
  385. var entries = [];
  386. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  387. return entries;
  388. },
  389. size: function() {
  390. var size = 0;
  391. for (var property in this) if (property[0] === prefix) ++size;
  392. return size;
  393. },
  394. empty: function() {
  395. for (var property in this) if (property[0] === prefix) return false;
  396. return true;
  397. },
  398. each: function(f) {
  399. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  400. }
  401. };
  402. function map$1(object, f) {
  403. var map = new Map;
  404. // Copy constructor.
  405. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  406. // Index array by numeric index or specified key function.
  407. else if (Array.isArray(object)) {
  408. var i = -1,
  409. n = object.length,
  410. o;
  411. if (f == null) while (++i < n) map.set(i, object[i]);
  412. else while (++i < n) map.set(f(o = object[i], i, object), o);
  413. }
  414. // Convert object to map.
  415. else if (object) for (var key in object) map.set(key, object[key]);
  416. return map;
  417. }
  418. function nest() {
  419. var keys = [],
  420. sortKeys = [],
  421. sortValues,
  422. rollup,
  423. nest;
  424. function apply(array, depth, createResult, setResult) {
  425. if (depth >= keys.length) return rollup != null
  426. ? rollup(array) : (sortValues != null
  427. ? array.sort(sortValues)
  428. : array);
  429. var i = -1,
  430. n = array.length,
  431. key = keys[depth++],
  432. keyValue,
  433. value,
  434. valuesByKey = map$1(),
  435. values,
  436. result = createResult();
  437. while (++i < n) {
  438. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  439. values.push(value);
  440. } else {
  441. valuesByKey.set(keyValue, [value]);
  442. }
  443. }
  444. valuesByKey.each(function(values, key) {
  445. setResult(result, key, apply(values, depth, createResult, setResult));
  446. });
  447. return result;
  448. }
  449. function entries(map, depth) {
  450. if (++depth > keys.length) return map;
  451. var array, sortKey = sortKeys[depth - 1];
  452. if (rollup != null && depth >= keys.length) array = map.entries();
  453. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  454. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  455. }
  456. return nest = {
  457. object: function(array) { return apply(array, 0, createObject, setObject); },
  458. map: function(array) { return apply(array, 0, createMap, setMap); },
  459. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  460. key: function(d) { keys.push(d); return nest; },
  461. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  462. sortValues: function(order) { sortValues = order; return nest; },
  463. rollup: function(f) { rollup = f; return nest; }
  464. };
  465. }
  466. function createObject() {
  467. return {};
  468. }
  469. function setObject(object, key, value) {
  470. object[key] = value;
  471. }
  472. function createMap() {
  473. return map$1();
  474. }
  475. function setMap(map, key, value) {
  476. map.set(key, value);
  477. }
  478. function Set() {}
  479. var proto = map$1.prototype;
  480. Set.prototype = set.prototype = {
  481. constructor: Set,
  482. has: proto.has,
  483. add: function(value) {
  484. value += "";
  485. this[prefix + value] = value;
  486. return this;
  487. },
  488. remove: proto.remove,
  489. clear: proto.clear,
  490. values: proto.keys,
  491. size: proto.size,
  492. empty: proto.empty,
  493. each: proto.each
  494. };
  495. function set(object, f) {
  496. var set = new Set;
  497. // Copy constructor.
  498. if (object instanceof Set) object.each(function(value) { set.add(value); });
  499. // Otherwise, assume it’s an array.
  500. else if (object) {
  501. var i = -1, n = object.length;
  502. if (f == null) while (++i < n) set.add(object[i]);
  503. else while (++i < n) set.add(f(object[i], i, object));
  504. }
  505. return set;
  506. }
  507. function keys(map) {
  508. var keys = [];
  509. for (var key in map) keys.push(key);
  510. return keys;
  511. }
  512. function values(map) {
  513. var values = [];
  514. for (var key in map) values.push(map[key]);
  515. return values;
  516. }
  517. function entries(map) {
  518. var entries = [];
  519. for (var key in map) entries.push({key: key, value: map[key]});
  520. return entries;
  521. }
  522. function uniform(min, max) {
  523. min = min == null ? 0 : +min;
  524. max = max == null ? 1 : +max;
  525. if (arguments.length === 1) max = min, min = 0;
  526. else max -= min;
  527. return function() {
  528. return Math.random() * max + min;
  529. };
  530. }
  531. function normal(mu, sigma) {
  532. var x, r;
  533. mu = mu == null ? 0 : +mu;
  534. sigma = sigma == null ? 1 : +sigma;
  535. return function() {
  536. var y;
  537. // If available, use the second previously-generated uniform random.
  538. if (x != null) y = x, x = null;
  539. // Otherwise, generate a new x and y.
  540. else do {
  541. x = Math.random() * 2 - 1;
  542. y = Math.random() * 2 - 1;
  543. r = x * x + y * y;
  544. } while (!r || r > 1);
  545. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  546. };
  547. }
  548. function logNormal() {
  549. var randomNormal = normal.apply(this, arguments);
  550. return function() {
  551. return Math.exp(randomNormal());
  552. };
  553. }
  554. function irwinHall(n) {
  555. return function() {
  556. for (var sum = 0, i = 0; i < n; ++i) sum += Math.random();
  557. return sum;
  558. };
  559. }
  560. function bates(n) {
  561. var randomIrwinHall = irwinHall(n);
  562. return function() {
  563. return randomIrwinHall() / n;
  564. };
  565. }
  566. function exponential(lambda) {
  567. return function() {
  568. return -Math.log(1 - Math.random()) / lambda;
  569. };
  570. }
  571. function linear(t) {
  572. return +t;
  573. }
  574. function quadIn(t) {
  575. return t * t;
  576. }
  577. function quadOut(t) {
  578. return t * (2 - t);
  579. }
  580. function quadInOut(t) {
  581. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  582. }
  583. function cubicIn(t) {
  584. return t * t * t;
  585. }
  586. function cubicOut(t) {
  587. return --t * t * t + 1;
  588. }
  589. function easeCubicInOut(t) {
  590. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  591. }
  592. var exponent = 3;
  593. var polyIn = (function custom(e) {
  594. e = +e;
  595. function polyIn(t) {
  596. return Math.pow(t, e);
  597. }
  598. polyIn.exponent = custom;
  599. return polyIn;
  600. })(exponent);
  601. var polyOut = (function custom(e) {
  602. e = +e;
  603. function polyOut(t) {
  604. return 1 - Math.pow(1 - t, e);
  605. }
  606. polyOut.exponent = custom;
  607. return polyOut;
  608. })(exponent);
  609. var polyInOut = (function custom(e) {
  610. e = +e;
  611. function polyInOut(t) {
  612. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  613. }
  614. polyInOut.exponent = custom;
  615. return polyInOut;
  616. })(exponent);
  617. var pi = Math.PI;
  618. var halfPi = pi / 2;
  619. function sinIn(t) {
  620. return 1 - Math.cos(t * halfPi);
  621. }
  622. function sinOut(t) {
  623. return Math.sin(t * halfPi);
  624. }
  625. function sinInOut(t) {
  626. return (1 - Math.cos(pi * t)) / 2;
  627. }
  628. function expIn(t) {
  629. return Math.pow(2, 10 * t - 10);
  630. }
  631. function expOut(t) {
  632. return 1 - Math.pow(2, -10 * t);
  633. }
  634. function expInOut(t) {
  635. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  636. }
  637. function circleIn(t) {
  638. return 1 - Math.sqrt(1 - t * t);
  639. }
  640. function circleOut(t) {
  641. return Math.sqrt(1 - --t * t);
  642. }
  643. function circleInOut(t) {
  644. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  645. }
  646. var b1 = 4 / 11;
  647. var b2 = 6 / 11;
  648. var b3 = 8 / 11;
  649. var b4 = 3 / 4;
  650. var b5 = 9 / 11;
  651. var b6 = 10 / 11;
  652. var b7 = 15 / 16;
  653. var b8 = 21 / 22;
  654. var b9 = 63 / 64;
  655. var b0 = 1 / b1 / b1;
  656. function bounceIn(t) {
  657. return 1 - bounceOut(1 - t);
  658. }
  659. function bounceOut(t) {
  660. 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;
  661. }
  662. function bounceInOut(t) {
  663. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  664. }
  665. var overshoot = 1.70158;
  666. var backIn = (function custom(s) {
  667. s = +s;
  668. function backIn(t) {
  669. return t * t * ((s + 1) * t - s);
  670. }
  671. backIn.overshoot = custom;
  672. return backIn;
  673. })(overshoot);
  674. var backOut = (function custom(s) {
  675. s = +s;
  676. function backOut(t) {
  677. return --t * t * ((s + 1) * t + s) + 1;
  678. }
  679. backOut.overshoot = custom;
  680. return backOut;
  681. })(overshoot);
  682. var backInOut = (function custom(s) {
  683. s = +s;
  684. function backInOut(t) {
  685. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  686. }
  687. backInOut.overshoot = custom;
  688. return backInOut;
  689. })(overshoot);
  690. var tau = 2 * Math.PI;
  691. var amplitude = 1;
  692. var period = 0.3;
  693. var elasticIn = (function custom(a, p) {
  694. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  695. function elasticIn(t) {
  696. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  697. }
  698. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  699. elasticIn.period = function(p) { return custom(a, p); };
  700. return elasticIn;
  701. })(amplitude, period);
  702. var elasticOut = (function custom(a, p) {
  703. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  704. function elasticOut(t) {
  705. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  706. }
  707. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  708. elasticOut.period = function(p) { return custom(a, p); };
  709. return elasticOut;
  710. })(amplitude, period);
  711. var elasticInOut = (function custom(a, p) {
  712. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  713. function elasticInOut(t) {
  714. return ((t = t * 2 - 1) < 0
  715. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  716. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  717. }
  718. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  719. elasticInOut.period = function(p) { return custom(a, p); };
  720. return elasticInOut;
  721. })(amplitude, period);
  722. function area(polygon) {
  723. var i = -1,
  724. n = polygon.length,
  725. a,
  726. b = polygon[n - 1],
  727. area = 0;
  728. while (++i < n) {
  729. a = b;
  730. b = polygon[i];
  731. area += a[1] * b[0] - a[0] * b[1];
  732. }
  733. return area / 2;
  734. }
  735. function centroid(polygon) {
  736. var i = -1,
  737. n = polygon.length,
  738. x = 0,
  739. y = 0,
  740. a,
  741. b = polygon[n - 1],
  742. c,
  743. k = 0;
  744. while (++i < n) {
  745. a = b;
  746. b = polygon[i];
  747. k += c = a[0] * b[1] - b[0] * a[1];
  748. x += (a[0] + b[0]) * c;
  749. y += (a[1] + b[1]) * c;
  750. }
  751. return k *= 3, [x / k, y / k];
  752. }
  753. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  754. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  755. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  756. // negative if clockwise, and zero if the points are collinear.
  757. function cross(a, b, c) {
  758. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  759. }
  760. function lexicographicOrder(a, b) {
  761. return a[0] - b[0] || a[1] - b[1];
  762. }
  763. // Computes the upper convex hull per the monotone chain algorithm.
  764. // Assumes points.length >= 3, is sorted by x, unique in y.
  765. // Returns an array of indices into points in left-to-right order.
  766. function computeUpperHullIndexes(points) {
  767. var n = points.length,
  768. indexes = [0, 1],
  769. size = 2;
  770. for (var i = 2; i < n; ++i) {
  771. while (size > 1 && cross(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  772. indexes[size++] = i;
  773. }
  774. return indexes.slice(0, size); // remove popped points
  775. }
  776. function hull(points) {
  777. if ((n = points.length) < 3) return null;
  778. var i,
  779. n,
  780. sortedPoints = new Array(n),
  781. flippedPoints = new Array(n);
  782. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  783. sortedPoints.sort(lexicographicOrder);
  784. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  785. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  786. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  787. // Construct the hull polygon, removing possible duplicate endpoints.
  788. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  789. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  790. hull = [];
  791. // Add upper hull in right-to-l order.
  792. // Then add lower hull in left-to-right order.
  793. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  794. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  795. return hull;
  796. }
  797. function contains(polygon, point) {
  798. var n = polygon.length,
  799. p = polygon[n - 1],
  800. x = point[0], y = point[1],
  801. x0 = p[0], y0 = p[1],
  802. x1, y1,
  803. inside = false;
  804. for (var i = 0; i < n; ++i) {
  805. p = polygon[i], x1 = p[0], y1 = p[1];
  806. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  807. x0 = x1, y0 = y1;
  808. }
  809. return inside;
  810. }
  811. function length$1(polygon) {
  812. var i = -1,
  813. n = polygon.length,
  814. b = polygon[n - 1],
  815. xa,
  816. ya,
  817. xb = b[0],
  818. yb = b[1],
  819. perimeter = 0;
  820. while (++i < n) {
  821. xa = xb;
  822. ya = yb;
  823. b = polygon[i];
  824. xb = b[0];
  825. yb = b[1];
  826. xa -= xb;
  827. ya -= yb;
  828. perimeter += Math.sqrt(xa * xa + ya * ya);
  829. }
  830. return perimeter;
  831. }
  832. var pi$1 = Math.PI;
  833. var tau$1 = 2 * pi$1;
  834. var epsilon = 1e-6;
  835. var tauEpsilon = tau$1 - epsilon;
  836. function Path() {
  837. this._x0 = this._y0 = // start of current subpath
  838. this._x1 = this._y1 = null; // end of current subpath
  839. this._ = [];
  840. }
  841. function path() {
  842. return new Path;
  843. }
  844. Path.prototype = path.prototype = {
  845. constructor: Path,
  846. moveTo: function(x, y) {
  847. this._.push("M", this._x0 = this._x1 = +x, ",", this._y0 = this._y1 = +y);
  848. },
  849. closePath: function() {
  850. if (this._x1 !== null) {
  851. this._x1 = this._x0, this._y1 = this._y0;
  852. this._.push("Z");
  853. }
  854. },
  855. lineTo: function(x, y) {
  856. this._.push("L", this._x1 = +x, ",", this._y1 = +y);
  857. },
  858. quadraticCurveTo: function(x1, y1, x, y) {
  859. this._.push("Q", +x1, ",", +y1, ",", this._x1 = +x, ",", this._y1 = +y);
  860. },
  861. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  862. this._.push("C", +x1, ",", +y1, ",", +x2, ",", +y2, ",", this._x1 = +x, ",", this._y1 = +y);
  863. },
  864. arcTo: function(x1, y1, x2, y2, r) {
  865. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  866. var x0 = this._x1,
  867. y0 = this._y1,
  868. x21 = x2 - x1,
  869. y21 = y2 - y1,
  870. x01 = x0 - x1,
  871. y01 = y0 - y1,
  872. l01_2 = x01 * x01 + y01 * y01;
  873. // Is the radius negative? Error.
  874. if (r < 0) throw new Error("negative radius: " + r);
  875. // Is this path empty? Move to (x1,y1).
  876. if (this._x1 === null) {
  877. this._.push(
  878. "M", this._x1 = x1, ",", this._y1 = y1
  879. );
  880. }
  881. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  882. else if (!(l01_2 > epsilon));
  883. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  884. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  885. // Or, is the radius zero? Line to (x1,y1).
  886. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon) || !r) {
  887. this._.push(
  888. "L", this._x1 = x1, ",", this._y1 = y1
  889. );
  890. }
  891. // Otherwise, draw an arc!
  892. else {
  893. var x20 = x2 - x0,
  894. y20 = y2 - y0,
  895. l21_2 = x21 * x21 + y21 * y21,
  896. l20_2 = x20 * x20 + y20 * y20,
  897. l21 = Math.sqrt(l21_2),
  898. l01 = Math.sqrt(l01_2),
  899. l = r * Math.tan((pi$1 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  900. t01 = l / l01,
  901. t21 = l / l21;
  902. // If the start tangent is not coincident with (x0,y0), line to.
  903. if (Math.abs(t01 - 1) > epsilon) {
  904. this._.push(
  905. "L", x1 + t01 * x01, ",", y1 + t01 * y01
  906. );
  907. }
  908. this._.push(
  909. "A", r, ",", r, ",0,0,", +(y01 * x20 > x01 * y20), ",", this._x1 = x1 + t21 * x21, ",", this._y1 = y1 + t21 * y21
  910. );
  911. }
  912. },
  913. arc: function(x, y, r, a0, a1, ccw) {
  914. x = +x, y = +y, r = +r;
  915. var dx = r * Math.cos(a0),
  916. dy = r * Math.sin(a0),
  917. x0 = x + dx,
  918. y0 = y + dy,
  919. cw = 1 ^ ccw,
  920. da = ccw ? a0 - a1 : a1 - a0;
  921. // Is the radius negative? Error.
  922. if (r < 0) throw new Error("negative radius: " + r);
  923. // Is this path empty? Move to (x0,y0).
  924. if (this._x1 === null) {
  925. this._.push(
  926. "M", x0, ",", y0
  927. );
  928. }
  929. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  930. else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) {
  931. this._.push(
  932. "L", x0, ",", y0
  933. );
  934. }
  935. // Is this arc empty? We’re done.
  936. if (!r) return;
  937. // Is this a complete circle? Draw two arcs to complete the circle.
  938. if (da > tauEpsilon) {
  939. this._.push(
  940. "A", r, ",", r, ",0,1,", cw, ",", x - dx, ",", y - dy,
  941. "A", r, ",", r, ",0,1,", cw, ",", this._x1 = x0, ",", this._y1 = y0
  942. );
  943. }
  944. // Otherwise, draw an arc!
  945. else {
  946. if (da < 0) da = da % tau$1 + tau$1;
  947. this._.push(
  948. "A", r, ",", r, ",0,", +(da >= pi$1), ",", cw, ",", this._x1 = x + r * Math.cos(a1), ",", this._y1 = y + r * Math.sin(a1)
  949. );
  950. }
  951. },
  952. rect: function(x, y, w, h) {
  953. this._.push("M", this._x0 = this._x1 = +x, ",", this._y0 = this._y1 = +y, "h", +w, "v", +h, "h", -w, "Z");
  954. },
  955. toString: function() {
  956. return this._.join("");
  957. }
  958. };
  959. function tree_add(d) {
  960. var x = +this._x.call(null, d),
  961. y = +this._y.call(null, d);
  962. return add(this.cover(x, y), x, y, d);
  963. }
  964. function add(tree, x, y, d) {
  965. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  966. var parent,
  967. node = tree._root,
  968. leaf = {data: d},
  969. x0 = tree._x0,
  970. y0 = tree._y0,
  971. x1 = tree._x1,
  972. y1 = tree._y1,
  973. xm,
  974. ym,
  975. xp,
  976. yp,
  977. right,
  978. bottom,
  979. i,
  980. j;
  981. // If the tree is empty, initialize the root as a leaf.
  982. if (!node) return tree._root = leaf, tree;
  983. // Find the existing leaf for the new point, or add it.
  984. while (node.length) {
  985. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  986. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  987. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  988. }
  989. // Is the new point is exactly coincident with the existing point?
  990. xp = +tree._x.call(null, node.data);
  991. yp = +tree._y.call(null, node.data);
  992. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  993. // Otherwise, split the leaf node until the old and new point are separated.
  994. do {
  995. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  996. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  997. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  998. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  999. return parent[j] = node, parent[i] = leaf, tree;
  1000. }
  1001. function addAll(data) {
  1002. var d, i, n = data.length,
  1003. x,
  1004. y,
  1005. xz = new Array(n),
  1006. yz = new Array(n),
  1007. x0 = Infinity,
  1008. y0 = Infinity,
  1009. x1 = -Infinity,
  1010. y1 = -Infinity;
  1011. // Compute the points and their extent.
  1012. for (i = 0; i < n; ++i) {
  1013. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  1014. xz[i] = x;
  1015. yz[i] = y;
  1016. if (x < x0) x0 = x;
  1017. if (x > x1) x1 = x;
  1018. if (y < y0) y0 = y;
  1019. if (y > y1) y1 = y;
  1020. }
  1021. // If there were no (valid) points, inherit the existing extent.
  1022. if (x1 < x0) x0 = this._x0, x1 = this._x1;
  1023. if (y1 < y0) y0 = this._y0, y1 = this._y1;
  1024. // Expand the tree to cover the new points.
  1025. this.cover(x0, y0).cover(x1, y1);
  1026. // Add the new points.
  1027. for (i = 0; i < n; ++i) {
  1028. add(this, xz[i], yz[i], data[i]);
  1029. }
  1030. return this;
  1031. }
  1032. function tree_cover(x, y) {
  1033. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  1034. var x0 = this._x0,
  1035. y0 = this._y0,
  1036. x1 = this._x1,
  1037. y1 = this._y1;
  1038. // If the quadtree has no extent, initialize them.
  1039. // Integer extent are necessary so that if we later double the extent,
  1040. // the existing quadrant boundaries don’t change due to floating point error!
  1041. if (isNaN(x0)) {
  1042. x1 = (x0 = Math.floor(x)) + 1;
  1043. y1 = (y0 = Math.floor(y)) + 1;
  1044. }
  1045. // Otherwise, double repeatedly to cover.
  1046. else if (x0 > x || x > x1 || y0 > y || y > y1) {
  1047. var z = x1 - x0,
  1048. node = this._root,
  1049. parent,
  1050. i;
  1051. switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
  1052. case 0: {
  1053. do parent = new Array(4), parent[i] = node, node = parent;
  1054. while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
  1055. break;
  1056. }
  1057. case 1: {
  1058. do parent = new Array(4), parent[i] = node, node = parent;
  1059. while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
  1060. break;
  1061. }
  1062. case 2: {
  1063. do parent = new Array(4), parent[i] = node, node = parent;
  1064. while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
  1065. break;
  1066. }
  1067. case 3: {
  1068. do parent = new Array(4), parent[i] = node, node = parent;
  1069. while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
  1070. break;
  1071. }
  1072. }
  1073. if (this._root && this._root.length) this._root = node;
  1074. }
  1075. // If the quadtree covers the point already, just return.
  1076. else return this;
  1077. this._x0 = x0;
  1078. this._y0 = y0;
  1079. this._x1 = x1;
  1080. this._y1 = y1;
  1081. return this;
  1082. }
  1083. function tree_data() {
  1084. var data = [];
  1085. this.visit(function(node) {
  1086. if (!node.length) do data.push(node.data); while (node = node.next)
  1087. });
  1088. return data;
  1089. }
  1090. function tree_extent(_) {
  1091. return arguments.length
  1092. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  1093. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  1094. }
  1095. function Quad(node, x0, y0, x1, y1) {
  1096. this.node = node;
  1097. this.x0 = x0;
  1098. this.y0 = y0;
  1099. this.x1 = x1;
  1100. this.y1 = y1;
  1101. }
  1102. function tree_find(x, y, radius) {
  1103. var data,
  1104. x0 = this._x0,
  1105. y0 = this._y0,
  1106. x1,
  1107. y1,
  1108. x2,
  1109. y2,
  1110. x3 = this._x1,
  1111. y3 = this._y1,
  1112. quads = [],
  1113. node = this._root,
  1114. q,
  1115. i;
  1116. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  1117. if (radius == null) radius = Infinity;
  1118. else {
  1119. x0 = x - radius, y0 = y - radius;
  1120. x3 = x + radius, y3 = y + radius;
  1121. radius *= radius;
  1122. }
  1123. while (q = quads.pop()) {
  1124. // Stop searching if this quadrant can’t contain a closer node.
  1125. if (!(node = q.node)
  1126. || (x1 = q.x0) > x3
  1127. || (y1 = q.y0) > y3
  1128. || (x2 = q.x1) < x0
  1129. || (y2 = q.y1) < y0) continue;
  1130. // Bisect the current quadrant.
  1131. if (node.length) {
  1132. var xm = (x1 + x2) / 2,
  1133. ym = (y1 + y2) / 2;
  1134. quads.push(
  1135. new Quad(node[3], xm, ym, x2, y2),
  1136. new Quad(node[2], x1, ym, xm, y2),
  1137. new Quad(node[1], xm, y1, x2, ym),
  1138. new Quad(node[0], x1, y1, xm, ym)
  1139. );
  1140. // Visit the closest quadrant first.
  1141. if (i = (y >= ym) << 1 | (x >= xm)) {
  1142. q = quads[quads.length - 1];
  1143. quads[quads.length - 1] = quads[quads.length - 1 - i];
  1144. quads[quads.length - 1 - i] = q;
  1145. }
  1146. }
  1147. // Visit this point. (Visiting coincident points isn’t necessary!)
  1148. else {
  1149. var dx = x - +this._x.call(null, node.data),
  1150. dy = y - +this._y.call(null, node.data),
  1151. d2 = dx * dx + dy * dy;
  1152. if (d2 < radius) {
  1153. var d = Math.sqrt(radius = d2);
  1154. x0 = x - d, y0 = y - d;
  1155. x3 = x + d, y3 = y + d;
  1156. data = node.data;
  1157. }
  1158. }
  1159. }
  1160. return data;
  1161. }
  1162. function tree_remove(d) {
  1163. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  1164. var parent,
  1165. node = this._root,
  1166. retainer,
  1167. previous,
  1168. next,
  1169. x0 = this._x0,
  1170. y0 = this._y0,
  1171. x1 = this._x1,
  1172. y1 = this._y1,
  1173. x,
  1174. y,
  1175. xm,
  1176. ym,
  1177. right,
  1178. bottom,
  1179. i,
  1180. j;
  1181. // If the tree is empty, initialize the root as a leaf.
  1182. if (!node) return this;
  1183. // Find the leaf node for the point.
  1184. // While descending, also retain the deepest parent with a non-removed sibling.
  1185. if (node.length) while (true) {
  1186. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  1187. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  1188. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  1189. if (!node.length) break;
  1190. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  1191. }
  1192. // Find the point to remove.
  1193. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  1194. if (next = node.next) delete node.next;
  1195. // If there are multiple coincident points, remove just the point.
  1196. if (previous) return (next ? previous.next = next : delete previous.next), this;
  1197. // If this is the root point, remove it.
  1198. if (!parent) return this._root = next, this;
  1199. // Remove this leaf.
  1200. next ? parent[i] = next : delete parent[i];
  1201. // If the parent now contains exactly one leaf, collapse superfluous parents.
  1202. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  1203. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  1204. && !node.length) {
  1205. if (retainer) retainer[j] = node;
  1206. else this._root = node;
  1207. }
  1208. return this;
  1209. }
  1210. function removeAll(data) {
  1211. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  1212. return this;
  1213. }
  1214. function tree_root() {
  1215. return this._root;
  1216. }
  1217. function tree_size() {
  1218. var size = 0;
  1219. this.visit(function(node) {
  1220. if (!node.length) do ++size; while (node = node.next)
  1221. });
  1222. return size;
  1223. }
  1224. function tree_visit(callback) {
  1225. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  1226. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  1227. while (q = quads.pop()) {
  1228. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  1229. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  1230. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  1231. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  1232. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  1233. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  1234. }
  1235. }
  1236. return this;
  1237. }
  1238. function tree_visitAfter(callback) {
  1239. var quads = [], next = [], q;
  1240. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  1241. while (q = quads.pop()) {
  1242. var node = q.node;
  1243. if (node.length) {
  1244. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  1245. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  1246. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  1247. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  1248. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  1249. }
  1250. next.push(q);
  1251. }
  1252. while (q = next.pop()) {
  1253. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  1254. }
  1255. return this;
  1256. }
  1257. function defaultX(d) {
  1258. return d[0];
  1259. }
  1260. function tree_x(_) {
  1261. return arguments.length ? (this._x = _, this) : this._x;
  1262. }
  1263. function defaultY(d) {
  1264. return d[1];
  1265. }
  1266. function tree_y(_) {
  1267. return arguments.length ? (this._y = _, this) : this._y;
  1268. }
  1269. function quadtree(nodes, x, y) {
  1270. var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
  1271. return nodes == null ? tree : tree.addAll(nodes);
  1272. }
  1273. function Quadtree(x, y, x0, y0, x1, y1) {
  1274. this._x = x;
  1275. this._y = y;
  1276. this._x0 = x0;
  1277. this._y0 = y0;
  1278. this._x1 = x1;
  1279. this._y1 = y1;
  1280. this._root = undefined;
  1281. }
  1282. function leaf_copy(leaf) {
  1283. var copy = {data: leaf.data}, next = copy;
  1284. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  1285. return copy;
  1286. }
  1287. var treeProto = quadtree.prototype = Quadtree.prototype;
  1288. treeProto.copy = function() {
  1289. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  1290. node = this._root,
  1291. nodes,
  1292. child;
  1293. if (!node) return copy;
  1294. if (!node.length) return copy._root = leaf_copy(node), copy;
  1295. nodes = [{source: node, target: copy._root = new Array(4)}];
  1296. while (node = nodes.pop()) {
  1297. for (var i = 0; i < 4; ++i) {
  1298. if (child = node.source[i]) {
  1299. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  1300. else node.target[i] = leaf_copy(child);
  1301. }
  1302. }
  1303. }
  1304. return copy;
  1305. };
  1306. treeProto.add = tree_add;
  1307. treeProto.addAll = addAll;
  1308. treeProto.cover = tree_cover;
  1309. treeProto.data = tree_data;
  1310. treeProto.extent = tree_extent;
  1311. treeProto.find = tree_find;
  1312. treeProto.remove = tree_remove;
  1313. treeProto.removeAll = removeAll;
  1314. treeProto.root = tree_root;
  1315. treeProto.size = tree_size;
  1316. treeProto.visit = tree_visit;
  1317. treeProto.visitAfter = tree_visitAfter;
  1318. treeProto.x = tree_x;
  1319. treeProto.y = tree_y;
  1320. var slice$1 = [].slice;
  1321. var noabort = {};
  1322. function Queue(size) {
  1323. if (!(size >= 1)) throw new Error;
  1324. this._size = size;
  1325. this._call =
  1326. this._error = null;
  1327. this._tasks = [];
  1328. this._data = [];
  1329. this._waiting =
  1330. this._active =
  1331. this._ended =
  1332. this._start = 0; // inside a synchronous task callback?
  1333. }
  1334. Queue.prototype = queue.prototype = {
  1335. constructor: Queue,
  1336. defer: function(callback) {
  1337. if (typeof callback !== "function" || this._call) throw new Error;
  1338. if (this._error != null) return this;
  1339. var t = slice$1.call(arguments, 1);
  1340. t.push(callback);
  1341. ++this._waiting, this._tasks.push(t);
  1342. poke(this);
  1343. return this;
  1344. },
  1345. abort: function() {
  1346. if (this._error == null) abort(this, new Error("abort"));
  1347. return this;
  1348. },
  1349. await: function(callback) {
  1350. if (typeof callback !== "function" || this._call) throw new Error;
  1351. this._call = function(error, results) { callback.apply(null, [error].concat(results)); };
  1352. maybeNotify(this);
  1353. return this;
  1354. },
  1355. awaitAll: function(callback) {
  1356. if (typeof callback !== "function" || this._call) throw new Error;
  1357. this._call = callback;
  1358. maybeNotify(this);
  1359. return this;
  1360. }
  1361. };
  1362. function poke(q) {
  1363. if (!q._start) try { start(q); } // let the current task complete
  1364. catch (e) { if (q._tasks[q._ended + q._active - 1]) abort(q, e); } // task errored synchronously
  1365. }
  1366. function start(q) {
  1367. while (q._start = q._waiting && q._active < q._size) {
  1368. var i = q._ended + q._active,
  1369. t = q._tasks[i],
  1370. j = t.length - 1,
  1371. c = t[j];
  1372. t[j] = end(q, i);
  1373. --q._waiting, ++q._active;
  1374. t = c.apply(null, t);
  1375. if (!q._tasks[i]) continue; // task finished synchronously
  1376. q._tasks[i] = t || noabort;
  1377. }
  1378. }
  1379. function end(q, i) {
  1380. return function(e, r) {
  1381. if (!q._tasks[i]) return; // ignore multiple callbacks
  1382. --q._active, ++q._ended;
  1383. q._tasks[i] = null;
  1384. if (q._error != null) return; // ignore secondary errors
  1385. if (e != null) {
  1386. abort(q, e);
  1387. } else {
  1388. q._data[i] = r;
  1389. if (q._waiting) poke(q);
  1390. else maybeNotify(q);
  1391. }
  1392. };
  1393. }
  1394. function abort(q, e) {
  1395. var i = q._tasks.length, t;
  1396. q._error = e; // ignore active callbacks
  1397. q._data = undefined; // allow gc
  1398. q._waiting = NaN; // prevent starting
  1399. while (--i >= 0) {
  1400. if (t = q._tasks[i]) {
  1401. q._tasks[i] = null;
  1402. if (t.abort) try { t.abort(); }
  1403. catch (e) { /* ignore */ }
  1404. }
  1405. }
  1406. q._active = NaN; // allow notification
  1407. maybeNotify(q);
  1408. }
  1409. function maybeNotify(q) {
  1410. if (!q._active && q._call) q._call(q._error, q._data);
  1411. }
  1412. function queue(concurrency) {
  1413. return new Queue(arguments.length ? +concurrency : Infinity);
  1414. }
  1415. function constant$1(x) {
  1416. return function constant() {
  1417. return x;
  1418. };
  1419. }
  1420. var epsilon$1 = 1e-12;
  1421. var pi$2 = Math.PI;
  1422. var halfPi$1 = pi$2 / 2;
  1423. var tau$2 = 2 * pi$2;
  1424. function arcInnerRadius(d) {
  1425. return d.innerRadius;
  1426. }
  1427. function arcOuterRadius(d) {
  1428. return d.outerRadius;
  1429. }
  1430. function arcStartAngle(d) {
  1431. return d.startAngle;
  1432. }
  1433. function arcEndAngle(d) {
  1434. return d.endAngle;
  1435. }
  1436. function arcPadAngle(d) {
  1437. return d && d.padAngle; // Note: optional!
  1438. }
  1439. function asin(x) {
  1440. return x >= 1 ? halfPi$1 : x <= -1 ? -halfPi$1 : Math.asin(x);
  1441. }
  1442. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  1443. var x10 = x1 - x0, y10 = y1 - y0,
  1444. x32 = x3 - x2, y32 = y3 - y2,
  1445. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  1446. return [x0 + t * x10, y0 + t * y10];
  1447. }
  1448. // Compute perpendicular offset line of length rc.
  1449. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  1450. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  1451. var x01 = x0 - x1,
  1452. y01 = y0 - y1,
  1453. lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01),
  1454. ox = lo * y01,
  1455. oy = -lo * x01,
  1456. x11 = x0 + ox,
  1457. y11 = y0 + oy,
  1458. x10 = x1 + ox,
  1459. y10 = y1 + oy,
  1460. x00 = (x11 + x10) / 2,
  1461. y00 = (y11 + y10) / 2,
  1462. dx = x10 - x11,
  1463. dy = y10 - y11,
  1464. d2 = dx * dx + dy * dy,
  1465. r = r1 - rc,
  1466. D = x11 * y10 - x10 * y11,
  1467. d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)),
  1468. cx0 = (D * dy - dx * d) / d2,
  1469. cy0 = (-D * dx - dy * d) / d2,
  1470. cx1 = (D * dy + dx * d) / d2,
  1471. cy1 = (-D * dx + dy * d) / d2,
  1472. dx0 = cx0 - x00,
  1473. dy0 = cy0 - y00,
  1474. dx1 = cx1 - x00,
  1475. dy1 = cy1 - y00;
  1476. // Pick the closer of the two intersection points.
  1477. // TODO Is there a faster way to determine which intersection to use?
  1478. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  1479. return {
  1480. cx: cx0,
  1481. cy: cy0,
  1482. x01: -ox,
  1483. y01: -oy,
  1484. x11: cx0 * (r1 / r - 1),
  1485. y11: cy0 * (r1 / r - 1)
  1486. };
  1487. }
  1488. function arc() {
  1489. var innerRadius = arcInnerRadius,
  1490. outerRadius = arcOuterRadius,
  1491. cornerRadius = constant$1(0),
  1492. padRadius = null,
  1493. startAngle = arcStartAngle,
  1494. endAngle = arcEndAngle,
  1495. padAngle = arcPadAngle,
  1496. context = null;
  1497. function arc() {
  1498. var buffer,
  1499. r,
  1500. r0 = +innerRadius.apply(this, arguments),
  1501. r1 = +outerRadius.apply(this, arguments),
  1502. a0 = startAngle.apply(this, arguments) - halfPi$1,
  1503. a1 = endAngle.apply(this, arguments) - halfPi$1,
  1504. da = Math.abs(a1 - a0),
  1505. cw = a1 > a0;
  1506. if (!context) context = buffer = path();
  1507. // Ensure that the outer radius is always larger than the inner radius.
  1508. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  1509. // Is it a point?
  1510. if (!(r1 > epsilon$1)) context.moveTo(0, 0);
  1511. // Or is it a circle or annulus?
  1512. else if (da > tau$2 - epsilon$1) {
  1513. context.moveTo(r1 * Math.cos(a0), r1 * Math.sin(a0));
  1514. context.arc(0, 0, r1, a0, a1, !cw);
  1515. if (r0 > epsilon$1) {
  1516. context.moveTo(r0 * Math.cos(a1), r0 * Math.sin(a1));
  1517. context.arc(0, 0, r0, a1, a0, cw);
  1518. }
  1519. }
  1520. // Or is it a circular or annular sector?
  1521. else {
  1522. var a01 = a0,
  1523. a11 = a1,
  1524. a00 = a0,
  1525. a10 = a1,
  1526. da0 = da,
  1527. da1 = da,
  1528. ap = padAngle.apply(this, arguments) / 2,
  1529. rp = (ap > epsilon$1) && (padRadius ? +padRadius.apply(this, arguments) : Math.sqrt(r0 * r0 + r1 * r1)),
  1530. rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  1531. rc0 = rc,
  1532. rc1 = rc,
  1533. t0,
  1534. t1;
  1535. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  1536. if (rp > epsilon$1) {
  1537. var p0 = asin(rp / r0 * Math.sin(ap)),
  1538. p1 = asin(rp / r1 * Math.sin(ap));
  1539. if ((da0 -= p0 * 2) > epsilon$1) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  1540. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  1541. if ((da1 -= p1 * 2) > epsilon$1) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  1542. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  1543. }
  1544. var x01 = r1 * Math.cos(a01),
  1545. y01 = r1 * Math.sin(a01),
  1546. x10 = r0 * Math.cos(a10),
  1547. y10 = r0 * Math.sin(a10);
  1548. // Apply rounded corners?
  1549. if (rc > epsilon$1) {
  1550. var x11 = r1 * Math.cos(a11),
  1551. y11 = r1 * Math.sin(a11),
  1552. x00 = r0 * Math.cos(a00),
  1553. y00 = r0 * Math.sin(a00);
  1554. // Restrict the corner radius according to the sector angle.
  1555. if (da < pi$2) {
  1556. var oc = da0 > epsilon$1 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  1557. ax = x01 - oc[0],
  1558. ay = y01 - oc[1],
  1559. bx = x11 - oc[0],
  1560. by = y11 - oc[1],
  1561. kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2),
  1562. lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
  1563. rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
  1564. rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
  1565. }
  1566. }
  1567. // Is the sector collapsed to a line?
  1568. if (!(da1 > epsilon$1)) context.moveTo(x01, y01);
  1569. // Does the sector’s outer ring have rounded corners?
  1570. else if (rc1 > epsilon$1) {
  1571. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  1572. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  1573. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  1574. // Have the corners merged?
  1575. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, Math.atan2(t0.y01, t0.x01), Math.atan2(t1.y01, t1.x01), !cw);
  1576. // Otherwise, draw the two corners and the ring.
  1577. else {
  1578. context.arc(t0.cx, t0.cy, rc1, Math.atan2(t0.y01, t0.x01), Math.atan2(t0.y11, t0.x11), !cw);
  1579. context.arc(0, 0, r1, Math.atan2(t0.cy + t0.y11, t0.cx + t0.x11), Math.atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
  1580. context.arc(t1.cx, t1.cy, rc1, Math.atan2(t1.y11, t1.x11), Math.atan2(t1.y01, t1.x01), !cw);
  1581. }
  1582. }
  1583. // Or is the outer ring just a circular arc?
  1584. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  1585. // Is there no inner ring, and it’s a circular sector?
  1586. // Or perhaps it’s an annular sector collapsed due to padding?
  1587. if (!(r0 > epsilon$1) || !(da0 > epsilon$1)) context.lineTo(x10, y10);
  1588. // Does the sector’s inner ring (or point) have rounded corners?
  1589. else if (rc0 > epsilon$1) {
  1590. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  1591. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  1592. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  1593. // Have the corners merged?
  1594. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, Math.atan2(t0.y01, t0.x01), Math.atan2(t1.y01, t1.x01), !cw);
  1595. // Otherwise, draw the two corners and the ring.
  1596. else {
  1597. context.arc(t0.cx, t0.cy, rc0, Math.atan2(t0.y01, t0.x01), Math.atan2(t0.y11, t0.x11), !cw);
  1598. context.arc(0, 0, r0, Math.atan2(t0.cy + t0.y11, t0.cx + t0.x11), Math.atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
  1599. context.arc(t1.cx, t1.cy, rc0, Math.atan2(t1.y11, t1.x11), Math.atan2(t1.y01, t1.x01), !cw);
  1600. }
  1601. }
  1602. // Or is the inner ring just a circular arc?
  1603. else context.arc(0, 0, r0, a10, a00, cw);
  1604. }
  1605. context.closePath();
  1606. if (buffer) return context = null, buffer + "" || null;
  1607. }
  1608. arc.centroid = function() {
  1609. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  1610. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$2 / 2;
  1611. return [Math.cos(a) * r, Math.sin(a) * r];
  1612. };
  1613. arc.innerRadius = function(_) {
  1614. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : innerRadius;
  1615. };
  1616. arc.outerRadius = function(_) {
  1617. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : outerRadius;
  1618. };
  1619. arc.cornerRadius = function(_) {
  1620. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : cornerRadius;
  1621. };
  1622. arc.padRadius = function(_) {
  1623. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), arc) : padRadius;
  1624. };
  1625. arc.startAngle = function(_) {
  1626. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : startAngle;
  1627. };
  1628. arc.endAngle = function(_) {
  1629. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : endAngle;
  1630. };
  1631. arc.padAngle = function(_) {
  1632. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : padAngle;
  1633. };
  1634. arc.context = function(_) {
  1635. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  1636. };
  1637. return arc;
  1638. }
  1639. function Linear(context) {
  1640. this._context = context;
  1641. }
  1642. Linear.prototype = {
  1643. areaStart: function() {
  1644. this._line = 0;
  1645. },
  1646. areaEnd: function() {
  1647. this._line = NaN;
  1648. },
  1649. lineStart: function() {
  1650. this._point = 0;
  1651. },
  1652. lineEnd: function() {
  1653. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  1654. this._line = 1 - this._line;
  1655. },
  1656. point: function(x, y) {
  1657. x = +x, y = +y;
  1658. switch (this._point) {
  1659. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  1660. case 1: this._point = 2; // proceed
  1661. default: this._context.lineTo(x, y); break;
  1662. }
  1663. }
  1664. };
  1665. function curveLinear(context) {
  1666. return new Linear(context);
  1667. }
  1668. function x(p) {
  1669. return p[0];
  1670. }
  1671. function y(p) {
  1672. return p[1];
  1673. }
  1674. function line() {
  1675. var x$$ = x,
  1676. y$$ = y,
  1677. defined = constant$1(true),
  1678. context = null,
  1679. curve = curveLinear,
  1680. output = null;
  1681. function line(data) {
  1682. var i,
  1683. n = data.length,
  1684. d,
  1685. defined0 = false,
  1686. buffer;
  1687. if (context == null) output = curve(buffer = path());
  1688. for (i = 0; i <= n; ++i) {
  1689. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  1690. if (defined0 = !defined0) output.lineStart();
  1691. else output.lineEnd();
  1692. }
  1693. if (defined0) output.point(+x$$(d, i, data), +y$$(d, i, data));
  1694. }
  1695. if (buffer) return output = null, buffer + "" || null;
  1696. }
  1697. line.x = function(_) {
  1698. return arguments.length ? (x$$ = typeof _ === "function" ? _ : constant$1(+_), line) : x$$;
  1699. };
  1700. line.y = function(_) {
  1701. return arguments.length ? (y$$ = typeof _ === "function" ? _ : constant$1(+_), line) : y$$;
  1702. };
  1703. line.defined = function(_) {
  1704. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), line) : defined;
  1705. };
  1706. line.curve = function(_) {
  1707. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  1708. };
  1709. line.context = function(_) {
  1710. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  1711. };
  1712. return line;
  1713. }
  1714. function area$1() {
  1715. var x0 = x,
  1716. x1 = null,
  1717. y0 = constant$1(0),
  1718. y1 = y,
  1719. defined = constant$1(true),
  1720. context = null,
  1721. curve = curveLinear,
  1722. output = null;
  1723. function area(data) {
  1724. var i,
  1725. j,
  1726. k,
  1727. n = data.length,
  1728. d,
  1729. defined0 = false,
  1730. buffer,
  1731. x0z = new Array(n),
  1732. y0z = new Array(n);
  1733. if (context == null) output = curve(buffer = path());
  1734. for (i = 0; i <= n; ++i) {
  1735. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  1736. if (defined0 = !defined0) {
  1737. j = i;
  1738. output.areaStart();
  1739. output.lineStart();
  1740. } else {
  1741. output.lineEnd();
  1742. output.lineStart();
  1743. for (k = i - 1; k >= j; --k) {
  1744. output.point(x0z[k], y0z[k]);
  1745. }
  1746. output.lineEnd();
  1747. output.areaEnd();
  1748. }
  1749. }
  1750. if (defined0) {
  1751. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  1752. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  1753. }
  1754. }
  1755. if (buffer) return output = null, buffer + "" || null;
  1756. }
  1757. function arealine() {
  1758. return line().defined(defined).curve(curve).context(context);
  1759. }
  1760. area.x = function(_) {
  1761. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), x1 = null, area) : x0;
  1762. };
  1763. area.x0 = function(_) {
  1764. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), area) : x0;
  1765. };
  1766. area.x1 = function(_) {
  1767. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : x1;
  1768. };
  1769. area.y = function(_) {
  1770. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), y1 = null, area) : y0;
  1771. };
  1772. area.y0 = function(_) {
  1773. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), area) : y0;
  1774. };
  1775. area.y1 = function(_) {
  1776. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : y1;
  1777. };
  1778. area.lineX0 =
  1779. area.lineY0 = function() {
  1780. return arealine().x(x0).y(y0);
  1781. };
  1782. area.lineY1 = function() {
  1783. return arealine().x(x0).y(y1);
  1784. };
  1785. area.lineX1 = function() {
  1786. return arealine().x(x1).y(y0);
  1787. };
  1788. area.defined = function(_) {
  1789. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), area) : defined;
  1790. };
  1791. area.curve = function(_) {
  1792. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  1793. };
  1794. area.context = function(_) {
  1795. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  1796. };
  1797. return area;
  1798. }
  1799. function descending$1(a, b) {
  1800. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  1801. }
  1802. function identity$1(d) {
  1803. return d;
  1804. }
  1805. function pie() {
  1806. var value = identity$1,
  1807. sortValues = descending$1,
  1808. sort = null,
  1809. startAngle = constant$1(0),
  1810. endAngle = constant$1(tau$2),
  1811. padAngle = constant$1(0);
  1812. function pie(data) {
  1813. var i,
  1814. n = data.length,
  1815. j,
  1816. k,
  1817. sum = 0,
  1818. index = new Array(n),
  1819. arcs = new Array(n),
  1820. a0 = +startAngle.apply(this, arguments),
  1821. da = Math.min(tau$2, Math.max(-tau$2, endAngle.apply(this, arguments) - a0)),
  1822. a1,
  1823. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  1824. pa = p * (da < 0 ? -1 : 1),
  1825. v;
  1826. for (i = 0; i < n; ++i) {
  1827. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  1828. sum += v;
  1829. }
  1830. }
  1831. // Optionally sort the arcs by previously-computed values or by data.
  1832. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  1833. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  1834. // Compute the arcs! They are stored in the original data's order.
  1835. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  1836. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  1837. data: data[j],
  1838. index: i,
  1839. value: v,
  1840. startAngle: a0,
  1841. endAngle: a1,
  1842. padAngle: p
  1843. };
  1844. }
  1845. return arcs;
  1846. }
  1847. pie.value = function(_) {
  1848. return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), pie) : value;
  1849. };
  1850. pie.sortValues = function(_) {
  1851. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  1852. };
  1853. pie.sort = function(_) {
  1854. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  1855. };
  1856. pie.startAngle = function(_) {
  1857. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : startAngle;
  1858. };
  1859. pie.endAngle = function(_) {
  1860. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : endAngle;
  1861. };
  1862. pie.padAngle = function(_) {
  1863. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : padAngle;
  1864. };
  1865. return pie;
  1866. }
  1867. var curveRadialLinear = curveRadial(curveLinear);
  1868. function Radial(curve) {
  1869. this._curve = curve;
  1870. }
  1871. Radial.prototype = {
  1872. areaStart: function() {
  1873. this._curve.areaStart();
  1874. },
  1875. areaEnd: function() {
  1876. this._curve.areaEnd();
  1877. },
  1878. lineStart: function() {
  1879. this._curve.lineStart();
  1880. },
  1881. lineEnd: function() {
  1882. this._curve.lineEnd();
  1883. },
  1884. point: function(a, r) {
  1885. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  1886. }
  1887. };
  1888. function curveRadial(curve) {
  1889. function radial(context) {
  1890. return new Radial(curve(context));
  1891. }
  1892. radial._curve = curve;
  1893. return radial;
  1894. }
  1895. function radialLine(l) {
  1896. var c = l.curve;
  1897. l.angle = l.x, delete l.x;
  1898. l.radius = l.y, delete l.y;
  1899. l.curve = function(_) {
  1900. return arguments.length ? c(curveRadial(_)) : c()._curve;
  1901. };
  1902. return l;
  1903. }
  1904. function radialLine$1() {
  1905. return radialLine(line().curve(curveRadialLinear));
  1906. }
  1907. function radialArea() {
  1908. var a = area$1().curve(curveRadialLinear),
  1909. c = a.curve,
  1910. x0 = a.lineX0,
  1911. x1 = a.lineX1,
  1912. y0 = a.lineY0,
  1913. y1 = a.lineY1;
  1914. a.angle = a.x, delete a.x;
  1915. a.startAngle = a.x0, delete a.x0;
  1916. a.endAngle = a.x1, delete a.x1;
  1917. a.radius = a.y, delete a.y;
  1918. a.innerRadius = a.y0, delete a.y0;
  1919. a.outerRadius = a.y1, delete a.y1;
  1920. a.lineStartAngle = function() { return radialLine(x0()); }, delete a.lineX0;
  1921. a.lineEndAngle = function() { return radialLine(x1()); }, delete a.lineX1;
  1922. a.lineInnerRadius = function() { return radialLine(y0()); }, delete a.lineY0;
  1923. a.lineOuterRadius = function() { return radialLine(y1()); }, delete a.lineY1;
  1924. a.curve = function(_) {
  1925. return arguments.length ? c(curveRadial(_)) : c()._curve;
  1926. };
  1927. return a;
  1928. }
  1929. var circle = {
  1930. draw: function(context, size) {
  1931. var r = Math.sqrt(size / pi$2);
  1932. context.moveTo(r, 0);
  1933. context.arc(0, 0, r, 0, tau$2);
  1934. }
  1935. };
  1936. var cross$1 = {
  1937. draw: function(context, size) {
  1938. var r = Math.sqrt(size / 5) / 2;
  1939. context.moveTo(-3 * r, -r);
  1940. context.lineTo(-r, -r);
  1941. context.lineTo(-r, -3 * r);
  1942. context.lineTo(r, -3 * r);
  1943. context.lineTo(r, -r);
  1944. context.lineTo(3 * r, -r);
  1945. context.lineTo(3 * r, r);
  1946. context.lineTo(r, r);
  1947. context.lineTo(r, 3 * r);
  1948. context.lineTo(-r, 3 * r);
  1949. context.lineTo(-r, r);
  1950. context.lineTo(-3 * r, r);
  1951. context.closePath();
  1952. }
  1953. };
  1954. var tan30 = Math.sqrt(1 / 3);
  1955. var tan30_2 = tan30 * 2;
  1956. var diamond = {
  1957. draw: function(context, size) {
  1958. var y = Math.sqrt(size / tan30_2),
  1959. x = y * tan30;
  1960. context.moveTo(0, -y);
  1961. context.lineTo(x, 0);
  1962. context.lineTo(0, y);
  1963. context.lineTo(-x, 0);
  1964. context.closePath();
  1965. }
  1966. };
  1967. var ka = 0.89081309152928522810;
  1968. var kr = Math.sin(pi$2 / 10) / Math.sin(7 * pi$2 / 10);
  1969. var kx = Math.sin(tau$2 / 10) * kr;
  1970. var ky = -Math.cos(tau$2 / 10) * kr;
  1971. var star = {
  1972. draw: function(context, size) {
  1973. var r = Math.sqrt(size * ka),
  1974. x = kx * r,
  1975. y = ky * r;
  1976. context.moveTo(0, -r);
  1977. context.lineTo(x, y);
  1978. for (var i = 1; i < 5; ++i) {
  1979. var a = tau$2 * i / 5,
  1980. c = Math.cos(a),
  1981. s = Math.sin(a);
  1982. context.lineTo(s * r, -c * r);
  1983. context.lineTo(c * x - s * y, s * x + c * y);
  1984. }
  1985. context.closePath();
  1986. }
  1987. };
  1988. var square = {
  1989. draw: function(context, size) {
  1990. var w = Math.sqrt(size),
  1991. x = -w / 2;
  1992. context.rect(x, x, w, w);
  1993. }
  1994. };
  1995. var sqrt3 = Math.sqrt(3);
  1996. var triangle = {
  1997. draw: function(context, size) {
  1998. var y = -Math.sqrt(size / (sqrt3 * 3));
  1999. context.moveTo(0, y * 2);
  2000. context.lineTo(-sqrt3 * y, -y);
  2001. context.lineTo(sqrt3 * y, -y);
  2002. context.closePath();
  2003. }
  2004. };
  2005. var c = -0.5;
  2006. var s = Math.sqrt(3) / 2;
  2007. var k = 1 / Math.sqrt(12);
  2008. var a = (k / 2 + 1) * 3;
  2009. var wye = {
  2010. draw: function(context, size) {
  2011. var r = Math.sqrt(size / a),
  2012. x0 = r / 2,
  2013. y0 = r * k,
  2014. x1 = x0,
  2015. y1 = r * k + r,
  2016. x2 = -x1,
  2017. y2 = y1;
  2018. context.moveTo(x0, y0);
  2019. context.lineTo(x1, y1);
  2020. context.lineTo(x2, y2);
  2021. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  2022. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  2023. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  2024. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  2025. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  2026. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  2027. context.closePath();
  2028. }
  2029. };
  2030. var symbols = [
  2031. circle,
  2032. cross$1,
  2033. diamond,
  2034. square,
  2035. star,
  2036. triangle,
  2037. wye
  2038. ];
  2039. function symbol() {
  2040. var type = constant$1(circle),
  2041. size = constant$1(64),
  2042. context = null;
  2043. function symbol() {
  2044. var buffer;
  2045. if (!context) context = buffer = path();
  2046. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  2047. if (buffer) return context = null, buffer + "" || null;
  2048. }
  2049. symbol.type = function(_) {
  2050. return arguments.length ? (type = typeof _ === "function" ? _ : constant$1(_), symbol) : type;
  2051. };
  2052. symbol.size = function(_) {
  2053. return arguments.length ? (size = typeof _ === "function" ? _ : constant$1(+_), symbol) : size;
  2054. };
  2055. symbol.context = function(_) {
  2056. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  2057. };
  2058. return symbol;
  2059. }
  2060. function noop() {}
  2061. function point(that, x, y) {
  2062. that._context.bezierCurveTo(
  2063. (2 * that._x0 + that._x1) / 3,
  2064. (2 * that._y0 + that._y1) / 3,
  2065. (that._x0 + 2 * that._x1) / 3,
  2066. (that._y0 + 2 * that._y1) / 3,
  2067. (that._x0 + 4 * that._x1 + x) / 6,
  2068. (that._y0 + 4 * that._y1 + y) / 6
  2069. );
  2070. }
  2071. function Basis(context) {
  2072. this._context = context;
  2073. }
  2074. Basis.prototype = {
  2075. areaStart: function() {
  2076. this._line = 0;
  2077. },
  2078. areaEnd: function() {
  2079. this._line = NaN;
  2080. },
  2081. lineStart: function() {
  2082. this._x0 = this._x1 =
  2083. this._y0 = this._y1 = NaN;
  2084. this._point = 0;
  2085. },
  2086. lineEnd: function() {
  2087. switch (this._point) {
  2088. case 3: point(this, this._x1, this._y1); // proceed
  2089. case 2: this._context.lineTo(this._x1, this._y1); break;
  2090. }
  2091. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  2092. this._line = 1 - this._line;
  2093. },
  2094. point: function(x, y) {
  2095. x = +x, y = +y;
  2096. switch (this._point) {
  2097. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  2098. case 1: this._point = 2; break;
  2099. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  2100. default: point(this, x, y); break;
  2101. }
  2102. this._x0 = this._x1, this._x1 = x;
  2103. this._y0 = this._y1, this._y1 = y;
  2104. }
  2105. };
  2106. function basis(context) {
  2107. return new Basis(context);
  2108. }
  2109. function BasisClosed(context) {
  2110. this._context = context;
  2111. }
  2112. BasisClosed.prototype = {
  2113. areaStart: noop,
  2114. areaEnd: noop,
  2115. lineStart: function() {
  2116. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  2117. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  2118. this._point = 0;
  2119. },
  2120. lineEnd: function() {
  2121. switch (this._point) {
  2122. case 1: {
  2123. this._context.moveTo(this._x2, this._y2);
  2124. this._context.closePath();
  2125. break;
  2126. }
  2127. case 2: {
  2128. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  2129. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  2130. this._context.closePath();
  2131. break;
  2132. }
  2133. case 3: {
  2134. this.point(this._x2, this._y2);
  2135. this.point(this._x3, this._y3);
  2136. this.point(this._x4, this._y4);
  2137. break;
  2138. }
  2139. }
  2140. },
  2141. point: function(x, y) {
  2142. x = +x, y = +y;
  2143. switch (this._point) {
  2144. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  2145. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  2146. 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;
  2147. default: point(this, x, y); break;
  2148. }
  2149. this._x0 = this._x1, this._x1 = x;
  2150. this._y0 = this._y1, this._y1 = y;
  2151. }
  2152. };
  2153. function basisClosed(context) {
  2154. return new BasisClosed(context);
  2155. }
  2156. function BasisOpen(context) {
  2157. this._context = context;
  2158. }
  2159. BasisOpen.prototype = {
  2160. areaStart: function() {
  2161. this._line = 0;
  2162. },
  2163. areaEnd: function() {
  2164. this._line = NaN;
  2165. },
  2166. lineStart: function() {
  2167. this._x0 = this._x1 =
  2168. this._y0 = this._y1 = NaN;
  2169. this._point = 0;
  2170. },
  2171. lineEnd: function() {
  2172. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  2173. this._line = 1 - this._line;
  2174. },
  2175. point: function(x, y) {
  2176. x = +x, y = +y;
  2177. switch (this._point) {
  2178. case 0: this._point = 1; break;
  2179. case 1: this._point = 2; break;
  2180. 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;
  2181. case 3: this._point = 4; // proceed
  2182. default: point(this, x, y); break;
  2183. }
  2184. this._x0 = this._x1, this._x1 = x;
  2185. this._y0 = this._y1, this._y1 = y;
  2186. }
  2187. };
  2188. function basisOpen(context) {
  2189. return new BasisOpen(context);
  2190. }
  2191. function Bundle(context, beta) {
  2192. this._basis = new Basis(context);
  2193. this._beta = beta;
  2194. }
  2195. Bundle.prototype = {
  2196. lineStart: function() {
  2197. this._x = [];
  2198. this._y = [];
  2199. this._basis.lineStart();
  2200. },
  2201. lineEnd: function() {
  2202. var x = this._x,
  2203. y = this._y,
  2204. j = x.length - 1;
  2205. if (j > 0) {
  2206. var x0 = x[0],
  2207. y0 = y[0],
  2208. dx = x[j] - x0,
  2209. dy = y[j] - y0,
  2210. i = -1,
  2211. t;
  2212. while (++i <= j) {
  2213. t = i / j;
  2214. this._basis.point(
  2215. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  2216. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  2217. );
  2218. }
  2219. }
  2220. this._x = this._y = null;
  2221. this._basis.lineEnd();
  2222. },
  2223. point: function(x, y) {
  2224. this._x.push(+x);
  2225. this._y.push(+y);
  2226. }
  2227. };
  2228. var bundle = (function custom(beta) {
  2229. function bundle(context) {
  2230. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  2231. }
  2232. bundle.beta = function(beta) {
  2233. return custom(+beta);
  2234. };
  2235. return bundle;
  2236. })(0.85);
  2237. function point$1(that, x, y) {
  2238. that._context.bezierCurveTo(
  2239. that._x1 + that._k * (that._x2 - that._x0),
  2240. that._y1 + that._k * (that._y2 - that._y0),
  2241. that._x2 + that._k * (that._x1 - x),
  2242. that._y2 + that._k * (that._y1 - y),
  2243. that._x2,
  2244. that._y2
  2245. );
  2246. }
  2247. function Cardinal(context, tension) {
  2248. this._context = context;
  2249. this._k = (1 - tension) / 6;
  2250. }
  2251. Cardinal.prototype = {
  2252. areaStart: function() {
  2253. this._line = 0;
  2254. },
  2255. areaEnd: function() {
  2256. this._line = NaN;
  2257. },
  2258. lineStart: function() {
  2259. this._x0 = this._x1 = this._x2 =
  2260. this._y0 = this._y1 = this._y2 = NaN;
  2261. this._point = 0;
  2262. },
  2263. lineEnd: function() {
  2264. switch (this._point) {
  2265. case 2: this._context.lineTo(this._x2, this._y2); break;
  2266. case 3: point$1(this, this._x1, this._y1); break;
  2267. }
  2268. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  2269. this._line = 1 - this._line;
  2270. },
  2271. point: function(x, y) {
  2272. x = +x, y = +y;
  2273. switch (this._point) {
  2274. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  2275. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  2276. case 2: this._point = 3; // proceed
  2277. default: point$1(this, x, y); break;
  2278. }
  2279. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2280. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2281. }
  2282. };
  2283. var cardinal = (function custom(tension) {
  2284. function cardinal(context) {
  2285. return new Cardinal(context, tension);
  2286. }
  2287. cardinal.tension = function(tension) {
  2288. return custom(+tension);
  2289. };
  2290. return cardinal;
  2291. })(0);
  2292. function CardinalClosed(context, tension) {
  2293. this._context = context;
  2294. this._k = (1 - tension) / 6;
  2295. }
  2296. CardinalClosed.prototype = {
  2297. areaStart: noop,
  2298. areaEnd: noop,
  2299. lineStart: function() {
  2300. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  2301. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  2302. this._point = 0;
  2303. },
  2304. lineEnd: function() {
  2305. switch (this._point) {
  2306. case 1: {
  2307. this._context.moveTo(this._x3, this._y3);
  2308. this._context.closePath();
  2309. break;
  2310. }
  2311. case 2: {
  2312. this._context.lineTo(this._x3, this._y3);
  2313. this._context.closePath();
  2314. break;
  2315. }
  2316. case 3: {
  2317. this.point(this._x3, this._y3);
  2318. this.point(this._x4, this._y4);
  2319. this.point(this._x5, this._y5);
  2320. break;
  2321. }
  2322. }
  2323. },
  2324. point: function(x, y) {
  2325. x = +x, y = +y;
  2326. switch (this._point) {
  2327. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  2328. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  2329. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  2330. default: point$1(this, x, y); break;
  2331. }
  2332. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2333. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2334. }
  2335. };
  2336. var cardinalClosed = (function custom(tension) {
  2337. function cardinal(context) {
  2338. return new CardinalClosed(context, tension);
  2339. }
  2340. cardinal.tension = function(tension) {
  2341. return custom(+tension);
  2342. };
  2343. return cardinal;
  2344. })(0);
  2345. function CardinalOpen(context, tension) {
  2346. this._context = context;
  2347. this._k = (1 - tension) / 6;
  2348. }
  2349. CardinalOpen.prototype = {
  2350. areaStart: function() {
  2351. this._line = 0;
  2352. },
  2353. areaEnd: function() {
  2354. this._line = NaN;
  2355. },
  2356. lineStart: function() {
  2357. this._x0 = this._x1 = this._x2 =
  2358. this._y0 = this._y1 = this._y2 = NaN;
  2359. this._point = 0;
  2360. },
  2361. lineEnd: function() {
  2362. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  2363. this._line = 1 - this._line;
  2364. },
  2365. point: function(x, y) {
  2366. x = +x, y = +y;
  2367. switch (this._point) {
  2368. case 0: this._point = 1; break;
  2369. case 1: this._point = 2; break;
  2370. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  2371. case 3: this._point = 4; // proceed
  2372. default: point$1(this, x, y); break;
  2373. }
  2374. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2375. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2376. }
  2377. };
  2378. var cardinalOpen = (function custom(tension) {
  2379. function cardinal(context) {
  2380. return new CardinalOpen(context, tension);
  2381. }
  2382. cardinal.tension = function(tension) {
  2383. return custom(+tension);
  2384. };
  2385. return cardinal;
  2386. })(0);
  2387. function point$2(that, x, y) {
  2388. var x1 = that._x1,
  2389. y1 = that._y1,
  2390. x2 = that._x2,
  2391. y2 = that._y2;
  2392. if (that._l01_a > epsilon$1) {
  2393. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  2394. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  2395. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  2396. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  2397. }
  2398. if (that._l23_a > epsilon$1) {
  2399. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  2400. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  2401. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  2402. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  2403. }
  2404. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  2405. }
  2406. function CatmullRom(context, alpha) {
  2407. this._context = context;
  2408. this._alpha = alpha;
  2409. }
  2410. CatmullRom.prototype = {
  2411. areaStart: function() {
  2412. this._line = 0;
  2413. },
  2414. areaEnd: function() {
  2415. this._line = NaN;
  2416. },
  2417. lineStart: function() {
  2418. this._x0 = this._x1 = this._x2 =
  2419. this._y0 = this._y1 = this._y2 = NaN;
  2420. this._l01_a = this._l12_a = this._l23_a =
  2421. this._l01_2a = this._l12_2a = this._l23_2a =
  2422. this._point = 0;
  2423. },
  2424. lineEnd: function() {
  2425. switch (this._point) {
  2426. case 2: this._context.lineTo(this._x2, this._y2); break;
  2427. case 3: this.point(this, this._x2, this._y2); break;
  2428. }
  2429. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  2430. this._line = 1 - this._line;
  2431. },
  2432. point: function(x, y) {
  2433. x = +x, y = +y;
  2434. if (this._point) {
  2435. var x23 = this._x2 - x,
  2436. y23 = this._y2 - y;
  2437. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  2438. }
  2439. switch (this._point) {
  2440. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  2441. case 1: this._point = 2; break;
  2442. case 2: this._point = 3; // proceed
  2443. default: point$2(this, x, y); break;
  2444. }
  2445. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  2446. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  2447. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2448. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2449. }
  2450. };
  2451. var catmullRom = (function custom(alpha) {
  2452. function catmullRom(context) {
  2453. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  2454. }
  2455. catmullRom.alpha = function(alpha) {
  2456. return custom(+alpha);
  2457. };
  2458. return catmullRom;
  2459. })(0.5);
  2460. function CatmullRomClosed(context, alpha) {
  2461. this._context = context;
  2462. this._alpha = alpha;
  2463. }
  2464. CatmullRomClosed.prototype = {
  2465. areaStart: noop,
  2466. areaEnd: noop,
  2467. lineStart: function() {
  2468. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  2469. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  2470. this._l01_a = this._l12_a = this._l23_a =
  2471. this._l01_2a = this._l12_2a = this._l23_2a =
  2472. this._point = 0;
  2473. },
  2474. lineEnd: function() {
  2475. switch (this._point) {
  2476. case 1: {
  2477. this._context.moveTo(this._x3, this._y3);
  2478. this._context.closePath();
  2479. break;
  2480. }
  2481. case 2: {
  2482. this._context.lineTo(this._x3, this._y3);
  2483. this._context.closePath();
  2484. break;
  2485. }
  2486. case 3: {
  2487. this.point(this._x3, this._y3);
  2488. this.point(this._x4, this._y4);
  2489. this.point(this._x5, this._y5);
  2490. break;
  2491. }
  2492. }
  2493. },
  2494. point: function(x, y) {
  2495. x = +x, y = +y;
  2496. if (this._point) {
  2497. var x23 = this._x2 - x,
  2498. y23 = this._y2 - y;
  2499. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  2500. }
  2501. switch (this._point) {
  2502. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  2503. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  2504. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  2505. default: point$2(this, x, y); break;
  2506. }
  2507. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  2508. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  2509. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2510. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2511. }
  2512. };
  2513. var catmullRomClosed = (function custom(alpha) {
  2514. function catmullRom(context) {
  2515. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  2516. }
  2517. catmullRom.alpha = function(alpha) {
  2518. return custom(+alpha);
  2519. };
  2520. return catmullRom;
  2521. })(0.5);
  2522. function CatmullRomOpen(context, alpha) {
  2523. this._context = context;
  2524. this._alpha = alpha;
  2525. }
  2526. CatmullRomOpen.prototype = {
  2527. areaStart: function() {
  2528. this._line = 0;
  2529. },
  2530. areaEnd: function() {
  2531. this._line = NaN;
  2532. },
  2533. lineStart: function() {
  2534. this._x0 = this._x1 = this._x2 =
  2535. this._y0 = this._y1 = this._y2 = NaN;
  2536. this._l01_a = this._l12_a = this._l23_a =
  2537. this._l01_2a = this._l12_2a = this._l23_2a =
  2538. this._point = 0;
  2539. },
  2540. lineEnd: function() {
  2541. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  2542. this._line = 1 - this._line;
  2543. },
  2544. point: function(x, y) {
  2545. x = +x, y = +y;
  2546. if (this._point) {
  2547. var x23 = this._x2 - x,
  2548. y23 = this._y2 - y;
  2549. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  2550. }
  2551. switch (this._point) {
  2552. case 0: this._point = 1; break;
  2553. case 1: this._point = 2; break;
  2554. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  2555. case 3: this._point = 4; // proceed
  2556. default: point$2(this, x, y); break;
  2557. }
  2558. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  2559. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  2560. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2561. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2562. }
  2563. };
  2564. var catmullRomOpen = (function custom(alpha) {
  2565. function catmullRom(context) {
  2566. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  2567. }
  2568. catmullRom.alpha = function(alpha) {
  2569. return custom(+alpha);
  2570. };
  2571. return catmullRom;
  2572. })(0.5);
  2573. function LinearClosed(context) {
  2574. this._context = context;
  2575. }
  2576. LinearClosed.prototype = {
  2577. areaStart: noop,
  2578. areaEnd: noop,
  2579. lineStart: function() {
  2580. this._point = 0;
  2581. },
  2582. lineEnd: function() {
  2583. if (this._point) this._context.closePath();
  2584. },
  2585. point: function(x, y) {
  2586. x = +x, y = +y;
  2587. if (this._point) this._context.lineTo(x, y);
  2588. else this._point = 1, this._context.moveTo(x, y);
  2589. }
  2590. };
  2591. function linearClosed(context) {
  2592. return new LinearClosed(context);
  2593. }
  2594. function sign(x) {
  2595. return x < 0 ? -1 : 1;
  2596. }
  2597. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  2598. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  2599. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  2600. // NOV(II), P. 443, 1990.
  2601. function slope3(that, x2, y2) {
  2602. var h0 = that._x1 - that._x0,
  2603. h1 = x2 - that._x1,
  2604. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  2605. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  2606. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  2607. return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  2608. }
  2609. // Calculate a one-sided slope.
  2610. function slope2(that, t) {
  2611. var h = that._x1 - that._x0;
  2612. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  2613. }
  2614. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  2615. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  2616. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  2617. function point$3(that, t0, t1) {
  2618. var x0 = that._x0,
  2619. y0 = that._y0,
  2620. x1 = that._x1,
  2621. y1 = that._y1,
  2622. dx = (x1 - x0) / 3;
  2623. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  2624. }
  2625. function MonotoneX(context) {
  2626. this._context = context;
  2627. }
  2628. MonotoneX.prototype = {
  2629. areaStart: function() {
  2630. this._line = 0;
  2631. },
  2632. areaEnd: function() {
  2633. this._line = NaN;
  2634. },
  2635. lineStart: function() {
  2636. this._x0 = this._x1 =
  2637. this._y0 = this._y1 =
  2638. this._t0 = NaN;
  2639. this._point = 0;
  2640. },
  2641. lineEnd: function() {
  2642. switch (this._point) {
  2643. case 2: this._context.lineTo(this._x1, this._y1); break;
  2644. case 3: point$3(this, this._t0, slope2(this, this._t0)); break;
  2645. }
  2646. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  2647. this._line = 1 - this._line;
  2648. },
  2649. point: function(x, y) {
  2650. var t1 = NaN;
  2651. x = +x, y = +y;
  2652. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  2653. switch (this._point) {
  2654. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  2655. case 1: this._point = 2; break;
  2656. case 2: this._point = 3; point$3(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  2657. default: point$3(this, this._t0, t1 = slope3(this, x, y)); break;
  2658. }
  2659. this._x0 = this._x1, this._x1 = x;
  2660. this._y0 = this._y1, this._y1 = y;
  2661. this._t0 = t1;
  2662. }
  2663. }
  2664. function MonotoneY(context) {
  2665. this._context = new ReflectContext(context);
  2666. }
  2667. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  2668. MonotoneX.prototype.point.call(this, y, x);
  2669. };
  2670. function ReflectContext(context) {
  2671. this._context = context;
  2672. }
  2673. ReflectContext.prototype = {
  2674. moveTo: function(x, y) { this._context.moveTo(y, x); },
  2675. closePath: function() { this._context.closePath(); },
  2676. lineTo: function(x, y) { this._context.lineTo(y, x); },
  2677. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  2678. };
  2679. function monotoneX(context) {
  2680. return new MonotoneX(context);
  2681. }
  2682. function monotoneY(context) {
  2683. return new MonotoneY(context);
  2684. }
  2685. function Natural(context) {
  2686. this._context = context;
  2687. }
  2688. Natural.prototype = {
  2689. areaStart: function() {
  2690. this._line = 0;
  2691. },
  2692. areaEnd: function() {
  2693. this._line = NaN;
  2694. },
  2695. lineStart: function() {
  2696. this._x = [];
  2697. this._y = [];
  2698. },
  2699. lineEnd: function() {
  2700. var x = this._x,
  2701. y = this._y,
  2702. n = x.length;
  2703. if (n) {
  2704. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  2705. if (n === 2) {
  2706. this._context.lineTo(x[1], y[1]);
  2707. } else {
  2708. var px = controlPoints(x),
  2709. py = controlPoints(y);
  2710. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  2711. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  2712. }
  2713. }
  2714. }
  2715. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  2716. this._line = 1 - this._line;
  2717. this._x = this._y = null;
  2718. },
  2719. point: function(x, y) {
  2720. this._x.push(+x);
  2721. this._y.push(+y);
  2722. }
  2723. };
  2724. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  2725. function controlPoints(x) {
  2726. var i,
  2727. n = x.length - 1,
  2728. m,
  2729. a = new Array(n),
  2730. b = new Array(n),
  2731. r = new Array(n);
  2732. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  2733. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  2734. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  2735. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  2736. a[n - 1] = r[n - 1] / b[n - 1];
  2737. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  2738. b[n - 1] = (x[n] + a[n - 1]) / 2;
  2739. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  2740. return [a, b];
  2741. }
  2742. function natural(context) {
  2743. return new Natural(context);
  2744. }
  2745. function Step(context, t) {
  2746. this._context = context;
  2747. this._t = t;
  2748. }
  2749. Step.prototype = {
  2750. areaStart: function() {
  2751. this._line = 0;
  2752. },
  2753. areaEnd: function() {
  2754. this._line = NaN;
  2755. },
  2756. lineStart: function() {
  2757. this._x = this._y = NaN;
  2758. this._point = 0;
  2759. },
  2760. lineEnd: function() {
  2761. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  2762. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  2763. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  2764. },
  2765. point: function(x, y) {
  2766. x = +x, y = +y;
  2767. switch (this._point) {
  2768. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  2769. case 1: this._point = 2; // proceed
  2770. default: {
  2771. if (this._t <= 0) {
  2772. this._context.lineTo(this._x, y);
  2773. this._context.lineTo(x, y);
  2774. } else {
  2775. var x1 = this._x * (1 - this._t) + x * this._t;
  2776. this._context.lineTo(x1, this._y);
  2777. this._context.lineTo(x1, y);
  2778. }
  2779. break;
  2780. }
  2781. }
  2782. this._x = x, this._y = y;
  2783. }
  2784. };
  2785. function step(context) {
  2786. return new Step(context, 0.5);
  2787. }
  2788. function stepBefore(context) {
  2789. return new Step(context, 0);
  2790. }
  2791. function stepAfter(context) {
  2792. return new Step(context, 1);
  2793. }
  2794. var slice$2 = Array.prototype.slice;
  2795. function none(series, order) {
  2796. if (!((n = series.length) > 1)) return;
  2797. for (var i = 1, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  2798. s0 = s1, s1 = series[order[i]];
  2799. for (var j = 0; j < m; ++j) {
  2800. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  2801. }
  2802. }
  2803. }
  2804. function none$1(series) {
  2805. var n = series.length, o = new Array(n);
  2806. while (--n >= 0) o[n] = n;
  2807. return o;
  2808. }
  2809. function stackValue(d, key) {
  2810. return d[key];
  2811. }
  2812. function stack() {
  2813. var keys = constant$1([]),
  2814. order = none$1,
  2815. offset = none,
  2816. value = stackValue;
  2817. function stack(data) {
  2818. var kz = keys.apply(this, arguments),
  2819. i,
  2820. m = data.length,
  2821. n = kz.length,
  2822. sz = new Array(n),
  2823. oz;
  2824. for (i = 0; i < n; ++i) {
  2825. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  2826. si[j] = sij = [0, +value(data[j], ki, j, data)];
  2827. sij.data = data[j];
  2828. }
  2829. si.key = ki;
  2830. }
  2831. for (i = 0, oz = order(sz); i < n; ++i) {
  2832. sz[oz[i]].index = i;
  2833. }
  2834. offset(sz, oz);
  2835. return sz;
  2836. }
  2837. stack.keys = function(_) {
  2838. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$1(slice$2.call(_)), stack) : keys;
  2839. };
  2840. stack.value = function(_) {
  2841. return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), stack) : value;
  2842. };
  2843. stack.order = function(_) {
  2844. return arguments.length ? (order = _ == null ? none$1 : typeof _ === "function" ? _ : constant$1(slice$2.call(_)), stack) : order;
  2845. };
  2846. stack.offset = function(_) {
  2847. return arguments.length ? (offset = _ == null ? none : _, stack) : offset;
  2848. };
  2849. return stack;
  2850. }
  2851. function expand(series, order) {
  2852. if (!((n = series.length) > 0)) return;
  2853. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  2854. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  2855. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  2856. }
  2857. none(series, order);
  2858. }
  2859. function silhouette(series, order) {
  2860. if (!((n = series.length) > 0)) return;
  2861. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  2862. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  2863. s0[j][1] += s0[j][0] = -y / 2;
  2864. }
  2865. none(series, order);
  2866. }
  2867. function wiggle(series, order) {
  2868. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  2869. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  2870. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  2871. var si = series[order[i]],
  2872. sij0 = si[j][1] || 0,
  2873. sij1 = si[j - 1][1] || 0,
  2874. s3 = (sij0 - sij1) / 2;
  2875. for (var k = 0; k < i; ++k) {
  2876. var sk = series[order[k]],
  2877. skj0 = sk[j][1] || 0,
  2878. skj1 = sk[j - 1][1] || 0;
  2879. s3 += skj0 - skj1;
  2880. }
  2881. s1 += sij0, s2 += s3 * sij0;
  2882. }
  2883. s0[j - 1][1] += s0[j - 1][0] = y;
  2884. if (s1) y -= s2 / s1;
  2885. }
  2886. s0[j - 1][1] += s0[j - 1][0] = y;
  2887. none(series, order);
  2888. }
  2889. function ascending$1(series) {
  2890. var sums = series.map(sum$1);
  2891. return none$1(series).sort(function(a, b) { return sums[a] - sums[b]; });
  2892. }
  2893. function sum$1(series) {
  2894. var s = 0, i = -1, n = series.length, v;
  2895. while (++i < n) if (v = +series[i][1]) s += v;
  2896. return s;
  2897. }
  2898. function descending$2(series) {
  2899. return ascending$1(series).reverse();
  2900. }
  2901. function insideOut(series) {
  2902. var n = series.length,
  2903. i,
  2904. j,
  2905. sums = series.map(sum$1),
  2906. order = none$1(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  2907. top = 0,
  2908. bottom = 0,
  2909. tops = [],
  2910. bottoms = [];
  2911. for (i = 0; i < n; ++i) {
  2912. j = order[i];
  2913. if (top < bottom) {
  2914. top += sums[j];
  2915. tops.push(j);
  2916. } else {
  2917. bottom += sums[j];
  2918. bottoms.push(j);
  2919. }
  2920. }
  2921. return bottoms.reverse().concat(tops);
  2922. }
  2923. function reverse(series) {
  2924. return none$1(series).reverse();
  2925. }
  2926. function define(constructor, factory, prototype) {
  2927. constructor.prototype = factory.prototype = prototype;
  2928. prototype.constructor = constructor;
  2929. }
  2930. function extend(parent, definition) {
  2931. var prototype = Object.create(parent.prototype);
  2932. for (var key in definition) prototype[key] = definition[key];
  2933. return prototype;
  2934. }
  2935. function Color() {}
  2936. var darker = 0.7;
  2937. var brighter = 1 / darker;
  2938. var reHex3 = /^#([0-9a-f]{3})$/;
  2939. var reHex6 = /^#([0-9a-f]{6})$/;
  2940. var reRgbInteger = /^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/;
  2941. var reRgbPercent = /^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
  2942. var reRgbaInteger = /^rgba\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
  2943. var reRgbaPercent = /^rgba\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
  2944. var reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
  2945. var reHslaPercent = /^hsla\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
  2946. var named = {
  2947. aliceblue: 0xf0f8ff,
  2948. antiquewhite: 0xfaebd7,
  2949. aqua: 0x00ffff,
  2950. aquamarine: 0x7fffd4,
  2951. azure: 0xf0ffff,
  2952. beige: 0xf5f5dc,
  2953. bisque: 0xffe4c4,
  2954. black: 0x000000,
  2955. blanchedalmond: 0xffebcd,
  2956. blue: 0x0000ff,
  2957. blueviolet: 0x8a2be2,
  2958. brown: 0xa52a2a,
  2959. burlywood: 0xdeb887,
  2960. cadetblue: 0x5f9ea0,
  2961. chartreuse: 0x7fff00,
  2962. chocolate: 0xd2691e,
  2963. coral: 0xff7f50,
  2964. cornflowerblue: 0x6495ed,
  2965. cornsilk: 0xfff8dc,
  2966. crimson: 0xdc143c,
  2967. cyan: 0x00ffff,
  2968. darkblue: 0x00008b,
  2969. darkcyan: 0x008b8b,
  2970. darkgoldenrod: 0xb8860b,
  2971. darkgray: 0xa9a9a9,
  2972. darkgreen: 0x006400,
  2973. darkgrey: 0xa9a9a9,
  2974. darkkhaki: 0xbdb76b,
  2975. darkmagenta: 0x8b008b,
  2976. darkolivegreen: 0x556b2f,
  2977. darkorange: 0xff8c00,
  2978. darkorchid: 0x9932cc,
  2979. darkred: 0x8b0000,
  2980. darksalmon: 0xe9967a,
  2981. darkseagreen: 0x8fbc8f,
  2982. darkslateblue: 0x483d8b,
  2983. darkslategray: 0x2f4f4f,
  2984. darkslategrey: 0x2f4f4f,
  2985. darkturquoise: 0x00ced1,
  2986. darkviolet: 0x9400d3,
  2987. deeppink: 0xff1493,
  2988. deepskyblue: 0x00bfff,
  2989. dimgray: 0x696969,
  2990. dimgrey: 0x696969,
  2991. dodgerblue: 0x1e90ff,
  2992. firebrick: 0xb22222,
  2993. floralwhite: 0xfffaf0,
  2994. forestgreen: 0x228b22,
  2995. fuchsia: 0xff00ff,
  2996. gainsboro: 0xdcdcdc,
  2997. ghostwhite: 0xf8f8ff,
  2998. gold: 0xffd700,
  2999. goldenrod: 0xdaa520,
  3000. gray: 0x808080,
  3001. green: 0x008000,
  3002. greenyellow: 0xadff2f,
  3003. grey: 0x808080,
  3004. honeydew: 0xf0fff0,
  3005. hotpink: 0xff69b4,
  3006. indianred: 0xcd5c5c,
  3007. indigo: 0x4b0082,
  3008. ivory: 0xfffff0,
  3009. khaki: 0xf0e68c,
  3010. lavender: 0xe6e6fa,
  3011. lavenderblush: 0xfff0f5,
  3012. lawngreen: 0x7cfc00,
  3013. lemonchiffon: 0xfffacd,
  3014. lightblue: 0xadd8e6,
  3015. lightcoral: 0xf08080,
  3016. lightcyan: 0xe0ffff,
  3017. lightgoldenrodyellow: 0xfafad2,
  3018. lightgray: 0xd3d3d3,
  3019. lightgreen: 0x90ee90,
  3020. lightgrey: 0xd3d3d3,
  3021. lightpink: 0xffb6c1,
  3022. lightsalmon: 0xffa07a,
  3023. lightseagreen: 0x20b2aa,
  3024. lightskyblue: 0x87cefa,
  3025. lightslategray: 0x778899,
  3026. lightslategrey: 0x778899,
  3027. lightsteelblue: 0xb0c4de,
  3028. lightyellow: 0xffffe0,
  3029. lime: 0x00ff00,
  3030. limegreen: 0x32cd32,
  3031. linen: 0xfaf0e6,
  3032. magenta: 0xff00ff,
  3033. maroon: 0x800000,
  3034. mediumaquamarine: 0x66cdaa,
  3035. mediumblue: 0x0000cd,
  3036. mediumorchid: 0xba55d3,
  3037. mediumpurple: 0x9370db,
  3038. mediumseagreen: 0x3cb371,
  3039. mediumslateblue: 0x7b68ee,
  3040. mediumspringgreen: 0x00fa9a,
  3041. mediumturquoise: 0x48d1cc,
  3042. mediumvioletred: 0xc71585,
  3043. midnightblue: 0x191970,
  3044. mintcream: 0xf5fffa,
  3045. mistyrose: 0xffe4e1,
  3046. moccasin: 0xffe4b5,
  3047. navajowhite: 0xffdead,
  3048. navy: 0x000080,
  3049. oldlace: 0xfdf5e6,
  3050. olive: 0x808000,
  3051. olivedrab: 0x6b8e23,
  3052. orange: 0xffa500,
  3053. orangered: 0xff4500,
  3054. orchid: 0xda70d6,
  3055. palegoldenrod: 0xeee8aa,
  3056. palegreen: 0x98fb98,
  3057. paleturquoise: 0xafeeee,
  3058. palevioletred: 0xdb7093,
  3059. papayawhip: 0xffefd5,
  3060. peachpuff: 0xffdab9,
  3061. peru: 0xcd853f,
  3062. pink: 0xffc0cb,
  3063. plum: 0xdda0dd,
  3064. powderblue: 0xb0e0e6,
  3065. purple: 0x800080,
  3066. rebeccapurple: 0x663399,
  3067. red: 0xff0000,
  3068. rosybrown: 0xbc8f8f,
  3069. royalblue: 0x4169e1,
  3070. saddlebrown: 0x8b4513,
  3071. salmon: 0xfa8072,
  3072. sandybrown: 0xf4a460,
  3073. seagreen: 0x2e8b57,
  3074. seashell: 0xfff5ee,
  3075. sienna: 0xa0522d,
  3076. silver: 0xc0c0c0,
  3077. skyblue: 0x87ceeb,
  3078. slateblue: 0x6a5acd,
  3079. slategray: 0x708090,
  3080. slategrey: 0x708090,
  3081. snow: 0xfffafa,
  3082. springgreen: 0x00ff7f,
  3083. steelblue: 0x4682b4,
  3084. tan: 0xd2b48c,
  3085. teal: 0x008080,
  3086. thistle: 0xd8bfd8,
  3087. tomato: 0xff6347,
  3088. turquoise: 0x40e0d0,
  3089. violet: 0xee82ee,
  3090. wheat: 0xf5deb3,
  3091. white: 0xffffff,
  3092. whitesmoke: 0xf5f5f5,
  3093. yellow: 0xffff00,
  3094. yellowgreen: 0x9acd32
  3095. };
  3096. define(Color, color, {
  3097. displayable: function() {
  3098. return this.rgb().displayable();
  3099. },
  3100. toString: function() {
  3101. return this.rgb() + "";
  3102. }
  3103. });
  3104. function color(format) {
  3105. var m;
  3106. format = (format + "").trim().toLowerCase();
  3107. 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
  3108. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  3109. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  3110. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  3111. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  3112. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  3113. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  3114. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  3115. : named.hasOwnProperty(format) ? rgbn(named[format])
  3116. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  3117. : null;
  3118. }
  3119. function rgbn(n) {
  3120. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  3121. }
  3122. function rgba(r, g, b, a) {
  3123. if (a <= 0) r = g = b = NaN;
  3124. return new Rgb(r, g, b, a);
  3125. }
  3126. function rgbConvert(o) {
  3127. if (!(o instanceof Color)) o = color(o);
  3128. if (!o) return new Rgb;
  3129. o = o.rgb();
  3130. return new Rgb(o.r, o.g, o.b, o.opacity);
  3131. }
  3132. function colorRgb(r, g, b, opacity) {
  3133. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  3134. }
  3135. function Rgb(r, g, b, opacity) {
  3136. this.r = +r;
  3137. this.g = +g;
  3138. this.b = +b;
  3139. this.opacity = +opacity;
  3140. }
  3141. define(Rgb, colorRgb, extend(Color, {
  3142. brighter: function(k) {
  3143. k = k == null ? brighter : Math.pow(brighter, k);
  3144. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  3145. },
  3146. darker: function(k) {
  3147. k = k == null ? darker : Math.pow(darker, k);
  3148. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  3149. },
  3150. rgb: function() {
  3151. return this;
  3152. },
  3153. displayable: function() {
  3154. return (0 <= this.r && this.r <= 255)
  3155. && (0 <= this.g && this.g <= 255)
  3156. && (0 <= this.b && this.b <= 255)
  3157. && (0 <= this.opacity && this.opacity <= 1);
  3158. },
  3159. toString: function() {
  3160. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  3161. return (a === 1 ? "rgb(" : "rgba(")
  3162. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  3163. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  3164. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  3165. + (a === 1 ? ")" : ", " + a + ")");
  3166. }
  3167. }));
  3168. function hsla(h, s, l, a) {
  3169. if (a <= 0) h = s = l = NaN;
  3170. else if (l <= 0 || l >= 1) h = s = NaN;
  3171. else if (s <= 0) h = NaN;
  3172. return new Hsl(h, s, l, a);
  3173. }
  3174. function hslConvert(o) {
  3175. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  3176. if (!(o instanceof Color)) o = color(o);
  3177. if (!o) return new Hsl;
  3178. if (o instanceof Hsl) return o;
  3179. o = o.rgb();
  3180. var r = o.r / 255,
  3181. g = o.g / 255,
  3182. b = o.b / 255,
  3183. min = Math.min(r, g, b),
  3184. max = Math.max(r, g, b),
  3185. h = NaN,
  3186. s = max - min,
  3187. l = (max + min) / 2;
  3188. if (s) {
  3189. if (r === max) h = (g - b) / s + (g < b) * 6;
  3190. else if (g === max) h = (b - r) / s + 2;
  3191. else h = (r - g) / s + 4;
  3192. s /= l < 0.5 ? max + min : 2 - max - min;
  3193. h *= 60;
  3194. } else {
  3195. s = l > 0 && l < 1 ? 0 : h;
  3196. }
  3197. return new Hsl(h, s, l, o.opacity);
  3198. }
  3199. function colorHsl(h, s, l, opacity) {
  3200. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  3201. }
  3202. function Hsl(h, s, l, opacity) {
  3203. this.h = +h;
  3204. this.s = +s;
  3205. this.l = +l;
  3206. this.opacity = +opacity;
  3207. }
  3208. define(Hsl, colorHsl, extend(Color, {
  3209. brighter: function(k) {
  3210. k = k == null ? brighter : Math.pow(brighter, k);
  3211. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  3212. },
  3213. darker: function(k) {
  3214. k = k == null ? darker : Math.pow(darker, k);
  3215. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  3216. },
  3217. rgb: function() {
  3218. var h = this.h % 360 + (this.h < 0) * 360,
  3219. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  3220. l = this.l,
  3221. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  3222. m1 = 2 * l - m2;
  3223. return new Rgb(
  3224. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  3225. hsl2rgb(h, m1, m2),
  3226. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  3227. this.opacity
  3228. );
  3229. },
  3230. displayable: function() {
  3231. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  3232. && (0 <= this.l && this.l <= 1)
  3233. && (0 <= this.opacity && this.opacity <= 1);
  3234. }
  3235. }));
  3236. /* From FvD 13.37, CSS Color Module Level 3 */
  3237. function hsl2rgb(h, m1, m2) {
  3238. return (h < 60 ? m1 + (m2 - m1) * h / 60
  3239. : h < 180 ? m2
  3240. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  3241. : m1) * 255;
  3242. }
  3243. var deg2rad = Math.PI / 180;
  3244. var rad2deg = 180 / Math.PI;
  3245. var Kn = 18;
  3246. var Xn = 0.950470;
  3247. var Yn = 1;
  3248. var Zn = 1.088830;
  3249. var t0 = 4 / 29;
  3250. var t1 = 6 / 29;
  3251. var t2 = 3 * t1 * t1;
  3252. var t3 = t1 * t1 * t1;
  3253. function labConvert(o) {
  3254. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  3255. if (o instanceof Hcl) {
  3256. var h = o.h * deg2rad;
  3257. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  3258. }
  3259. if (!(o instanceof Rgb)) o = rgbConvert(o);
  3260. var b = rgb2xyz(o.r),
  3261. a = rgb2xyz(o.g),
  3262. l = rgb2xyz(o.b),
  3263. x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
  3264. y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
  3265. z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
  3266. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  3267. }
  3268. function lab(l, a, b, opacity) {
  3269. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  3270. }
  3271. function Lab(l, a, b, opacity) {
  3272. this.l = +l;
  3273. this.a = +a;
  3274. this.b = +b;
  3275. this.opacity = +opacity;
  3276. }
  3277. define(Lab, lab, extend(Color, {
  3278. brighter: function(k) {
  3279. return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  3280. },
  3281. darker: function(k) {
  3282. return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  3283. },
  3284. rgb: function() {
  3285. var y = (this.l + 16) / 116,
  3286. x = isNaN(this.a) ? y : y + this.a / 500,
  3287. z = isNaN(this.b) ? y : y - this.b / 200;
  3288. y = Yn * lab2xyz(y);
  3289. x = Xn * lab2xyz(x);
  3290. z = Zn * lab2xyz(z);
  3291. return new Rgb(
  3292. xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
  3293. xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
  3294. xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
  3295. this.opacity
  3296. );
  3297. }
  3298. }));
  3299. function xyz2lab(t) {
  3300. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  3301. }
  3302. function lab2xyz(t) {
  3303. return t > t1 ? t * t * t : t2 * (t - t0);
  3304. }
  3305. function xyz2rgb(x) {
  3306. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  3307. }
  3308. function rgb2xyz(x) {
  3309. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  3310. }
  3311. function hclConvert(o) {
  3312. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  3313. if (!(o instanceof Lab)) o = labConvert(o);
  3314. var h = Math.atan2(o.b, o.a) * rad2deg;
  3315. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  3316. }
  3317. function colorHcl(h, c, l, opacity) {
  3318. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  3319. }
  3320. function Hcl(h, c, l, opacity) {
  3321. this.h = +h;
  3322. this.c = +c;
  3323. this.l = +l;
  3324. this.opacity = +opacity;
  3325. }
  3326. define(Hcl, colorHcl, extend(Color, {
  3327. brighter: function(k) {
  3328. return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
  3329. },
  3330. darker: function(k) {
  3331. return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
  3332. },
  3333. rgb: function() {
  3334. return labConvert(this).rgb();
  3335. }
  3336. }));
  3337. var A = -0.14861;
  3338. var B = +1.78277;
  3339. var C = -0.29227;
  3340. var D = -0.90649;
  3341. var E = +1.97294;
  3342. var ED = E * D;
  3343. var EB = E * B;
  3344. var BC_DA = B * C - D * A;
  3345. function cubehelixConvert(o) {
  3346. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  3347. if (!(o instanceof Rgb)) o = rgbConvert(o);
  3348. var r = o.r / 255,
  3349. g = o.g / 255,
  3350. b = o.b / 255,
  3351. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  3352. bl = b - l,
  3353. k = (E * (g - l) - C * bl) / D,
  3354. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  3355. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  3356. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  3357. }
  3358. function cubehelix(h, s, l, opacity) {
  3359. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  3360. }
  3361. function Cubehelix(h, s, l, opacity) {
  3362. this.h = +h;
  3363. this.s = +s;
  3364. this.l = +l;
  3365. this.opacity = +opacity;
  3366. }
  3367. define(Cubehelix, cubehelix, extend(Color, {
  3368. brighter: function(k) {
  3369. k = k == null ? brighter : Math.pow(brighter, k);
  3370. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  3371. },
  3372. darker: function(k) {
  3373. k = k == null ? darker : Math.pow(darker, k);
  3374. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  3375. },
  3376. rgb: function() {
  3377. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  3378. l = +this.l,
  3379. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  3380. cosh = Math.cos(h),
  3381. sinh = Math.sin(h);
  3382. return new Rgb(
  3383. 255 * (l + a * (A * cosh + B * sinh)),
  3384. 255 * (l + a * (C * cosh + D * sinh)),
  3385. 255 * (l + a * (E * cosh)),
  3386. this.opacity
  3387. );
  3388. }
  3389. }));
  3390. function basis$1(t1, v0, v1, v2, v3) {
  3391. var t2 = t1 * t1, t3 = t2 * t1;
  3392. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  3393. + (4 - 6 * t2 + 3 * t3) * v1
  3394. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  3395. + t3 * v3) / 6;
  3396. }
  3397. function basis$2(values) {
  3398. var n = values.length - 1;
  3399. return function(t) {
  3400. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  3401. v1 = values[i],
  3402. v2 = values[i + 1],
  3403. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  3404. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  3405. return basis$1((t - i / n) * n, v0, v1, v2, v3);
  3406. };
  3407. }
  3408. function basisClosed$1(values) {
  3409. var n = values.length;
  3410. return function(t) {
  3411. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  3412. v0 = values[(i + n - 1) % n],
  3413. v1 = values[i % n],
  3414. v2 = values[(i + 1) % n],
  3415. v3 = values[(i + 2) % n];
  3416. return basis$1((t - i / n) * n, v0, v1, v2, v3);
  3417. };
  3418. }
  3419. function constant$2(x) {
  3420. return function() {
  3421. return x;
  3422. };
  3423. }
  3424. function linear$1(a, d) {
  3425. return function(t) {
  3426. return a + t * d;
  3427. };
  3428. }
  3429. function exponential$1(a, b, y) {
  3430. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  3431. return Math.pow(a + t * b, y);
  3432. };
  3433. }
  3434. function hue(a, b) {
  3435. var d = b - a;
  3436. return d ? linear$1(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$2(isNaN(a) ? b : a);
  3437. }
  3438. function gamma(y) {
  3439. return (y = +y) === 1 ? nogamma : function(a, b) {
  3440. return b - a ? exponential$1(a, b, y) : constant$2(isNaN(a) ? b : a);
  3441. };
  3442. }
  3443. function nogamma(a, b) {
  3444. var d = b - a;
  3445. return d ? linear$1(a, d) : constant$2(isNaN(a) ? b : a);
  3446. }
  3447. var interpolateRgb = (function rgbGamma(y) {
  3448. var color = gamma(y);
  3449. function rgb(start, end) {
  3450. var r = color((start = colorRgb(start)).r, (end = colorRgb(end)).r),
  3451. g = color(start.g, end.g),
  3452. b = color(start.b, end.b),
  3453. opacity = color(start.opacity, end.opacity);
  3454. return function(t) {
  3455. start.r = r(t);
  3456. start.g = g(t);
  3457. start.b = b(t);
  3458. start.opacity = opacity(t);
  3459. return start + "";
  3460. };
  3461. }
  3462. rgb.gamma = rgbGamma;
  3463. return rgb;
  3464. })(1);
  3465. function rgbSpline(spline) {
  3466. return function(colors) {
  3467. var n = colors.length,
  3468. r = new Array(n),
  3469. g = new Array(n),
  3470. b = new Array(n),
  3471. i, color;
  3472. for (i = 0; i < n; ++i) {
  3473. color = colorRgb(colors[i]);
  3474. r[i] = color.r || 0;
  3475. g[i] = color.g || 0;
  3476. b[i] = color.b || 0;
  3477. }
  3478. r = spline(r);
  3479. g = spline(g);
  3480. b = spline(b);
  3481. color.opacity = 1;
  3482. return function(t) {
  3483. color.r = r(t);
  3484. color.g = g(t);
  3485. color.b = b(t);
  3486. return color + "";
  3487. };
  3488. };
  3489. }
  3490. var rgbBasis = rgbSpline(basis$2);
  3491. var rgbBasisClosed = rgbSpline(basisClosed$1);
  3492. function array$1(a, b) {
  3493. var nb = b ? b.length : 0,
  3494. na = a ? Math.min(nb, a.length) : 0,
  3495. x = new Array(nb),
  3496. c = new Array(nb),
  3497. i;
  3498. for (i = 0; i < na; ++i) x[i] = interpolate(a[i], b[i]);
  3499. for (; i < nb; ++i) c[i] = b[i];
  3500. return function(t) {
  3501. for (i = 0; i < na; ++i) c[i] = x[i](t);
  3502. return c;
  3503. };
  3504. }
  3505. function interpolateNumber(a, b) {
  3506. return a = +a, b -= a, function(t) {
  3507. return a + b * t;
  3508. };
  3509. }
  3510. function object(a, b) {
  3511. var i = {},
  3512. c = {},
  3513. k;
  3514. if (a === null || typeof a !== "object") a = {};
  3515. if (b === null || typeof b !== "object") b = {};
  3516. for (k in b) {
  3517. if (k in a) {
  3518. i[k] = interpolate(a[k], b[k]);
  3519. } else {
  3520. c[k] = b[k];
  3521. }
  3522. }
  3523. return function(t) {
  3524. for (k in i) c[k] = i[k](t);
  3525. return c;
  3526. };
  3527. }
  3528. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
  3529. var reB = new RegExp(reA.source, "g");
  3530. function zero(b) {
  3531. return function() {
  3532. return b;
  3533. };
  3534. }
  3535. function one(b) {
  3536. return function(t) {
  3537. return b(t) + "";
  3538. };
  3539. }
  3540. function interpolateString(a, b) {
  3541. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  3542. am, // current match in a
  3543. bm, // current match in b
  3544. bs, // string preceding current number in b, if any
  3545. i = -1, // index in s
  3546. s = [], // string constants and placeholders
  3547. q = []; // number interpolators
  3548. // Coerce inputs to strings.
  3549. a = a + "", b = b + "";
  3550. // Interpolate pairs of numbers in a & b.
  3551. while ((am = reA.exec(a))
  3552. && (bm = reB.exec(b))) {
  3553. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  3554. bs = b.slice(bi, bs);
  3555. if (s[i]) s[i] += bs; // coalesce with previous string
  3556. else s[++i] = bs;
  3557. }
  3558. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  3559. if (s[i]) s[i] += bm; // coalesce with previous string
  3560. else s[++i] = bm;
  3561. } else { // interpolate non-matching numbers
  3562. s[++i] = null;
  3563. q.push({i: i, x: interpolateNumber(am, bm)});
  3564. }
  3565. bi = reB.lastIndex;
  3566. }
  3567. // Add remains of b.
  3568. if (bi < b.length) {
  3569. bs = b.slice(bi);
  3570. if (s[i]) s[i] += bs; // coalesce with previous string
  3571. else s[++i] = bs;
  3572. }
  3573. // Special optimization for only a single match.
  3574. // Otherwise, interpolate each of the numbers and rejoin the string.
  3575. return s.length < 2 ? (q[0]
  3576. ? one(q[0].x)
  3577. : zero(b))
  3578. : (b = q.length, function(t) {
  3579. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  3580. return s.join("");
  3581. });
  3582. }
  3583. function interpolate(a, b) {
  3584. var t = typeof b, c;
  3585. return b == null || t === "boolean" ? constant$2(b)
  3586. : (t === "number" ? interpolateNumber
  3587. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  3588. : b instanceof color ? interpolateRgb
  3589. : Array.isArray(b) ? array$1
  3590. : object)(a, b);
  3591. }
  3592. function interpolateRound(a, b) {
  3593. return a = +a, b -= a, function(t) {
  3594. return Math.round(a + b * t);
  3595. };
  3596. }
  3597. var degrees = 180 / Math.PI;
  3598. var identity$2 = {
  3599. translateX: 0,
  3600. translateY: 0,
  3601. rotate: 0,
  3602. skewX: 0,
  3603. scaleX: 1,
  3604. scaleY: 1
  3605. };
  3606. function decompose(a, b, c, d, e, f) {
  3607. var scaleX, scaleY, skewX;
  3608. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  3609. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  3610. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  3611. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  3612. return {
  3613. translateX: e,
  3614. translateY: f,
  3615. rotate: Math.atan2(b, a) * degrees,
  3616. skewX: Math.atan(skewX) * degrees,
  3617. scaleX: scaleX,
  3618. scaleY: scaleY
  3619. };
  3620. }
  3621. var cssNode;
  3622. var cssRoot;
  3623. var cssView;
  3624. var svgNode;
  3625. function parseCss(value) {
  3626. if (value === "none") return identity$2;
  3627. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  3628. cssNode.style.transform = value;
  3629. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  3630. cssRoot.removeChild(cssNode);
  3631. var m = value.slice(7, -1).split(",");
  3632. return decompose(+m[0], +m[1], +m[2], +m[3], +m[4], +m[5]);
  3633. }
  3634. function parseSvg(value) {
  3635. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  3636. svgNode.setAttribute("transform", value == null ? "" : value);
  3637. var m = svgNode.transform.baseVal.consolidate().matrix;
  3638. return decompose(m.a, m.b, m.c, m.d, m.e, m.f);
  3639. }
  3640. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  3641. function pop(s) {
  3642. return s.length ? s.pop() + " " : "";
  3643. }
  3644. function translate(xa, ya, xb, yb, s, q) {
  3645. if (xa !== xb || ya !== yb) {
  3646. var i = s.push("translate(", null, pxComma, null, pxParen);
  3647. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  3648. } else if (xb || yb) {
  3649. s.push("translate(" + xb + pxComma + yb + pxParen);
  3650. }
  3651. }
  3652. function rotate(a, b, s, q) {
  3653. if (a !== b) {
  3654. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  3655. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  3656. } else if (b) {
  3657. s.push(pop(s) + "rotate(" + b + degParen);
  3658. }
  3659. }
  3660. function skewX(a, b, s, q) {
  3661. if (a !== b) {
  3662. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  3663. } else if (b) {
  3664. s.push(pop(s) + "skewX(" + b + degParen);
  3665. }
  3666. }
  3667. function scale(xa, ya, xb, yb, s, q) {
  3668. if (xa !== xb || ya !== yb) {
  3669. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  3670. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  3671. } else if (xb !== 1 || yb !== 1) {
  3672. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  3673. }
  3674. }
  3675. return function(a, b) {
  3676. var s = [], // string constants and placeholders
  3677. q = []; // number interpolators
  3678. a = parse(a), b = parse(b);
  3679. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  3680. rotate(a.rotate, b.rotate, s, q);
  3681. skewX(a.skewX, b.skewX, s, q);
  3682. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  3683. a = b = null; // gc
  3684. return function(t) {
  3685. var i = -1, n = q.length, o;
  3686. while (++i < n) s[(o = q[i]).i] = o.x(t);
  3687. return s.join("");
  3688. };
  3689. };
  3690. }
  3691. var interpolateTransform$1 = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  3692. var interpolateTransform$2 = interpolateTransform(parseSvg, ", ", ")", ")");
  3693. var rho = Math.SQRT2;
  3694. var rho2 = 2;
  3695. var rho4 = 4;
  3696. var epsilon2 = 1e-12;
  3697. function cosh(x) {
  3698. return ((x = Math.exp(x)) + 1 / x) / 2;
  3699. }
  3700. function sinh(x) {
  3701. return ((x = Math.exp(x)) - 1 / x) / 2;
  3702. }
  3703. function tanh(x) {
  3704. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  3705. }
  3706. // p0 = [ux0, uy0, w0]
  3707. // p1 = [ux1, uy1, w1]
  3708. function interpolateZoom(p0, p1) {
  3709. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  3710. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  3711. dx = ux1 - ux0,
  3712. dy = uy1 - uy0,
  3713. d2 = dx * dx + dy * dy,
  3714. i,
  3715. S;
  3716. // Special case for u0 ≅ u1.
  3717. if (d2 < epsilon2) {
  3718. S = Math.log(w1 / w0) / rho;
  3719. i = function(t) {
  3720. return [
  3721. ux0 + t * dx,
  3722. uy0 + t * dy,
  3723. w0 * Math.exp(rho * t * S)
  3724. ];
  3725. }
  3726. }
  3727. // General case.
  3728. else {
  3729. var d1 = Math.sqrt(d2),
  3730. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  3731. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  3732. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  3733. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  3734. S = (r1 - r0) / rho;
  3735. i = function(t) {
  3736. var s = t * S,
  3737. coshr0 = cosh(r0),
  3738. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  3739. return [
  3740. ux0 + u * dx,
  3741. uy0 + u * dy,
  3742. w0 * coshr0 / cosh(rho * s + r0)
  3743. ];
  3744. }
  3745. }
  3746. i.duration = S * 1000;
  3747. return i;
  3748. }
  3749. function hsl(hue) {
  3750. return function(start, end) {
  3751. var h = hue((start = colorHsl(start)).h, (end = colorHsl(end)).h),
  3752. s = nogamma(start.s, end.s),
  3753. l = nogamma(start.l, end.l),
  3754. opacity = nogamma(start.opacity, end.opacity);
  3755. return function(t) {
  3756. start.h = h(t);
  3757. start.s = s(t);
  3758. start.l = l(t);
  3759. start.opacity = opacity(t);
  3760. return start + "";
  3761. };
  3762. }
  3763. }
  3764. var hsl$1 = hsl(hue);
  3765. var hslLong = hsl(nogamma);
  3766. function lab$1(start, end) {
  3767. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  3768. a = nogamma(start.a, end.a),
  3769. b = nogamma(start.b, end.b),
  3770. opacity = nogamma(start.opacity, end.opacity);
  3771. return function(t) {
  3772. start.l = l(t);
  3773. start.a = a(t);
  3774. start.b = b(t);
  3775. start.opacity = opacity(t);
  3776. return start + "";
  3777. };
  3778. }
  3779. function hcl(hue) {
  3780. return function(start, end) {
  3781. var h = hue((start = colorHcl(start)).h, (end = colorHcl(end)).h),
  3782. c = nogamma(start.c, end.c),
  3783. l = nogamma(start.l, end.l),
  3784. opacity = nogamma(start.opacity, end.opacity);
  3785. return function(t) {
  3786. start.h = h(t);
  3787. start.c = c(t);
  3788. start.l = l(t);
  3789. start.opacity = opacity(t);
  3790. return start + "";
  3791. };
  3792. }
  3793. }
  3794. var hcl$1 = hcl(hue);
  3795. var hclLong = hcl(nogamma);
  3796. function cubehelix$1(hue) {
  3797. return (function cubehelixGamma(y) {
  3798. y = +y;
  3799. function cubehelix$$(start, end) {
  3800. var h = hue((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  3801. s = nogamma(start.s, end.s),
  3802. l = nogamma(start.l, end.l),
  3803. opacity = nogamma(start.opacity, end.opacity);
  3804. return function(t) {
  3805. start.h = h(t);
  3806. start.s = s(t);
  3807. start.l = l(Math.pow(t, y));
  3808. start.opacity = opacity(t);
  3809. return start + "";
  3810. };
  3811. }
  3812. cubehelix$$.gamma = cubehelixGamma;
  3813. return cubehelix$$;
  3814. })(1);
  3815. }
  3816. var cubehelix$2 = cubehelix$1(hue);
  3817. var interpolateCubehelixLong = cubehelix$1(nogamma);
  3818. function quantize(interpolate, n) {
  3819. var samples = new Array(n);
  3820. for (var i = 0; i < n; ++i) samples[i] = interpolate(i / (n - 1));
  3821. return samples;
  3822. }
  3823. var noop$1 = {value: function() {}};
  3824. function dispatch() {
  3825. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  3826. if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
  3827. _[t] = [];
  3828. }
  3829. return new Dispatch(_);
  3830. }
  3831. function Dispatch(_) {
  3832. this._ = _;
  3833. }
  3834. function parseTypenames(typenames, types) {
  3835. return typenames.trim().split(/^|\s+/).map(function(t) {
  3836. var name = "", i = t.indexOf(".");
  3837. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  3838. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  3839. return {type: t, name: name};
  3840. });
  3841. }
  3842. Dispatch.prototype = dispatch.prototype = {
  3843. constructor: Dispatch,
  3844. on: function(typename, callback) {
  3845. var _ = this._,
  3846. T = parseTypenames(typename + "", _),
  3847. t,
  3848. i = -1,
  3849. n = T.length;
  3850. // If no callback was specified, return the callback of the given type and name.
  3851. if (arguments.length < 2) {
  3852. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  3853. return;
  3854. }
  3855. // If a type was specified, set the callback for the given type and name.
  3856. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  3857. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  3858. while (++i < n) {
  3859. if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);
  3860. else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null);
  3861. }
  3862. return this;
  3863. },
  3864. copy: function() {
  3865. var copy = {}, _ = this._;
  3866. for (var t in _) copy[t] = _[t].slice();
  3867. return new Dispatch(copy);
  3868. },
  3869. call: function(type, that) {
  3870. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  3871. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  3872. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  3873. },
  3874. apply: function(type, that, args) {
  3875. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  3876. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  3877. }
  3878. };
  3879. function get(type, name) {
  3880. for (var i = 0, n = type.length, c; i < n; ++i) {
  3881. if ((c = type[i]).name === name) {
  3882. return c.value;
  3883. }
  3884. }
  3885. }
  3886. function set$1(type, name, callback) {
  3887. for (var i = 0, n = type.length; i < n; ++i) {
  3888. if (type[i].name === name) {
  3889. type[i] = noop$1, type = type.slice(0, i).concat(type.slice(i + 1));
  3890. break;
  3891. }
  3892. }
  3893. if (callback != null) type.push({name: name, value: callback});
  3894. return type;
  3895. }
  3896. function objectConverter(columns) {
  3897. return new Function("d", "return {" + columns.map(function(name, i) {
  3898. return JSON.stringify(name) + ": d[" + i + "]";
  3899. }).join(",") + "}");
  3900. }
  3901. function customConverter(columns, f) {
  3902. var object = objectConverter(columns);
  3903. return function(row, i) {
  3904. return f(object(row), i, columns);
  3905. };
  3906. }
  3907. // Compute unique columns in order of discovery.
  3908. function inferColumns(rows) {
  3909. var columnSet = Object.create(null),
  3910. columns = [];
  3911. rows.forEach(function(row) {
  3912. for (var column in row) {
  3913. if (!(column in columnSet)) {
  3914. columns.push(columnSet[column] = column);
  3915. }
  3916. }
  3917. });
  3918. return columns;
  3919. }
  3920. function dsv(delimiter) {
  3921. var reFormat = new RegExp("[\"" + delimiter + "\n]"),
  3922. delimiterCode = delimiter.charCodeAt(0);
  3923. function parse(text, f) {
  3924. var convert, columns, rows = parseRows(text, function(row, i) {
  3925. if (convert) return convert(row, i - 1);
  3926. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  3927. });
  3928. rows.columns = columns;
  3929. return rows;
  3930. }
  3931. function parseRows(text, f) {
  3932. var EOL = {}, // sentinel value for end-of-line
  3933. EOF = {}, // sentinel value for end-of-file
  3934. rows = [], // output rows
  3935. N = text.length,
  3936. I = 0, // current character index
  3937. n = 0, // the current line number
  3938. t, // the current token
  3939. eol; // is the current token followed by EOL?
  3940. function token() {
  3941. if (I >= N) return EOF; // special case: end of file
  3942. if (eol) return eol = false, EOL; // special case: end of line
  3943. // special case: quotes
  3944. var j = I, c;
  3945. if (text.charCodeAt(j) === 34) {
  3946. var i = j;
  3947. while (i++ < N) {
  3948. if (text.charCodeAt(i) === 34) {
  3949. if (text.charCodeAt(i + 1) !== 34) break;
  3950. ++i;
  3951. }
  3952. }
  3953. I = i + 2;
  3954. c = text.charCodeAt(i + 1);
  3955. if (c === 13) {
  3956. eol = true;
  3957. if (text.charCodeAt(i + 2) === 10) ++I;
  3958. } else if (c === 10) {
  3959. eol = true;
  3960. }
  3961. return text.slice(j + 1, i).replace(/""/g, "\"");
  3962. }
  3963. // common case: find next delimiter or newline
  3964. while (I < N) {
  3965. var k = 1;
  3966. c = text.charCodeAt(I++);
  3967. if (c === 10) eol = true; // \n
  3968. else if (c === 13) { eol = true; if (text.charCodeAt(I) === 10) ++I, ++k; } // \r|\r\n
  3969. else if (c !== delimiterCode) continue;
  3970. return text.slice(j, I - k);
  3971. }
  3972. // special case: last token before EOF
  3973. return text.slice(j);
  3974. }
  3975. while ((t = token()) !== EOF) {
  3976. var a = [];
  3977. while (t !== EOL && t !== EOF) {
  3978. a.push(t);
  3979. t = token();
  3980. }
  3981. if (f && (a = f(a, n++)) == null) continue;
  3982. rows.push(a);
  3983. }
  3984. return rows;
  3985. }
  3986. function format(rows, columns) {
  3987. if (columns == null) columns = inferColumns(rows);
  3988. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  3989. return columns.map(function(column) {
  3990. return formatValue(row[column]);
  3991. }).join(delimiter);
  3992. })).join("\n");
  3993. }
  3994. function formatRows(rows) {
  3995. return rows.map(formatRow).join("\n");
  3996. }
  3997. function formatRow(row) {
  3998. return row.map(formatValue).join(delimiter);
  3999. }
  4000. function formatValue(text) {
  4001. return text == null ? ""
  4002. : reFormat.test(text += "") ? "\"" + text.replace(/\"/g, "\"\"") + "\""
  4003. : text;
  4004. }
  4005. return {
  4006. parse: parse,
  4007. parseRows: parseRows,
  4008. format: format,
  4009. formatRows: formatRows
  4010. };
  4011. }
  4012. var csv = dsv(",");
  4013. var csvParse = csv.parse;
  4014. var csvParseRows = csv.parseRows;
  4015. var csvFormat = csv.format;
  4016. var csvFormatRows = csv.formatRows;
  4017. var tsv = dsv("\t");
  4018. var tsvParse = tsv.parse;
  4019. var tsvParseRows = tsv.parseRows;
  4020. var tsvFormat = tsv.format;
  4021. var tsvFormatRows = tsv.formatRows;
  4022. function request(url, callback) {
  4023. var request,
  4024. event = dispatch("beforesend", "progress", "load", "error"),
  4025. mimeType,
  4026. headers = map$1(),
  4027. xhr = new XMLHttpRequest,
  4028. user = null,
  4029. password = null,
  4030. response,
  4031. responseType,
  4032. timeout = 0;
  4033. // If IE does not support CORS, use XDomainRequest.
  4034. if (typeof XDomainRequest !== "undefined"
  4035. && !("withCredentials" in xhr)
  4036. && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
  4037. "onload" in xhr
  4038. ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
  4039. : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
  4040. function respond(o) {
  4041. var status = xhr.status, result;
  4042. if (!status && hasResponse(xhr)
  4043. || status >= 200 && status < 300
  4044. || status === 304) {
  4045. if (response) {
  4046. try {
  4047. result = response.call(request, xhr);
  4048. } catch (e) {
  4049. event.call("error", request, e);
  4050. return;
  4051. }
  4052. } else {
  4053. result = xhr;
  4054. }
  4055. event.call("load", request, result);
  4056. } else {
  4057. event.call("error", request, o);
  4058. }
  4059. }
  4060. xhr.onprogress = function(e) {
  4061. event.call("progress", request, e);
  4062. };
  4063. request = {
  4064. header: function(name, value) {
  4065. name = (name + "").toLowerCase();
  4066. if (arguments.length < 2) return headers.get(name);
  4067. if (value == null) headers.remove(name);
  4068. else headers.set(name, value + "");
  4069. return request;
  4070. },
  4071. // If mimeType is non-null and no Accept header is set, a default is used.
  4072. mimeType: function(value) {
  4073. if (!arguments.length) return mimeType;
  4074. mimeType = value == null ? null : value + "";
  4075. return request;
  4076. },
  4077. // Specifies what type the response value should take;
  4078. // for instance, arraybuffer, blob, document, or text.
  4079. responseType: function(value) {
  4080. if (!arguments.length) return responseType;
  4081. responseType = value;
  4082. return request;
  4083. },
  4084. timeout: function(value) {
  4085. if (!arguments.length) return timeout;
  4086. timeout = +value;
  4087. return request;
  4088. },
  4089. user: function(value) {
  4090. return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
  4091. },
  4092. password: function(value) {
  4093. return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
  4094. },
  4095. // Specify how to convert the response content to a specific type;
  4096. // changes the callback value on "load" events.
  4097. response: function(value) {
  4098. response = value;
  4099. return request;
  4100. },
  4101. // Alias for send("GET", …).
  4102. get: function(data, callback) {
  4103. return request.send("GET", data, callback);
  4104. },
  4105. // Alias for send("POST", …).
  4106. post: function(data, callback) {
  4107. return request.send("POST", data, callback);
  4108. },
  4109. // If callback is non-null, it will be used for error and load events.
  4110. send: function(method, data, callback) {
  4111. if (!callback && typeof data === "function") callback = data, data = null;
  4112. if (callback && callback.length === 1) callback = fixCallback(callback);
  4113. xhr.open(method, url, true, user, password);
  4114. if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
  4115. if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
  4116. if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
  4117. if (responseType != null) xhr.responseType = responseType;
  4118. if (timeout > 0) xhr.timeout = timeout;
  4119. if (callback) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
  4120. event.call("beforesend", request, xhr);
  4121. xhr.send(data == null ? null : data);
  4122. return request;
  4123. },
  4124. abort: function() {
  4125. xhr.abort();
  4126. return request;
  4127. },
  4128. on: function() {
  4129. var value = event.on.apply(event, arguments);
  4130. return value === event ? request : value;
  4131. }
  4132. };
  4133. return callback
  4134. ? request.get(callback)
  4135. : request;
  4136. }
  4137. function fixCallback(callback) {
  4138. return function(error, xhr) {
  4139. callback(error == null ? xhr : null);
  4140. };
  4141. }
  4142. function hasResponse(xhr) {
  4143. var type = xhr.responseType;
  4144. return type && type !== "text"
  4145. ? xhr.response // null on error
  4146. : xhr.responseText; // "" on error
  4147. }
  4148. function type(defaultMimeType, response) {
  4149. return function(url, callback) {
  4150. var r = request(url).mimeType(defaultMimeType).response(response);
  4151. return callback ? r.get(callback) : r;
  4152. };
  4153. }
  4154. var html = type("text/html", function(xhr) {
  4155. return document.createRange().createContextualFragment(xhr.responseText);
  4156. });
  4157. var json = type("application/json", function(xhr) {
  4158. return JSON.parse(xhr.responseText);
  4159. });
  4160. var text = type("text/plain", function(xhr) {
  4161. return xhr.responseText;
  4162. });
  4163. var xml = type("application/xml", function(xhr) {
  4164. var xml = xhr.responseXML;
  4165. if (!xml) throw new Error("parse error");
  4166. return xml;
  4167. });
  4168. function dsv$1(defaultMimeType, parse) {
  4169. return function(url, row, callback) {
  4170. if (arguments.length < 3) callback = row, row = null;
  4171. var r = request(url).mimeType(defaultMimeType);
  4172. r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
  4173. r.row(row);
  4174. return callback ? r.get(callback) : r;
  4175. };
  4176. }
  4177. function responseOf(parse, row) {
  4178. return function(request) {
  4179. return parse(request.responseText, row);
  4180. };
  4181. }
  4182. var csv$1 = dsv$1("text/csv", csvParse);
  4183. var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
  4184. var frame = 0;
  4185. var timeout = 0;
  4186. var interval = 0;
  4187. var pokeDelay = 1000;
  4188. var taskHead;
  4189. var taskTail;
  4190. var clockLast = 0;
  4191. var clockNow = 0;
  4192. var clockSkew = 0;
  4193. var clock = typeof performance === "object" ? performance : Date;
  4194. var setFrame = typeof requestAnimationFrame === "function"
  4195. ? (clock === Date ? function(f) { requestAnimationFrame(function() { f(clock.now()); }); } : requestAnimationFrame)
  4196. : function(f) { setTimeout(f, 17); };
  4197. function now() {
  4198. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  4199. }
  4200. function clearNow() {
  4201. clockNow = 0;
  4202. }
  4203. function Timer() {
  4204. this._call =
  4205. this._time =
  4206. this._next = null;
  4207. }
  4208. Timer.prototype = timer.prototype = {
  4209. constructor: Timer,
  4210. restart: function(callback, delay, time) {
  4211. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  4212. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  4213. if (!this._next && taskTail !== this) {
  4214. if (taskTail) taskTail._next = this;
  4215. else taskHead = this;
  4216. taskTail = this;
  4217. }
  4218. this._call = callback;
  4219. this._time = time;
  4220. sleep();
  4221. },
  4222. stop: function() {
  4223. if (this._call) {
  4224. this._call = null;
  4225. this._time = Infinity;
  4226. sleep();
  4227. }
  4228. }
  4229. };
  4230. function timer(callback, delay, time) {
  4231. var t = new Timer;
  4232. t.restart(callback, delay, time);
  4233. return t;
  4234. }
  4235. function timerFlush() {
  4236. now(); // Get the current time, if not already set.
  4237. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  4238. var t = taskHead, e;
  4239. while (t) {
  4240. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  4241. t = t._next;
  4242. }
  4243. --frame;
  4244. }
  4245. function wake(time) {
  4246. clockNow = (clockLast = time || clock.now()) + clockSkew;
  4247. frame = timeout = 0;
  4248. try {
  4249. timerFlush();
  4250. } finally {
  4251. frame = 0;
  4252. nap();
  4253. clockNow = 0;
  4254. }
  4255. }
  4256. function poke$1() {
  4257. var now = clock.now(), delay = now - clockLast;
  4258. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  4259. }
  4260. function nap() {
  4261. var t0, t1 = taskHead, t2, time = Infinity;
  4262. while (t1) {
  4263. if (t1._call) {
  4264. if (time > t1._time) time = t1._time;
  4265. t0 = t1, t1 = t1._next;
  4266. } else {
  4267. t2 = t1._next, t1._next = null;
  4268. t1 = t0 ? t0._next = t2 : taskHead = t2;
  4269. }
  4270. }
  4271. taskTail = t0;
  4272. sleep(time);
  4273. }
  4274. function sleep(time) {
  4275. if (frame) return; // Soonest alarm already set, or will be.
  4276. if (timeout) timeout = clearTimeout(timeout);
  4277. var delay = time - clockNow;
  4278. if (delay > 24) {
  4279. if (time < Infinity) timeout = setTimeout(wake, delay);
  4280. if (interval) interval = clearInterval(interval);
  4281. } else {
  4282. if (!interval) interval = setInterval(poke$1, pokeDelay);
  4283. frame = 1, setFrame(wake);
  4284. }
  4285. }
  4286. function timeout$1(callback, delay, time) {
  4287. var t = new Timer;
  4288. delay = delay == null ? 0 : +delay;
  4289. t.restart(function(elapsed) {
  4290. t.stop();
  4291. callback(elapsed + delay);
  4292. }, delay, time);
  4293. return t;
  4294. }
  4295. function interval$1(callback, delay, time) {
  4296. var t = new Timer, total = delay;
  4297. if (delay == null) return t.restart(callback, delay, time), t;
  4298. delay = +delay, time = time == null ? now() : +time;
  4299. t.restart(function tick(elapsed) {
  4300. elapsed += total;
  4301. t.restart(tick, total += delay, time);
  4302. callback(elapsed);
  4303. }, delay, time);
  4304. return t;
  4305. }
  4306. var t0$1 = new Date;
  4307. var t1$1 = new Date;
  4308. function newInterval(floori, offseti, count, field) {
  4309. function interval(date) {
  4310. return floori(date = new Date(+date)), date;
  4311. }
  4312. interval.floor = interval;
  4313. interval.ceil = function(date) {
  4314. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  4315. };
  4316. interval.round = function(date) {
  4317. var d0 = interval(date),
  4318. d1 = interval.ceil(date);
  4319. return date - d0 < d1 - date ? d0 : d1;
  4320. };
  4321. interval.offset = function(date, step) {
  4322. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  4323. };
  4324. interval.range = function(start, stop, step) {
  4325. var range = [];
  4326. start = interval.ceil(start);
  4327. step = step == null ? 1 : Math.floor(step);
  4328. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  4329. do range.push(new Date(+start)); while (offseti(start, step), floori(start), start < stop)
  4330. return range;
  4331. };
  4332. interval.filter = function(test) {
  4333. return newInterval(function(date) {
  4334. while (floori(date), !test(date)) date.setTime(date - 1);
  4335. }, function(date, step) {
  4336. while (--step >= 0) while (offseti(date, 1), !test(date));
  4337. });
  4338. };
  4339. if (count) {
  4340. interval.count = function(start, end) {
  4341. t0$1.setTime(+start), t1$1.setTime(+end);
  4342. floori(t0$1), floori(t1$1);
  4343. return Math.floor(count(t0$1, t1$1));
  4344. };
  4345. interval.every = function(step) {
  4346. step = Math.floor(step);
  4347. return !isFinite(step) || !(step > 0) ? null
  4348. : !(step > 1) ? interval
  4349. : interval.filter(field
  4350. ? function(d) { return field(d) % step === 0; }
  4351. : function(d) { return interval.count(0, d) % step === 0; });
  4352. };
  4353. }
  4354. return interval;
  4355. }
  4356. var millisecond = newInterval(function() {
  4357. // noop
  4358. }, function(date, step) {
  4359. date.setTime(+date + step);
  4360. }, function(start, end) {
  4361. return end - start;
  4362. });
  4363. // An optimized implementation for this simple case.
  4364. millisecond.every = function(k) {
  4365. k = Math.floor(k);
  4366. if (!isFinite(k) || !(k > 0)) return null;
  4367. if (!(k > 1)) return millisecond;
  4368. return newInterval(function(date) {
  4369. date.setTime(Math.floor(date / k) * k);
  4370. }, function(date, step) {
  4371. date.setTime(+date + step * k);
  4372. }, function(start, end) {
  4373. return (end - start) / k;
  4374. });
  4375. };
  4376. var milliseconds = millisecond.range;
  4377. var durationSecond = 1e3;
  4378. var durationMinute = 6e4;
  4379. var durationHour = 36e5;
  4380. var durationDay = 864e5;
  4381. var durationWeek = 6048e5;
  4382. var second = newInterval(function(date) {
  4383. date.setTime(Math.floor(date / durationSecond) * durationSecond);
  4384. }, function(date, step) {
  4385. date.setTime(+date + step * durationSecond);
  4386. }, function(start, end) {
  4387. return (end - start) / durationSecond;
  4388. }, function(date) {
  4389. return date.getUTCSeconds();
  4390. });
  4391. var seconds = second.range;
  4392. var minute = newInterval(function(date) {
  4393. date.setTime(Math.floor(date / durationMinute) * durationMinute);
  4394. }, function(date, step) {
  4395. date.setTime(+date + step * durationMinute);
  4396. }, function(start, end) {
  4397. return (end - start) / durationMinute;
  4398. }, function(date) {
  4399. return date.getMinutes();
  4400. });
  4401. var minutes = minute.range;
  4402. var hour = newInterval(function(date) {
  4403. var offset = date.getTimezoneOffset() * durationMinute % durationHour;
  4404. if (offset < 0) offset += durationHour;
  4405. date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
  4406. }, function(date, step) {
  4407. date.setTime(+date + step * durationHour);
  4408. }, function(start, end) {
  4409. return (end - start) / durationHour;
  4410. }, function(date) {
  4411. return date.getHours();
  4412. });
  4413. var hours = hour.range;
  4414. var day = newInterval(function(date) {
  4415. date.setHours(0, 0, 0, 0);
  4416. }, function(date, step) {
  4417. date.setDate(date.getDate() + step);
  4418. }, function(start, end) {
  4419. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  4420. }, function(date) {
  4421. return date.getDate() - 1;
  4422. });
  4423. var days = day.range;
  4424. function weekday(i) {
  4425. return newInterval(function(date) {
  4426. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  4427. date.setHours(0, 0, 0, 0);
  4428. }, function(date, step) {
  4429. date.setDate(date.getDate() + step * 7);
  4430. }, function(start, end) {
  4431. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  4432. });
  4433. }
  4434. var timeWeek = weekday(0);
  4435. var timeMonday = weekday(1);
  4436. var tuesday = weekday(2);
  4437. var wednesday = weekday(3);
  4438. var thursday = weekday(4);
  4439. var friday = weekday(5);
  4440. var saturday = weekday(6);
  4441. var sundays = timeWeek.range;
  4442. var mondays = timeMonday.range;
  4443. var tuesdays = tuesday.range;
  4444. var wednesdays = wednesday.range;
  4445. var thursdays = thursday.range;
  4446. var fridays = friday.range;
  4447. var saturdays = saturday.range;
  4448. var month = newInterval(function(date) {
  4449. date.setDate(1);
  4450. date.setHours(0, 0, 0, 0);
  4451. }, function(date, step) {
  4452. date.setMonth(date.getMonth() + step);
  4453. }, function(start, end) {
  4454. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  4455. }, function(date) {
  4456. return date.getMonth();
  4457. });
  4458. var months = month.range;
  4459. var year = newInterval(function(date) {
  4460. date.setMonth(0, 1);
  4461. date.setHours(0, 0, 0, 0);
  4462. }, function(date, step) {
  4463. date.setFullYear(date.getFullYear() + step);
  4464. }, function(start, end) {
  4465. return end.getFullYear() - start.getFullYear();
  4466. }, function(date) {
  4467. return date.getFullYear();
  4468. });
  4469. // An optimized implementation for this simple case.
  4470. year.every = function(k) {
  4471. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  4472. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  4473. date.setMonth(0, 1);
  4474. date.setHours(0, 0, 0, 0);
  4475. }, function(date, step) {
  4476. date.setFullYear(date.getFullYear() + step * k);
  4477. });
  4478. };
  4479. var years = year.range;
  4480. var utcMinute = newInterval(function(date) {
  4481. date.setUTCSeconds(0, 0);
  4482. }, function(date, step) {
  4483. date.setTime(+date + step * durationMinute);
  4484. }, function(start, end) {
  4485. return (end - start) / durationMinute;
  4486. }, function(date) {
  4487. return date.getUTCMinutes();
  4488. });
  4489. var utcMinutes = utcMinute.range;
  4490. var utcHour = newInterval(function(date) {
  4491. date.setUTCMinutes(0, 0, 0);
  4492. }, function(date, step) {
  4493. date.setTime(+date + step * durationHour);
  4494. }, function(start, end) {
  4495. return (end - start) / durationHour;
  4496. }, function(date) {
  4497. return date.getUTCHours();
  4498. });
  4499. var utcHours = utcHour.range;
  4500. var utcDay = newInterval(function(date) {
  4501. date.setUTCHours(0, 0, 0, 0);
  4502. }, function(date, step) {
  4503. date.setUTCDate(date.getUTCDate() + step);
  4504. }, function(start, end) {
  4505. return (end - start) / durationDay;
  4506. }, function(date) {
  4507. return date.getUTCDate() - 1;
  4508. });
  4509. var utcDays = utcDay.range;
  4510. function utcWeekday(i) {
  4511. return newInterval(function(date) {
  4512. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  4513. date.setUTCHours(0, 0, 0, 0);
  4514. }, function(date, step) {
  4515. date.setUTCDate(date.getUTCDate() + step * 7);
  4516. }, function(start, end) {
  4517. return (end - start) / durationWeek;
  4518. });
  4519. }
  4520. var utcWeek = utcWeekday(0);
  4521. var utcMonday = utcWeekday(1);
  4522. var utcTuesday = utcWeekday(2);
  4523. var utcWednesday = utcWeekday(3);
  4524. var utcThursday = utcWeekday(4);
  4525. var utcFriday = utcWeekday(5);
  4526. var utcSaturday = utcWeekday(6);
  4527. var utcSundays = utcWeek.range;
  4528. var utcMondays = utcMonday.range;
  4529. var utcTuesdays = utcTuesday.range;
  4530. var utcWednesdays = utcWednesday.range;
  4531. var utcThursdays = utcThursday.range;
  4532. var utcFridays = utcFriday.range;
  4533. var utcSaturdays = utcSaturday.range;
  4534. var utcMonth = newInterval(function(date) {
  4535. date.setUTCDate(1);
  4536. date.setUTCHours(0, 0, 0, 0);
  4537. }, function(date, step) {
  4538. date.setUTCMonth(date.getUTCMonth() + step);
  4539. }, function(start, end) {
  4540. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  4541. }, function(date) {
  4542. return date.getUTCMonth();
  4543. });
  4544. var utcMonths = utcMonth.range;
  4545. var utcYear = newInterval(function(date) {
  4546. date.setUTCMonth(0, 1);
  4547. date.setUTCHours(0, 0, 0, 0);
  4548. }, function(date, step) {
  4549. date.setUTCFullYear(date.getUTCFullYear() + step);
  4550. }, function(start, end) {
  4551. return end.getUTCFullYear() - start.getUTCFullYear();
  4552. }, function(date) {
  4553. return date.getUTCFullYear();
  4554. });
  4555. // An optimized implementation for this simple case.
  4556. utcYear.every = function(k) {
  4557. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  4558. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  4559. date.setUTCMonth(0, 1);
  4560. date.setUTCHours(0, 0, 0, 0);
  4561. }, function(date, step) {
  4562. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  4563. });
  4564. };
  4565. var utcYears = utcYear.range;
  4566. // Computes the decimal coefficient and exponent of the specified number x with
  4567. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  4568. // For example, formatDecimal(1.23) returns ["123", 0].
  4569. function formatDecimal(x, p) {
  4570. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  4571. var i, coefficient = x.slice(0, i);
  4572. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  4573. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  4574. return [
  4575. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  4576. +x.slice(i + 1)
  4577. ];
  4578. }
  4579. function exponent$1(x) {
  4580. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  4581. }
  4582. function formatGroup(grouping, thousands) {
  4583. return function(value, width) {
  4584. var i = value.length,
  4585. t = [],
  4586. j = 0,
  4587. g = grouping[0],
  4588. length = 0;
  4589. while (i > 0 && g > 0) {
  4590. if (length + g + 1 > width) g = Math.max(1, width - length);
  4591. t.push(value.substring(i -= g, i + g));
  4592. if ((length += g + 1) > width) break;
  4593. g = grouping[j = (j + 1) % grouping.length];
  4594. }
  4595. return t.reverse().join(thousands);
  4596. };
  4597. }
  4598. function formatDefault(x, p) {
  4599. x = x.toPrecision(p);
  4600. out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
  4601. switch (x[i]) {
  4602. case ".": i0 = i1 = i; break;
  4603. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  4604. case "e": break out;
  4605. default: if (i0 > 0) i0 = 0; break;
  4606. }
  4607. }
  4608. return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
  4609. }
  4610. var prefixExponent;
  4611. function formatPrefixAuto(x, p) {
  4612. var d = formatDecimal(x, p);
  4613. if (!d) return x + "";
  4614. var coefficient = d[0],
  4615. exponent = d[1],
  4616. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  4617. n = coefficient.length;
  4618. return i === n ? coefficient
  4619. : i > n ? coefficient + new Array(i - n + 1).join("0")
  4620. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  4621. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  4622. }
  4623. function formatRounded(x, p) {
  4624. var d = formatDecimal(x, p);
  4625. if (!d) return x + "";
  4626. var coefficient = d[0],
  4627. exponent = d[1];
  4628. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  4629. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  4630. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  4631. }
  4632. var formatTypes = {
  4633. "": formatDefault,
  4634. "%": function(x, p) { return (x * 100).toFixed(p); },
  4635. "b": function(x) { return Math.round(x).toString(2); },
  4636. "c": function(x) { return x + ""; },
  4637. "d": function(x) { return Math.round(x).toString(10); },
  4638. "e": function(x, p) { return x.toExponential(p); },
  4639. "f": function(x, p) { return x.toFixed(p); },
  4640. "g": function(x, p) { return x.toPrecision(p); },
  4641. "o": function(x) { return Math.round(x).toString(8); },
  4642. "p": function(x, p) { return formatRounded(x * 100, p); },
  4643. "r": formatRounded,
  4644. "s": formatPrefixAuto,
  4645. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  4646. "x": function(x) { return Math.round(x).toString(16); }
  4647. };
  4648. // [[fill]align][sign][symbol][0][width][,][.precision][type]
  4649. var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
  4650. function formatSpecifier(specifier) {
  4651. return new FormatSpecifier(specifier);
  4652. }
  4653. function FormatSpecifier(specifier) {
  4654. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  4655. var match,
  4656. fill = match[1] || " ",
  4657. align = match[2] || ">",
  4658. sign = match[3] || "-",
  4659. symbol = match[4] || "",
  4660. zero = !!match[5],
  4661. width = match[6] && +match[6],
  4662. comma = !!match[7],
  4663. precision = match[8] && +match[8].slice(1),
  4664. type = match[9] || "";
  4665. // The "n" type is an alias for ",g".
  4666. if (type === "n") comma = true, type = "g";
  4667. // Map invalid types to the default format.
  4668. else if (!formatTypes[type]) type = "";
  4669. // If zero fill is specified, padding goes after sign and before digits.
  4670. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  4671. this.fill = fill;
  4672. this.align = align;
  4673. this.sign = sign;
  4674. this.symbol = symbol;
  4675. this.zero = zero;
  4676. this.width = width;
  4677. this.comma = comma;
  4678. this.precision = precision;
  4679. this.type = type;
  4680. }
  4681. FormatSpecifier.prototype.toString = function() {
  4682. return this.fill
  4683. + this.align
  4684. + this.sign
  4685. + this.symbol
  4686. + (this.zero ? "0" : "")
  4687. + (this.width == null ? "" : Math.max(1, this.width | 0))
  4688. + (this.comma ? "," : "")
  4689. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  4690. + this.type;
  4691. };
  4692. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  4693. function identity$3(x) {
  4694. return x;
  4695. }
  4696. function formatLocale(locale) {
  4697. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  4698. currency = locale.currency,
  4699. decimal = locale.decimal;
  4700. function newFormat(specifier) {
  4701. specifier = formatSpecifier(specifier);
  4702. var fill = specifier.fill,
  4703. align = specifier.align,
  4704. sign = specifier.sign,
  4705. symbol = specifier.symbol,
  4706. zero = specifier.zero,
  4707. width = specifier.width,
  4708. comma = specifier.comma,
  4709. precision = specifier.precision,
  4710. type = specifier.type;
  4711. // Compute the prefix and suffix.
  4712. // For SI-prefix, the suffix is lazily computed.
  4713. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  4714. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? "%" : "";
  4715. // What format function should we use?
  4716. // Is this an integer type?
  4717. // Can this type generate exponential notation?
  4718. var formatType = formatTypes[type],
  4719. maybeSuffix = !type || /[defgprs%]/.test(type);
  4720. // Set the default precision if not specified,
  4721. // or clamp the specified precision to the supported range.
  4722. // For significant precision, it must be in [1, 21].
  4723. // For fixed precision, it must be in [0, 20].
  4724. precision = precision == null ? (type ? 6 : 12)
  4725. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  4726. : Math.max(0, Math.min(20, precision));
  4727. function format(value) {
  4728. var valuePrefix = prefix,
  4729. valueSuffix = suffix,
  4730. i, n, c;
  4731. if (type === "c") {
  4732. valueSuffix = formatType(value) + valueSuffix;
  4733. value = "";
  4734. } else {
  4735. value = +value;
  4736. // Convert negative to positive, and compute the prefix.
  4737. // Note that -0 is not less than 0, but 1 / -0 is!
  4738. var valueNegative = (value < 0 || 1 / value < 0) && (value *= -1, true);
  4739. // Perform the initial formatting.
  4740. value = formatType(value, precision);
  4741. // If the original value was negative, it may be rounded to zero during
  4742. // formatting; treat this as (positive) zero.
  4743. if (valueNegative) {
  4744. i = -1, n = value.length;
  4745. valueNegative = false;
  4746. while (++i < n) {
  4747. if (c = value.charCodeAt(i), (48 < c && c < 58)
  4748. || (type === "x" && 96 < c && c < 103)
  4749. || (type === "X" && 64 < c && c < 71)) {
  4750. valueNegative = true;
  4751. break;
  4752. }
  4753. }
  4754. }
  4755. // Compute the prefix and suffix.
  4756. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  4757. valueSuffix = valueSuffix + (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + (valueNegative && sign === "(" ? ")" : "");
  4758. // Break the formatted value into the integer “value” part that can be
  4759. // grouped, and fractional or exponential “suffix” part that is not.
  4760. if (maybeSuffix) {
  4761. i = -1, n = value.length;
  4762. while (++i < n) {
  4763. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  4764. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  4765. value = value.slice(0, i);
  4766. break;
  4767. }
  4768. }
  4769. }
  4770. }
  4771. // If the fill character is not "0", grouping is applied before padding.
  4772. if (comma && !zero) value = group(value, Infinity);
  4773. // Compute the padding.
  4774. var length = valuePrefix.length + value.length + valueSuffix.length,
  4775. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  4776. // If the fill character is "0", grouping is applied after padding.
  4777. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  4778. // Reconstruct the final output based on the desired alignment.
  4779. switch (align) {
  4780. case "<": return valuePrefix + value + valueSuffix + padding;
  4781. case "=": return valuePrefix + padding + value + valueSuffix;
  4782. case "^": return padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length);
  4783. }
  4784. return padding + valuePrefix + value + valueSuffix;
  4785. }
  4786. format.toString = function() {
  4787. return specifier + "";
  4788. };
  4789. return format;
  4790. }
  4791. function formatPrefix(specifier, value) {
  4792. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  4793. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  4794. k = Math.pow(10, -e),
  4795. prefix = prefixes[8 + e / 3];
  4796. return function(value) {
  4797. return f(k * value) + prefix;
  4798. };
  4799. }
  4800. return {
  4801. format: newFormat,
  4802. formatPrefix: formatPrefix
  4803. };
  4804. }
  4805. var locale;
  4806. exports.format;
  4807. exports.formatPrefix;
  4808. defaultLocale({
  4809. decimal: ".",
  4810. thousands: ",",
  4811. grouping: [3],
  4812. currency: ["$", ""]
  4813. });
  4814. function defaultLocale(definition) {
  4815. locale = formatLocale(definition);
  4816. exports.format = locale.format;
  4817. exports.formatPrefix = locale.formatPrefix;
  4818. return locale;
  4819. }
  4820. function precisionFixed(step) {
  4821. return Math.max(0, -exponent$1(Math.abs(step)));
  4822. }
  4823. function precisionPrefix(step, value) {
  4824. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  4825. }
  4826. function precisionRound(step, max) {
  4827. step = Math.abs(step), max = Math.abs(max) - step;
  4828. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  4829. }
  4830. function localDate(d) {
  4831. if (0 <= d.y && d.y < 100) {
  4832. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  4833. date.setFullYear(d.y);
  4834. return date;
  4835. }
  4836. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  4837. }
  4838. function utcDate(d) {
  4839. if (0 <= d.y && d.y < 100) {
  4840. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  4841. date.setUTCFullYear(d.y);
  4842. return date;
  4843. }
  4844. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  4845. }
  4846. function newYear(y) {
  4847. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  4848. }
  4849. function formatLocale$1(locale) {
  4850. var locale_dateTime = locale.dateTime,
  4851. locale_date = locale.date,
  4852. locale_time = locale.time,
  4853. locale_periods = locale.periods,
  4854. locale_weekdays = locale.days,
  4855. locale_shortWeekdays = locale.shortDays,
  4856. locale_months = locale.months,
  4857. locale_shortMonths = locale.shortMonths;
  4858. var periodRe = formatRe(locale_periods),
  4859. periodLookup = formatLookup(locale_periods),
  4860. weekdayRe = formatRe(locale_weekdays),
  4861. weekdayLookup = formatLookup(locale_weekdays),
  4862. shortWeekdayRe = formatRe(locale_shortWeekdays),
  4863. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  4864. monthRe = formatRe(locale_months),
  4865. monthLookup = formatLookup(locale_months),
  4866. shortMonthRe = formatRe(locale_shortMonths),
  4867. shortMonthLookup = formatLookup(locale_shortMonths);
  4868. var formats = {
  4869. "a": formatShortWeekday,
  4870. "A": formatWeekday,
  4871. "b": formatShortMonth,
  4872. "B": formatMonth,
  4873. "c": null,
  4874. "d": formatDayOfMonth,
  4875. "e": formatDayOfMonth,
  4876. "H": formatHour24,
  4877. "I": formatHour12,
  4878. "j": formatDayOfYear,
  4879. "L": formatMilliseconds,
  4880. "m": formatMonthNumber,
  4881. "M": formatMinutes,
  4882. "p": formatPeriod,
  4883. "S": formatSeconds,
  4884. "U": formatWeekNumberSunday,
  4885. "w": formatWeekdayNumber,
  4886. "W": formatWeekNumberMonday,
  4887. "x": null,
  4888. "X": null,
  4889. "y": formatYear,
  4890. "Y": formatFullYear,
  4891. "Z": formatZone,
  4892. "%": formatLiteralPercent
  4893. };
  4894. var utcFormats = {
  4895. "a": formatUTCShortWeekday,
  4896. "A": formatUTCWeekday,
  4897. "b": formatUTCShortMonth,
  4898. "B": formatUTCMonth,
  4899. "c": null,
  4900. "d": formatUTCDayOfMonth,
  4901. "e": formatUTCDayOfMonth,
  4902. "H": formatUTCHour24,
  4903. "I": formatUTCHour12,
  4904. "j": formatUTCDayOfYear,
  4905. "L": formatUTCMilliseconds,
  4906. "m": formatUTCMonthNumber,
  4907. "M": formatUTCMinutes,
  4908. "p": formatUTCPeriod,
  4909. "S": formatUTCSeconds,
  4910. "U": formatUTCWeekNumberSunday,
  4911. "w": formatUTCWeekdayNumber,
  4912. "W": formatUTCWeekNumberMonday,
  4913. "x": null,
  4914. "X": null,
  4915. "y": formatUTCYear,
  4916. "Y": formatUTCFullYear,
  4917. "Z": formatUTCZone,
  4918. "%": formatLiteralPercent
  4919. };
  4920. var parses = {
  4921. "a": parseShortWeekday,
  4922. "A": parseWeekday,
  4923. "b": parseShortMonth,
  4924. "B": parseMonth,
  4925. "c": parseLocaleDateTime,
  4926. "d": parseDayOfMonth,
  4927. "e": parseDayOfMonth,
  4928. "H": parseHour24,
  4929. "I": parseHour24,
  4930. "j": parseDayOfYear,
  4931. "L": parseMilliseconds,
  4932. "m": parseMonthNumber,
  4933. "M": parseMinutes,
  4934. "p": parsePeriod,
  4935. "S": parseSeconds,
  4936. "U": parseWeekNumberSunday,
  4937. "w": parseWeekdayNumber,
  4938. "W": parseWeekNumberMonday,
  4939. "x": parseLocaleDate,
  4940. "X": parseLocaleTime,
  4941. "y": parseYear,
  4942. "Y": parseFullYear,
  4943. "Z": parseZone,
  4944. "%": parseLiteralPercent
  4945. };
  4946. // These recursive directive definitions must be deferred.
  4947. formats.x = newFormat(locale_date, formats);
  4948. formats.X = newFormat(locale_time, formats);
  4949. formats.c = newFormat(locale_dateTime, formats);
  4950. utcFormats.x = newFormat(locale_date, utcFormats);
  4951. utcFormats.X = newFormat(locale_time, utcFormats);
  4952. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  4953. function newFormat(specifier, formats) {
  4954. return function(date) {
  4955. var string = [],
  4956. i = -1,
  4957. j = 0,
  4958. n = specifier.length,
  4959. c,
  4960. pad,
  4961. format;
  4962. if (!(date instanceof Date)) date = new Date(+date);
  4963. while (++i < n) {
  4964. if (specifier.charCodeAt(i) === 37) {
  4965. string.push(specifier.slice(j, i));
  4966. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  4967. else pad = c === "e" ? " " : "0";
  4968. if (format = formats[c]) c = format(date, pad);
  4969. string.push(c);
  4970. j = i + 1;
  4971. }
  4972. }
  4973. string.push(specifier.slice(j, i));
  4974. return string.join("");
  4975. };
  4976. }
  4977. function newParse(specifier, newDate) {
  4978. return function(string) {
  4979. var d = newYear(1900),
  4980. i = parseSpecifier(d, specifier, string += "", 0);
  4981. if (i != string.length) return null;
  4982. // The am-pm flag is 0 for AM, and 1 for PM.
  4983. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  4984. // Convert day-of-week and week-of-year to day-of-year.
  4985. if ("W" in d || "U" in d) {
  4986. if (!("w" in d)) d.w = "W" in d ? 1 : 0;
  4987. var day = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  4988. d.m = 0;
  4989. d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
  4990. }
  4991. // If a time zone is specified, all fields are interpreted as UTC and then
  4992. // offset according to the specified time zone.
  4993. if ("Z" in d) {
  4994. d.H += d.Z / 100 | 0;
  4995. d.M += d.Z % 100;
  4996. return utcDate(d);
  4997. }
  4998. // Otherwise, all fields are in local time.
  4999. return newDate(d);
  5000. };
  5001. }
  5002. function parseSpecifier(d, specifier, string, j) {
  5003. var i = 0,
  5004. n = specifier.length,
  5005. m = string.length,
  5006. c,
  5007. parse;
  5008. while (i < n) {
  5009. if (j >= m) return -1;
  5010. c = specifier.charCodeAt(i++);
  5011. if (c === 37) {
  5012. c = specifier.charAt(i++);
  5013. parse = parses[c in pads ? specifier.charAt(i++) : c];
  5014. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  5015. } else if (c != string.charCodeAt(j++)) {
  5016. return -1;
  5017. }
  5018. }
  5019. return j;
  5020. }
  5021. function parsePeriod(d, string, i) {
  5022. var n = periodRe.exec(string.slice(i));
  5023. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  5024. }
  5025. function parseShortWeekday(d, string, i) {
  5026. var n = shortWeekdayRe.exec(string.slice(i));
  5027. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  5028. }
  5029. function parseWeekday(d, string, i) {
  5030. var n = weekdayRe.exec(string.slice(i));
  5031. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  5032. }
  5033. function parseShortMonth(d, string, i) {
  5034. var n = shortMonthRe.exec(string.slice(i));
  5035. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  5036. }
  5037. function parseMonth(d, string, i) {
  5038. var n = monthRe.exec(string.slice(i));
  5039. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  5040. }
  5041. function parseLocaleDateTime(d, string, i) {
  5042. return parseSpecifier(d, locale_dateTime, string, i);
  5043. }
  5044. function parseLocaleDate(d, string, i) {
  5045. return parseSpecifier(d, locale_date, string, i);
  5046. }
  5047. function parseLocaleTime(d, string, i) {
  5048. return parseSpecifier(d, locale_time, string, i);
  5049. }
  5050. function formatShortWeekday(d) {
  5051. return locale_shortWeekdays[d.getDay()];
  5052. }
  5053. function formatWeekday(d) {
  5054. return locale_weekdays[d.getDay()];
  5055. }
  5056. function formatShortMonth(d) {
  5057. return locale_shortMonths[d.getMonth()];
  5058. }
  5059. function formatMonth(d) {
  5060. return locale_months[d.getMonth()];
  5061. }
  5062. function formatPeriod(d) {
  5063. return locale_periods[+(d.getHours() >= 12)];
  5064. }
  5065. function formatUTCShortWeekday(d) {
  5066. return locale_shortWeekdays[d.getUTCDay()];
  5067. }
  5068. function formatUTCWeekday(d) {
  5069. return locale_weekdays[d.getUTCDay()];
  5070. }
  5071. function formatUTCShortMonth(d) {
  5072. return locale_shortMonths[d.getUTCMonth()];
  5073. }
  5074. function formatUTCMonth(d) {
  5075. return locale_months[d.getUTCMonth()];
  5076. }
  5077. function formatUTCPeriod(d) {
  5078. return locale_periods[+(d.getUTCHours() >= 12)];
  5079. }
  5080. return {
  5081. format: function(specifier) {
  5082. var f = newFormat(specifier += "", formats);
  5083. f.toString = function() { return specifier; };
  5084. return f;
  5085. },
  5086. parse: function(specifier) {
  5087. var p = newParse(specifier += "", localDate);
  5088. p.toString = function() { return specifier; };
  5089. return p;
  5090. },
  5091. utcFormat: function(specifier) {
  5092. var f = newFormat(specifier += "", utcFormats);
  5093. f.toString = function() { return specifier; };
  5094. return f;
  5095. },
  5096. utcParse: function(specifier) {
  5097. var p = newParse(specifier, utcDate);
  5098. p.toString = function() { return specifier; };
  5099. return p;
  5100. }
  5101. };
  5102. }
  5103. var pads = {"-": "", "_": " ", "0": "0"};
  5104. var numberRe = /^\s*\d+/;
  5105. var percentRe = /^%/;
  5106. var requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  5107. function pad(value, fill, width) {
  5108. var sign = value < 0 ? "-" : "",
  5109. string = (sign ? -value : value) + "",
  5110. length = string.length;
  5111. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  5112. }
  5113. function requote(s) {
  5114. return s.replace(requoteRe, "\\$&");
  5115. }
  5116. function formatRe(names) {
  5117. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  5118. }
  5119. function formatLookup(names) {
  5120. var map = {}, i = -1, n = names.length;
  5121. while (++i < n) map[names[i].toLowerCase()] = i;
  5122. return map;
  5123. }
  5124. function parseWeekdayNumber(d, string, i) {
  5125. var n = numberRe.exec(string.slice(i, i + 1));
  5126. return n ? (d.w = +n[0], i + n[0].length) : -1;
  5127. }
  5128. function parseWeekNumberSunday(d, string, i) {
  5129. var n = numberRe.exec(string.slice(i));
  5130. return n ? (d.U = +n[0], i + n[0].length) : -1;
  5131. }
  5132. function parseWeekNumberMonday(d, string, i) {
  5133. var n = numberRe.exec(string.slice(i));
  5134. return n ? (d.W = +n[0], i + n[0].length) : -1;
  5135. }
  5136. function parseFullYear(d, string, i) {
  5137. var n = numberRe.exec(string.slice(i, i + 4));
  5138. return n ? (d.y = +n[0], i + n[0].length) : -1;
  5139. }
  5140. function parseYear(d, string, i) {
  5141. var n = numberRe.exec(string.slice(i, i + 2));
  5142. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  5143. }
  5144. function parseZone(d, string, i) {
  5145. var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6));
  5146. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  5147. }
  5148. function parseMonthNumber(d, string, i) {
  5149. var n = numberRe.exec(string.slice(i, i + 2));
  5150. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  5151. }
  5152. function parseDayOfMonth(d, string, i) {
  5153. var n = numberRe.exec(string.slice(i, i + 2));
  5154. return n ? (d.d = +n[0], i + n[0].length) : -1;
  5155. }
  5156. function parseDayOfYear(d, string, i) {
  5157. var n = numberRe.exec(string.slice(i, i + 3));
  5158. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  5159. }
  5160. function parseHour24(d, string, i) {
  5161. var n = numberRe.exec(string.slice(i, i + 2));
  5162. return n ? (d.H = +n[0], i + n[0].length) : -1;
  5163. }
  5164. function parseMinutes(d, string, i) {
  5165. var n = numberRe.exec(string.slice(i, i + 2));
  5166. return n ? (d.M = +n[0], i + n[0].length) : -1;
  5167. }
  5168. function parseSeconds(d, string, i) {
  5169. var n = numberRe.exec(string.slice(i, i + 2));
  5170. return n ? (d.S = +n[0], i + n[0].length) : -1;
  5171. }
  5172. function parseMilliseconds(d, string, i) {
  5173. var n = numberRe.exec(string.slice(i, i + 3));
  5174. return n ? (d.L = +n[0], i + n[0].length) : -1;
  5175. }
  5176. function parseLiteralPercent(d, string, i) {
  5177. var n = percentRe.exec(string.slice(i, i + 1));
  5178. return n ? i + n[0].length : -1;
  5179. }
  5180. function formatDayOfMonth(d, p) {
  5181. return pad(d.getDate(), p, 2);
  5182. }
  5183. function formatHour24(d, p) {
  5184. return pad(d.getHours(), p, 2);
  5185. }
  5186. function formatHour12(d, p) {
  5187. return pad(d.getHours() % 12 || 12, p, 2);
  5188. }
  5189. function formatDayOfYear(d, p) {
  5190. return pad(1 + day.count(year(d), d), p, 3);
  5191. }
  5192. function formatMilliseconds(d, p) {
  5193. return pad(d.getMilliseconds(), p, 3);
  5194. }
  5195. function formatMonthNumber(d, p) {
  5196. return pad(d.getMonth() + 1, p, 2);
  5197. }
  5198. function formatMinutes(d, p) {
  5199. return pad(d.getMinutes(), p, 2);
  5200. }
  5201. function formatSeconds(d, p) {
  5202. return pad(d.getSeconds(), p, 2);
  5203. }
  5204. function formatWeekNumberSunday(d, p) {
  5205. return pad(timeWeek.count(year(d), d), p, 2);
  5206. }
  5207. function formatWeekdayNumber(d) {
  5208. return d.getDay();
  5209. }
  5210. function formatWeekNumberMonday(d, p) {
  5211. return pad(timeMonday.count(year(d), d), p, 2);
  5212. }
  5213. function formatYear(d, p) {
  5214. return pad(d.getFullYear() % 100, p, 2);
  5215. }
  5216. function formatFullYear(d, p) {
  5217. return pad(d.getFullYear() % 10000, p, 4);
  5218. }
  5219. function formatZone(d) {
  5220. var z = d.getTimezoneOffset();
  5221. return (z > 0 ? "-" : (z *= -1, "+"))
  5222. + pad(z / 60 | 0, "0", 2)
  5223. + pad(z % 60, "0", 2);
  5224. }
  5225. function formatUTCDayOfMonth(d, p) {
  5226. return pad(d.getUTCDate(), p, 2);
  5227. }
  5228. function formatUTCHour24(d, p) {
  5229. return pad(d.getUTCHours(), p, 2);
  5230. }
  5231. function formatUTCHour12(d, p) {
  5232. return pad(d.getUTCHours() % 12 || 12, p, 2);
  5233. }
  5234. function formatUTCDayOfYear(d, p) {
  5235. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  5236. }
  5237. function formatUTCMilliseconds(d, p) {
  5238. return pad(d.getUTCMilliseconds(), p, 3);
  5239. }
  5240. function formatUTCMonthNumber(d, p) {
  5241. return pad(d.getUTCMonth() + 1, p, 2);
  5242. }
  5243. function formatUTCMinutes(d, p) {
  5244. return pad(d.getUTCMinutes(), p, 2);
  5245. }
  5246. function formatUTCSeconds(d, p) {
  5247. return pad(d.getUTCSeconds(), p, 2);
  5248. }
  5249. function formatUTCWeekNumberSunday(d, p) {
  5250. return pad(utcWeek.count(utcYear(d), d), p, 2);
  5251. }
  5252. function formatUTCWeekdayNumber(d) {
  5253. return d.getUTCDay();
  5254. }
  5255. function formatUTCWeekNumberMonday(d, p) {
  5256. return pad(utcMonday.count(utcYear(d), d), p, 2);
  5257. }
  5258. function formatUTCYear(d, p) {
  5259. return pad(d.getUTCFullYear() % 100, p, 2);
  5260. }
  5261. function formatUTCFullYear(d, p) {
  5262. return pad(d.getUTCFullYear() % 10000, p, 4);
  5263. }
  5264. function formatUTCZone() {
  5265. return "+0000";
  5266. }
  5267. function formatLiteralPercent() {
  5268. return "%";
  5269. }
  5270. var locale$1;
  5271. exports.timeFormat;
  5272. exports.timeParse;
  5273. exports.utcFormat;
  5274. exports.utcParse;
  5275. defaultLocale$1({
  5276. dateTime: "%x, %X",
  5277. date: "%-m/%-d/%Y",
  5278. time: "%-I:%M:%S %p",
  5279. periods: ["AM", "PM"],
  5280. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  5281. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  5282. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  5283. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  5284. });
  5285. function defaultLocale$1(definition) {
  5286. locale$1 = formatLocale$1(definition);
  5287. exports.timeFormat = locale$1.format;
  5288. exports.timeParse = locale$1.parse;
  5289. exports.utcFormat = locale$1.utcFormat;
  5290. exports.utcParse = locale$1.utcParse;
  5291. return locale$1;
  5292. }
  5293. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  5294. function formatIsoNative(date) {
  5295. return date.toISOString();
  5296. }
  5297. var formatIso = Date.prototype.toISOString
  5298. ? formatIsoNative
  5299. : exports.utcFormat(isoSpecifier);
  5300. function parseIsoNative(string) {
  5301. var date = new Date(string);
  5302. return isNaN(date) ? null : date;
  5303. }
  5304. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  5305. ? parseIsoNative
  5306. : exports.utcParse(isoSpecifier);
  5307. var array$2 = Array.prototype;
  5308. var map$2 = array$2.map;
  5309. var slice$3 = array$2.slice;
  5310. var implicit = {name: "implicit"};
  5311. function ordinal(range) {
  5312. var index = map$1(),
  5313. domain = [],
  5314. unknown = implicit;
  5315. range = range == null ? [] : slice$3.call(range);
  5316. function scale(d) {
  5317. var key = d + "", i = index.get(key);
  5318. if (!i) {
  5319. if (unknown !== implicit) return unknown;
  5320. index.set(key, i = domain.push(d));
  5321. }
  5322. return range[(i - 1) % range.length];
  5323. }
  5324. scale.domain = function(_) {
  5325. if (!arguments.length) return domain.slice();
  5326. domain = [], index = map$1();
  5327. var i = -1, n = _.length, d, key;
  5328. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  5329. return scale;
  5330. };
  5331. scale.range = function(_) {
  5332. return arguments.length ? (range = slice$3.call(_), scale) : range.slice();
  5333. };
  5334. scale.unknown = function(_) {
  5335. return arguments.length ? (unknown = _, scale) : unknown;
  5336. };
  5337. scale.copy = function() {
  5338. return ordinal()
  5339. .domain(domain)
  5340. .range(range)
  5341. .unknown(unknown);
  5342. };
  5343. return scale;
  5344. }
  5345. function band() {
  5346. var scale = ordinal().unknown(undefined),
  5347. domain = scale.domain,
  5348. ordinalRange = scale.range,
  5349. range$$ = [0, 1],
  5350. step,
  5351. bandwidth,
  5352. round = false,
  5353. paddingInner = 0,
  5354. paddingOuter = 0,
  5355. align = 0.5;
  5356. delete scale.unknown;
  5357. function rescale() {
  5358. var n = domain().length,
  5359. reverse = range$$[1] < range$$[0],
  5360. start = range$$[reverse - 0],
  5361. stop = range$$[1 - reverse];
  5362. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  5363. if (round) step = Math.floor(step);
  5364. start += (stop - start - step * (n - paddingInner)) * align;
  5365. bandwidth = step * (1 - paddingInner);
  5366. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  5367. var values = range(n).map(function(i) { return start + step * i; });
  5368. return ordinalRange(reverse ? values.reverse() : values);
  5369. }
  5370. scale.domain = function(_) {
  5371. return arguments.length ? (domain(_), rescale()) : domain();
  5372. };
  5373. scale.range = function(_) {
  5374. return arguments.length ? (range$$ = [+_[0], +_[1]], rescale()) : range$$.slice();
  5375. };
  5376. scale.rangeRound = function(_) {
  5377. return range$$ = [+_[0], +_[1]], round = true, rescale();
  5378. };
  5379. scale.bandwidth = function() {
  5380. return bandwidth;
  5381. };
  5382. scale.step = function() {
  5383. return step;
  5384. };
  5385. scale.round = function(_) {
  5386. return arguments.length ? (round = !!_, rescale()) : round;
  5387. };
  5388. scale.padding = function(_) {
  5389. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  5390. };
  5391. scale.paddingInner = function(_) {
  5392. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  5393. };
  5394. scale.paddingOuter = function(_) {
  5395. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  5396. };
  5397. scale.align = function(_) {
  5398. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  5399. };
  5400. scale.copy = function() {
  5401. return band()
  5402. .domain(domain())
  5403. .range(range$$)
  5404. .round(round)
  5405. .paddingInner(paddingInner)
  5406. .paddingOuter(paddingOuter)
  5407. .align(align);
  5408. };
  5409. return rescale();
  5410. }
  5411. function pointish(scale) {
  5412. var copy = scale.copy;
  5413. scale.padding = scale.paddingOuter;
  5414. delete scale.paddingInner;
  5415. delete scale.paddingOuter;
  5416. scale.copy = function() {
  5417. return pointish(copy());
  5418. };
  5419. return scale;
  5420. }
  5421. function point$4() {
  5422. return pointish(band().paddingInner(1));
  5423. }
  5424. function constant$3(x) {
  5425. return function() {
  5426. return x;
  5427. };
  5428. }
  5429. function number$1(x) {
  5430. return +x;
  5431. }
  5432. var unit = [0, 1];
  5433. function deinterpolate(a, b) {
  5434. return (b -= (a = +a))
  5435. ? function(x) { return (x - a) / b; }
  5436. : constant$3(b);
  5437. }
  5438. function deinterpolateClamp(deinterpolate) {
  5439. return function(a, b) {
  5440. var d = deinterpolate(a = +a, b = +b);
  5441. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  5442. };
  5443. }
  5444. function reinterpolateClamp(reinterpolate) {
  5445. return function(a, b) {
  5446. var r = reinterpolate(a = +a, b = +b);
  5447. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  5448. };
  5449. }
  5450. function bimap(domain, range, deinterpolate, reinterpolate) {
  5451. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  5452. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
  5453. else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
  5454. return function(x) { return r0(d0(x)); };
  5455. }
  5456. function polymap(domain, range, deinterpolate, reinterpolate) {
  5457. var j = Math.min(domain.length, range.length) - 1,
  5458. d = new Array(j),
  5459. r = new Array(j),
  5460. i = -1;
  5461. // Reverse descending domains.
  5462. if (domain[j] < domain[0]) {
  5463. domain = domain.slice().reverse();
  5464. range = range.slice().reverse();
  5465. }
  5466. while (++i < j) {
  5467. d[i] = deinterpolate(domain[i], domain[i + 1]);
  5468. r[i] = reinterpolate(range[i], range[i + 1]);
  5469. }
  5470. return function(x) {
  5471. var i = bisectRight(domain, x, 1, j) - 1;
  5472. return r[i](d[i](x));
  5473. };
  5474. }
  5475. function copy(source, target) {
  5476. return target
  5477. .domain(source.domain())
  5478. .range(source.range())
  5479. .interpolate(source.interpolate())
  5480. .clamp(source.clamp());
  5481. }
  5482. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  5483. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  5484. function continuous(deinterpolate$$, reinterpolate) {
  5485. var domain = unit,
  5486. range = unit,
  5487. interpolate$$ = interpolate,
  5488. clamp = false,
  5489. piecewise,
  5490. output,
  5491. input;
  5492. function rescale() {
  5493. piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  5494. output = input = null;
  5495. return scale;
  5496. }
  5497. function scale(x) {
  5498. return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate$$) : deinterpolate$$, interpolate$$)))(+x);
  5499. }
  5500. scale.invert = function(y) {
  5501. return (input || (input = piecewise(range, domain, deinterpolate, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
  5502. };
  5503. scale.domain = function(_) {
  5504. return arguments.length ? (domain = map$2.call(_, number$1), rescale()) : domain.slice();
  5505. };
  5506. scale.range = function(_) {
  5507. return arguments.length ? (range = slice$3.call(_), rescale()) : range.slice();
  5508. };
  5509. scale.rangeRound = function(_) {
  5510. return range = slice$3.call(_), interpolate$$ = interpolateRound, rescale();
  5511. };
  5512. scale.clamp = function(_) {
  5513. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  5514. };
  5515. scale.interpolate = function(_) {
  5516. return arguments.length ? (interpolate$$ = _, rescale()) : interpolate$$;
  5517. };
  5518. return rescale();
  5519. }
  5520. function tickFormat(domain, count, specifier) {
  5521. var start = domain[0],
  5522. stop = domain[domain.length - 1],
  5523. step = tickStep(start, stop, count == null ? 10 : count),
  5524. precision;
  5525. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  5526. switch (specifier.type) {
  5527. case "s": {
  5528. var value = Math.max(Math.abs(start), Math.abs(stop));
  5529. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  5530. return exports.formatPrefix(specifier, value);
  5531. }
  5532. case "":
  5533. case "e":
  5534. case "g":
  5535. case "p":
  5536. case "r": {
  5537. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  5538. break;
  5539. }
  5540. case "f":
  5541. case "%": {
  5542. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  5543. break;
  5544. }
  5545. }
  5546. return exports.format(specifier);
  5547. }
  5548. function linearish(scale) {
  5549. var domain = scale.domain;
  5550. scale.ticks = function(count) {
  5551. var d = domain();
  5552. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  5553. };
  5554. scale.tickFormat = function(count, specifier) {
  5555. return tickFormat(domain(), count, specifier);
  5556. };
  5557. scale.nice = function(count) {
  5558. var d = domain(),
  5559. i = d.length - 1,
  5560. n = count == null ? 10 : count,
  5561. start = d[0],
  5562. stop = d[i],
  5563. step = tickStep(start, stop, n);
  5564. if (step) {
  5565. step = tickStep(Math.floor(start / step) * step, Math.ceil(stop / step) * step, n);
  5566. d[0] = Math.floor(start / step) * step;
  5567. d[i] = Math.ceil(stop / step) * step;
  5568. domain(d);
  5569. }
  5570. return scale;
  5571. };
  5572. return scale;
  5573. }
  5574. function linear$2() {
  5575. var scale = continuous(deinterpolate, interpolateNumber);
  5576. scale.copy = function() {
  5577. return copy(scale, linear$2());
  5578. };
  5579. return linearish(scale);
  5580. }
  5581. function identity$4() {
  5582. var domain = [0, 1];
  5583. function scale(x) {
  5584. return +x;
  5585. }
  5586. scale.invert = scale;
  5587. scale.domain = scale.range = function(_) {
  5588. return arguments.length ? (domain = map$2.call(_, number$1), scale) : domain.slice();
  5589. };
  5590. scale.copy = function() {
  5591. return identity$4().domain(domain);
  5592. };
  5593. return linearish(scale);
  5594. }
  5595. function nice(domain, interval) {
  5596. domain = domain.slice();
  5597. var i0 = 0,
  5598. i1 = domain.length - 1,
  5599. x0 = domain[i0],
  5600. x1 = domain[i1],
  5601. t;
  5602. if (x1 < x0) {
  5603. t = i0, i0 = i1, i1 = t;
  5604. t = x0, x0 = x1, x1 = t;
  5605. }
  5606. domain[i0] = interval.floor(x0);
  5607. domain[i1] = interval.ceil(x1);
  5608. return domain;
  5609. }
  5610. function deinterpolate$1(a, b) {
  5611. return (b = Math.log(b / a))
  5612. ? function(x) { return Math.log(x / a) / b; }
  5613. : constant$3(b);
  5614. }
  5615. function reinterpolate(a, b) {
  5616. return a < 0
  5617. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  5618. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  5619. }
  5620. function pow10(x) {
  5621. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  5622. }
  5623. function powp(base) {
  5624. return base === 10 ? pow10
  5625. : base === Math.E ? Math.exp
  5626. : function(x) { return Math.pow(base, x); };
  5627. }
  5628. function logp(base) {
  5629. return base === Math.E ? Math.log
  5630. : base === 10 && Math.log10
  5631. || base === 2 && Math.log2
  5632. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  5633. }
  5634. function reflect(f) {
  5635. return function(x) {
  5636. return -f(-x);
  5637. };
  5638. }
  5639. function log() {
  5640. var scale = continuous(deinterpolate$1, reinterpolate).domain([1, 10]),
  5641. domain = scale.domain,
  5642. base = 10,
  5643. logs = logp(10),
  5644. pows = powp(10);
  5645. function rescale() {
  5646. logs = logp(base), pows = powp(base);
  5647. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  5648. return scale;
  5649. }
  5650. scale.base = function(_) {
  5651. return arguments.length ? (base = +_, rescale()) : base;
  5652. };
  5653. scale.domain = function(_) {
  5654. return arguments.length ? (domain(_), rescale()) : domain();
  5655. };
  5656. scale.ticks = function(count) {
  5657. var d = domain(),
  5658. u = d[0],
  5659. v = d[d.length - 1],
  5660. r;
  5661. if (r = v < u) i = u, u = v, v = i;
  5662. var i = logs(u),
  5663. j = logs(v),
  5664. p,
  5665. k,
  5666. t,
  5667. n = count == null ? 10 : +count,
  5668. z = [];
  5669. if (!(base % 1) && j - i < n) {
  5670. i = Math.round(i) - 1, j = Math.round(j) + 1;
  5671. if (u > 0) for (; i < j; ++i) {
  5672. for (k = 1, p = pows(i); k < base; ++k) {
  5673. t = p * k;
  5674. if (t < u) continue;
  5675. if (t > v) break;
  5676. z.push(t);
  5677. }
  5678. } else for (; i < j; ++i) {
  5679. for (k = base - 1, p = pows(i); k >= 1; --k) {
  5680. t = p * k;
  5681. if (t < u) continue;
  5682. if (t > v) break;
  5683. z.push(t);
  5684. }
  5685. }
  5686. } else {
  5687. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  5688. }
  5689. return r ? z.reverse() : z;
  5690. };
  5691. scale.tickFormat = function(count, specifier) {
  5692. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  5693. if (typeof specifier !== "function") specifier = exports.format(specifier);
  5694. if (count === Infinity) return specifier;
  5695. if (count == null) count = 10;
  5696. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  5697. return function(d) {
  5698. var i = d / pows(Math.round(logs(d)));
  5699. if (i * base < base - 0.5) i *= base;
  5700. return i <= k ? specifier(d) : "";
  5701. };
  5702. };
  5703. scale.nice = function() {
  5704. return domain(nice(domain(), {
  5705. floor: function(x) { return pows(Math.floor(logs(x))); },
  5706. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  5707. }));
  5708. };
  5709. scale.copy = function() {
  5710. return copy(scale, log().base(base));
  5711. };
  5712. return scale;
  5713. }
  5714. function raise(x, exponent) {
  5715. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  5716. }
  5717. function pow() {
  5718. var exponent = 1,
  5719. scale = continuous(deinterpolate, reinterpolate),
  5720. domain = scale.domain;
  5721. function deinterpolate(a, b) {
  5722. return (b = raise(b, exponent) - (a = raise(a, exponent)))
  5723. ? function(x) { return (raise(x, exponent) - a) / b; }
  5724. : constant$3(b);
  5725. }
  5726. function reinterpolate(a, b) {
  5727. b = raise(b, exponent) - (a = raise(a, exponent));
  5728. return function(t) { return raise(a + b * t, 1 / exponent); };
  5729. }
  5730. scale.exponent = function(_) {
  5731. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  5732. };
  5733. scale.copy = function() {
  5734. return copy(scale, pow().exponent(exponent));
  5735. };
  5736. return linearish(scale);
  5737. }
  5738. function sqrt() {
  5739. return pow().exponent(0.5);
  5740. }
  5741. function quantile() {
  5742. var domain = [],
  5743. range = [],
  5744. thresholds = [];
  5745. function rescale() {
  5746. var i = 0, n = Math.max(1, range.length);
  5747. thresholds = new Array(n - 1);
  5748. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  5749. return scale;
  5750. }
  5751. function scale(x) {
  5752. if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
  5753. }
  5754. scale.invertExtent = function(y) {
  5755. var i = range.indexOf(y);
  5756. return i < 0 ? [NaN, NaN] : [
  5757. i > 0 ? thresholds[i - 1] : domain[0],
  5758. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  5759. ];
  5760. };
  5761. scale.domain = function(_) {
  5762. if (!arguments.length) return domain.slice();
  5763. domain = [];
  5764. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  5765. domain.sort(ascending);
  5766. return rescale();
  5767. };
  5768. scale.range = function(_) {
  5769. return arguments.length ? (range = slice$3.call(_), rescale()) : range.slice();
  5770. };
  5771. scale.quantiles = function() {
  5772. return thresholds.slice();
  5773. };
  5774. scale.copy = function() {
  5775. return quantile()
  5776. .domain(domain)
  5777. .range(range);
  5778. };
  5779. return scale;
  5780. }
  5781. function quantize$1() {
  5782. var x0 = 0,
  5783. x1 = 1,
  5784. n = 1,
  5785. domain = [0.5],
  5786. range = [0, 1];
  5787. function scale(x) {
  5788. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  5789. }
  5790. function rescale() {
  5791. var i = -1;
  5792. domain = new Array(n);
  5793. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  5794. return scale;
  5795. }
  5796. scale.domain = function(_) {
  5797. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  5798. };
  5799. scale.range = function(_) {
  5800. return arguments.length ? (n = (range = slice$3.call(_)).length - 1, rescale()) : range.slice();
  5801. };
  5802. scale.invertExtent = function(y) {
  5803. var i = range.indexOf(y);
  5804. return i < 0 ? [NaN, NaN]
  5805. : i < 1 ? [x0, domain[0]]
  5806. : i >= n ? [domain[n - 1], x1]
  5807. : [domain[i - 1], domain[i]];
  5808. };
  5809. scale.copy = function() {
  5810. return quantize$1()
  5811. .domain([x0, x1])
  5812. .range(range);
  5813. };
  5814. return linearish(scale);
  5815. }
  5816. function threshold$1() {
  5817. var domain = [0.5],
  5818. range = [0, 1],
  5819. n = 1;
  5820. function scale(x) {
  5821. if (x <= x) return range[bisectRight(domain, x, 0, n)];
  5822. }
  5823. scale.domain = function(_) {
  5824. return arguments.length ? (domain = slice$3.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  5825. };
  5826. scale.range = function(_) {
  5827. return arguments.length ? (range = slice$3.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  5828. };
  5829. scale.invertExtent = function(y) {
  5830. var i = range.indexOf(y);
  5831. return [domain[i - 1], domain[i]];
  5832. };
  5833. scale.copy = function() {
  5834. return threshold$1()
  5835. .domain(domain)
  5836. .range(range);
  5837. };
  5838. return scale;
  5839. }
  5840. var durationSecond$1 = 1000;
  5841. var durationMinute$1 = durationSecond$1 * 60;
  5842. var durationHour$1 = durationMinute$1 * 60;
  5843. var durationDay$1 = durationHour$1 * 24;
  5844. var durationWeek$1 = durationDay$1 * 7;
  5845. var durationMonth = durationDay$1 * 30;
  5846. var durationYear = durationDay$1 * 365;
  5847. function date(t) {
  5848. return new Date(t);
  5849. }
  5850. function number$2(t) {
  5851. return t instanceof Date ? +t : +new Date(+t);
  5852. }
  5853. function calendar(year, month, week, day, hour, minute, second, millisecond, format) {
  5854. var scale = continuous(deinterpolate, interpolateNumber),
  5855. invert = scale.invert,
  5856. domain = scale.domain;
  5857. var formatMillisecond = format(".%L"),
  5858. formatSecond = format(":%S"),
  5859. formatMinute = format("%I:%M"),
  5860. formatHour = format("%I %p"),
  5861. formatDay = format("%a %d"),
  5862. formatWeek = format("%b %d"),
  5863. formatMonth = format("%B"),
  5864. formatYear = format("%Y");
  5865. var tickIntervals = [
  5866. [second, 1, durationSecond$1],
  5867. [second, 5, 5 * durationSecond$1],
  5868. [second, 15, 15 * durationSecond$1],
  5869. [second, 30, 30 * durationSecond$1],
  5870. [minute, 1, durationMinute$1],
  5871. [minute, 5, 5 * durationMinute$1],
  5872. [minute, 15, 15 * durationMinute$1],
  5873. [minute, 30, 30 * durationMinute$1],
  5874. [ hour, 1, durationHour$1 ],
  5875. [ hour, 3, 3 * durationHour$1 ],
  5876. [ hour, 6, 6 * durationHour$1 ],
  5877. [ hour, 12, 12 * durationHour$1 ],
  5878. [ day, 1, durationDay$1 ],
  5879. [ day, 2, 2 * durationDay$1 ],
  5880. [ week, 1, durationWeek$1 ],
  5881. [ month, 1, durationMonth ],
  5882. [ month, 3, 3 * durationMonth ],
  5883. [ year, 1, durationYear ]
  5884. ];
  5885. function tickFormat(date) {
  5886. return (second(date) < date ? formatMillisecond
  5887. : minute(date) < date ? formatSecond
  5888. : hour(date) < date ? formatMinute
  5889. : day(date) < date ? formatHour
  5890. : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
  5891. : year(date) < date ? formatMonth
  5892. : formatYear)(date);
  5893. }
  5894. function tickInterval(interval, start, stop, step) {
  5895. if (interval == null) interval = 10;
  5896. // If a desired tick count is specified, pick a reasonable tick interval
  5897. // based on the extent of the domain and a rough estimate of tick size.
  5898. // Otherwise, assume interval is already a time interval and use it.
  5899. if (typeof interval === "number") {
  5900. var target = Math.abs(stop - start) / interval,
  5901. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  5902. if (i === tickIntervals.length) {
  5903. step = tickStep(start / durationYear, stop / durationYear, interval);
  5904. interval = year;
  5905. } else if (i) {
  5906. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  5907. step = i[1];
  5908. interval = i[0];
  5909. } else {
  5910. step = tickStep(start, stop, interval);
  5911. interval = millisecond;
  5912. }
  5913. }
  5914. return step == null ? interval : interval.every(step);
  5915. }
  5916. scale.invert = function(y) {
  5917. return new Date(invert(y));
  5918. };
  5919. scale.domain = function(_) {
  5920. return arguments.length ? domain(map$2.call(_, number$2)) : domain().map(date);
  5921. };
  5922. scale.ticks = function(interval, step) {
  5923. var d = domain(),
  5924. t0 = d[0],
  5925. t1 = d[d.length - 1],
  5926. r = t1 < t0,
  5927. t;
  5928. if (r) t = t0, t0 = t1, t1 = t;
  5929. t = tickInterval(interval, t0, t1, step);
  5930. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  5931. return r ? t.reverse() : t;
  5932. };
  5933. scale.tickFormat = function(count, specifier) {
  5934. return specifier == null ? tickFormat : format(specifier);
  5935. };
  5936. scale.nice = function(interval, step) {
  5937. var d = domain();
  5938. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  5939. ? domain(nice(d, interval))
  5940. : scale;
  5941. };
  5942. scale.copy = function() {
  5943. return copy(scale, calendar(year, month, week, day, hour, minute, second, millisecond, format));
  5944. };
  5945. return scale;
  5946. }
  5947. function time() {
  5948. return calendar(year, month, timeWeek, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  5949. }
  5950. function utcTime() {
  5951. return calendar(utcYear, utcMonth, utcWeek, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  5952. }
  5953. function colors(s) {
  5954. return s.match(/.{6}/g).map(function(x) {
  5955. return "#" + x;
  5956. });
  5957. }
  5958. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  5959. var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
  5960. var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
  5961. var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
  5962. var cubehelix$3 = interpolateCubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  5963. var warm = interpolateCubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  5964. var cool = interpolateCubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  5965. var rainbow = cubehelix();
  5966. function rainbow$1(t) {
  5967. if (t < 0 || t > 1) t -= Math.floor(t);
  5968. var ts = Math.abs(t - 0.5);
  5969. rainbow.h = 360 * t - 100;
  5970. rainbow.s = 1.5 - 1.5 * ts;
  5971. rainbow.l = 0.8 - 0.9 * ts;
  5972. return rainbow + "";
  5973. }
  5974. function ramp(range) {
  5975. var n = range.length;
  5976. return function(t) {
  5977. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  5978. };
  5979. }
  5980. var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  5981. var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  5982. var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  5983. var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  5984. function sequential(interpolator) {
  5985. var x0 = 0,
  5986. x1 = 1,
  5987. clamp = false;
  5988. function scale(x) {
  5989. var t = (x - x0) / (x1 - x0);
  5990. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  5991. }
  5992. scale.domain = function(_) {
  5993. return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
  5994. };
  5995. scale.clamp = function(_) {
  5996. return arguments.length ? (clamp = !!_, scale) : clamp;
  5997. };
  5998. scale.interpolator = function(_) {
  5999. return arguments.length ? (interpolator = _, scale) : interpolator;
  6000. };
  6001. scale.copy = function() {
  6002. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  6003. };
  6004. return linearish(scale);
  6005. }
  6006. var xhtml = "http://www.w3.org/1999/xhtml";
  6007. var namespaces = {
  6008. svg: "http://www.w3.org/2000/svg",
  6009. xhtml: xhtml,
  6010. xlink: "http://www.w3.org/1999/xlink",
  6011. xml: "http://www.w3.org/XML/1998/namespace",
  6012. xmlns: "http://www.w3.org/2000/xmlns/"
  6013. };
  6014. function namespace(name) {
  6015. var prefix = name += "", i = prefix.indexOf(":");
  6016. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  6017. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  6018. }
  6019. function creatorInherit(name) {
  6020. return function() {
  6021. var document = this.ownerDocument,
  6022. uri = this.namespaceURI;
  6023. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  6024. ? document.createElement(name)
  6025. : document.createElementNS(uri, name);
  6026. };
  6027. }
  6028. function creatorFixed(fullname) {
  6029. return function() {
  6030. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  6031. };
  6032. }
  6033. function creator(name) {
  6034. var fullname = namespace(name);
  6035. return (fullname.local
  6036. ? creatorFixed
  6037. : creatorInherit)(fullname);
  6038. }
  6039. var nextId = 0;
  6040. function local() {
  6041. return new Local;
  6042. }
  6043. function Local() {
  6044. this._ = "@" + (++nextId).toString(36);
  6045. }
  6046. Local.prototype = local.prototype = {
  6047. constructor: Local,
  6048. get: function(node) {
  6049. var id = this._;
  6050. while (!(id in node)) if (!(node = node.parentNode)) return;
  6051. return node[id];
  6052. },
  6053. set: function(node, value) {
  6054. return node[this._] = value;
  6055. },
  6056. remove: function(node) {
  6057. return this._ in node && delete node[this._];
  6058. },
  6059. toString: function() {
  6060. return this._;
  6061. }
  6062. };
  6063. var matcher = function(selector) {
  6064. return function() {
  6065. return this.matches(selector);
  6066. };
  6067. };
  6068. if (typeof document !== "undefined") {
  6069. var element = document.documentElement;
  6070. if (!element.matches) {
  6071. var vendorMatches = element.webkitMatchesSelector
  6072. || element.msMatchesSelector
  6073. || element.mozMatchesSelector
  6074. || element.oMatchesSelector;
  6075. matcher = function(selector) {
  6076. return function() {
  6077. return vendorMatches.call(this, selector);
  6078. };
  6079. };
  6080. }
  6081. }
  6082. var matcher$1 = matcher;
  6083. var filterEvents = {};
  6084. exports.event = null;
  6085. if (typeof document !== "undefined") {
  6086. var element$1 = document.documentElement;
  6087. if (!("onmouseenter" in element$1)) {
  6088. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  6089. }
  6090. }
  6091. function filterContextListener(listener, index, group) {
  6092. listener = contextListener(listener, index, group);
  6093. return function(event) {
  6094. var related = event.relatedTarget;
  6095. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  6096. listener.call(this, event);
  6097. }
  6098. };
  6099. }
  6100. function contextListener(listener, index, group) {
  6101. return function(event1) {
  6102. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  6103. exports.event = event1;
  6104. try {
  6105. listener.call(this, this.__data__, index, group);
  6106. } finally {
  6107. exports.event = event0;
  6108. }
  6109. };
  6110. }
  6111. function parseTypenames$1(typenames) {
  6112. return typenames.trim().split(/^|\s+/).map(function(t) {
  6113. var name = "", i = t.indexOf(".");
  6114. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  6115. return {type: t, name: name};
  6116. });
  6117. }
  6118. function onRemove(typename) {
  6119. return function() {
  6120. var on = this.__on;
  6121. if (!on) return;
  6122. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  6123. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  6124. this.removeEventListener(o.type, o.listener, o.capture);
  6125. } else {
  6126. on[++i] = o;
  6127. }
  6128. }
  6129. if (++i) on.length = i;
  6130. else delete this.__on;
  6131. };
  6132. }
  6133. function onAdd(typename, value, capture) {
  6134. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  6135. return function(d, i, group) {
  6136. var on = this.__on, o, listener = wrap(value, i, group);
  6137. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  6138. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  6139. this.removeEventListener(o.type, o.listener, o.capture);
  6140. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  6141. o.value = value;
  6142. return;
  6143. }
  6144. }
  6145. this.addEventListener(typename.type, listener, capture);
  6146. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  6147. if (!on) this.__on = [o];
  6148. else on.push(o);
  6149. };
  6150. }
  6151. function selection_on(typename, value, capture) {
  6152. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  6153. if (arguments.length < 2) {
  6154. var on = this.node().__on;
  6155. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  6156. for (i = 0, o = on[j]; i < n; ++i) {
  6157. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  6158. return o.value;
  6159. }
  6160. }
  6161. }
  6162. return;
  6163. }
  6164. on = value ? onAdd : onRemove;
  6165. if (capture == null) capture = false;
  6166. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  6167. return this;
  6168. }
  6169. function customEvent(event1, listener, that, args) {
  6170. var event0 = exports.event;
  6171. event1.sourceEvent = exports.event;
  6172. exports.event = event1;
  6173. try {
  6174. return listener.apply(that, args);
  6175. } finally {
  6176. exports.event = event0;
  6177. }
  6178. }
  6179. function sourceEvent() {
  6180. var current = exports.event, source;
  6181. while (source = current.sourceEvent) current = source;
  6182. return current;
  6183. }
  6184. function point$5(node, event) {
  6185. var svg = node.ownerSVGElement || node;
  6186. if (svg.createSVGPoint) {
  6187. var point = svg.createSVGPoint();
  6188. point.x = event.clientX, point.y = event.clientY;
  6189. point = point.matrixTransform(node.getScreenCTM().inverse());
  6190. return [point.x, point.y];
  6191. }
  6192. var rect = node.getBoundingClientRect();
  6193. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  6194. }
  6195. function mouse(node) {
  6196. var event = sourceEvent();
  6197. if (event.changedTouches) event = event.changedTouches[0];
  6198. return point$5(node, event);
  6199. }
  6200. function none$2() {}
  6201. function selector(selector) {
  6202. return selector == null ? none$2 : function() {
  6203. return this.querySelector(selector);
  6204. };
  6205. }
  6206. function selection_select(select) {
  6207. if (typeof select !== "function") select = selector(select);
  6208. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  6209. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  6210. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  6211. if ("__data__" in node) subnode.__data__ = node.__data__;
  6212. subgroup[i] = subnode;
  6213. }
  6214. }
  6215. }
  6216. return new Selection(subgroups, this._parents);
  6217. }
  6218. function empty() {
  6219. return [];
  6220. }
  6221. function selectorAll(selector) {
  6222. return selector == null ? empty : function() {
  6223. return this.querySelectorAll(selector);
  6224. };
  6225. }
  6226. function selection_selectAll(select) {
  6227. if (typeof select !== "function") select = selectorAll(select);
  6228. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  6229. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  6230. if (node = group[i]) {
  6231. subgroups.push(select.call(node, node.__data__, i, group));
  6232. parents.push(node);
  6233. }
  6234. }
  6235. }
  6236. return new Selection(subgroups, parents);
  6237. }
  6238. function selection_filter(match) {
  6239. if (typeof match !== "function") match = matcher$1(match);
  6240. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  6241. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  6242. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  6243. subgroup.push(node);
  6244. }
  6245. }
  6246. }
  6247. return new Selection(subgroups, this._parents);
  6248. }
  6249. function sparse(update) {
  6250. return new Array(update.length);
  6251. }
  6252. function selection_enter() {
  6253. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  6254. }
  6255. function EnterNode(parent, datum) {
  6256. this.ownerDocument = parent.ownerDocument;
  6257. this.namespaceURI = parent.namespaceURI;
  6258. this._next = null;
  6259. this._parent = parent;
  6260. this.__data__ = datum;
  6261. }
  6262. EnterNode.prototype = {
  6263. constructor: EnterNode,
  6264. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  6265. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  6266. querySelector: function(selector) { return this._parent.querySelector(selector); },
  6267. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  6268. };
  6269. function constant$4(x) {
  6270. return function() {
  6271. return x;
  6272. };
  6273. }
  6274. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  6275. function bindIndex(parent, group, enter, update, exit, data) {
  6276. var i = 0,
  6277. node,
  6278. groupLength = group.length,
  6279. dataLength = data.length;
  6280. // Put any non-null nodes that fit into update.
  6281. // Put any null nodes into enter.
  6282. // Put any remaining data into enter.
  6283. for (; i < dataLength; ++i) {
  6284. if (node = group[i]) {
  6285. node.__data__ = data[i];
  6286. update[i] = node;
  6287. } else {
  6288. enter[i] = new EnterNode(parent, data[i]);
  6289. }
  6290. }
  6291. // Put any non-null nodes that don’t fit into exit.
  6292. for (; i < groupLength; ++i) {
  6293. if (node = group[i]) {
  6294. exit[i] = node;
  6295. }
  6296. }
  6297. }
  6298. function bindKey(parent, group, enter, update, exit, data, key) {
  6299. var i,
  6300. node,
  6301. nodeByKeyValue = {},
  6302. groupLength = group.length,
  6303. dataLength = data.length,
  6304. keyValues = new Array(groupLength),
  6305. keyValue;
  6306. // Compute the key for each node.
  6307. // If multiple nodes have the same key, the duplicates are added to exit.
  6308. for (i = 0; i < groupLength; ++i) {
  6309. if (node = group[i]) {
  6310. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  6311. if (keyValue in nodeByKeyValue) {
  6312. exit[i] = node;
  6313. } else {
  6314. nodeByKeyValue[keyValue] = node;
  6315. }
  6316. }
  6317. }
  6318. // Compute the key for each datum.
  6319. // If there a node associated with this key, join and add it to update.
  6320. // If there is not (or the key is a duplicate), add it to enter.
  6321. for (i = 0; i < dataLength; ++i) {
  6322. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  6323. if (node = nodeByKeyValue[keyValue]) {
  6324. update[i] = node;
  6325. node.__data__ = data[i];
  6326. nodeByKeyValue[keyValue] = null;
  6327. } else {
  6328. enter[i] = new EnterNode(parent, data[i]);
  6329. }
  6330. }
  6331. // Add any remaining nodes that were not bound to data to exit.
  6332. for (i = 0; i < groupLength; ++i) {
  6333. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  6334. exit[i] = node;
  6335. }
  6336. }
  6337. }
  6338. function selection_data(value, key) {
  6339. if (!value) {
  6340. data = new Array(this.size()), j = -1;
  6341. this.each(function(d) { data[++j] = d; });
  6342. return data;
  6343. }
  6344. var bind = key ? bindKey : bindIndex,
  6345. parents = this._parents,
  6346. groups = this._groups;
  6347. if (typeof value !== "function") value = constant$4(value);
  6348. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  6349. var parent = parents[j],
  6350. group = groups[j],
  6351. groupLength = group.length,
  6352. data = value.call(parent, parent && parent.__data__, j, parents),
  6353. dataLength = data.length,
  6354. enterGroup = enter[j] = new Array(dataLength),
  6355. updateGroup = update[j] = new Array(dataLength),
  6356. exitGroup = exit[j] = new Array(groupLength);
  6357. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  6358. // Now connect the enter nodes to their following update node, such that
  6359. // appendChild can insert the materialized enter node before this node,
  6360. // rather than at the end of the parent node.
  6361. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  6362. if (previous = enterGroup[i0]) {
  6363. if (i0 >= i1) i1 = i0 + 1;
  6364. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  6365. previous._next = next || null;
  6366. }
  6367. }
  6368. }
  6369. update = new Selection(update, parents);
  6370. update._enter = enter;
  6371. update._exit = exit;
  6372. return update;
  6373. }
  6374. function selection_exit() {
  6375. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  6376. }
  6377. function selection_merge(selection) {
  6378. for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  6379. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  6380. if (node = group0[i] || group1[i]) {
  6381. merge[i] = node;
  6382. }
  6383. }
  6384. }
  6385. for (; j < m0; ++j) {
  6386. merges[j] = groups0[j];
  6387. }
  6388. return new Selection(merges, this._parents);
  6389. }
  6390. function selection_order() {
  6391. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  6392. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  6393. if (node = group[i]) {
  6394. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  6395. next = node;
  6396. }
  6397. }
  6398. }
  6399. return this;
  6400. }
  6401. function selection_sort(compare) {
  6402. if (!compare) compare = ascending$2;
  6403. function compareNode(a, b) {
  6404. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  6405. }
  6406. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  6407. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  6408. if (node = group[i]) {
  6409. sortgroup[i] = node;
  6410. }
  6411. }
  6412. sortgroup.sort(compareNode);
  6413. }
  6414. return new Selection(sortgroups, this._parents).order();
  6415. }
  6416. function ascending$2(a, b) {
  6417. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  6418. }
  6419. function selection_call() {
  6420. var callback = arguments[0];
  6421. arguments[0] = this;
  6422. callback.apply(null, arguments);
  6423. return this;
  6424. }
  6425. function selection_nodes() {
  6426. var nodes = new Array(this.size()), i = -1;
  6427. this.each(function() { nodes[++i] = this; });
  6428. return nodes;
  6429. }
  6430. function selection_node() {
  6431. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  6432. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  6433. var node = group[i];
  6434. if (node) return node;
  6435. }
  6436. }
  6437. return null;
  6438. }
  6439. function selection_size() {
  6440. var size = 0;
  6441. this.each(function() { ++size; });
  6442. return size;
  6443. }
  6444. function selection_empty() {
  6445. return !this.node();
  6446. }
  6447. function selection_each(callback) {
  6448. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  6449. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  6450. if (node = group[i]) callback.call(node, node.__data__, i, group);
  6451. }
  6452. }
  6453. return this;
  6454. }
  6455. function attrRemove(name) {
  6456. return function() {
  6457. this.removeAttribute(name);
  6458. };
  6459. }
  6460. function attrRemoveNS(fullname) {
  6461. return function() {
  6462. this.removeAttributeNS(fullname.space, fullname.local);
  6463. };
  6464. }
  6465. function attrConstant(name, value) {
  6466. return function() {
  6467. this.setAttribute(name, value);
  6468. };
  6469. }
  6470. function attrConstantNS(fullname, value) {
  6471. return function() {
  6472. this.setAttributeNS(fullname.space, fullname.local, value);
  6473. };
  6474. }
  6475. function attrFunction(name, value) {
  6476. return function() {
  6477. var v = value.apply(this, arguments);
  6478. if (v == null) this.removeAttribute(name);
  6479. else this.setAttribute(name, v);
  6480. };
  6481. }
  6482. function attrFunctionNS(fullname, value) {
  6483. return function() {
  6484. var v = value.apply(this, arguments);
  6485. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  6486. else this.setAttributeNS(fullname.space, fullname.local, v);
  6487. };
  6488. }
  6489. function selection_attr(name, value) {
  6490. var fullname = namespace(name);
  6491. if (arguments.length < 2) {
  6492. var node = this.node();
  6493. return fullname.local
  6494. ? node.getAttributeNS(fullname.space, fullname.local)
  6495. : node.getAttribute(fullname);
  6496. }
  6497. return this.each((value == null
  6498. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  6499. ? (fullname.local ? attrFunctionNS : attrFunction)
  6500. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  6501. }
  6502. function window(node) {
  6503. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  6504. || (node.document && node) // node is a Window
  6505. || node.defaultView; // node is a Document
  6506. }
  6507. function styleRemove(name) {
  6508. return function() {
  6509. this.style.removeProperty(name);
  6510. };
  6511. }
  6512. function styleConstant(name, value, priority) {
  6513. return function() {
  6514. this.style.setProperty(name, value, priority);
  6515. };
  6516. }
  6517. function styleFunction(name, value, priority) {
  6518. return function() {
  6519. var v = value.apply(this, arguments);
  6520. if (v == null) this.style.removeProperty(name);
  6521. else this.style.setProperty(name, v, priority);
  6522. };
  6523. }
  6524. function selection_style(name, value, priority) {
  6525. var node;
  6526. return arguments.length > 1
  6527. ? this.each((value == null
  6528. ? styleRemove : typeof value === "function"
  6529. ? styleFunction
  6530. : styleConstant)(name, value, priority == null ? "" : priority))
  6531. : window(node = this.node())
  6532. .getComputedStyle(node, null)
  6533. .getPropertyValue(name);
  6534. }
  6535. function propertyRemove(name) {
  6536. return function() {
  6537. delete this[name];
  6538. };
  6539. }
  6540. function propertyConstant(name, value) {
  6541. return function() {
  6542. this[name] = value;
  6543. };
  6544. }
  6545. function propertyFunction(name, value) {
  6546. return function() {
  6547. var v = value.apply(this, arguments);
  6548. if (v == null) delete this[name];
  6549. else this[name] = v;
  6550. };
  6551. }
  6552. function selection_property(name, value) {
  6553. return arguments.length > 1
  6554. ? this.each((value == null
  6555. ? propertyRemove : typeof value === "function"
  6556. ? propertyFunction
  6557. : propertyConstant)(name, value))
  6558. : this.node()[name];
  6559. }
  6560. function classArray(string) {
  6561. return string.trim().split(/^|\s+/);
  6562. }
  6563. function classList(node) {
  6564. return node.classList || new ClassList(node);
  6565. }
  6566. function ClassList(node) {
  6567. this._node = node;
  6568. this._names = classArray(node.getAttribute("class") || "");
  6569. }
  6570. ClassList.prototype = {
  6571. add: function(name) {
  6572. var i = this._names.indexOf(name);
  6573. if (i < 0) {
  6574. this._names.push(name);
  6575. this._node.setAttribute("class", this._names.join(" "));
  6576. }
  6577. },
  6578. remove: function(name) {
  6579. var i = this._names.indexOf(name);
  6580. if (i >= 0) {
  6581. this._names.splice(i, 1);
  6582. this._node.setAttribute("class", this._names.join(" "));
  6583. }
  6584. },
  6585. contains: function(name) {
  6586. return this._names.indexOf(name) >= 0;
  6587. }
  6588. };
  6589. function classedAdd(node, names) {
  6590. var list = classList(node), i = -1, n = names.length;
  6591. while (++i < n) list.add(names[i]);
  6592. }
  6593. function classedRemove(node, names) {
  6594. var list = classList(node), i = -1, n = names.length;
  6595. while (++i < n) list.remove(names[i]);
  6596. }
  6597. function classedTrue(names) {
  6598. return function() {
  6599. classedAdd(this, names);
  6600. };
  6601. }
  6602. function classedFalse(names) {
  6603. return function() {
  6604. classedRemove(this, names);
  6605. };
  6606. }
  6607. function classedFunction(names, value) {
  6608. return function() {
  6609. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  6610. };
  6611. }
  6612. function selection_classed(name, value) {
  6613. var names = classArray(name + "");
  6614. if (arguments.length < 2) {
  6615. var list = classList(this.node()), i = -1, n = names.length;
  6616. while (++i < n) if (!list.contains(names[i])) return false;
  6617. return true;
  6618. }
  6619. return this.each((typeof value === "function"
  6620. ? classedFunction : value
  6621. ? classedTrue
  6622. : classedFalse)(names, value));
  6623. }
  6624. function textRemove() {
  6625. this.textContent = "";
  6626. }
  6627. function textConstant(value) {
  6628. return function() {
  6629. this.textContent = value;
  6630. };
  6631. }
  6632. function textFunction(value) {
  6633. return function() {
  6634. var v = value.apply(this, arguments);
  6635. this.textContent = v == null ? "" : v;
  6636. };
  6637. }
  6638. function selection_text(value) {
  6639. return arguments.length
  6640. ? this.each(value == null
  6641. ? textRemove : (typeof value === "function"
  6642. ? textFunction
  6643. : textConstant)(value))
  6644. : this.node().textContent;
  6645. }
  6646. function htmlRemove() {
  6647. this.innerHTML = "";
  6648. }
  6649. function htmlConstant(value) {
  6650. return function() {
  6651. this.innerHTML = value;
  6652. };
  6653. }
  6654. function htmlFunction(value) {
  6655. return function() {
  6656. var v = value.apply(this, arguments);
  6657. this.innerHTML = v == null ? "" : v;
  6658. };
  6659. }
  6660. function selection_html(value) {
  6661. return arguments.length
  6662. ? this.each(value == null
  6663. ? htmlRemove : (typeof value === "function"
  6664. ? htmlFunction
  6665. : htmlConstant)(value))
  6666. : this.node().innerHTML;
  6667. }
  6668. function raise$1() {
  6669. if (this.nextSibling) this.parentNode.appendChild(this);
  6670. }
  6671. function selection_raise() {
  6672. return this.each(raise$1);
  6673. }
  6674. function lower() {
  6675. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  6676. }
  6677. function selection_lower() {
  6678. return this.each(lower);
  6679. }
  6680. function selection_append(name) {
  6681. var create = typeof name === "function" ? name : creator(name);
  6682. return this.select(function() {
  6683. return this.appendChild(create.apply(this, arguments));
  6684. });
  6685. }
  6686. function constantNull() {
  6687. return null;
  6688. }
  6689. function selection_insert(name, before) {
  6690. var create = typeof name === "function" ? name : creator(name),
  6691. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  6692. return this.select(function() {
  6693. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  6694. });
  6695. }
  6696. function remove() {
  6697. var parent = this.parentNode;
  6698. if (parent) parent.removeChild(this);
  6699. }
  6700. function selection_remove() {
  6701. return this.each(remove);
  6702. }
  6703. function selection_datum(value) {
  6704. return arguments.length
  6705. ? this.property("__data__", value)
  6706. : this.node().__data__;
  6707. }
  6708. function dispatchEvent(node, type, params) {
  6709. var window$$ = window(node),
  6710. event = window$$.CustomEvent;
  6711. if (event) {
  6712. event = new event(type, params);
  6713. } else {
  6714. event = window$$.document.createEvent("Event");
  6715. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  6716. else event.initEvent(type, false, false);
  6717. }
  6718. node.dispatchEvent(event);
  6719. }
  6720. function dispatchConstant(type, params) {
  6721. return function() {
  6722. return dispatchEvent(this, type, params);
  6723. };
  6724. }
  6725. function dispatchFunction(type, params) {
  6726. return function() {
  6727. return dispatchEvent(this, type, params.apply(this, arguments));
  6728. };
  6729. }
  6730. function selection_dispatch(type, params) {
  6731. return this.each((typeof params === "function"
  6732. ? dispatchFunction
  6733. : dispatchConstant)(type, params));
  6734. }
  6735. var root = [null];
  6736. function Selection(groups, parents) {
  6737. this._groups = groups;
  6738. this._parents = parents;
  6739. }
  6740. function selection() {
  6741. return new Selection([[document.documentElement]], root);
  6742. }
  6743. Selection.prototype = selection.prototype = {
  6744. constructor: Selection,
  6745. select: selection_select,
  6746. selectAll: selection_selectAll,
  6747. filter: selection_filter,
  6748. data: selection_data,
  6749. enter: selection_enter,
  6750. exit: selection_exit,
  6751. merge: selection_merge,
  6752. order: selection_order,
  6753. sort: selection_sort,
  6754. call: selection_call,
  6755. nodes: selection_nodes,
  6756. node: selection_node,
  6757. size: selection_size,
  6758. empty: selection_empty,
  6759. each: selection_each,
  6760. attr: selection_attr,
  6761. style: selection_style,
  6762. property: selection_property,
  6763. classed: selection_classed,
  6764. text: selection_text,
  6765. html: selection_html,
  6766. raise: selection_raise,
  6767. lower: selection_lower,
  6768. append: selection_append,
  6769. insert: selection_insert,
  6770. remove: selection_remove,
  6771. datum: selection_datum,
  6772. on: selection_on,
  6773. dispatch: selection_dispatch
  6774. };
  6775. function select(selector) {
  6776. return typeof selector === "string"
  6777. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  6778. : new Selection([[selector]], root);
  6779. }
  6780. function selectAll(selector) {
  6781. return typeof selector === "string"
  6782. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  6783. : new Selection([selector == null ? [] : selector], root);
  6784. }
  6785. function touch(node, touches, identifier) {
  6786. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  6787. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  6788. if ((touch = touches[i]).identifier === identifier) {
  6789. return point$5(node, touch);
  6790. }
  6791. }
  6792. return null;
  6793. }
  6794. function touches(node, touches) {
  6795. if (touches == null) touches = sourceEvent().touches;
  6796. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  6797. points[i] = point$5(node, touches[i]);
  6798. }
  6799. return points;
  6800. }
  6801. var emptyOn = dispatch("start", "end", "interrupt");
  6802. var emptyTween = [];
  6803. var CREATED = 0;
  6804. var SCHEDULED = 1;
  6805. var STARTING = 2;
  6806. var STARTED = 3;
  6807. var ENDING = 4;
  6808. var ENDED = 5;
  6809. function schedule(node, name, id, index, group, timing) {
  6810. var schedules = node.__transition;
  6811. if (!schedules) node.__transition = {};
  6812. else if (id in schedules) return;
  6813. create(node, id, {
  6814. name: name,
  6815. index: index, // For context during callback.
  6816. group: group, // For context during callback.
  6817. on: emptyOn,
  6818. tween: emptyTween,
  6819. time: timing.time,
  6820. delay: timing.delay,
  6821. duration: timing.duration,
  6822. ease: timing.ease,
  6823. timer: null,
  6824. state: CREATED
  6825. });
  6826. }
  6827. function init(node, id) {
  6828. var schedule = node.__transition;
  6829. if (!schedule || !(schedule = schedule[id]) || schedule.state > CREATED) throw new Error("too late");
  6830. return schedule;
  6831. }
  6832. function set$2(node, id) {
  6833. var schedule = node.__transition;
  6834. if (!schedule || !(schedule = schedule[id]) || schedule.state > STARTING) throw new Error("too late");
  6835. return schedule;
  6836. }
  6837. function get$1(node, id) {
  6838. var schedule = node.__transition;
  6839. if (!schedule || !(schedule = schedule[id])) throw new Error("too late");
  6840. return schedule;
  6841. }
  6842. function create(node, id, self) {
  6843. var schedules = node.__transition,
  6844. tween;
  6845. // Initialize the self timer when the transition is created.
  6846. // Note the actual delay is not known until the first callback!
  6847. schedules[id] = self;
  6848. self.timer = timer(schedule, 0, self.time);
  6849. // If the delay is greater than this first sleep, sleep some more;
  6850. // otherwise, start immediately.
  6851. function schedule(elapsed) {
  6852. self.state = SCHEDULED;
  6853. if (self.delay <= elapsed) start(elapsed - self.delay);
  6854. else self.timer.restart(start, self.delay, self.time);
  6855. }
  6856. function start(elapsed) {
  6857. var i, j, n, o;
  6858. for (i in schedules) {
  6859. o = schedules[i];
  6860. if (o.name !== self.name) continue;
  6861. // Interrupt the active transition, if any.
  6862. // Dispatch the interrupt event.
  6863. if (o.state === STARTED) {
  6864. o.state = ENDED;
  6865. o.timer.stop();
  6866. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  6867. delete schedules[i];
  6868. }
  6869. // Cancel any pre-empted transitions. No interrupt event is dispatched
  6870. // because the cancelled transitions never started. Note that this also
  6871. // removes this transition from the pending list!
  6872. else if (+i < id) {
  6873. o.state = ENDED;
  6874. o.timer.stop();
  6875. delete schedules[i];
  6876. }
  6877. }
  6878. // Defer the first tick to end of the current frame; see mbostock/d3#1576.
  6879. // Note the transition may be canceled after start and before the first tick!
  6880. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  6881. // Assuming this is successful, subsequent callbacks go straight to tick.
  6882. timeout$1(function() {
  6883. if (self.state === STARTED) {
  6884. self.timer.restart(tick, self.delay, self.time);
  6885. tick(elapsed);
  6886. }
  6887. });
  6888. // Dispatch the start event.
  6889. // Note this must be done before the tween are initialized.
  6890. self.state = STARTING;
  6891. self.on.call("start", node, node.__data__, self.index, self.group);
  6892. if (self.state !== STARTING) return; // interrupted
  6893. self.state = STARTED;
  6894. // Initialize the tween, deleting null tween.
  6895. tween = new Array(n = self.tween.length);
  6896. for (i = 0, j = -1; i < n; ++i) {
  6897. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  6898. tween[++j] = o;
  6899. }
  6900. }
  6901. tween.length = j + 1;
  6902. }
  6903. function tick(elapsed) {
  6904. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.state = ENDING, 1),
  6905. i = -1,
  6906. n = tween.length;
  6907. while (++i < n) {
  6908. tween[i].call(null, t);
  6909. }
  6910. // Dispatch the end event.
  6911. if (self.state === ENDING) {
  6912. self.state = ENDED;
  6913. self.timer.stop();
  6914. self.on.call("end", node, node.__data__, self.index, self.group);
  6915. for (i in schedules) if (+i !== id) return void delete schedules[id];
  6916. delete node.__transition;
  6917. }
  6918. }
  6919. }
  6920. function interrupt(node, name) {
  6921. var schedules = node.__transition,
  6922. schedule,
  6923. active,
  6924. empty = true,
  6925. i;
  6926. if (!schedules) return;
  6927. name = name == null ? null : name + "";
  6928. for (i in schedules) {
  6929. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  6930. active = schedule.state === STARTED;
  6931. schedule.state = ENDED;
  6932. schedule.timer.stop();
  6933. if (active) schedule.on.call("interrupt", node, node.__data__, schedule.index, schedule.group);
  6934. delete schedules[i];
  6935. }
  6936. if (empty) delete node.__transition;
  6937. }
  6938. function selection_interrupt(name) {
  6939. return this.each(function() {
  6940. interrupt(this, name);
  6941. });
  6942. }
  6943. function tweenRemove(id, name) {
  6944. var tween0, tween1;
  6945. return function() {
  6946. var schedule = set$2(this, id),
  6947. tween = schedule.tween;
  6948. // If this node shared tween with the previous node,
  6949. // just assign the updated shared tween and we’re done!
  6950. // Otherwise, copy-on-write.
  6951. if (tween !== tween0) {
  6952. tween1 = tween0 = tween;
  6953. for (var i = 0, n = tween1.length; i < n; ++i) {
  6954. if (tween1[i].name === name) {
  6955. tween1 = tween1.slice();
  6956. tween1.splice(i, 1);
  6957. break;
  6958. }
  6959. }
  6960. }
  6961. schedule.tween = tween1;
  6962. };
  6963. }
  6964. function tweenFunction(id, name, value) {
  6965. var tween0, tween1;
  6966. if (typeof value !== "function") throw new Error;
  6967. return function() {
  6968. var schedule = set$2(this, id),
  6969. tween = schedule.tween;
  6970. // If this node shared tween with the previous node,
  6971. // just assign the updated shared tween and we’re done!
  6972. // Otherwise, copy-on-write.
  6973. if (tween !== tween0) {
  6974. tween1 = (tween0 = tween).slice();
  6975. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  6976. if (tween1[i].name === name) {
  6977. tween1[i] = t;
  6978. break;
  6979. }
  6980. }
  6981. if (i === n) tween1.push(t);
  6982. }
  6983. schedule.tween = tween1;
  6984. };
  6985. }
  6986. function transition_tween(name, value) {
  6987. var id = this._id;
  6988. name += "";
  6989. if (arguments.length < 2) {
  6990. var tween = get$1(this.node(), id).tween;
  6991. for (var i = 0, n = tween.length, t; i < n; ++i) {
  6992. if ((t = tween[i]).name === name) {
  6993. return t.value;
  6994. }
  6995. }
  6996. return null;
  6997. }
  6998. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  6999. }
  7000. function tweenValue(transition, name, value) {
  7001. var id = transition._id;
  7002. transition.each(function() {
  7003. var schedule = set$2(this, id);
  7004. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  7005. });
  7006. return function(node) {
  7007. return get$1(node, id).value[name];
  7008. };
  7009. }
  7010. function interpolate$1(a, b) {
  7011. var c;
  7012. return (typeof b === "number" ? interpolateNumber
  7013. : b instanceof color ? interpolateRgb
  7014. : (c = color(b)) ? (b = c, interpolateRgb)
  7015. : interpolateString)(a, b);
  7016. }
  7017. function attrRemove$1(name) {
  7018. return function() {
  7019. this.removeAttribute(name);
  7020. };
  7021. }
  7022. function attrRemoveNS$1(fullname) {
  7023. return function() {
  7024. this.removeAttributeNS(fullname.space, fullname.local);
  7025. };
  7026. }
  7027. function attrConstant$1(name, interpolate, value1) {
  7028. var value00,
  7029. interpolate0;
  7030. return function() {
  7031. var value0 = this.getAttribute(name);
  7032. return value0 === value1 ? null
  7033. : value0 === value00 ? interpolate0
  7034. : interpolate0 = interpolate(value00 = value0, value1);
  7035. };
  7036. }
  7037. function attrConstantNS$1(fullname, interpolate, value1) {
  7038. var value00,
  7039. interpolate0;
  7040. return function() {
  7041. var value0 = this.getAttributeNS(fullname.space, fullname.local);
  7042. return value0 === value1 ? null
  7043. : value0 === value00 ? interpolate0
  7044. : interpolate0 = interpolate(value00 = value0, value1);
  7045. };
  7046. }
  7047. function attrFunction$1(name, interpolate, value) {
  7048. var value00,
  7049. value10,
  7050. interpolate0;
  7051. return function() {
  7052. var value0, value1 = value(this);
  7053. if (value1 == null) return void this.removeAttribute(name);
  7054. value0 = this.getAttribute(name);
  7055. return value0 === value1 ? null
  7056. : value0 === value00 && value1 === value10 ? interpolate0
  7057. : interpolate0 = interpolate(value00 = value0, value10 = value1);
  7058. };
  7059. }
  7060. function attrFunctionNS$1(fullname, interpolate, value) {
  7061. var value00,
  7062. value10,
  7063. interpolate0;
  7064. return function() {
  7065. var value0, value1 = value(this);
  7066. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  7067. value0 = this.getAttributeNS(fullname.space, fullname.local);
  7068. return value0 === value1 ? null
  7069. : value0 === value00 && value1 === value10 ? interpolate0
  7070. : interpolate0 = interpolate(value00 = value0, value10 = value1);
  7071. };
  7072. }
  7073. function transition_attr(name, value) {
  7074. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransform$2 : interpolate$1;
  7075. return this.attrTween(name, typeof value === "function"
  7076. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  7077. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  7078. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
  7079. }
  7080. function attrTweenNS(fullname, value) {
  7081. function tween() {
  7082. var node = this, i = value.apply(node, arguments);
  7083. return i && function(t) {
  7084. node.setAttributeNS(fullname.space, fullname.local, i(t));
  7085. };
  7086. }
  7087. tween._value = value;
  7088. return tween;
  7089. }
  7090. function attrTween(name, value) {
  7091. function tween() {
  7092. var node = this, i = value.apply(node, arguments);
  7093. return i && function(t) {
  7094. node.setAttribute(name, i(t));
  7095. };
  7096. }
  7097. tween._value = value;
  7098. return tween;
  7099. }
  7100. function transition_attrTween(name, value) {
  7101. var key = "attr." + name;
  7102. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  7103. if (value == null) return this.tween(key, null);
  7104. if (typeof value !== "function") throw new Error;
  7105. var fullname = namespace(name);
  7106. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  7107. }
  7108. function delayFunction(id, value) {
  7109. return function() {
  7110. init(this, id).delay = +value.apply(this, arguments);
  7111. };
  7112. }
  7113. function delayConstant(id, value) {
  7114. return value = +value, function() {
  7115. init(this, id).delay = value;
  7116. };
  7117. }
  7118. function transition_delay(value) {
  7119. var id = this._id;
  7120. return arguments.length
  7121. ? this.each((typeof value === "function"
  7122. ? delayFunction
  7123. : delayConstant)(id, value))
  7124. : get$1(this.node(), id).delay;
  7125. }
  7126. function durationFunction(id, value) {
  7127. return function() {
  7128. set$2(this, id).duration = +value.apply(this, arguments);
  7129. };
  7130. }
  7131. function durationConstant(id, value) {
  7132. return value = +value, function() {
  7133. set$2(this, id).duration = value;
  7134. };
  7135. }
  7136. function transition_duration(value) {
  7137. var id = this._id;
  7138. return arguments.length
  7139. ? this.each((typeof value === "function"
  7140. ? durationFunction
  7141. : durationConstant)(id, value))
  7142. : get$1(this.node(), id).duration;
  7143. }
  7144. function easeConstant(id, value) {
  7145. if (typeof value !== "function") throw new Error;
  7146. return function() {
  7147. set$2(this, id).ease = value;
  7148. };
  7149. }
  7150. function transition_ease(value) {
  7151. var id = this._id;
  7152. return arguments.length
  7153. ? this.each(easeConstant(id, value))
  7154. : get$1(this.node(), id).ease;
  7155. }
  7156. function transition_filter(match) {
  7157. if (typeof match !== "function") match = matcher$1(match);
  7158. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  7159. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  7160. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  7161. subgroup.push(node);
  7162. }
  7163. }
  7164. }
  7165. return new Transition(subgroups, this._parents, this._name, this._id);
  7166. }
  7167. function transition_merge(transition) {
  7168. if (transition._id !== this._id) throw new Error;
  7169. for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  7170. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  7171. if (node = group0[i] || group1[i]) {
  7172. merge[i] = node;
  7173. }
  7174. }
  7175. }
  7176. for (; j < m0; ++j) {
  7177. merges[j] = groups0[j];
  7178. }
  7179. return new Transition(merges, this._parents, this._name, this._id);
  7180. }
  7181. function start$1(name) {
  7182. return (name + "").trim().split(/^|\s+/).every(function(t) {
  7183. var i = t.indexOf(".");
  7184. if (i >= 0) t = t.slice(0, i);
  7185. return !t || t === "start";
  7186. });
  7187. }
  7188. function onFunction(id, name, listener) {
  7189. var on0, on1, sit = start$1(name) ? init : set$2;
  7190. return function() {
  7191. var schedule = sit(this, id),
  7192. on = schedule.on;
  7193. // If this node shared a dispatch with the previous node,
  7194. // just assign the updated shared dispatch and we’re done!
  7195. // Otherwise, copy-on-write.
  7196. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  7197. schedule.on = on1;
  7198. };
  7199. }
  7200. function transition_on(name, listener) {
  7201. var id = this._id;
  7202. return arguments.length < 2
  7203. ? get$1(this.node(), id).on.on(name)
  7204. : this.each(onFunction(id, name, listener));
  7205. }
  7206. function removeFunction(id) {
  7207. return function() {
  7208. var parent = this.parentNode;
  7209. for (var i in this.__transition) if (+i !== id) return;
  7210. if (parent) parent.removeChild(this);
  7211. };
  7212. }
  7213. function transition_remove() {
  7214. return this.on("end.remove", removeFunction(this._id));
  7215. }
  7216. function transition_select(select) {
  7217. var name = this._name,
  7218. id = this._id;
  7219. if (typeof select !== "function") select = selector(select);
  7220. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  7221. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  7222. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  7223. if ("__data__" in node) subnode.__data__ = node.__data__;
  7224. subgroup[i] = subnode;
  7225. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  7226. }
  7227. }
  7228. }
  7229. return new Transition(subgroups, this._parents, name, id);
  7230. }
  7231. function transition_selectAll(select) {
  7232. var name = this._name,
  7233. id = this._id;
  7234. if (typeof select !== "function") select = selectorAll(select);
  7235. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  7236. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  7237. if (node = group[i]) {
  7238. for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  7239. if (child = children[k]) {
  7240. schedule(child, name, id, k, children, inherit);
  7241. }
  7242. }
  7243. subgroups.push(children);
  7244. parents.push(node);
  7245. }
  7246. }
  7247. }
  7248. return new Transition(subgroups, parents, name, id);
  7249. }
  7250. var Selection$1 = selection.prototype.constructor;
  7251. function transition_selection() {
  7252. return new Selection$1(this._groups, this._parents);
  7253. }
  7254. function styleRemove$1(name, interpolate) {
  7255. var value00,
  7256. value10,
  7257. interpolate0;
  7258. return function() {
  7259. var style = window(this).getComputedStyle(this, null),
  7260. value0 = style.getPropertyValue(name),
  7261. value1 = (this.style.removeProperty(name), style.getPropertyValue(name));
  7262. return value0 === value1 ? null
  7263. : value0 === value00 && value1 === value10 ? interpolate0
  7264. : interpolate0 = interpolate(value00 = value0, value10 = value1);
  7265. };
  7266. }
  7267. function styleRemoveEnd(name) {
  7268. return function() {
  7269. this.style.removeProperty(name);
  7270. };
  7271. }
  7272. function styleConstant$1(name, interpolate, value1) {
  7273. var value00,
  7274. interpolate0;
  7275. return function() {
  7276. var value0 = window(this).getComputedStyle(this, null).getPropertyValue(name);
  7277. return value0 === value1 ? null
  7278. : value0 === value00 ? interpolate0
  7279. : interpolate0 = interpolate(value00 = value0, value1);
  7280. };
  7281. }
  7282. function styleFunction$1(name, interpolate, value) {
  7283. var value00,
  7284. value10,
  7285. interpolate0;
  7286. return function() {
  7287. var style = window(this).getComputedStyle(this, null),
  7288. value0 = style.getPropertyValue(name),
  7289. value1 = value(this);
  7290. if (value1 == null) value1 = (this.style.removeProperty(name), style.getPropertyValue(name));
  7291. return value0 === value1 ? null
  7292. : value0 === value00 && value1 === value10 ? interpolate0
  7293. : interpolate0 = interpolate(value00 = value0, value10 = value1);
  7294. };
  7295. }
  7296. function transition_style(name, value, priority) {
  7297. var i = (name += "") === "transform" ? interpolateTransform$1 : interpolate$1;
  7298. return value == null ? this
  7299. .styleTween(name, styleRemove$1(name, i))
  7300. .on("end.style." + name, styleRemoveEnd(name))
  7301. : this.styleTween(name, typeof value === "function"
  7302. ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
  7303. : styleConstant$1(name, i, value), priority);
  7304. }
  7305. function styleTween(name, value, priority) {
  7306. function tween() {
  7307. var node = this, i = value.apply(node, arguments);
  7308. return i && function(t) {
  7309. node.style.setProperty(name, i(t), priority);
  7310. };
  7311. }
  7312. tween._value = value;
  7313. return tween;
  7314. }
  7315. function transition_styleTween(name, value, priority) {
  7316. var key = "style." + (name += "");
  7317. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  7318. if (value == null) return this.tween(key, null);
  7319. if (typeof value !== "function") throw new Error;
  7320. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  7321. }
  7322. function textConstant$1(value) {
  7323. return function() {
  7324. this.textContent = value;
  7325. };
  7326. }
  7327. function textFunction$1(value) {
  7328. return function() {
  7329. var value1 = value(this);
  7330. this.textContent = value1 == null ? "" : value1;
  7331. };
  7332. }
  7333. function transition_text(value) {
  7334. return this.tween("text", typeof value === "function"
  7335. ? textFunction$1(tweenValue(this, "text", value))
  7336. : textConstant$1(value == null ? "" : value + ""));
  7337. }
  7338. function transition_transition() {
  7339. var name = this._name,
  7340. id0 = this._id,
  7341. id1 = newId();
  7342. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  7343. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  7344. if (node = group[i]) {
  7345. var inherit = get$1(node, id0);
  7346. schedule(node, name, id1, i, group, {
  7347. time: inherit.time + inherit.delay + inherit.duration,
  7348. delay: 0,
  7349. duration: inherit.duration,
  7350. ease: inherit.ease
  7351. });
  7352. }
  7353. }
  7354. }
  7355. return new Transition(groups, this._parents, name, id1);
  7356. }
  7357. var id = 0;
  7358. function Transition(groups, parents, name, id) {
  7359. this._groups = groups;
  7360. this._parents = parents;
  7361. this._name = name;
  7362. this._id = id;
  7363. }
  7364. function transition(name) {
  7365. return selection().transition(name);
  7366. }
  7367. function newId() {
  7368. return ++id;
  7369. }
  7370. var selection_prototype = selection.prototype;
  7371. Transition.prototype = transition.prototype = {
  7372. constructor: Transition,
  7373. select: transition_select,
  7374. selectAll: transition_selectAll,
  7375. filter: transition_filter,
  7376. merge: transition_merge,
  7377. selection: transition_selection,
  7378. transition: transition_transition,
  7379. call: selection_prototype.call,
  7380. nodes: selection_prototype.nodes,
  7381. node: selection_prototype.node,
  7382. size: selection_prototype.size,
  7383. empty: selection_prototype.empty,
  7384. each: selection_prototype.each,
  7385. on: transition_on,
  7386. attr: transition_attr,
  7387. attrTween: transition_attrTween,
  7388. style: transition_style,
  7389. styleTween: transition_styleTween,
  7390. text: transition_text,
  7391. remove: transition_remove,
  7392. tween: transition_tween,
  7393. delay: transition_delay,
  7394. duration: transition_duration,
  7395. ease: transition_ease
  7396. };
  7397. var defaultTiming = {
  7398. time: null, // Set on use.
  7399. delay: 0,
  7400. duration: 250,
  7401. ease: easeCubicInOut
  7402. };
  7403. function inherit(node, id) {
  7404. var timing;
  7405. while (!(timing = node.__transition) || !(timing = timing[id])) {
  7406. if (!(node = node.parentNode)) {
  7407. return defaultTiming.time = now(), defaultTiming;
  7408. }
  7409. }
  7410. return timing;
  7411. }
  7412. function selection_transition(name) {
  7413. var id,
  7414. timing;
  7415. if (name instanceof Transition) {
  7416. id = name._id, name = name._name;
  7417. } else {
  7418. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  7419. }
  7420. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  7421. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  7422. if (node = group[i]) {
  7423. schedule(node, name, id, i, group, timing || inherit(node, id));
  7424. }
  7425. }
  7426. }
  7427. return new Transition(groups, this._parents, name, id);
  7428. }
  7429. selection.prototype.interrupt = selection_interrupt;
  7430. selection.prototype.transition = selection_transition;
  7431. var root$1 = [null];
  7432. function active(node, name) {
  7433. var schedules = node.__transition,
  7434. schedule,
  7435. i;
  7436. if (schedules) {
  7437. name = name == null ? null : name + "";
  7438. for (i in schedules) {
  7439. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  7440. return new Transition([[node]], root$1, name, +i);
  7441. }
  7442. }
  7443. }
  7444. return null;
  7445. }
  7446. var slice$4 = Array.prototype.slice;
  7447. function identity$5(x) {
  7448. return x;
  7449. }
  7450. var top = 1;
  7451. var right = 2;
  7452. var bottom = 3;
  7453. var left = 4;
  7454. var epsilon$2 = 1e-6;
  7455. function translateX(scale0, scale1, d) {
  7456. var x = scale0(d);
  7457. return "translate(" + (isFinite(x) ? x : scale1(d)) + ",0)";
  7458. }
  7459. function translateY(scale0, scale1, d) {
  7460. var y = scale0(d);
  7461. return "translate(0," + (isFinite(y) ? y : scale1(d)) + ")";
  7462. }
  7463. function center(scale) {
  7464. var width = scale.bandwidth() / 2;
  7465. return function(d) {
  7466. return scale(d) + width;
  7467. };
  7468. }
  7469. function entering() {
  7470. return !this.__axis;
  7471. }
  7472. function axis(orient, scale) {
  7473. var tickArguments = [],
  7474. tickValues = null,
  7475. tickFormat = null,
  7476. tickSizeInner = 6,
  7477. tickSizeOuter = 6,
  7478. tickPadding = 3;
  7479. function axis(context) {
  7480. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  7481. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$5) : tickFormat,
  7482. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  7483. transform = orient === top || orient === bottom ? translateX : translateY,
  7484. range = scale.range(),
  7485. range0 = range[0] + 0.5,
  7486. range1 = range[range.length - 1] + 0.5,
  7487. position = (scale.bandwidth ? center : identity$5)(scale.copy()),
  7488. selection = context.selection ? context.selection() : context,
  7489. path = selection.selectAll(".domain").data([null]),
  7490. tick = selection.selectAll(".tick").data(values, scale).order(),
  7491. tickExit = tick.exit(),
  7492. tickEnter = tick.enter().append("g").attr("class", "tick"),
  7493. line = tick.select("line"),
  7494. text = tick.select("text"),
  7495. k = orient === top || orient === left ? -1 : 1,
  7496. x, y = orient === left || orient === right ? (x = "x", "y") : (x = "y", "x");
  7497. path = path.merge(path.enter().insert("path", ".tick")
  7498. .attr("class", "domain")
  7499. .attr("stroke", "#000"));
  7500. tick = tick.merge(tickEnter);
  7501. line = line.merge(tickEnter.append("line")
  7502. .attr("stroke", "#000")
  7503. .attr(x + "2", k * tickSizeInner)
  7504. .attr(y + "1", 0.5)
  7505. .attr(y + "2", 0.5));
  7506. text = text.merge(tickEnter.append("text")
  7507. .attr("fill", "#000")
  7508. .attr(x, k * spacing)
  7509. .attr(y, 0.5)
  7510. .attr("dy", orient === top ? "0em" : orient === bottom ? ".71em" : ".32em"));
  7511. if (context !== selection) {
  7512. path = path.transition(context);
  7513. tick = tick.transition(context);
  7514. line = line.transition(context);
  7515. text = text.transition(context);
  7516. tickExit = tickExit.transition(context)
  7517. .attr("opacity", epsilon$2)
  7518. .attr("transform", function(d) { return transform(position, this.parentNode.__axis || position, d); });
  7519. tickEnter
  7520. .attr("opacity", epsilon$2)
  7521. .attr("transform", function(d) { return transform(this.parentNode.__axis || position, position, d); });
  7522. }
  7523. tickExit.remove();
  7524. path
  7525. .attr("d", orient === left || orient == right
  7526. ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
  7527. : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
  7528. tick
  7529. .attr("opacity", 1)
  7530. .attr("transform", function(d) { return transform(position, position, d); });
  7531. line
  7532. .attr(x + "2", k * tickSizeInner);
  7533. text
  7534. .attr(x, k * spacing)
  7535. .text(format);
  7536. selection.filter(entering)
  7537. .attr("fill", "none")
  7538. .attr("font-size", 10)
  7539. .attr("font-family", "sans-serif")
  7540. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  7541. selection
  7542. .each(function() { this.__axis = position; });
  7543. }
  7544. axis.scale = function(_) {
  7545. return arguments.length ? (scale = _, axis) : scale;
  7546. };
  7547. axis.ticks = function() {
  7548. return tickArguments = slice$4.call(arguments), axis;
  7549. };
  7550. axis.tickArguments = function(_) {
  7551. return arguments.length ? (tickArguments = _ == null ? [] : slice$4.call(_), axis) : tickArguments.slice();
  7552. };
  7553. axis.tickValues = function(_) {
  7554. return arguments.length ? (tickValues = _ == null ? null : slice$4.call(_), axis) : tickValues && tickValues.slice();
  7555. };
  7556. axis.tickFormat = function(_) {
  7557. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  7558. };
  7559. axis.tickSize = function(_) {
  7560. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  7561. };
  7562. axis.tickSizeInner = function(_) {
  7563. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  7564. };
  7565. axis.tickSizeOuter = function(_) {
  7566. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  7567. };
  7568. axis.tickPadding = function(_) {
  7569. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  7570. };
  7571. return axis;
  7572. }
  7573. function axisTop(scale) {
  7574. return axis(top, scale);
  7575. }
  7576. function axisRight(scale) {
  7577. return axis(right, scale);
  7578. }
  7579. function axisBottom(scale) {
  7580. return axis(bottom, scale);
  7581. }
  7582. function axisLeft(scale) {
  7583. return axis(left, scale);
  7584. }
  7585. function defaultSeparation(a, b) {
  7586. return a.parent === b.parent ? 1 : 2;
  7587. }
  7588. function meanX(children) {
  7589. return children.reduce(meanXReduce, 0) / children.length;
  7590. }
  7591. function meanXReduce(x, c) {
  7592. return x + c.x;
  7593. }
  7594. function maxY(children) {
  7595. return 1 + children.reduce(maxYReduce, 0);
  7596. }
  7597. function maxYReduce(y, c) {
  7598. return Math.max(y, c.y);
  7599. }
  7600. function leafLeft(node) {
  7601. var children;
  7602. while (children = node.children) node = children[0];
  7603. return node;
  7604. }
  7605. function leafRight(node) {
  7606. var children;
  7607. while (children = node.children) node = children[children.length - 1];
  7608. return node;
  7609. }
  7610. function cluster() {
  7611. var separation = defaultSeparation,
  7612. dx = 1,
  7613. dy = 1,
  7614. nodeSize = false;
  7615. function cluster(root) {
  7616. var previousNode,
  7617. x = 0;
  7618. // First walk, computing the initial x & y values.
  7619. root.eachAfter(function(node) {
  7620. var children = node.children;
  7621. if (children) {
  7622. node.x = meanX(children);
  7623. node.y = maxY(children);
  7624. } else {
  7625. node.x = previousNode ? x += separation(node, previousNode) : 0;
  7626. node.y = 0;
  7627. previousNode = node;
  7628. }
  7629. });
  7630. var left = leafLeft(root),
  7631. right = leafRight(root),
  7632. x0 = left.x - separation(left, right) / 2,
  7633. x1 = right.x + separation(right, left) / 2;
  7634. // Second walk, normalizing x & y to the desired size.
  7635. return root.eachAfter(nodeSize ? function(node) {
  7636. node.x = (node.x - root.x) * dx;
  7637. node.y = (root.y - node.y) * dy;
  7638. } : function(node) {
  7639. node.x = (node.x - x0) / (x1 - x0) * dx;
  7640. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  7641. });
  7642. }
  7643. cluster.separation = function(x) {
  7644. return arguments.length ? (separation = x, cluster) : separation;
  7645. };
  7646. cluster.size = function(x) {
  7647. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  7648. };
  7649. cluster.nodeSize = function(x) {
  7650. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  7651. };
  7652. return cluster;
  7653. }
  7654. function node_each(callback) {
  7655. var node = this, current, next = [node], children, i, n;
  7656. do {
  7657. current = next.reverse(), next = [];
  7658. while (node = current.pop()) {
  7659. callback(node), children = node.children;
  7660. if (children) for (i = 0, n = children.length; i < n; ++i) {
  7661. next.push(children[i]);
  7662. }
  7663. }
  7664. } while (next.length);
  7665. return this;
  7666. }
  7667. function node_eachBefore(callback) {
  7668. var node = this, nodes = [node], children, i;
  7669. while (node = nodes.pop()) {
  7670. callback(node), children = node.children;
  7671. if (children) for (i = children.length - 1; i >= 0; --i) {
  7672. nodes.push(children[i]);
  7673. }
  7674. }
  7675. return this;
  7676. }
  7677. function node_eachAfter(callback) {
  7678. var node = this, nodes = [node], next = [], children, i, n;
  7679. while (node = nodes.pop()) {
  7680. next.push(node), children = node.children;
  7681. if (children) for (i = 0, n = children.length; i < n; ++i) {
  7682. nodes.push(children[i]);
  7683. }
  7684. }
  7685. while (node = next.pop()) {
  7686. callback(node);
  7687. }
  7688. return this;
  7689. }
  7690. function node_sum(value) {
  7691. return this.eachAfter(function(node) {
  7692. var sum = +value(node.data) || 0,
  7693. children = node.children,
  7694. i = children && children.length;
  7695. while (--i >= 0) sum += children[i].value;
  7696. node.value = sum;
  7697. });
  7698. }
  7699. function node_sort(compare) {
  7700. return this.eachBefore(function(node) {
  7701. if (node.children) {
  7702. node.children.sort(compare);
  7703. }
  7704. });
  7705. }
  7706. function node_path(end) {
  7707. var start = this,
  7708. ancestor = leastCommonAncestor(start, end),
  7709. nodes = [start];
  7710. while (start !== ancestor) {
  7711. start = start.parent;
  7712. nodes.push(start);
  7713. }
  7714. var k = nodes.length;
  7715. while (end !== ancestor) {
  7716. nodes.splice(k, 0, end);
  7717. end = end.parent;
  7718. }
  7719. return nodes;
  7720. }
  7721. function leastCommonAncestor(a, b) {
  7722. if (a === b) return a;
  7723. var aNodes = a.ancestors(),
  7724. bNodes = b.ancestors(),
  7725. c = null;
  7726. a = aNodes.pop();
  7727. b = bNodes.pop();
  7728. while (a === b) {
  7729. c = a;
  7730. a = aNodes.pop();
  7731. b = bNodes.pop();
  7732. }
  7733. return c;
  7734. }
  7735. function node_ancestors() {
  7736. var node = this, nodes = [node];
  7737. while (node = node.parent) {
  7738. nodes.push(node);
  7739. }
  7740. return nodes;
  7741. }
  7742. function node_descendants() {
  7743. var nodes = [];
  7744. this.each(function(node) {
  7745. nodes.push(node);
  7746. });
  7747. return nodes;
  7748. }
  7749. function node_leaves() {
  7750. var leaves = [];
  7751. this.eachBefore(function(node) {
  7752. if (!node.children) {
  7753. leaves.push(node);
  7754. }
  7755. });
  7756. return leaves;
  7757. }
  7758. function node_links() {
  7759. var root = this, links = [];
  7760. root.each(function(node) {
  7761. if (node !== root) { // Don’t include the root’s parent, if any.
  7762. links.push({source: node.parent, target: node});
  7763. }
  7764. });
  7765. return links;
  7766. }
  7767. function hierarchy(data, children) {
  7768. var root = new Node(data),
  7769. valued = +data.value && (root.value = data.value),
  7770. node,
  7771. nodes = [root],
  7772. child,
  7773. childs,
  7774. i,
  7775. n;
  7776. if (children == null) children = defaultChildren;
  7777. while (node = nodes.pop()) {
  7778. if (valued) node.value = +node.data.value;
  7779. if ((childs = children(node.data)) && (n = childs.length)) {
  7780. node.children = new Array(n);
  7781. for (i = n - 1; i >= 0; --i) {
  7782. nodes.push(child = node.children[i] = new Node(childs[i]));
  7783. child.parent = node;
  7784. child.depth = node.depth + 1;
  7785. }
  7786. }
  7787. }
  7788. return root.eachBefore(computeHeight);
  7789. }
  7790. function node_copy() {
  7791. return hierarchy(this).eachBefore(copyData);
  7792. }
  7793. function defaultChildren(d) {
  7794. return d.children;
  7795. }
  7796. function copyData(node) {
  7797. node.data = node.data.data;
  7798. }
  7799. function computeHeight(node) {
  7800. var height = 0;
  7801. do node.height = height;
  7802. while ((node = node.parent) && (node.height < ++height));
  7803. }
  7804. function Node(data) {
  7805. this.data = data;
  7806. this.depth =
  7807. this.height = 0;
  7808. this.parent = null;
  7809. }
  7810. Node.prototype = hierarchy.prototype = {
  7811. constructor: Node,
  7812. each: node_each,
  7813. eachAfter: node_eachAfter,
  7814. eachBefore: node_eachBefore,
  7815. sum: node_sum,
  7816. sort: node_sort,
  7817. path: node_path,
  7818. ancestors: node_ancestors,
  7819. descendants: node_descendants,
  7820. leaves: node_leaves,
  7821. links: node_links,
  7822. copy: node_copy
  7823. };
  7824. function Node$2(value) {
  7825. this._ = value;
  7826. this.next = null;
  7827. }
  7828. function shuffle$1(array) {
  7829. var i,
  7830. n = (array = array.slice()).length,
  7831. head = null,
  7832. node = head;
  7833. while (n) {
  7834. var next = new Node$2(array[n - 1]);
  7835. if (node) node = node.next = next;
  7836. else node = head = next;
  7837. array[i] = array[--n];
  7838. }
  7839. return {
  7840. head: head,
  7841. tail: node
  7842. };
  7843. }
  7844. function enclose(circles) {
  7845. return encloseN(shuffle$1(circles), []);
  7846. }
  7847. function encloses(a, b) {
  7848. var dx = b.x - a.x,
  7849. dy = b.y - a.y,
  7850. dr = a.r - b.r;
  7851. return dr * dr + 1e-6 > dx * dx + dy * dy;
  7852. }
  7853. // Returns the smallest circle that contains circles L and intersects circles B.
  7854. function encloseN(L, B) {
  7855. var circle,
  7856. l0 = null,
  7857. l1 = L.head,
  7858. l2,
  7859. p1;
  7860. switch (B.length) {
  7861. case 1: circle = enclose1(B[0]); break;
  7862. case 2: circle = enclose2(B[0], B[1]); break;
  7863. case 3: circle = enclose3(B[0], B[1], B[2]); break;
  7864. }
  7865. while (l1) {
  7866. p1 = l1._, l2 = l1.next;
  7867. if (!circle || !encloses(circle, p1)) {
  7868. // Temporarily truncate L before l1.
  7869. if (l0) L.tail = l0, l0.next = null;
  7870. else L.head = L.tail = null;
  7871. B.push(p1);
  7872. circle = encloseN(L, B); // Note: reorders L!
  7873. B.pop();
  7874. // Move l1 to the front of L and reconnect the truncated list L.
  7875. if (L.head) l1.next = L.head, L.head = l1;
  7876. else l1.next = null, L.head = L.tail = l1;
  7877. l0 = L.tail, l0.next = l2;
  7878. } else {
  7879. l0 = l1;
  7880. }
  7881. l1 = l2;
  7882. }
  7883. L.tail = l0;
  7884. return circle;
  7885. }
  7886. function enclose1(a) {
  7887. return {
  7888. x: a.x,
  7889. y: a.y,
  7890. r: a.r
  7891. };
  7892. }
  7893. function enclose2(a, b) {
  7894. var x1 = a.x, y1 = a.y, r1 = a.r,
  7895. x2 = b.x, y2 = b.y, r2 = b.r,
  7896. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  7897. l = Math.sqrt(x21 * x21 + y21 * y21);
  7898. return {
  7899. x: (x1 + x2 + x21 / l * r21) / 2,
  7900. y: (y1 + y2 + y21 / l * r21) / 2,
  7901. r: (l + r1 + r2) / 2
  7902. };
  7903. }
  7904. function enclose3(a, b, c) {
  7905. var x1 = a.x, y1 = a.y, r1 = a.r,
  7906. x2 = b.x, y2 = b.y, r2 = b.r,
  7907. x3 = c.x, y3 = c.y, r3 = c.r,
  7908. a2 = 2 * (x1 - x2),
  7909. b2 = 2 * (y1 - y2),
  7910. c2 = 2 * (r2 - r1),
  7911. d2 = x1 * x1 + y1 * y1 - r1 * r1 - x2 * x2 - y2 * y2 + r2 * r2,
  7912. a3 = 2 * (x1 - x3),
  7913. b3 = 2 * (y1 - y3),
  7914. c3 = 2 * (r3 - r1),
  7915. d3 = x1 * x1 + y1 * y1 - r1 * r1 - x3 * x3 - y3 * y3 + r3 * r3,
  7916. ab = a3 * b2 - a2 * b3,
  7917. xa = (b2 * d3 - b3 * d2) / ab - x1,
  7918. xb = (b3 * c2 - b2 * c3) / ab,
  7919. ya = (a3 * d2 - a2 * d3) / ab - y1,
  7920. yb = (a2 * c3 - a3 * c2) / ab,
  7921. A = xb * xb + yb * yb - 1,
  7922. B = 2 * (xa * xb + ya * yb + r1),
  7923. C = xa * xa + ya * ya - r1 * r1,
  7924. r = (-B - Math.sqrt(B * B - 4 * A * C)) / (2 * A);
  7925. return {
  7926. x: xa + xb * r + x1,
  7927. y: ya + yb * r + y1,
  7928. r: r
  7929. };
  7930. }
  7931. function place(a, b, c) {
  7932. var ax = a.x,
  7933. ay = a.y,
  7934. da = b.r + c.r,
  7935. db = a.r + c.r,
  7936. dx = b.x - ax,
  7937. dy = b.y - ay,
  7938. dc = dx * dx + dy * dy;
  7939. if (dc) {
  7940. var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
  7941. y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  7942. c.x = ax + x * dx + y * dy;
  7943. c.y = ay + x * dy - y * dx;
  7944. } else {
  7945. c.x = ax + db;
  7946. c.y = ay;
  7947. }
  7948. }
  7949. function intersects(a, b) {
  7950. var dx = b.x - a.x,
  7951. dy = b.y - a.y,
  7952. dr = a.r + b.r;
  7953. return dr * dr > dx * dx + dy * dy;
  7954. }
  7955. function distance2(circle, x, y) {
  7956. var dx = circle.x - x,
  7957. dy = circle.y - y;
  7958. return dx * dx + dy * dy;
  7959. }
  7960. function Node$1(circle) {
  7961. this._ = circle;
  7962. this.next = null;
  7963. this.previous = null;
  7964. }
  7965. function packEnclose(circles) {
  7966. if (!(n = circles.length)) return 0;
  7967. var a, b, c, n;
  7968. // Place the first circle.
  7969. a = circles[0], a.x = 0, a.y = 0;
  7970. if (!(n > 1)) return a.r;
  7971. // Place the second circle.
  7972. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  7973. if (!(n > 2)) return a.r + b.r;
  7974. // Place the third circle.
  7975. place(b, a, c = circles[2]);
  7976. // Initialize the weighted centroid.
  7977. var aa = a.r * a.r,
  7978. ba = b.r * b.r,
  7979. ca = c.r * c.r,
  7980. oa = aa + ba + ca,
  7981. ox = aa * a.x + ba * b.x + ca * c.x,
  7982. oy = aa * a.y + ba * b.y + ca * c.y,
  7983. cx, cy, i, j, k, sj, sk;
  7984. // Initialize the front-chain using the first three circles a, b and c.
  7985. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  7986. a.next = c.previous = b;
  7987. b.next = a.previous = c;
  7988. c.next = b.previous = a;
  7989. // Attempt to place each remaining circle…
  7990. pack: for (i = 3; i < n; ++i) {
  7991. place(a._, b._, c = circles[i]), c = new Node$1(c);
  7992. // If there are only three elements in the front-chain…
  7993. if ((k = a.previous) === (j = b.next)) {
  7994. // If the new circle intersects the third circle,
  7995. // rotate the front chain to try the next position.
  7996. if (intersects(j._, c._)) {
  7997. a = b, b = j, --i;
  7998. continue pack;
  7999. }
  8000. }
  8001. // Find the closest intersecting circle on the front-chain, if any.
  8002. else {
  8003. sj = j._.r, sk = k._.r;
  8004. do {
  8005. if (sj <= sk) {
  8006. if (intersects(j._, c._)) {
  8007. b = j, a.next = b, b.previous = a, --i;
  8008. continue pack;
  8009. }
  8010. j = j.next, sj += j._.r;
  8011. } else {
  8012. if (intersects(k._, c._)) {
  8013. a = k, a.next = b, b.previous = a, --i;
  8014. continue pack;
  8015. }
  8016. k = k.previous, sk += k._.r;
  8017. }
  8018. } while (j !== k.next);
  8019. }
  8020. // Success! Insert the new circle c between a and b.
  8021. c.previous = a, c.next = b, a.next = b.previous = b = c;
  8022. // Update the weighted centroid.
  8023. oa += ca = c._.r * c._.r;
  8024. ox += ca * c._.x;
  8025. oy += ca * c._.y;
  8026. // Compute the new closest circle a to centroid.
  8027. aa = distance2(a._, cx = ox / oa, cy = oy / oa);
  8028. while ((c = c.next) !== b) {
  8029. if ((ca = distance2(c._, cx, cy)) < aa) {
  8030. a = c, aa = ca;
  8031. }
  8032. }
  8033. b = a.next;
  8034. }
  8035. // Compute the enclosing circle of the front chain.
  8036. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  8037. // Translate the circles to put the enclosing circle around the origin.
  8038. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  8039. return c.r;
  8040. }
  8041. function siblings(circles) {
  8042. packEnclose(circles);
  8043. return circles;
  8044. }
  8045. function optional(f) {
  8046. return f == null ? null : required(f);
  8047. }
  8048. function required(f) {
  8049. if (typeof f !== "function") throw new Error;
  8050. return f;
  8051. }
  8052. function constantZero() {
  8053. return 0;
  8054. }
  8055. function constant$5(x) {
  8056. return function() {
  8057. return x;
  8058. };
  8059. }
  8060. function defaultRadius(d) {
  8061. return Math.sqrt(d.value);
  8062. }
  8063. function index() {
  8064. var radius = null,
  8065. dx = 1,
  8066. dy = 1,
  8067. padding = constantZero;
  8068. function pack(root) {
  8069. root.x = dx / 2, root.y = dy / 2;
  8070. if (radius) {
  8071. root.eachBefore(radiusLeaf(radius))
  8072. .eachAfter(packChildren(padding, 0.5))
  8073. .eachBefore(translateChild(1));
  8074. } else {
  8075. root.eachBefore(radiusLeaf(defaultRadius))
  8076. .eachAfter(packChildren(constantZero, 1))
  8077. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  8078. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  8079. }
  8080. return root;
  8081. }
  8082. pack.radius = function(x) {
  8083. return arguments.length ? (radius = optional(x), pack) : radius;
  8084. };
  8085. pack.size = function(x) {
  8086. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  8087. };
  8088. pack.padding = function(x) {
  8089. return arguments.length ? (padding = typeof x === "function" ? x : constant$5(+x), pack) : padding;
  8090. };
  8091. return pack;
  8092. }
  8093. function radiusLeaf(radius) {
  8094. return function(node) {
  8095. if (!node.children) {
  8096. node.r = Math.max(0, +radius(node) || 0);
  8097. }
  8098. };
  8099. }
  8100. function packChildren(padding, k) {
  8101. return function(node) {
  8102. if (children = node.children) {
  8103. var children,
  8104. i,
  8105. n = children.length,
  8106. r = padding(node) * k || 0,
  8107. e;
  8108. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  8109. e = packEnclose(children);
  8110. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  8111. node.r = e + r;
  8112. }
  8113. };
  8114. }
  8115. function translateChild(k) {
  8116. return function(node) {
  8117. var parent = node.parent;
  8118. node.r *= k;
  8119. if (parent) {
  8120. node.x = parent.x + k * node.x;
  8121. node.y = parent.y + k * node.y;
  8122. }
  8123. };
  8124. }
  8125. function roundNode(node) {
  8126. node.x0 = Math.round(node.x0);
  8127. node.y0 = Math.round(node.y0);
  8128. node.x1 = Math.round(node.x1);
  8129. node.y1 = Math.round(node.y1);
  8130. }
  8131. function treemapDice(parent, x0, y0, x1, y1) {
  8132. var nodes = parent.children,
  8133. node,
  8134. i = -1,
  8135. n = nodes.length,
  8136. k = parent.value && (x1 - x0) / parent.value;
  8137. while (++i < n) {
  8138. node = nodes[i], node.y0 = y0, node.y1 = y1;
  8139. node.x0 = x0, node.x1 = x0 += node.value * k;
  8140. }
  8141. }
  8142. function partition() {
  8143. var dx = 1,
  8144. dy = 1,
  8145. padding = 0,
  8146. round = false;
  8147. function partition(root) {
  8148. var n = root.height + 1;
  8149. root.x0 =
  8150. root.y0 = padding;
  8151. root.x1 = dx;
  8152. root.y1 = dy / n;
  8153. root.eachBefore(positionNode(dy, n));
  8154. if (round) root.eachBefore(roundNode);
  8155. return root;
  8156. }
  8157. function positionNode(dy, n) {
  8158. return function(node) {
  8159. if (node.children) {
  8160. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  8161. }
  8162. var x0 = node.x0,
  8163. y0 = node.y0,
  8164. x1 = node.x1 - padding,
  8165. y1 = node.y1 - padding;
  8166. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  8167. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  8168. node.x0 = x0;
  8169. node.y0 = y0;
  8170. node.x1 = x1;
  8171. node.y1 = y1;
  8172. };
  8173. }
  8174. partition.round = function(x) {
  8175. return arguments.length ? (round = !!x, partition) : round;
  8176. };
  8177. partition.size = function(x) {
  8178. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  8179. };
  8180. partition.padding = function(x) {
  8181. return arguments.length ? (padding = +x, partition) : padding;
  8182. };
  8183. return partition;
  8184. }
  8185. var keyPrefix$1 = "$";
  8186. var preroot = {depth: -1};
  8187. var ambiguous = {};
  8188. function defaultId(d) {
  8189. return d.id;
  8190. }
  8191. function defaultParentId(d) {
  8192. return d.parentId;
  8193. }
  8194. function stratify() {
  8195. var id = defaultId,
  8196. parentId = defaultParentId;
  8197. function stratify(data) {
  8198. var d,
  8199. i,
  8200. n = data.length,
  8201. root,
  8202. parent,
  8203. node,
  8204. nodes = new Array(n),
  8205. nodeId,
  8206. nodeKey,
  8207. nodeByKey = {};
  8208. for (i = 0; i < n; ++i) {
  8209. d = data[i], node = nodes[i] = new Node(d);
  8210. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  8211. nodeKey = keyPrefix$1 + (node.id = nodeId);
  8212. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  8213. }
  8214. }
  8215. for (i = 0; i < n; ++i) {
  8216. node = nodes[i], nodeId = parentId(data[i], i, data);
  8217. if (nodeId == null || !(nodeId += "")) {
  8218. if (root) throw new Error("multiple roots");
  8219. root = node;
  8220. } else {
  8221. parent = nodeByKey[keyPrefix$1 + nodeId];
  8222. if (!parent) throw new Error("missing: " + nodeId);
  8223. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  8224. if (parent.children) parent.children.push(node);
  8225. else parent.children = [node];
  8226. node.parent = parent;
  8227. }
  8228. }
  8229. if (!root) throw new Error("no root");
  8230. root.parent = preroot;
  8231. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  8232. root.parent = null;
  8233. if (n > 0) throw new Error("cycle");
  8234. return root;
  8235. }
  8236. stratify.id = function(x) {
  8237. return arguments.length ? (id = required(x), stratify) : id;
  8238. };
  8239. stratify.parentId = function(x) {
  8240. return arguments.length ? (parentId = required(x), stratify) : parentId;
  8241. };
  8242. return stratify;
  8243. }
  8244. function defaultSeparation$1(a, b) {
  8245. return a.parent === b.parent ? 1 : 2;
  8246. }
  8247. // function radialSeparation(a, b) {
  8248. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  8249. // }
  8250. // This function is used to traverse the left contour of a subtree (or
  8251. // subforest). It returns the successor of v on this contour. This successor is
  8252. // either given by the leftmost child of v or by the thread of v. The function
  8253. // returns null if and only if v is on the highest level of its subtree.
  8254. function nextLeft(v) {
  8255. var children = v.children;
  8256. return children ? children[0] : v.t;
  8257. }
  8258. // This function works analogously to nextLeft.
  8259. function nextRight(v) {
  8260. var children = v.children;
  8261. return children ? children[children.length - 1] : v.t;
  8262. }
  8263. // Shifts the current subtree rooted at w+. This is done by increasing
  8264. // prelim(w+) and mod(w+) by shift.
  8265. function moveSubtree(wm, wp, shift) {
  8266. var change = shift / (wp.i - wm.i);
  8267. wp.c -= change;
  8268. wp.s += shift;
  8269. wm.c += change;
  8270. wp.z += shift;
  8271. wp.m += shift;
  8272. }
  8273. // All other shifts, applied to the smaller subtrees between w- and w+, are
  8274. // performed by this function. To prepare the shifts, we have to adjust
  8275. // change(w+), shift(w+), and change(w-).
  8276. function executeShifts(v) {
  8277. var shift = 0,
  8278. change = 0,
  8279. children = v.children,
  8280. i = children.length,
  8281. w;
  8282. while (--i >= 0) {
  8283. w = children[i];
  8284. w.z += shift;
  8285. w.m += shift;
  8286. shift += w.s + (change += w.c);
  8287. }
  8288. }
  8289. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  8290. // returns the specified (default) ancestor.
  8291. function nextAncestor(vim, v, ancestor) {
  8292. return vim.a.parent === v.parent ? vim.a : ancestor;
  8293. }
  8294. function TreeNode(node, i) {
  8295. this._ = node;
  8296. this.parent = null;
  8297. this.children = null;
  8298. this.A = null; // default ancestor
  8299. this.a = this; // ancestor
  8300. this.z = 0; // prelim
  8301. this.m = 0; // mod
  8302. this.c = 0; // change
  8303. this.s = 0; // shift
  8304. this.t = null; // thread
  8305. this.i = i; // number
  8306. }
  8307. TreeNode.prototype = Object.create(Node.prototype);
  8308. function treeRoot(root) {
  8309. var tree = new TreeNode(root, 0),
  8310. node,
  8311. nodes = [tree],
  8312. child,
  8313. children,
  8314. i,
  8315. n;
  8316. while (node = nodes.pop()) {
  8317. if (children = node._.children) {
  8318. node.children = new Array(n = children.length);
  8319. for (i = n - 1; i >= 0; --i) {
  8320. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  8321. child.parent = node;
  8322. }
  8323. }
  8324. }
  8325. (tree.parent = new TreeNode(null, 0)).children = [tree];
  8326. return tree;
  8327. }
  8328. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  8329. function tree() {
  8330. var separation = defaultSeparation$1,
  8331. dx = 1,
  8332. dy = 1,
  8333. nodeSize = null;
  8334. function tree(root) {
  8335. var t = treeRoot(root);
  8336. // Compute the layout using Buchheim et al.’s algorithm.
  8337. t.eachAfter(firstWalk), t.parent.m = -t.z;
  8338. t.eachBefore(secondWalk);
  8339. // If a fixed node size is specified, scale x and y.
  8340. if (nodeSize) root.eachBefore(sizeNode);
  8341. // If a fixed tree size is specified, scale x and y based on the extent.
  8342. // Compute the left-most, right-most, and depth-most nodes for extents.
  8343. else {
  8344. var left = root,
  8345. right = root,
  8346. bottom = root;
  8347. root.eachBefore(function(node) {
  8348. if (node.x < left.x) left = node;
  8349. if (node.x > right.x) right = node;
  8350. if (node.depth > bottom.depth) bottom = node;
  8351. });
  8352. var s = left === right ? 1 : separation(left, right) / 2,
  8353. tx = s - left.x,
  8354. kx = dx / (right.x + s + tx),
  8355. ky = dy / (bottom.depth || 1);
  8356. root.eachBefore(function(node) {
  8357. node.x = (node.x + tx) * kx;
  8358. node.y = node.depth * ky;
  8359. });
  8360. }
  8361. return root;
  8362. }
  8363. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  8364. // applied recursively to the children of v, as well as the function
  8365. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  8366. // node v is placed to the midpoint of its outermost children.
  8367. function firstWalk(v) {
  8368. var children = v.children,
  8369. siblings = v.parent.children,
  8370. w = v.i ? siblings[v.i - 1] : null;
  8371. if (children) {
  8372. executeShifts(v);
  8373. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  8374. if (w) {
  8375. v.z = w.z + separation(v._, w._);
  8376. v.m = v.z - midpoint;
  8377. } else {
  8378. v.z = midpoint;
  8379. }
  8380. } else if (w) {
  8381. v.z = w.z + separation(v._, w._);
  8382. }
  8383. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  8384. }
  8385. // Computes all real x-coordinates by summing up the modifiers recursively.
  8386. function secondWalk(v) {
  8387. v._.x = v.z + v.parent.m;
  8388. v.m += v.parent.m;
  8389. }
  8390. // The core of the algorithm. Here, a new subtree is combined with the
  8391. // previous subtrees. Threads are used to traverse the inside and outside
  8392. // contours of the left and right subtree up to the highest common level. The
  8393. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  8394. // superscript o means outside and i means inside, the subscript - means left
  8395. // subtree and + means right subtree. For summing up the modifiers along the
  8396. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  8397. // nodes of the inside contours conflict, we compute the left one of the
  8398. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  8399. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  8400. // Finally, we add a new thread (if necessary).
  8401. function apportion(v, w, ancestor) {
  8402. if (w) {
  8403. var vip = v,
  8404. vop = v,
  8405. vim = w,
  8406. vom = vip.parent.children[0],
  8407. sip = vip.m,
  8408. sop = vop.m,
  8409. sim = vim.m,
  8410. som = vom.m,
  8411. shift;
  8412. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  8413. vom = nextLeft(vom);
  8414. vop = nextRight(vop);
  8415. vop.a = v;
  8416. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  8417. if (shift > 0) {
  8418. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  8419. sip += shift;
  8420. sop += shift;
  8421. }
  8422. sim += vim.m;
  8423. sip += vip.m;
  8424. som += vom.m;
  8425. sop += vop.m;
  8426. }
  8427. if (vim && !nextRight(vop)) {
  8428. vop.t = vim;
  8429. vop.m += sim - sop;
  8430. }
  8431. if (vip && !nextLeft(vom)) {
  8432. vom.t = vip;
  8433. vom.m += sip - som;
  8434. ancestor = v;
  8435. }
  8436. }
  8437. return ancestor;
  8438. }
  8439. function sizeNode(node) {
  8440. node.x *= dx;
  8441. node.y = node.depth * dy;
  8442. }
  8443. tree.separation = function(x) {
  8444. return arguments.length ? (separation = x, tree) : separation;
  8445. };
  8446. tree.size = function(x) {
  8447. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  8448. };
  8449. tree.nodeSize = function(x) {
  8450. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  8451. };
  8452. return tree;
  8453. }
  8454. function treemapSlice(parent, x0, y0, x1, y1) {
  8455. var nodes = parent.children,
  8456. node,
  8457. i = -1,
  8458. n = nodes.length,
  8459. k = parent.value && (y1 - y0) / parent.value;
  8460. while (++i < n) {
  8461. node = nodes[i], node.x0 = x0, node.x1 = x1;
  8462. node.y0 = y0, node.y1 = y0 += node.value * k;
  8463. }
  8464. }
  8465. var phi = (1 + Math.sqrt(5)) / 2;
  8466. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  8467. var rows = [],
  8468. nodes = parent.children,
  8469. row,
  8470. nodeValue,
  8471. i0 = 0,
  8472. i1,
  8473. n = nodes.length,
  8474. dx, dy,
  8475. value = parent.value,
  8476. sumValue,
  8477. minValue,
  8478. maxValue,
  8479. newRatio,
  8480. minRatio,
  8481. alpha,
  8482. beta;
  8483. while (i0 < n) {
  8484. dx = x1 - x0, dy = y1 - y0;
  8485. minValue = maxValue = sumValue = nodes[i0].value;
  8486. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  8487. beta = sumValue * sumValue * alpha;
  8488. minRatio = Math.max(maxValue / beta, beta / minValue);
  8489. // Keep adding nodes while the aspect ratio maintains or improves.
  8490. for (i1 = i0 + 1; i1 < n; ++i1) {
  8491. sumValue += nodeValue = nodes[i1].value;
  8492. if (nodeValue < minValue) minValue = nodeValue;
  8493. if (nodeValue > maxValue) maxValue = nodeValue;
  8494. beta = sumValue * sumValue * alpha;
  8495. newRatio = Math.max(maxValue / beta, beta / minValue);
  8496. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  8497. minRatio = newRatio;
  8498. }
  8499. // Position and record the row orientation.
  8500. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  8501. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  8502. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  8503. value -= sumValue, i0 = i1;
  8504. }
  8505. return rows;
  8506. }
  8507. var squarify = (function custom(ratio) {
  8508. function squarify(parent, x0, y0, x1, y1) {
  8509. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  8510. }
  8511. squarify.ratio = function(x) {
  8512. return custom((x = +x) > 1 ? x : 1);
  8513. };
  8514. return squarify;
  8515. })(phi);
  8516. function index$1() {
  8517. var tile = squarify,
  8518. round = false,
  8519. dx = 1,
  8520. dy = 1,
  8521. paddingStack = [0],
  8522. paddingInner = constantZero,
  8523. paddingTop = constantZero,
  8524. paddingRight = constantZero,
  8525. paddingBottom = constantZero,
  8526. paddingLeft = constantZero;
  8527. function treemap(root) {
  8528. root.x0 =
  8529. root.y0 = 0;
  8530. root.x1 = dx;
  8531. root.y1 = dy;
  8532. root.eachBefore(positionNode);
  8533. paddingStack = [0];
  8534. if (round) root.eachBefore(roundNode);
  8535. return root;
  8536. }
  8537. function positionNode(node) {
  8538. var p = paddingStack[node.depth],
  8539. x0 = node.x0 + p,
  8540. y0 = node.y0 + p,
  8541. x1 = node.x1 - p,
  8542. y1 = node.y1 - p;
  8543. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  8544. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  8545. node.x0 = x0;
  8546. node.y0 = y0;
  8547. node.x1 = x1;
  8548. node.y1 = y1;
  8549. if (node.children) {
  8550. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  8551. x0 += paddingLeft(node) - p;
  8552. y0 += paddingTop(node) - p;
  8553. x1 -= paddingRight(node) - p;
  8554. y1 -= paddingBottom(node) - p;
  8555. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  8556. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  8557. tile(node, x0, y0, x1, y1);
  8558. }
  8559. }
  8560. treemap.round = function(x) {
  8561. return arguments.length ? (round = !!x, treemap) : round;
  8562. };
  8563. treemap.size = function(x) {
  8564. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  8565. };
  8566. treemap.tile = function(x) {
  8567. return arguments.length ? (tile = required(x), treemap) : tile;
  8568. };
  8569. treemap.padding = function(x) {
  8570. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  8571. };
  8572. treemap.paddingInner = function(x) {
  8573. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$5(+x), treemap) : paddingInner;
  8574. };
  8575. treemap.paddingOuter = function(x) {
  8576. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  8577. };
  8578. treemap.paddingTop = function(x) {
  8579. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$5(+x), treemap) : paddingTop;
  8580. };
  8581. treemap.paddingRight = function(x) {
  8582. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$5(+x), treemap) : paddingRight;
  8583. };
  8584. treemap.paddingBottom = function(x) {
  8585. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$5(+x), treemap) : paddingBottom;
  8586. };
  8587. treemap.paddingLeft = function(x) {
  8588. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$5(+x), treemap) : paddingLeft;
  8589. };
  8590. return treemap;
  8591. }
  8592. function binary(parent, x0, y0, x1, y1) {
  8593. var nodes = parent.children,
  8594. i, n = nodes.length,
  8595. sum, sums = new Array(n + 1);
  8596. for (sums[0] = sum = i = 0; i < n; ++i) {
  8597. sums[i + 1] = sum += nodes[i].value;
  8598. }
  8599. partition(0, n, parent.value, x0, y0, x1, y1);
  8600. function partition(i, j, value, x0, y0, x1, y1) {
  8601. if (i >= j - 1) {
  8602. var node = nodes[i];
  8603. node.x0 = x0, node.y0 = y0;
  8604. node.x1 = x1, node.y1 = y1;
  8605. return;
  8606. }
  8607. var valueOffset = sums[i],
  8608. valueTarget = (value / 2) + valueOffset,
  8609. k = i + 1,
  8610. hi = j - 1;
  8611. while (k < hi) {
  8612. var mid = k + hi >>> 1;
  8613. if (sums[mid] < valueTarget) k = mid + 1;
  8614. else hi = mid;
  8615. }
  8616. var valueLeft = sums[k] - valueOffset,
  8617. valueRight = value - valueLeft;
  8618. if ((y1 - y0) > (x1 - x0)) {
  8619. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  8620. partition(i, k, valueLeft, x0, y0, x1, yk);
  8621. partition(k, j, valueRight, x0, yk, x1, y1);
  8622. } else {
  8623. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  8624. partition(i, k, valueLeft, x0, y0, xk, y1);
  8625. partition(k, j, valueRight, xk, y0, x1, y1);
  8626. }
  8627. }
  8628. }
  8629. function sliceDice(parent, x0, y0, x1, y1) {
  8630. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  8631. }
  8632. var resquarify = (function custom(ratio) {
  8633. function resquarify(parent, x0, y0, x1, y1) {
  8634. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  8635. var rows,
  8636. row,
  8637. nodes,
  8638. i,
  8639. j = -1,
  8640. n,
  8641. m = rows.length,
  8642. value = parent.value;
  8643. while (++j < m) {
  8644. row = rows[j], nodes = row.children;
  8645. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  8646. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  8647. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  8648. value -= row.value;
  8649. }
  8650. } else {
  8651. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  8652. rows.ratio = ratio;
  8653. }
  8654. }
  8655. resquarify.ratio = function(x) {
  8656. return custom((x = +x) > 1 ? x : 1);
  8657. };
  8658. return resquarify;
  8659. })(phi);
  8660. function center$1(x, y) {
  8661. var nodes;
  8662. if (x == null) x = 0;
  8663. if (y == null) y = 0;
  8664. function force() {
  8665. var i,
  8666. n = nodes.length,
  8667. node,
  8668. sx = 0,
  8669. sy = 0;
  8670. for (i = 0; i < n; ++i) {
  8671. node = nodes[i], sx += node.x, sy += node.y;
  8672. }
  8673. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  8674. node = nodes[i], node.x -= sx, node.y -= sy;
  8675. }
  8676. }
  8677. force.initialize = function(_) {
  8678. nodes = _;
  8679. };
  8680. force.x = function(_) {
  8681. return arguments.length ? (x = +_, force) : x;
  8682. };
  8683. force.y = function(_) {
  8684. return arguments.length ? (y = +_, force) : y;
  8685. };
  8686. return force;
  8687. }
  8688. function constant$6(x) {
  8689. return function() {
  8690. return x;
  8691. };
  8692. }
  8693. function jiggle() {
  8694. return (Math.random() - 0.5) * 1e-6;
  8695. }
  8696. function x$1(d) {
  8697. return d.x + d.vx;
  8698. }
  8699. function y$1(d) {
  8700. return d.y + d.vy;
  8701. }
  8702. function collide(radius) {
  8703. var nodes,
  8704. radii,
  8705. strength = 1,
  8706. iterations = 1;
  8707. if (typeof radius !== "function") radius = constant$6(radius == null ? 1 : +radius);
  8708. function force() {
  8709. var i, n = nodes.length,
  8710. tree,
  8711. node,
  8712. xi,
  8713. yi,
  8714. ri,
  8715. ri2;
  8716. for (var k = 0; k < iterations; ++k) {
  8717. tree = quadtree(nodes, x$1, y$1).visitAfter(prepare);
  8718. for (i = 0; i < n; ++i) {
  8719. node = nodes[i];
  8720. ri = radii[i], ri2 = ri * ri;
  8721. xi = node.x + node.vx;
  8722. yi = node.y + node.vy;
  8723. tree.visit(apply);
  8724. }
  8725. }
  8726. function apply(quad, x0, y0, x1, y1) {
  8727. var data = quad.data, rj = quad.r, r = ri + rj;
  8728. if (data) {
  8729. if (data.index > i) {
  8730. var x = xi - data.x - data.vx,
  8731. y = yi - data.y - data.vy,
  8732. l = x * x + y * y;
  8733. if (l < r * r) {
  8734. if (x === 0) x = jiggle(), l += x * x;
  8735. if (y === 0) y = jiggle(), l += y * y;
  8736. l = (r - (l = Math.sqrt(l))) / l * strength;
  8737. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  8738. node.vy += (y *= l) * r;
  8739. data.vx -= x * (r = 1 - r);
  8740. data.vy -= y * r;
  8741. }
  8742. }
  8743. return;
  8744. }
  8745. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  8746. }
  8747. }
  8748. function prepare(quad) {
  8749. if (quad.data) return quad.r = radii[quad.data.index];
  8750. for (var i = quad.r = 0; i < 4; ++i) {
  8751. if (quad[i] && quad[i].r > quad.r) {
  8752. quad.r = quad[i].r;
  8753. }
  8754. }
  8755. }
  8756. force.initialize = function(_) {
  8757. var i, n = (nodes = _).length; radii = new Array(n);
  8758. for (i = 0; i < n; ++i) radii[i] = +radius(nodes[i], i, nodes);
  8759. };
  8760. force.iterations = function(_) {
  8761. return arguments.length ? (iterations = +_, force) : iterations;
  8762. };
  8763. force.strength = function(_) {
  8764. return arguments.length ? (strength = +_, force) : strength;
  8765. };
  8766. force.radius = function(_) {
  8767. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), force) : radius;
  8768. };
  8769. return force;
  8770. }
  8771. function index$2(d, i) {
  8772. return i;
  8773. }
  8774. function link(links) {
  8775. var id = index$2,
  8776. strength = defaultStrength,
  8777. strengths,
  8778. distance = constant$6(30),
  8779. distances,
  8780. nodes,
  8781. count,
  8782. bias,
  8783. iterations = 1;
  8784. if (links == null) links = [];
  8785. function defaultStrength(link) {
  8786. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  8787. }
  8788. function force(alpha) {
  8789. for (var k = 0, n = links.length; k < iterations; ++k) {
  8790. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  8791. link = links[i], source = link.source, target = link.target;
  8792. x = target.x + target.vx - source.x - source.vx || jiggle();
  8793. y = target.y + target.vy - source.y - source.vy || jiggle();
  8794. l = Math.sqrt(x * x + y * y);
  8795. l = (l - distances[i]) / l * alpha * strengths[i];
  8796. x *= l, y *= l;
  8797. target.vx -= x * (b = bias[i]);
  8798. target.vy -= y * b;
  8799. source.vx += x * (b = 1 - b);
  8800. source.vy += y * b;
  8801. }
  8802. }
  8803. }
  8804. function initialize() {
  8805. if (!nodes) return;
  8806. var i,
  8807. n = nodes.length,
  8808. m = links.length,
  8809. nodeById = map$1(nodes, id),
  8810. link;
  8811. for (i = 0, count = new Array(n); i < n; ++i) {
  8812. count[i] = 0;
  8813. }
  8814. for (i = 0; i < m; ++i) {
  8815. link = links[i], link.index = i;
  8816. if (typeof link.source !== "object") link.source = nodeById.get(link.source);
  8817. if (typeof link.target !== "object") link.target = nodeById.get(link.target);
  8818. ++count[link.source.index], ++count[link.target.index];
  8819. }
  8820. for (i = 0, bias = new Array(m); i < m; ++i) {
  8821. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  8822. }
  8823. strengths = new Array(m), initializeStrength();
  8824. distances = new Array(m), initializeDistance();
  8825. }
  8826. function initializeStrength() {
  8827. if (!nodes) return;
  8828. for (var i = 0, n = links.length; i < n; ++i) {
  8829. strengths[i] = +strength(links[i], i, links);
  8830. }
  8831. }
  8832. function initializeDistance() {
  8833. if (!nodes) return;
  8834. for (var i = 0, n = links.length; i < n; ++i) {
  8835. distances[i] = +distance(links[i], i, links);
  8836. }
  8837. }
  8838. force.initialize = function(_) {
  8839. nodes = _;
  8840. initialize();
  8841. };
  8842. force.links = function(_) {
  8843. return arguments.length ? (links = _, initialize(), force) : links;
  8844. };
  8845. force.id = function(_) {
  8846. return arguments.length ? (id = _, force) : id;
  8847. };
  8848. force.iterations = function(_) {
  8849. return arguments.length ? (iterations = +_, force) : iterations;
  8850. };
  8851. force.strength = function(_) {
  8852. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initializeStrength(), force) : strength;
  8853. };
  8854. force.distance = function(_) {
  8855. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$6(+_), initializeDistance(), force) : distance;
  8856. };
  8857. return force;
  8858. }
  8859. function x$2(d) {
  8860. return d.x;
  8861. }
  8862. function y$2(d) {
  8863. return d.y;
  8864. }
  8865. var initialRadius = 10;
  8866. var initialAngle = Math.PI * (3 - Math.sqrt(5));
  8867. function simulation(nodes) {
  8868. var simulation,
  8869. alpha = 1,
  8870. alphaMin = 0.001,
  8871. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  8872. alphaTarget = 0,
  8873. velocityDecay = 0.6,
  8874. forces = map$1(),
  8875. stepper = timer(step),
  8876. event = dispatch("tick", "end");
  8877. if (nodes == null) nodes = [];
  8878. function step() {
  8879. tick();
  8880. event.call("tick", simulation);
  8881. if (alpha < alphaMin) {
  8882. stepper.stop();
  8883. event.call("end", simulation);
  8884. }
  8885. }
  8886. function tick() {
  8887. var i, n = nodes.length, node;
  8888. alpha += (alphaTarget - alpha) * alphaDecay;
  8889. forces.each(function(force) {
  8890. force(alpha);
  8891. });
  8892. for (i = 0; i < n; ++i) {
  8893. node = nodes[i];
  8894. if (node.fx == null) node.x += node.vx *= velocityDecay;
  8895. else node.x = node.fx, node.vx = 0;
  8896. if (node.fy == null) node.y += node.vy *= velocityDecay;
  8897. else node.y = node.fy, node.vy = 0;
  8898. }
  8899. }
  8900. function initializeNodes() {
  8901. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  8902. node = nodes[i], node.index = i;
  8903. if (isNaN(node.x) || isNaN(node.y)) {
  8904. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  8905. node.x = radius * Math.cos(angle);
  8906. node.y = radius * Math.sin(angle);
  8907. }
  8908. if (isNaN(node.vx) || isNaN(node.vy)) {
  8909. node.vx = node.vy = 0;
  8910. }
  8911. }
  8912. }
  8913. function initializeForce(force) {
  8914. if (force.initialize) force.initialize(nodes);
  8915. return force;
  8916. }
  8917. initializeNodes();
  8918. return simulation = {
  8919. tick: tick,
  8920. restart: function() {
  8921. return stepper.restart(step), simulation;
  8922. },
  8923. stop: function() {
  8924. return stepper.stop(), simulation;
  8925. },
  8926. nodes: function(_) {
  8927. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  8928. },
  8929. alpha: function(_) {
  8930. return arguments.length ? (alpha = +_, simulation) : alpha;
  8931. },
  8932. alphaMin: function(_) {
  8933. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  8934. },
  8935. alphaDecay: function(_) {
  8936. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  8937. },
  8938. alphaTarget: function(_) {
  8939. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  8940. },
  8941. velocityDecay: function(_) {
  8942. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  8943. },
  8944. force: function(name, _) {
  8945. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  8946. },
  8947. find: function(x, y, radius) {
  8948. var i = 0,
  8949. n = nodes.length,
  8950. dx,
  8951. dy,
  8952. d2,
  8953. node,
  8954. closest;
  8955. if (radius == null) radius = Infinity;
  8956. else radius *= radius;
  8957. for (i = 0; i < n; ++i) {
  8958. node = nodes[i];
  8959. dx = x - node.x;
  8960. dy = y - node.y;
  8961. d2 = dx * dx + dy * dy;
  8962. if (d2 < radius) closest = node, radius = d2;
  8963. }
  8964. return closest;
  8965. },
  8966. on: function(name, _) {
  8967. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  8968. }
  8969. };
  8970. }
  8971. function manyBody() {
  8972. var nodes,
  8973. node,
  8974. alpha,
  8975. strength = constant$6(-30),
  8976. strengths,
  8977. distanceMin2 = 1,
  8978. distanceMax2 = Infinity,
  8979. theta2 = 0.81;
  8980. function force(_) {
  8981. var i, n = nodes.length, tree = quadtree(nodes, x$2, y$2).visitAfter(accumulate);
  8982. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  8983. }
  8984. function initialize() {
  8985. if (!nodes) return;
  8986. var i, n = nodes.length;
  8987. strengths = new Array(n);
  8988. for (i = 0; i < n; ++i) strengths[i] = +strength(nodes[i], i, nodes);
  8989. }
  8990. function accumulate(quad) {
  8991. var strength = 0, q, c, x, y, i;
  8992. // For internal nodes, accumulate forces from child quadrants.
  8993. if (quad.length) {
  8994. for (x = y = i = 0; i < 4; ++i) {
  8995. if ((q = quad[i]) && (c = q.value)) {
  8996. strength += c, x += c * q.x, y += c * q.y;
  8997. }
  8998. }
  8999. quad.x = x / strength;
  9000. quad.y = y / strength;
  9001. }
  9002. // For leaf nodes, accumulate forces from coincident quadrants.
  9003. else {
  9004. q = quad;
  9005. q.x = q.data.x;
  9006. q.y = q.data.y;
  9007. do strength += strengths[q.data.index];
  9008. while (q = q.next);
  9009. }
  9010. quad.value = strength;
  9011. }
  9012. function apply(quad, x1, _, x2) {
  9013. if (!quad.value) return true;
  9014. var x = quad.x - node.x,
  9015. y = quad.y - node.y,
  9016. w = x2 - x1,
  9017. l = x * x + y * y;
  9018. // Apply the Barnes-Hut approximation if possible.
  9019. // Limit forces for very close nodes; randomize direction if coincident.
  9020. if (w * w / theta2 < l) {
  9021. if (l < distanceMax2) {
  9022. if (x === 0) x = jiggle(), l += x * x;
  9023. if (y === 0) y = jiggle(), l += y * y;
  9024. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  9025. node.vx += x * quad.value * alpha / l;
  9026. node.vy += y * quad.value * alpha / l;
  9027. }
  9028. return true;
  9029. }
  9030. // Otherwise, process points directly.
  9031. else if (quad.length || l >= distanceMax2) return;
  9032. // Limit forces for very close nodes; randomize direction if coincident.
  9033. if (quad.data !== node || quad.next) {
  9034. if (x === 0) x = jiggle(), l += x * x;
  9035. if (y === 0) y = jiggle(), l += y * y;
  9036. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  9037. }
  9038. do if (quad.data !== node) {
  9039. w = strengths[quad.data.index] * alpha / l;
  9040. node.vx += x * w;
  9041. node.vy += y * w;
  9042. } while (quad = quad.next);
  9043. }
  9044. force.initialize = function(_) {
  9045. nodes = _;
  9046. initialize();
  9047. };
  9048. force.strength = function(_) {
  9049. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  9050. };
  9051. force.distanceMin = function(_) {
  9052. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  9053. };
  9054. force.distanceMax = function(_) {
  9055. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  9056. };
  9057. force.theta = function(_) {
  9058. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  9059. };
  9060. return force;
  9061. }
  9062. function x$3(x) {
  9063. var strength = constant$6(0.1),
  9064. nodes,
  9065. strengths,
  9066. xz;
  9067. if (typeof x !== "function") x = constant$6(x == null ? 0 : +x);
  9068. function force(alpha) {
  9069. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  9070. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  9071. }
  9072. }
  9073. function initialize() {
  9074. if (!nodes) return;
  9075. var i, n = nodes.length;
  9076. strengths = new Array(n);
  9077. xz = new Array(n);
  9078. for (i = 0; i < n; ++i) {
  9079. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  9080. }
  9081. }
  9082. force.initialize = function(_) {
  9083. nodes = _;
  9084. initialize();
  9085. };
  9086. force.strength = function(_) {
  9087. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  9088. };
  9089. force.x = function(_) {
  9090. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : x;
  9091. };
  9092. return force;
  9093. }
  9094. function y$3(y) {
  9095. var strength = constant$6(0.1),
  9096. nodes,
  9097. strengths,
  9098. yz;
  9099. if (typeof y !== "function") y = constant$6(y == null ? 0 : +y);
  9100. function force(alpha) {
  9101. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  9102. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  9103. }
  9104. }
  9105. function initialize() {
  9106. if (!nodes) return;
  9107. var i, n = nodes.length;
  9108. strengths = new Array(n);
  9109. yz = new Array(n);
  9110. for (i = 0; i < n; ++i) {
  9111. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  9112. }
  9113. }
  9114. force.initialize = function(_) {
  9115. nodes = _;
  9116. initialize();
  9117. };
  9118. force.strength = function(_) {
  9119. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
  9120. };
  9121. force.y = function(_) {
  9122. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : y;
  9123. };
  9124. return force;
  9125. }
  9126. function nopropagation() {
  9127. exports.event.stopImmediatePropagation();
  9128. }
  9129. function noevent() {
  9130. exports.event.preventDefault();
  9131. exports.event.stopImmediatePropagation();
  9132. }
  9133. function dragDisable(view) {
  9134. var root = view.document.documentElement,
  9135. selection = select(view).on("dragstart.drag", noevent, true);
  9136. if ("onselectstart" in root) {
  9137. selection.on("selectstart.drag", noevent, true);
  9138. } else {
  9139. root.__noselect = root.style.MozUserSelect;
  9140. root.style.MozUserSelect = "none";
  9141. }
  9142. }
  9143. function dragEnable(view, noclick) {
  9144. var root = view.document.documentElement,
  9145. selection = select(view).on("dragstart.drag", null);
  9146. if (noclick) {
  9147. selection.on("click.drag", noevent, true);
  9148. setTimeout(function() { selection.on("click.drag", null); }, 0);
  9149. }
  9150. if ("onselectstart" in root) {
  9151. selection.on("selectstart.drag", null);
  9152. } else {
  9153. root.style.MozUserSelect = root.__noselect;
  9154. delete root.__noselect;
  9155. }
  9156. }
  9157. function constant$7(x) {
  9158. return function() {
  9159. return x;
  9160. };
  9161. }
  9162. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  9163. this.target = target;
  9164. this.type = type;
  9165. this.subject = subject;
  9166. this.identifier = id;
  9167. this.active = active;
  9168. this.x = x;
  9169. this.y = y;
  9170. this.dx = dx;
  9171. this.dy = dy;
  9172. this._ = dispatch;
  9173. }
  9174. DragEvent.prototype.on = function() {
  9175. var value = this._.on.apply(this._, arguments);
  9176. return value === this._ ? this : value;
  9177. };
  9178. // Ignore right-click, since that should open the context menu.
  9179. function defaultFilter() {
  9180. return !exports.event.button;
  9181. }
  9182. function defaultContainer() {
  9183. return this.parentNode;
  9184. }
  9185. function defaultSubject(d) {
  9186. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  9187. }
  9188. function drag() {
  9189. var filter = defaultFilter,
  9190. container = defaultContainer,
  9191. subject = defaultSubject,
  9192. gestures = {},
  9193. listeners = dispatch("start", "drag", "end"),
  9194. active = 0,
  9195. mousemoving,
  9196. touchending;
  9197. function drag(selection) {
  9198. selection
  9199. .on("mousedown.drag", mousedowned)
  9200. .on("touchstart.drag", touchstarted)
  9201. .on("touchmove.drag", touchmoved)
  9202. .on("touchend.drag touchcancel.drag", touchended)
  9203. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  9204. }
  9205. function mousedowned() {
  9206. if (touchending || !filter.apply(this, arguments)) return;
  9207. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  9208. if (!gesture) return;
  9209. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  9210. dragDisable(exports.event.view);
  9211. nopropagation();
  9212. mousemoving = false;
  9213. gesture("start");
  9214. }
  9215. function mousemoved() {
  9216. noevent();
  9217. mousemoving = true;
  9218. gestures.mouse("drag");
  9219. }
  9220. function mouseupped() {
  9221. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  9222. dragEnable(exports.event.view, mousemoving);
  9223. noevent();
  9224. gestures.mouse("end");
  9225. }
  9226. function touchstarted() {
  9227. if (!filter.apply(this, arguments)) return;
  9228. var touches = exports.event.changedTouches,
  9229. c = container.apply(this, arguments),
  9230. n = touches.length, i, gesture;
  9231. for (i = 0; i < n; ++i) {
  9232. if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
  9233. nopropagation();
  9234. gesture("start");
  9235. }
  9236. }
  9237. }
  9238. function touchmoved() {
  9239. var touches = exports.event.changedTouches,
  9240. n = touches.length, i, gesture;
  9241. for (i = 0; i < n; ++i) {
  9242. if (gesture = gestures[touches[i].identifier]) {
  9243. noevent();
  9244. gesture("drag");
  9245. }
  9246. }
  9247. }
  9248. function touchended() {
  9249. var touches = exports.event.changedTouches,
  9250. n = touches.length, i, gesture;
  9251. if (touchending) clearTimeout(touchending);
  9252. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  9253. for (i = 0; i < n; ++i) {
  9254. if (gesture = gestures[touches[i].identifier]) {
  9255. nopropagation();
  9256. gesture("end");
  9257. }
  9258. }
  9259. }
  9260. function beforestart(id, container, point, that, args) {
  9261. var p = point(container, id), s, dx, dy,
  9262. sublisteners = listeners.copy();
  9263. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  9264. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  9265. dx = s.x - p[0] || 0;
  9266. dy = s.y - p[1] || 0;
  9267. return true;
  9268. })) return;
  9269. return function gesture(type) {
  9270. var p0 = p, n;
  9271. switch (type) {
  9272. case "start": gestures[id] = gesture, n = active++; break;
  9273. case "end": delete gestures[id], --active; // nobreak
  9274. case "drag": p = point(container, id), n = active; break;
  9275. }
  9276. 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]);
  9277. };
  9278. }
  9279. drag.filter = function(_) {
  9280. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$7(!!_), drag) : filter;
  9281. };
  9282. drag.container = function(_) {
  9283. return arguments.length ? (container = typeof _ === "function" ? _ : constant$7(_), drag) : container;
  9284. };
  9285. drag.subject = function(_) {
  9286. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$7(_), drag) : subject;
  9287. };
  9288. drag.on = function() {
  9289. var value = listeners.on.apply(listeners, arguments);
  9290. return value === listeners ? drag : value;
  9291. };
  9292. return drag;
  9293. }
  9294. function constant$8(x) {
  9295. return function() {
  9296. return x;
  9297. };
  9298. }
  9299. function x$4(d) {
  9300. return d[0];
  9301. }
  9302. function y$4(d) {
  9303. return d[1];
  9304. }
  9305. function RedBlackTree() {
  9306. this._ = null; // root node
  9307. }
  9308. function RedBlackNode(node) {
  9309. node.U = // parent node
  9310. node.C = // color - true for red, false for black
  9311. node.L = // left node
  9312. node.R = // right node
  9313. node.P = // previous node
  9314. node.N = null; // next node
  9315. }
  9316. RedBlackTree.prototype = {
  9317. constructor: RedBlackTree,
  9318. insert: function(after, node) {
  9319. var parent, grandpa, uncle;
  9320. if (after) {
  9321. node.P = after;
  9322. node.N = after.N;
  9323. if (after.N) after.N.P = node;
  9324. after.N = node;
  9325. if (after.R) {
  9326. after = after.R;
  9327. while (after.L) after = after.L;
  9328. after.L = node;
  9329. } else {
  9330. after.R = node;
  9331. }
  9332. parent = after;
  9333. } else if (this._) {
  9334. after = RedBlackFirst(this._);
  9335. node.P = null;
  9336. node.N = after;
  9337. after.P = after.L = node;
  9338. parent = after;
  9339. } else {
  9340. node.P = node.N = null;
  9341. this._ = node;
  9342. parent = null;
  9343. }
  9344. node.L = node.R = null;
  9345. node.U = parent;
  9346. node.C = true;
  9347. after = node;
  9348. while (parent && parent.C) {
  9349. grandpa = parent.U;
  9350. if (parent === grandpa.L) {
  9351. uncle = grandpa.R;
  9352. if (uncle && uncle.C) {
  9353. parent.C = uncle.C = false;
  9354. grandpa.C = true;
  9355. after = grandpa;
  9356. } else {
  9357. if (after === parent.R) {
  9358. RedBlackRotateLeft(this, parent);
  9359. after = parent;
  9360. parent = after.U;
  9361. }
  9362. parent.C = false;
  9363. grandpa.C = true;
  9364. RedBlackRotateRight(this, grandpa);
  9365. }
  9366. } else {
  9367. uncle = grandpa.L;
  9368. if (uncle && uncle.C) {
  9369. parent.C = uncle.C = false;
  9370. grandpa.C = true;
  9371. after = grandpa;
  9372. } else {
  9373. if (after === parent.L) {
  9374. RedBlackRotateRight(this, parent);
  9375. after = parent;
  9376. parent = after.U;
  9377. }
  9378. parent.C = false;
  9379. grandpa.C = true;
  9380. RedBlackRotateLeft(this, grandpa);
  9381. }
  9382. }
  9383. parent = after.U;
  9384. }
  9385. this._.C = false;
  9386. },
  9387. remove: function(node) {
  9388. if (node.N) node.N.P = node.P;
  9389. if (node.P) node.P.N = node.N;
  9390. node.N = node.P = null;
  9391. var parent = node.U,
  9392. sibling,
  9393. left = node.L,
  9394. right = node.R,
  9395. next,
  9396. red;
  9397. if (!left) next = right;
  9398. else if (!right) next = left;
  9399. else next = RedBlackFirst(right);
  9400. if (parent) {
  9401. if (parent.L === node) parent.L = next;
  9402. else parent.R = next;
  9403. } else {
  9404. this._ = next;
  9405. }
  9406. if (left && right) {
  9407. red = next.C;
  9408. next.C = node.C;
  9409. next.L = left;
  9410. left.U = next;
  9411. if (next !== right) {
  9412. parent = next.U;
  9413. next.U = node.U;
  9414. node = next.R;
  9415. parent.L = node;
  9416. next.R = right;
  9417. right.U = next;
  9418. } else {
  9419. next.U = parent;
  9420. parent = next;
  9421. node = next.R;
  9422. }
  9423. } else {
  9424. red = node.C;
  9425. node = next;
  9426. }
  9427. if (node) node.U = parent;
  9428. if (red) return;
  9429. if (node && node.C) { node.C = false; return; }
  9430. do {
  9431. if (node === this._) break;
  9432. if (node === parent.L) {
  9433. sibling = parent.R;
  9434. if (sibling.C) {
  9435. sibling.C = false;
  9436. parent.C = true;
  9437. RedBlackRotateLeft(this, parent);
  9438. sibling = parent.R;
  9439. }
  9440. if ((sibling.L && sibling.L.C)
  9441. || (sibling.R && sibling.R.C)) {
  9442. if (!sibling.R || !sibling.R.C) {
  9443. sibling.L.C = false;
  9444. sibling.C = true;
  9445. RedBlackRotateRight(this, sibling);
  9446. sibling = parent.R;
  9447. }
  9448. sibling.C = parent.C;
  9449. parent.C = sibling.R.C = false;
  9450. RedBlackRotateLeft(this, parent);
  9451. node = this._;
  9452. break;
  9453. }
  9454. } else {
  9455. sibling = parent.L;
  9456. if (sibling.C) {
  9457. sibling.C = false;
  9458. parent.C = true;
  9459. RedBlackRotateRight(this, parent);
  9460. sibling = parent.L;
  9461. }
  9462. if ((sibling.L && sibling.L.C)
  9463. || (sibling.R && sibling.R.C)) {
  9464. if (!sibling.L || !sibling.L.C) {
  9465. sibling.R.C = false;
  9466. sibling.C = true;
  9467. RedBlackRotateLeft(this, sibling);
  9468. sibling = parent.L;
  9469. }
  9470. sibling.C = parent.C;
  9471. parent.C = sibling.L.C = false;
  9472. RedBlackRotateRight(this, parent);
  9473. node = this._;
  9474. break;
  9475. }
  9476. }
  9477. sibling.C = true;
  9478. node = parent;
  9479. parent = parent.U;
  9480. } while (!node.C);
  9481. if (node) node.C = false;
  9482. }
  9483. };
  9484. function RedBlackRotateLeft(tree, node) {
  9485. var p = node,
  9486. q = node.R,
  9487. parent = p.U;
  9488. if (parent) {
  9489. if (parent.L === p) parent.L = q;
  9490. else parent.R = q;
  9491. } else {
  9492. tree._ = q;
  9493. }
  9494. q.U = parent;
  9495. p.U = q;
  9496. p.R = q.L;
  9497. if (p.R) p.R.U = p;
  9498. q.L = p;
  9499. }
  9500. function RedBlackRotateRight(tree, node) {
  9501. var p = node,
  9502. q = node.L,
  9503. parent = p.U;
  9504. if (parent) {
  9505. if (parent.L === p) parent.L = q;
  9506. else parent.R = q;
  9507. } else {
  9508. tree._ = q;
  9509. }
  9510. q.U = parent;
  9511. p.U = q;
  9512. p.L = q.R;
  9513. if (p.L) p.L.U = p;
  9514. q.R = p;
  9515. }
  9516. function RedBlackFirst(node) {
  9517. while (node.L) node = node.L;
  9518. return node;
  9519. }
  9520. function createEdge(left, right, v0, v1) {
  9521. var edge = [null, null],
  9522. index = edges.push(edge) - 1;
  9523. edge.left = left;
  9524. edge.right = right;
  9525. if (v0) setEdgeEnd(edge, left, right, v0);
  9526. if (v1) setEdgeEnd(edge, right, left, v1);
  9527. cells[left.index].halfedges.push(index);
  9528. cells[right.index].halfedges.push(index);
  9529. return edge;
  9530. }
  9531. function createBorderEdge(left, v0, v1) {
  9532. var edge = [v0, v1];
  9533. edge.left = left;
  9534. return edge;
  9535. }
  9536. function setEdgeEnd(edge, left, right, vertex) {
  9537. if (!edge[0] && !edge[1]) {
  9538. edge[0] = vertex;
  9539. edge.left = left;
  9540. edge.right = right;
  9541. } else if (edge.left === right) {
  9542. edge[1] = vertex;
  9543. } else {
  9544. edge[0] = vertex;
  9545. }
  9546. }
  9547. // Liang–Barsky line clipping.
  9548. function clipEdge(edge, x0, y0, x1, y1) {
  9549. var a = edge[0],
  9550. b = edge[1],
  9551. ax = a[0],
  9552. ay = a[1],
  9553. bx = b[0],
  9554. by = b[1],
  9555. t0 = 0,
  9556. t1 = 1,
  9557. dx = bx - ax,
  9558. dy = by - ay,
  9559. r;
  9560. r = x0 - ax;
  9561. if (!dx && r > 0) return;
  9562. r /= dx;
  9563. if (dx < 0) {
  9564. if (r < t0) return;
  9565. if (r < t1) t1 = r;
  9566. } else if (dx > 0) {
  9567. if (r > t1) return;
  9568. if (r > t0) t0 = r;
  9569. }
  9570. r = x1 - ax;
  9571. if (!dx && r < 0) return;
  9572. r /= dx;
  9573. if (dx < 0) {
  9574. if (r > t1) return;
  9575. if (r > t0) t0 = r;
  9576. } else if (dx > 0) {
  9577. if (r < t0) return;
  9578. if (r < t1) t1 = r;
  9579. }
  9580. r = y0 - ay;
  9581. if (!dy && r > 0) return;
  9582. r /= dy;
  9583. if (dy < 0) {
  9584. if (r < t0) return;
  9585. if (r < t1) t1 = r;
  9586. } else if (dy > 0) {
  9587. if (r > t1) return;
  9588. if (r > t0) t0 = r;
  9589. }
  9590. r = y1 - ay;
  9591. if (!dy && r < 0) return;
  9592. r /= dy;
  9593. if (dy < 0) {
  9594. if (r > t1) return;
  9595. if (r > t0) t0 = r;
  9596. } else if (dy > 0) {
  9597. if (r < t0) return;
  9598. if (r < t1) t1 = r;
  9599. }
  9600. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  9601. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  9602. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  9603. return true;
  9604. }
  9605. function connectEdge(edge, x0, y0, x1, y1) {
  9606. var v1 = edge[1];
  9607. if (v1) return true;
  9608. var v0 = edge[0],
  9609. left = edge.left,
  9610. right = edge.right,
  9611. lx = left[0],
  9612. ly = left[1],
  9613. rx = right[0],
  9614. ry = right[1],
  9615. fx = (lx + rx) / 2,
  9616. fy = (ly + ry) / 2,
  9617. fm,
  9618. fb;
  9619. if (ry === ly) {
  9620. if (fx < x0 || fx >= x1) return;
  9621. if (lx > rx) {
  9622. if (!v0) v0 = [fx, y0];
  9623. else if (v0[1] >= y1) return;
  9624. v1 = [fx, y1];
  9625. } else {
  9626. if (!v0) v0 = [fx, y1];
  9627. else if (v0[1] < y0) return;
  9628. v1 = [fx, y0];
  9629. }
  9630. } else {
  9631. fm = (lx - rx) / (ry - ly);
  9632. fb = fy - fm * fx;
  9633. if (fm < -1 || fm > 1) {
  9634. if (lx > rx) {
  9635. if (!v0) v0 = [(y0 - fb) / fm, y0];
  9636. else if (v0[1] >= y1) return;
  9637. v1 = [(y1 - fb) / fm, y1];
  9638. } else {
  9639. if (!v0) v0 = [(y1 - fb) / fm, y1];
  9640. else if (v0[1] < y0) return;
  9641. v1 = [(y0 - fb) / fm, y0];
  9642. }
  9643. } else {
  9644. if (ly < ry) {
  9645. if (!v0) v0 = [x0, fm * x0 + fb];
  9646. else if (v0[0] >= x1) return;
  9647. v1 = [x1, fm * x1 + fb];
  9648. } else {
  9649. if (!v0) v0 = [x1, fm * x1 + fb];
  9650. else if (v0[0] < x0) return;
  9651. v1 = [x0, fm * x0 + fb];
  9652. }
  9653. }
  9654. }
  9655. edge[0] = v0;
  9656. edge[1] = v1;
  9657. return true;
  9658. }
  9659. function clipEdges(x0, y0, x1, y1) {
  9660. var i = edges.length,
  9661. edge;
  9662. while (i--) {
  9663. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  9664. || !clipEdge(edge, x0, y0, x1, y1)
  9665. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$3
  9666. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$3)) {
  9667. delete edges[i];
  9668. }
  9669. }
  9670. }
  9671. function createCell(site) {
  9672. return cells[site.index] = {
  9673. site: site,
  9674. halfedges: []
  9675. };
  9676. }
  9677. function cellHalfedgeAngle(cell, edge) {
  9678. var site = cell.site,
  9679. va = edge.left,
  9680. vb = edge.right;
  9681. if (site === vb) vb = va, va = site;
  9682. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  9683. if (site === va) va = edge[1], vb = edge[0];
  9684. else va = edge[0], vb = edge[1];
  9685. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  9686. }
  9687. function cellHalfedgeStart(cell, edge) {
  9688. return edge[+(edge.left !== cell.site)];
  9689. }
  9690. function cellHalfedgeEnd(cell, edge) {
  9691. return edge[+(edge.left === cell.site)];
  9692. }
  9693. function sortCellHalfedges() {
  9694. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  9695. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  9696. var index = new Array(m),
  9697. array = new Array(m);
  9698. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  9699. index.sort(function(i, j) { return array[j] - array[i]; });
  9700. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  9701. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  9702. }
  9703. }
  9704. }
  9705. function clipCells(x0, y0, x1, y1) {
  9706. var nCells = cells.length,
  9707. iCell,
  9708. cell,
  9709. site,
  9710. iHalfedge,
  9711. halfedges,
  9712. nHalfedges,
  9713. start,
  9714. startX,
  9715. startY,
  9716. end,
  9717. endX,
  9718. endY,
  9719. cover = true;
  9720. for (iCell = 0; iCell < nCells; ++iCell) {
  9721. if (cell = cells[iCell]) {
  9722. site = cell.site;
  9723. halfedges = cell.halfedges;
  9724. iHalfedge = halfedges.length;
  9725. // Remove any dangling clipped edges.
  9726. while (iHalfedge--) {
  9727. if (!edges[halfedges[iHalfedge]]) {
  9728. halfedges.splice(iHalfedge, 1);
  9729. }
  9730. }
  9731. // Insert any border edges as necessary.
  9732. iHalfedge = 0, nHalfedges = halfedges.length;
  9733. while (iHalfedge < nHalfedges) {
  9734. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  9735. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  9736. if (Math.abs(endX - startX) > epsilon$3 || Math.abs(endY - startY) > epsilon$3) {
  9737. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  9738. Math.abs(endX - x0) < epsilon$3 && y1 - endY > epsilon$3 ? [x0, Math.abs(startX - x0) < epsilon$3 ? startY : y1]
  9739. : Math.abs(endY - y1) < epsilon$3 && x1 - endX > epsilon$3 ? [Math.abs(startY - y1) < epsilon$3 ? startX : x1, y1]
  9740. : Math.abs(endX - x1) < epsilon$3 && endY - y0 > epsilon$3 ? [x1, Math.abs(startX - x1) < epsilon$3 ? startY : y0]
  9741. : Math.abs(endY - y0) < epsilon$3 && endX - x0 > epsilon$3 ? [Math.abs(startY - y0) < epsilon$3 ? startX : x0, y0]
  9742. : null)) - 1);
  9743. ++nHalfedges;
  9744. }
  9745. }
  9746. if (nHalfedges) cover = false;
  9747. }
  9748. }
  9749. // If there weren’t any edges, have the closest site cover the extent.
  9750. // It doesn’t matter which corner of the extent we measure!
  9751. if (cover) {
  9752. var dx, dy, d2, dc = Infinity;
  9753. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  9754. if (cell = cells[iCell]) {
  9755. site = cell.site;
  9756. dx = site[0] - x0;
  9757. dy = site[1] - y0;
  9758. d2 = dx * dx + dy * dy;
  9759. if (d2 < dc) dc = d2, cover = cell;
  9760. }
  9761. }
  9762. if (cover) {
  9763. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  9764. cover.halfedges.push(
  9765. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  9766. edges.push(createBorderEdge(site, v01, v11)) - 1,
  9767. edges.push(createBorderEdge(site, v11, v10)) - 1,
  9768. edges.push(createBorderEdge(site, v10, v00)) - 1
  9769. );
  9770. }
  9771. }
  9772. // Lastly delete any cells with no edges; these were entirely clipped.
  9773. for (iCell = 0; iCell < nCells; ++iCell) {
  9774. if (cell = cells[iCell]) {
  9775. if (!cell.halfedges.length) {
  9776. delete cells[iCell];
  9777. }
  9778. }
  9779. }
  9780. }
  9781. var circlePool = [];
  9782. var firstCircle;
  9783. function Circle() {
  9784. RedBlackNode(this);
  9785. this.x =
  9786. this.y =
  9787. this.arc =
  9788. this.site =
  9789. this.cy = null;
  9790. }
  9791. function attachCircle(arc) {
  9792. var lArc = arc.P,
  9793. rArc = arc.N;
  9794. if (!lArc || !rArc) return;
  9795. var lSite = lArc.site,
  9796. cSite = arc.site,
  9797. rSite = rArc.site;
  9798. if (lSite === rSite) return;
  9799. var bx = cSite[0],
  9800. by = cSite[1],
  9801. ax = lSite[0] - bx,
  9802. ay = lSite[1] - by,
  9803. cx = rSite[0] - bx,
  9804. cy = rSite[1] - by;
  9805. var d = 2 * (ax * cy - ay * cx);
  9806. if (d >= -epsilon2$1) return;
  9807. var ha = ax * ax + ay * ay,
  9808. hc = cx * cx + cy * cy,
  9809. x = (cy * ha - ay * hc) / d,
  9810. y = (ax * hc - cx * ha) / d;
  9811. var circle = circlePool.pop() || new Circle;
  9812. circle.arc = arc;
  9813. circle.site = cSite;
  9814. circle.x = x + bx;
  9815. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  9816. arc.circle = circle;
  9817. var before = null,
  9818. node = circles._;
  9819. while (node) {
  9820. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  9821. if (node.L) node = node.L;
  9822. else { before = node.P; break; }
  9823. } else {
  9824. if (node.R) node = node.R;
  9825. else { before = node; break; }
  9826. }
  9827. }
  9828. circles.insert(before, circle);
  9829. if (!before) firstCircle = circle;
  9830. }
  9831. function detachCircle(arc) {
  9832. var circle = arc.circle;
  9833. if (circle) {
  9834. if (!circle.P) firstCircle = circle.N;
  9835. circles.remove(circle);
  9836. circlePool.push(circle);
  9837. RedBlackNode(circle);
  9838. arc.circle = null;
  9839. }
  9840. }
  9841. var beachPool = [];
  9842. function Beach() {
  9843. RedBlackNode(this);
  9844. this.edge =
  9845. this.site =
  9846. this.circle = null;
  9847. }
  9848. function createBeach(site) {
  9849. var beach = beachPool.pop() || new Beach;
  9850. beach.site = site;
  9851. return beach;
  9852. }
  9853. function detachBeach(beach) {
  9854. detachCircle(beach);
  9855. beaches.remove(beach);
  9856. beachPool.push(beach);
  9857. RedBlackNode(beach);
  9858. }
  9859. function removeBeach(beach) {
  9860. var circle = beach.circle,
  9861. x = circle.x,
  9862. y = circle.cy,
  9863. vertex = [x, y],
  9864. previous = beach.P,
  9865. next = beach.N,
  9866. disappearing = [beach];
  9867. detachBeach(beach);
  9868. var lArc = previous;
  9869. while (lArc.circle
  9870. && Math.abs(x - lArc.circle.x) < epsilon$3
  9871. && Math.abs(y - lArc.circle.cy) < epsilon$3) {
  9872. previous = lArc.P;
  9873. disappearing.unshift(lArc);
  9874. detachBeach(lArc);
  9875. lArc = previous;
  9876. }
  9877. disappearing.unshift(lArc);
  9878. detachCircle(lArc);
  9879. var rArc = next;
  9880. while (rArc.circle
  9881. && Math.abs(x - rArc.circle.x) < epsilon$3
  9882. && Math.abs(y - rArc.circle.cy) < epsilon$3) {
  9883. next = rArc.N;
  9884. disappearing.push(rArc);
  9885. detachBeach(rArc);
  9886. rArc = next;
  9887. }
  9888. disappearing.push(rArc);
  9889. detachCircle(rArc);
  9890. var nArcs = disappearing.length,
  9891. iArc;
  9892. for (iArc = 1; iArc < nArcs; ++iArc) {
  9893. rArc = disappearing[iArc];
  9894. lArc = disappearing[iArc - 1];
  9895. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  9896. }
  9897. lArc = disappearing[0];
  9898. rArc = disappearing[nArcs - 1];
  9899. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  9900. attachCircle(lArc);
  9901. attachCircle(rArc);
  9902. }
  9903. function addBeach(site) {
  9904. var x = site[0],
  9905. directrix = site[1],
  9906. lArc,
  9907. rArc,
  9908. dxl,
  9909. dxr,
  9910. node = beaches._;
  9911. while (node) {
  9912. dxl = leftBreakPoint(node, directrix) - x;
  9913. if (dxl > epsilon$3) node = node.L; else {
  9914. dxr = x - rightBreakPoint(node, directrix);
  9915. if (dxr > epsilon$3) {
  9916. if (!node.R) {
  9917. lArc = node;
  9918. break;
  9919. }
  9920. node = node.R;
  9921. } else {
  9922. if (dxl > -epsilon$3) {
  9923. lArc = node.P;
  9924. rArc = node;
  9925. } else if (dxr > -epsilon$3) {
  9926. lArc = node;
  9927. rArc = node.N;
  9928. } else {
  9929. lArc = rArc = node;
  9930. }
  9931. break;
  9932. }
  9933. }
  9934. }
  9935. createCell(site);
  9936. var newArc = createBeach(site);
  9937. beaches.insert(lArc, newArc);
  9938. if (!lArc && !rArc) return;
  9939. if (lArc === rArc) {
  9940. detachCircle(lArc);
  9941. rArc = createBeach(lArc.site);
  9942. beaches.insert(newArc, rArc);
  9943. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  9944. attachCircle(lArc);
  9945. attachCircle(rArc);
  9946. return;
  9947. }
  9948. if (!rArc) { // && lArc
  9949. newArc.edge = createEdge(lArc.site, newArc.site);
  9950. return;
  9951. }
  9952. // else lArc !== rArc
  9953. detachCircle(lArc);
  9954. detachCircle(rArc);
  9955. var lSite = lArc.site,
  9956. ax = lSite[0],
  9957. ay = lSite[1],
  9958. bx = site[0] - ax,
  9959. by = site[1] - ay,
  9960. rSite = rArc.site,
  9961. cx = rSite[0] - ax,
  9962. cy = rSite[1] - ay,
  9963. d = 2 * (bx * cy - by * cx),
  9964. hb = bx * bx + by * by,
  9965. hc = cx * cx + cy * cy,
  9966. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  9967. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  9968. newArc.edge = createEdge(lSite, site, null, vertex);
  9969. rArc.edge = createEdge(site, rSite, null, vertex);
  9970. attachCircle(lArc);
  9971. attachCircle(rArc);
  9972. }
  9973. function leftBreakPoint(arc, directrix) {
  9974. var site = arc.site,
  9975. rfocx = site[0],
  9976. rfocy = site[1],
  9977. pby2 = rfocy - directrix;
  9978. if (!pby2) return rfocx;
  9979. var lArc = arc.P;
  9980. if (!lArc) return -Infinity;
  9981. site = lArc.site;
  9982. var lfocx = site[0],
  9983. lfocy = site[1],
  9984. plby2 = lfocy - directrix;
  9985. if (!plby2) return lfocx;
  9986. var hl = lfocx - rfocx,
  9987. aby2 = 1 / pby2 - 1 / plby2,
  9988. b = hl / plby2;
  9989. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  9990. return (rfocx + lfocx) / 2;
  9991. }
  9992. function rightBreakPoint(arc, directrix) {
  9993. var rArc = arc.N;
  9994. if (rArc) return leftBreakPoint(rArc, directrix);
  9995. var site = arc.site;
  9996. return site[1] === directrix ? site[0] : Infinity;
  9997. }
  9998. var epsilon$3 = 1e-6;
  9999. var epsilon2$1 = 1e-12;
  10000. var beaches;
  10001. var cells;
  10002. var circles;
  10003. var edges;
  10004. function triangleArea(a, b, c) {
  10005. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  10006. }
  10007. function lexicographic(a, b) {
  10008. return b[1] - a[1]
  10009. || b[0] - a[0];
  10010. }
  10011. function Diagram(sites, extent) {
  10012. var site = sites.sort(lexicographic).pop(),
  10013. x,
  10014. y,
  10015. circle;
  10016. edges = [];
  10017. cells = new Array(sites.length);
  10018. beaches = new RedBlackTree;
  10019. circles = new RedBlackTree;
  10020. while (true) {
  10021. circle = firstCircle;
  10022. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  10023. if (site[0] !== x || site[1] !== y) {
  10024. addBeach(site);
  10025. x = site[0], y = site[1];
  10026. }
  10027. site = sites.pop();
  10028. } else if (circle) {
  10029. removeBeach(circle.arc);
  10030. } else {
  10031. break;
  10032. }
  10033. }
  10034. sortCellHalfedges();
  10035. if (extent) {
  10036. var x0 = +extent[0][0],
  10037. y0 = +extent[0][1],
  10038. x1 = +extent[1][0],
  10039. y1 = +extent[1][1];
  10040. clipEdges(x0, y0, x1, y1);
  10041. clipCells(x0, y0, x1, y1);
  10042. }
  10043. this.edges = edges;
  10044. this.cells = cells;
  10045. beaches =
  10046. circles =
  10047. edges =
  10048. cells = null;
  10049. }
  10050. Diagram.prototype = {
  10051. constructor: Diagram,
  10052. polygons: function() {
  10053. var edges = this.edges;
  10054. return this.cells.map(function(cell) {
  10055. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  10056. polygon.data = cell.site.data;
  10057. return polygon;
  10058. });
  10059. },
  10060. triangles: function() {
  10061. var triangles = [],
  10062. edges = this.edges;
  10063. this.cells.forEach(function(cell, i) {
  10064. var site = cell.site,
  10065. halfedges = cell.halfedges,
  10066. j = -1,
  10067. m = halfedges.length,
  10068. s0,
  10069. e1 = edges[halfedges[m - 1]],
  10070. s1 = e1.left === site ? e1.right : e1.left;
  10071. while (++j < m) {
  10072. s0 = s1;
  10073. e1 = edges[halfedges[j]];
  10074. s1 = e1.left === site ? e1.right : e1.left;
  10075. if (i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  10076. triangles.push([site.data, s0.data, s1.data]);
  10077. }
  10078. }
  10079. });
  10080. return triangles;
  10081. },
  10082. links: function() {
  10083. return this.edges.filter(function(edge) {
  10084. return edge.right;
  10085. }).map(function(edge) {
  10086. return {
  10087. source: edge.left.data,
  10088. target: edge.right.data
  10089. };
  10090. });
  10091. }
  10092. }
  10093. function voronoi() {
  10094. var x = x$4,
  10095. y = y$4,
  10096. extent = null;
  10097. function voronoi(data) {
  10098. return new Diagram(data.map(function(d, i) {
  10099. var s = [Math.round(x(d, i, data) / epsilon$3) * epsilon$3, Math.round(y(d, i, data) / epsilon$3) * epsilon$3];
  10100. s.index = i;
  10101. s.data = d;
  10102. return s;
  10103. }), extent);
  10104. }
  10105. voronoi.polygons = function(data) {
  10106. return voronoi(data).polygons();
  10107. };
  10108. voronoi.links = function(data) {
  10109. return voronoi(data).links();
  10110. };
  10111. voronoi.triangles = function(data) {
  10112. return voronoi(data).triangles();
  10113. };
  10114. voronoi.x = function(_) {
  10115. return arguments.length ? (x = typeof _ === "function" ? _ : constant$8(+_), voronoi) : x;
  10116. };
  10117. voronoi.y = function(_) {
  10118. return arguments.length ? (y = typeof _ === "function" ? _ : constant$8(+_), voronoi) : y;
  10119. };
  10120. voronoi.extent = function(_) {
  10121. 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]]];
  10122. };
  10123. voronoi.size = function(_) {
  10124. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0], extent[1][1]];
  10125. };
  10126. return voronoi;
  10127. }
  10128. function constant$9(x) {
  10129. return function() {
  10130. return x;
  10131. };
  10132. }
  10133. function ZoomEvent(target, type, transform) {
  10134. this.target = target;
  10135. this.type = type;
  10136. this.transform = transform;
  10137. }
  10138. function Transform(k, x, y) {
  10139. this.k = k;
  10140. this.x = x;
  10141. this.y = y;
  10142. }
  10143. Transform.prototype = {
  10144. constructor: Transform,
  10145. scale: function(k) {
  10146. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  10147. },
  10148. translate: function(x, y) {
  10149. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  10150. },
  10151. apply: function(point) {
  10152. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  10153. },
  10154. applyX: function(x) {
  10155. return x * this.k + this.x;
  10156. },
  10157. applyY: function(y) {
  10158. return y * this.k + this.y;
  10159. },
  10160. invert: function(location) {
  10161. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  10162. },
  10163. invertX: function(x) {
  10164. return (x - this.x) / this.k;
  10165. },
  10166. invertY: function(y) {
  10167. return (y - this.y) / this.k;
  10168. },
  10169. rescaleX: function(x) {
  10170. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  10171. },
  10172. rescaleY: function(y) {
  10173. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  10174. },
  10175. toString: function() {
  10176. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  10177. }
  10178. };
  10179. var identity$6 = new Transform(1, 0, 0);
  10180. transform.prototype = Transform.prototype;
  10181. function transform(node) {
  10182. return node.__zoom || identity$6;
  10183. }
  10184. function nopropagation$1() {
  10185. exports.event.stopImmediatePropagation();
  10186. }
  10187. function noevent$1() {
  10188. exports.event.preventDefault();
  10189. exports.event.stopImmediatePropagation();
  10190. }
  10191. // Ignore right-click, since that should open the context menu.
  10192. function defaultFilter$1() {
  10193. return !exports.event.button;
  10194. }
  10195. function defaultExtent() {
  10196. var e = this, w, h;
  10197. if (e instanceof SVGElement) {
  10198. e = e.ownerSVGElement || e;
  10199. w = e.width.baseVal.value;
  10200. h = e.height.baseVal.value;
  10201. } else {
  10202. w = e.clientWidth;
  10203. h = e.clientHeight;
  10204. }
  10205. return [[0, 0], [w, h]];
  10206. }
  10207. function defaultTransform() {
  10208. return this.__zoom || identity$6;
  10209. }
  10210. function zoom() {
  10211. var filter = defaultFilter$1,
  10212. extent = defaultExtent,
  10213. k0 = 0,
  10214. k1 = Infinity,
  10215. x0 = -k1,
  10216. x1 = k1,
  10217. y0 = x0,
  10218. y1 = x1,
  10219. duration = 250,
  10220. gestures = [],
  10221. listeners = dispatch("start", "zoom", "end"),
  10222. mousemoving,
  10223. mousePoint,
  10224. mouseLocation,
  10225. touchstarting,
  10226. touchending,
  10227. touchDelay = 500,
  10228. wheelTimer,
  10229. wheelDelay = 150;
  10230. function zoom(selection) {
  10231. selection
  10232. .on("wheel.zoom", wheeled)
  10233. .on("mousedown.zoom", mousedowned)
  10234. .on("dblclick.zoom", dblclicked)
  10235. .on("touchstart.zoom", touchstarted)
  10236. .on("touchmove.zoom", touchmoved)
  10237. .on("touchend.zoom touchcancel.zoom", touchended)
  10238. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  10239. .property("__zoom", defaultTransform);
  10240. }
  10241. zoom.transform = function(collection, transform) {
  10242. var selection = collection.selection ? collection.selection() : collection;
  10243. selection.property("__zoom", defaultTransform);
  10244. if (collection !== selection) {
  10245. schedule(collection, transform);
  10246. } else {
  10247. selection.interrupt().each(function() {
  10248. gesture(this, arguments)
  10249. .start()
  10250. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  10251. .end();
  10252. });
  10253. }
  10254. };
  10255. zoom.scaleBy = function(selection, k) {
  10256. zoom.scaleTo(selection, function() {
  10257. var k0 = this.__zoom.k,
  10258. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  10259. return k0 * k1;
  10260. });
  10261. };
  10262. zoom.scaleTo = function(selection, k) {
  10263. zoom.transform(selection, function() {
  10264. var e = extent.apply(this, arguments),
  10265. t0 = this.__zoom,
  10266. p0 = centroid(e),
  10267. p1 = t0.invert(p0),
  10268. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  10269. return constrain(translate(scale(t0, k1), p0, p1), e);
  10270. });
  10271. };
  10272. zoom.translateBy = function(selection, x, y) {
  10273. zoom.transform(selection, function() {
  10274. return constrain(this.__zoom.translate(
  10275. typeof x === "function" ? x.apply(this, arguments) : x,
  10276. typeof y === "function" ? y.apply(this, arguments) : y
  10277. ), extent.apply(this, arguments));
  10278. });
  10279. };
  10280. function scale(transform, k) {
  10281. k = Math.max(k0, Math.min(k1, k));
  10282. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  10283. }
  10284. function translate(transform, p0, p1) {
  10285. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  10286. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  10287. }
  10288. function constrain(transform, extent) {
  10289. var dx = Math.min(0, transform.invertX(extent[0][0]) - x0) || Math.max(0, transform.invertX(extent[1][0]) - x1),
  10290. dy = Math.min(0, transform.invertY(extent[0][1]) - y0) || Math.max(0, transform.invertY(extent[1][1]) - y1);
  10291. return dx || dy ? transform.translate(dx, dy) : transform;
  10292. }
  10293. function centroid(extent) {
  10294. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  10295. }
  10296. function schedule(transition, transform, center) {
  10297. transition
  10298. .on("start.zoom", function() { gesture(this, arguments).start(); })
  10299. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  10300. .tween("zoom", function() {
  10301. var that = this,
  10302. args = arguments,
  10303. g = gesture(that, args),
  10304. e = extent.apply(that, args),
  10305. p = center || centroid(e),
  10306. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  10307. a = that.__zoom,
  10308. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  10309. i = interpolateZoom(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  10310. return function(t) {
  10311. if (t === 1) t = b; // Avoid rounding error on end.
  10312. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  10313. g.zoom(null, t);
  10314. };
  10315. });
  10316. }
  10317. function gesture(that, args) {
  10318. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  10319. if ((g = gestures[i]).that === that) {
  10320. return g;
  10321. }
  10322. }
  10323. return new Gesture(that, args);
  10324. }
  10325. function Gesture(that, args) {
  10326. this.that = that;
  10327. this.args = args;
  10328. this.index = -1;
  10329. this.active = 0;
  10330. }
  10331. Gesture.prototype = {
  10332. start: function() {
  10333. if (++this.active === 1) {
  10334. this.index = gestures.push(this) - 1;
  10335. this.emit("start");
  10336. }
  10337. return this;
  10338. },
  10339. zoom: function(key, transform) {
  10340. if (mousePoint && key !== "mouse") mouseLocation = transform.invert(mousePoint);
  10341. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  10342. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  10343. this.that.__zoom = transform;
  10344. this.emit("zoom");
  10345. return this;
  10346. },
  10347. end: function() {
  10348. if (--this.active === 0) {
  10349. gestures.splice(this.index, 1);
  10350. mousePoint = mouseLocation = null;
  10351. this.index = -1;
  10352. this.emit("end");
  10353. }
  10354. return this;
  10355. },
  10356. emit: function(type) {
  10357. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  10358. }
  10359. };
  10360. function wheeled() {
  10361. if (!filter.apply(this, arguments)) return;
  10362. var g = gesture(this, arguments),
  10363. t = this.__zoom,
  10364. k = Math.max(k0, Math.min(k1, t.k * Math.pow(2, -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500)));
  10365. // If the mouse is in the same location as before, reuse it.
  10366. // If there were recent wheel events, reset the wheel idle timeout.
  10367. if (wheelTimer) {
  10368. var point = mouse(this);
  10369. if (mousePoint[0] !== point[0] || mousePoint[1] !== point[1]) {
  10370. mouseLocation = t.invert(mousePoint = point);
  10371. }
  10372. clearTimeout(wheelTimer);
  10373. }
  10374. // If this wheel event won’t trigger a transform change, ignore it.
  10375. else if (t.k === k) return;
  10376. // Otherwise, capture the mouse point and location at the start.
  10377. else {
  10378. g.extent = extent.apply(this, arguments);
  10379. mouseLocation = t.invert(mousePoint = mouse(this));
  10380. interrupt(this);
  10381. g.start();
  10382. }
  10383. noevent$1();
  10384. wheelTimer = setTimeout(wheelidled, wheelDelay);
  10385. g.zoom("mouse", constrain(translate(scale(t, k), mousePoint, mouseLocation), g.extent));
  10386. function wheelidled() {
  10387. wheelTimer = null;
  10388. g.end();
  10389. }
  10390. }
  10391. function mousedowned() {
  10392. if (touchending || !filter.apply(this, arguments)) return;
  10393. var g = gesture(this, arguments),
  10394. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true);
  10395. dragDisable(exports.event.view);
  10396. nopropagation$1();
  10397. mousemoving = false;
  10398. g.extent = extent.apply(this, arguments);
  10399. mouseLocation = this.__zoom.invert(mousePoint = mouse(this));
  10400. interrupt(this);
  10401. g.start();
  10402. function mousemoved() {
  10403. noevent$1();
  10404. mousemoving = true;
  10405. g.zoom("mouse", constrain(translate(g.that.__zoom, mousePoint = mouse(g.that), mouseLocation), g.extent));
  10406. }
  10407. function mouseupped() {
  10408. v.on("mousemove.zoom mouseup.zoom", null);
  10409. dragEnable(exports.event.view, mousemoving);
  10410. noevent$1();
  10411. g.end();
  10412. }
  10413. }
  10414. function dblclicked() {
  10415. if (!filter.apply(this, arguments)) return;
  10416. var t0 = this.__zoom,
  10417. p0 = mouse(this),
  10418. p1 = t0.invert(p0),
  10419. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  10420. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments));
  10421. noevent$1();
  10422. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  10423. else select(this).call(zoom.transform, t1);
  10424. }
  10425. function touchstarted() {
  10426. if (!filter.apply(this, arguments)) return;
  10427. var g = gesture(this, arguments),
  10428. touches = exports.event.changedTouches,
  10429. n = touches.length, i, t, p;
  10430. nopropagation$1();
  10431. for (i = 0; i < n; ++i) {
  10432. t = touches[i], p = touch(this, touches, t.identifier);
  10433. p = [p, this.__zoom.invert(p), t.identifier];
  10434. if (!g.touch0) g.touch0 = p;
  10435. else if (!g.touch1) g.touch1 = p;
  10436. }
  10437. if (touchstarting) {
  10438. touchstarting = clearTimeout(touchstarting);
  10439. if (!g.touch1) return g.end(), dblclicked.apply(this, arguments);
  10440. }
  10441. if (exports.event.touches.length === n) {
  10442. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  10443. interrupt(this);
  10444. g.extent = extent.apply(this, arguments);
  10445. g.start();
  10446. }
  10447. }
  10448. function touchmoved() {
  10449. var g = gesture(this, arguments),
  10450. touches = exports.event.changedTouches,
  10451. n = touches.length, i, t, p, l;
  10452. noevent$1();
  10453. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  10454. for (i = 0; i < n; ++i) {
  10455. t = touches[i], p = touch(this, touches, t.identifier);
  10456. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  10457. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  10458. }
  10459. t = g.that.__zoom;
  10460. if (g.touch1) {
  10461. var p0 = g.touch0[0], l0 = g.touch0[1],
  10462. p1 = g.touch1[0], l1 = g.touch1[1],
  10463. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  10464. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  10465. t = scale(t, Math.sqrt(dp / dl));
  10466. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  10467. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  10468. }
  10469. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  10470. else return;
  10471. g.zoom("touch", constrain(translate(t, p, l), g.extent));
  10472. }
  10473. function touchended() {
  10474. var g = gesture(this, arguments),
  10475. touches = exports.event.changedTouches,
  10476. n = touches.length, i, t;
  10477. nopropagation$1();
  10478. if (touchending) clearTimeout(touchending);
  10479. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  10480. for (i = 0; i < n; ++i) {
  10481. t = touches[i];
  10482. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  10483. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  10484. }
  10485. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  10486. if (!g.touch0) g.end();
  10487. }
  10488. zoom.filter = function(_) {
  10489. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$9(!!_), zoom) : filter;
  10490. };
  10491. zoom.extent = function(_) {
  10492. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$9([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  10493. };
  10494. zoom.scaleExtent = function(_) {
  10495. return arguments.length ? (k0 = +_[0], k1 = +_[1], zoom) : [k0, k1];
  10496. };
  10497. zoom.translateExtent = function(_) {
  10498. return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], zoom) : [[x0, y0], [x1, y1]];
  10499. };
  10500. zoom.duration = function(_) {
  10501. return arguments.length ? (duration = +_, zoom) : duration;
  10502. };
  10503. zoom.on = function() {
  10504. var value = listeners.on.apply(listeners, arguments);
  10505. return value === listeners ? zoom : value;
  10506. };
  10507. return zoom;
  10508. }
  10509. function constant$10(x) {
  10510. return function() {
  10511. return x;
  10512. };
  10513. }
  10514. function BrushEvent(target, type, selection) {
  10515. this.target = target;
  10516. this.type = type;
  10517. this.selection = selection;
  10518. }
  10519. function nopropagation$2() {
  10520. exports.event.stopImmediatePropagation();
  10521. }
  10522. function noevent$2() {
  10523. exports.event.preventDefault();
  10524. exports.event.stopImmediatePropagation();
  10525. }
  10526. var MODE_DRAG = {name: "drag"};
  10527. var MODE_SPACE = {name: "space"};
  10528. var MODE_HANDLE = {name: "handle"};
  10529. var MODE_CENTER = {name: "center"};
  10530. var X = {
  10531. name: "x",
  10532. handles: ["e", "w"].map(type$1),
  10533. input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
  10534. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  10535. };
  10536. var Y = {
  10537. name: "y",
  10538. handles: ["n", "s"].map(type$1),
  10539. input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
  10540. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  10541. };
  10542. var XY = {
  10543. name: "xy",
  10544. handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type$1),
  10545. input: function(xy) { return xy; },
  10546. output: function(xy) { return xy; }
  10547. };
  10548. var cursors = {
  10549. overlay: "crosshair",
  10550. selection: "move",
  10551. n: "ns-resize",
  10552. e: "ew-resize",
  10553. s: "ns-resize",
  10554. w: "ew-resize",
  10555. nw: "nwse-resize",
  10556. ne: "nesw-resize",
  10557. se: "nwse-resize",
  10558. sw: "nesw-resize"
  10559. };
  10560. var flipX = {
  10561. e: "w",
  10562. w: "e",
  10563. nw: "ne",
  10564. ne: "nw",
  10565. se: "sw",
  10566. sw: "se"
  10567. };
  10568. var flipY = {
  10569. n: "s",
  10570. s: "n",
  10571. nw: "sw",
  10572. ne: "se",
  10573. se: "ne",
  10574. sw: "nw"
  10575. };
  10576. var signsX = {
  10577. overlay: +1,
  10578. selection: +1,
  10579. n: null,
  10580. e: +1,
  10581. s: null,
  10582. w: -1,
  10583. nw: -1,
  10584. ne: +1,
  10585. se: +1,
  10586. sw: -1
  10587. };
  10588. var signsY = {
  10589. overlay: +1,
  10590. selection: +1,
  10591. n: -1,
  10592. e: null,
  10593. s: +1,
  10594. w: null,
  10595. nw: -1,
  10596. ne: -1,
  10597. se: +1,
  10598. sw: +1
  10599. };
  10600. function type$1(t) {
  10601. return {type: t};
  10602. }
  10603. // Ignore right-click, since that should open the context menu.
  10604. function defaultFilter$2() {
  10605. return !exports.event.button;
  10606. }
  10607. function defaultExtent$1() {
  10608. var svg = this.ownerSVGElement || this;
  10609. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  10610. }
  10611. // Like d3.local, but with the name “__brush” rather than auto-generated.
  10612. function local$1(node) {
  10613. while (!node.__brush) if (!(node = node.parentNode)) return;
  10614. return node.__brush;
  10615. }
  10616. function empty$1(extent) {
  10617. return extent[0][0] === extent[1][0]
  10618. || extent[0][1] === extent[1][1];
  10619. }
  10620. function brushSelection(node) {
  10621. var state = node.__brush;
  10622. return state ? state.dim.output(state.selection) : null;
  10623. }
  10624. function brushX() {
  10625. return brush$1(X);
  10626. }
  10627. function brushY() {
  10628. return brush$1(Y);
  10629. }
  10630. function brush() {
  10631. return brush$1(XY);
  10632. }
  10633. function brush$1(dim) {
  10634. var extent = defaultExtent$1,
  10635. filter = defaultFilter$2,
  10636. listeners = dispatch(brush, "start", "brush", "end"),
  10637. handleSize = 6,
  10638. touchending;
  10639. function brush(group) {
  10640. var overlay = group
  10641. .property("__brush", initialize)
  10642. .selectAll(".overlay")
  10643. .data([type$1("overlay")]);
  10644. overlay.enter().append("rect")
  10645. .attr("class", "overlay")
  10646. .attr("pointer-events", "all")
  10647. .attr("cursor", cursors.overlay)
  10648. .merge(overlay)
  10649. .each(function() {
  10650. var extent = local$1(this).extent;
  10651. select(this)
  10652. .attr("x", extent[0][0])
  10653. .attr("y", extent[0][1])
  10654. .attr("width", extent[1][0] - extent[0][0])
  10655. .attr("height", extent[1][1] - extent[0][1]);
  10656. });
  10657. group.selectAll(".selection")
  10658. .data([type$1("selection")])
  10659. .enter().append("rect")
  10660. .attr("class", "selection")
  10661. .attr("cursor", cursors.selection)
  10662. .attr("fill", "#777")
  10663. .attr("fill-opacity", 0.3)
  10664. .attr("stroke", "#fff")
  10665. .attr("shape-rendering", "crispEdges");
  10666. var handle = group.selectAll(".handle")
  10667. .data(dim.handles, function(d) { return d.type; });
  10668. handle.exit().remove();
  10669. handle.enter().append("rect")
  10670. .attr("class", function(d) { return "handle handle--" + d.type; })
  10671. .attr("cursor", function(d) { return cursors[d.type]; });
  10672. group
  10673. .each(redraw)
  10674. .attr("fill", "none")
  10675. .attr("pointer-events", "all")
  10676. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  10677. .on("mousedown.brush touchstart.brush", started);
  10678. }
  10679. brush.move = function(group, selection) {
  10680. if (group.selection) {
  10681. group
  10682. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  10683. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  10684. .tween("brush", function() {
  10685. var that = this,
  10686. state = that.__brush,
  10687. emit = emitter(that, arguments),
  10688. selection0 = state.selection,
  10689. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  10690. i = interpolate(selection0, selection1);
  10691. function tween(t) {
  10692. state.selection = t === 1 && empty$1(selection1) ? null : i(t);
  10693. redraw.call(that);
  10694. emit.brush();
  10695. }
  10696. return selection0 && selection1 ? tween : tween(1);
  10697. });
  10698. } else {
  10699. group
  10700. .each(function() {
  10701. var that = this,
  10702. args = arguments,
  10703. state = that.__brush,
  10704. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  10705. emit = emitter(that, args).beforestart();
  10706. interrupt(that);
  10707. state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
  10708. redraw.call(that);
  10709. emit.start().brush().end();
  10710. });
  10711. }
  10712. };
  10713. function redraw() {
  10714. var group = select(this),
  10715. selection = local$1(this).selection;
  10716. if (selection) {
  10717. group.selectAll(".selection")
  10718. .style("display", null)
  10719. .attr("x", selection[0][0])
  10720. .attr("y", selection[0][1])
  10721. .attr("width", selection[1][0] - selection[0][0])
  10722. .attr("height", selection[1][1] - selection[0][1]);
  10723. group.selectAll(".handle")
  10724. .style("display", null)
  10725. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  10726. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  10727. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  10728. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  10729. }
  10730. else {
  10731. group.selectAll(".selection,.handle")
  10732. .style("display", "none")
  10733. .attr("x", null)
  10734. .attr("y", null)
  10735. .attr("width", null)
  10736. .attr("height", null);
  10737. }
  10738. }
  10739. function emitter(that, args) {
  10740. return that.__brush.emitter || new Emitter(that, args);
  10741. }
  10742. function Emitter(that, args) {
  10743. this.that = that;
  10744. this.args = args;
  10745. this.state = that.__brush;
  10746. this.active = 0;
  10747. }
  10748. Emitter.prototype = {
  10749. beforestart: function() {
  10750. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  10751. return this;
  10752. },
  10753. start: function() {
  10754. if (this.starting) this.starting = false, this.emit("start");
  10755. return this;
  10756. },
  10757. brush: function() {
  10758. this.emit("brush");
  10759. return this;
  10760. },
  10761. end: function() {
  10762. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  10763. return this;
  10764. },
  10765. emit: function(type) {
  10766. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  10767. }
  10768. };
  10769. function started() {
  10770. if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$2(); }
  10771. else if (touchending) return;
  10772. if (!filter.apply(this, arguments)) return;
  10773. var that = this,
  10774. type = exports.event.target.__data__.type,
  10775. mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  10776. signX = dim === Y ? null : signsX[type],
  10777. signY = dim === X ? null : signsY[type],
  10778. state = local$1(that),
  10779. extent = state.extent,
  10780. selection = state.selection,
  10781. W = extent[0][0], w0, w1,
  10782. N = extent[0][1], n0, n1,
  10783. E = extent[1][0], e0, e1,
  10784. S = extent[1][1], s0, s1,
  10785. dx,
  10786. dy,
  10787. moving,
  10788. shifting = signX && signY && exports.event.shiftKey,
  10789. lockX,
  10790. lockY,
  10791. point0 = mouse(that),
  10792. point = point0,
  10793. emit = emitter(that, arguments).beforestart();
  10794. if (type === "overlay") {
  10795. state.selection = selection = [
  10796. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  10797. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  10798. ];
  10799. } else {
  10800. w0 = selection[0][0];
  10801. n0 = selection[0][1];
  10802. e0 = selection[1][0];
  10803. s0 = selection[1][1];
  10804. }
  10805. w1 = w0;
  10806. n1 = n0;
  10807. e1 = e0;
  10808. s1 = s0;
  10809. var group = select(that)
  10810. .attr("pointer-events", "none");
  10811. var overlay = group.selectAll(".overlay")
  10812. .attr("cursor", cursors[type]);
  10813. if (exports.event.touches) {
  10814. group
  10815. .on("touchmove.brush", moved, true)
  10816. .on("touchend.brush touchcancel.brush", ended, true);
  10817. } else {
  10818. var view = select(exports.event.view)
  10819. .on("keydown.brush", keydowned, true)
  10820. .on("keyup.brush", keyupped, true)
  10821. .on("mousemove.brush", moved, true)
  10822. .on("mouseup.brush", ended, true);
  10823. dragDisable(exports.event.view);
  10824. }
  10825. nopropagation$2();
  10826. interrupt(that);
  10827. redraw.call(that);
  10828. emit.start();
  10829. function moved() {
  10830. var point1 = mouse(that);
  10831. if (shifting && !lockX && !lockY) {
  10832. if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
  10833. else lockX = true;
  10834. }
  10835. point = point1;
  10836. moving = true;
  10837. noevent$2();
  10838. move();
  10839. }
  10840. function move() {
  10841. var t;
  10842. dx = point[0] - point0[0];
  10843. dy = point[1] - point0[1];
  10844. switch (mode) {
  10845. case MODE_SPACE:
  10846. case MODE_DRAG: {
  10847. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  10848. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  10849. break;
  10850. }
  10851. case MODE_HANDLE: {
  10852. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  10853. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  10854. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  10855. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  10856. break;
  10857. }
  10858. case MODE_CENTER: {
  10859. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  10860. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  10861. break;
  10862. }
  10863. }
  10864. if (e1 < w1) {
  10865. signX *= -1;
  10866. t = w0, w0 = e0, e0 = t;
  10867. t = w1, w1 = e1, e1 = t;
  10868. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  10869. }
  10870. if (s1 < n1) {
  10871. signY *= -1;
  10872. t = n0, n0 = s0, s0 = t;
  10873. t = n1, n1 = s1, s1 = t;
  10874. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  10875. }
  10876. selection = state.selection; // May be set by brush.move!
  10877. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  10878. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  10879. if (selection[0][0] !== w1
  10880. || selection[0][1] !== n1
  10881. || selection[1][0] !== e1
  10882. || selection[1][1] !== s1) {
  10883. state.selection = [[w1, n1], [e1, s1]];
  10884. redraw.call(that);
  10885. emit.brush();
  10886. }
  10887. }
  10888. function ended() {
  10889. nopropagation$2();
  10890. if (exports.event.touches) {
  10891. if (exports.event.touches.length) return;
  10892. if (touchending) clearTimeout(touchending);
  10893. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  10894. group.on("touchmove.brush touchend.brush touchcancel.brush", null);
  10895. } else {
  10896. dragEnable(exports.event.view, moving);
  10897. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  10898. }
  10899. group.attr("pointer-events", "all");
  10900. overlay.attr("cursor", cursors.overlay);
  10901. if (empty$1(selection)) state.selection = null, redraw.call(that);
  10902. emit.end();
  10903. }
  10904. function keydowned() {
  10905. switch (exports.event.keyCode) {
  10906. case 16: { // SHIFT
  10907. shifting = signX && signY;
  10908. break;
  10909. }
  10910. case 18: { // ALT
  10911. if (mode === MODE_HANDLE) {
  10912. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  10913. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  10914. mode = MODE_CENTER;
  10915. move();
  10916. }
  10917. break;
  10918. }
  10919. case 32: { // SPACE; takes priority over ALT
  10920. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  10921. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  10922. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  10923. mode = MODE_SPACE;
  10924. overlay.attr("cursor", cursors.selection);
  10925. move();
  10926. }
  10927. break;
  10928. }
  10929. default: return;
  10930. }
  10931. noevent$2();
  10932. }
  10933. function keyupped() {
  10934. switch (exports.event.keyCode) {
  10935. case 16: { // SHIFT
  10936. if (shifting) {
  10937. lockX = lockY = shifting = false;
  10938. move();
  10939. }
  10940. break;
  10941. }
  10942. case 18: { // ALT
  10943. if (mode === MODE_CENTER) {
  10944. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  10945. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  10946. mode = MODE_HANDLE;
  10947. move();
  10948. }
  10949. break;
  10950. }
  10951. case 32: { // SPACE
  10952. if (mode === MODE_SPACE) {
  10953. if (exports.event.altKey) {
  10954. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  10955. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  10956. mode = MODE_CENTER;
  10957. } else {
  10958. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  10959. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  10960. mode = MODE_HANDLE;
  10961. }
  10962. overlay.attr("cursor", cursors[type]);
  10963. move();
  10964. }
  10965. break;
  10966. }
  10967. default: return;
  10968. }
  10969. noevent$2();
  10970. }
  10971. }
  10972. function initialize() {
  10973. var state = this.__brush || {selection: null};
  10974. state.extent = extent.apply(this, arguments);
  10975. state.dim = dim;
  10976. return state;
  10977. }
  10978. brush.extent = function(_) {
  10979. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$10([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
  10980. };
  10981. brush.filter = function(_) {
  10982. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$10(!!_), brush) : filter;
  10983. };
  10984. brush.handleSize = function(_) {
  10985. return arguments.length ? (handleSize = +_, brush) : handleSize;
  10986. };
  10987. brush.on = function() {
  10988. var value = listeners.on.apply(listeners, arguments);
  10989. return value === listeners ? brush : value;
  10990. };
  10991. return brush;
  10992. }
  10993. // Adds floating point numbers with twice the normal precision.
  10994. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  10995. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  10996. // 305–363 (1997).
  10997. // Code adapted from GeographicLib by Charles F. F. Karney,
  10998. // http://geographiclib.sourceforge.net/
  10999. function adder() {
  11000. return new Adder;
  11001. }
  11002. function Adder() {
  11003. this.reset();
  11004. }
  11005. Adder.prototype = {
  11006. constructor: Adder,
  11007. reset: function() {
  11008. this.s = // rounded value
  11009. this.t = 0; // exact error
  11010. },
  11011. add: function(y) {
  11012. add$1(temp, y, this.t);
  11013. add$1(this, temp.s, this.s);
  11014. if (this.s) this.t += temp.t;
  11015. else this.s = temp.t;
  11016. },
  11017. valueOf: function() {
  11018. return this.s;
  11019. }
  11020. };
  11021. var temp = new Adder;
  11022. function add$1(adder, a, b) {
  11023. var x = adder.s = a + b,
  11024. bv = x - a,
  11025. av = x - bv;
  11026. adder.t = (a - av) + (b - bv);
  11027. }
  11028. var epsilon$4 = 1e-6;
  11029. var epsilon2$2 = 1e-12;
  11030. var pi$3 = Math.PI;
  11031. var halfPi$2 = pi$3 / 2;
  11032. var quarterPi = pi$3 / 4;
  11033. var tau$3 = pi$3 * 2;
  11034. var degrees$1 = 180 / pi$3;
  11035. var radians = pi$3 / 180;
  11036. var abs = Math.abs;
  11037. var atan = Math.atan;
  11038. var atan2 = Math.atan2;
  11039. var cos = Math.cos;
  11040. var ceil = Math.ceil;
  11041. var exp = Math.exp;
  11042. var log$1 = Math.log;
  11043. var pow$1 = Math.pow;
  11044. var sin = Math.sin;
  11045. var sign$1 = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  11046. var sqrt$1 = Math.sqrt;
  11047. var tan = Math.tan;
  11048. function acos(x) {
  11049. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  11050. }
  11051. function asin$1(x) {
  11052. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  11053. }
  11054. function haversin(x) {
  11055. return (x = sin(x / 2)) * x;
  11056. }
  11057. function noop$2() {}
  11058. function streamGeometry(geometry, stream) {
  11059. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  11060. streamGeometryType[geometry.type](geometry, stream);
  11061. }
  11062. }
  11063. var streamObjectType = {
  11064. Feature: function(feature, stream) {
  11065. streamGeometry(feature.geometry, stream);
  11066. },
  11067. FeatureCollection: function(object, stream) {
  11068. var features = object.features, i = -1, n = features.length;
  11069. while (++i < n) streamGeometry(features[i].geometry, stream);
  11070. }
  11071. };
  11072. var streamGeometryType = {
  11073. Sphere: function(object, stream) {
  11074. stream.sphere();
  11075. },
  11076. Point: function(object, stream) {
  11077. object = object.coordinates;
  11078. stream.point(object[0], object[1], object[2]);
  11079. },
  11080. MultiPoint: function(object, stream) {
  11081. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  11082. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  11083. },
  11084. LineString: function(object, stream) {
  11085. streamLine(object.coordinates, stream, 0);
  11086. },
  11087. MultiLineString: function(object, stream) {
  11088. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  11089. while (++i < n) streamLine(coordinates[i], stream, 0);
  11090. },
  11091. Polygon: function(object, stream) {
  11092. streamPolygon(object.coordinates, stream);
  11093. },
  11094. MultiPolygon: function(object, stream) {
  11095. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  11096. while (++i < n) streamPolygon(coordinates[i], stream);
  11097. },
  11098. GeometryCollection: function(object, stream) {
  11099. var geometries = object.geometries, i = -1, n = geometries.length;
  11100. while (++i < n) streamGeometry(geometries[i], stream);
  11101. }
  11102. };
  11103. function streamLine(coordinates, stream, closed) {
  11104. var i = -1, n = coordinates.length - closed, coordinate;
  11105. stream.lineStart();
  11106. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  11107. stream.lineEnd();
  11108. }
  11109. function streamPolygon(coordinates, stream) {
  11110. var i = -1, n = coordinates.length;
  11111. stream.polygonStart();
  11112. while (++i < n) streamLine(coordinates[i], stream, 1);
  11113. stream.polygonEnd();
  11114. }
  11115. function stream(object, stream) {
  11116. if (object && streamObjectType.hasOwnProperty(object.type)) {
  11117. streamObjectType[object.type](object, stream);
  11118. } else {
  11119. streamGeometry(object, stream);
  11120. }
  11121. }
  11122. var areaRingSum;
  11123. var areaSum;
  11124. var lambda00;
  11125. var phi00;
  11126. var lambda0;
  11127. var cosPhi0;
  11128. var sinPhi0;
  11129. var areaStream = {
  11130. point: noop$2,
  11131. lineStart: noop$2,
  11132. lineEnd: noop$2,
  11133. polygonStart: function() {
  11134. areaRingSum.reset();
  11135. areaStream.lineStart = areaRingStart;
  11136. areaStream.lineEnd = areaRingEnd;
  11137. },
  11138. polygonEnd: function() {
  11139. var areaRing = +areaRingSum;
  11140. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  11141. this.lineStart = this.lineEnd = this.point = noop$2;
  11142. },
  11143. sphere: function() {
  11144. areaSum.add(tau$3);
  11145. }
  11146. };
  11147. function areaRingStart() {
  11148. areaStream.point = areaPointFirst;
  11149. }
  11150. function areaRingEnd() {
  11151. areaPoint(lambda00, phi00);
  11152. }
  11153. function areaPointFirst(lambda, phi) {
  11154. areaStream.point = areaPoint;
  11155. lambda00 = lambda, phi00 = phi;
  11156. lambda *= radians, phi *= radians;
  11157. lambda0 = lambda, cosPhi0 = cos(phi = phi / 2 + quarterPi), sinPhi0 = sin(phi);
  11158. }
  11159. function areaPoint(lambda, phi) {
  11160. lambda *= radians, phi *= radians;
  11161. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  11162. // Spherical excess E for a spherical triangle with vertices: south pole,
  11163. // previous point, current point. Uses a formula derived from Cagnoli’s
  11164. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  11165. var dLambda = lambda - lambda0,
  11166. sdLambda = dLambda >= 0 ? 1 : -1,
  11167. adLambda = sdLambda * dLambda,
  11168. cosPhi = cos(phi),
  11169. sinPhi = sin(phi),
  11170. k = sinPhi0 * sinPhi,
  11171. u = cosPhi0 * cosPhi + k * cos(adLambda),
  11172. v = k * sdLambda * sin(adLambda);
  11173. areaRingSum.add(atan2(v, u));
  11174. // Advance the previous points.
  11175. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  11176. }
  11177. function area$2(object) {
  11178. if (areaSum) areaSum.reset();
  11179. else areaSum = adder(), areaRingSum = adder();
  11180. stream(object, areaStream);
  11181. return areaSum * 2;
  11182. }
  11183. function spherical(cartesian) {
  11184. return [atan2(cartesian[1], cartesian[0]), asin$1(cartesian[2])];
  11185. }
  11186. function cartesian(spherical) {
  11187. var lambda = spherical[0], phi = spherical[1], cosPhi = cos(phi);
  11188. return [cosPhi * cos(lambda), cosPhi * sin(lambda), sin(phi)];
  11189. }
  11190. function cartesianDot(a, b) {
  11191. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  11192. }
  11193. function cartesianCross(a, b) {
  11194. 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]];
  11195. }
  11196. // TODO return a
  11197. function cartesianAddInPlace(a, b) {
  11198. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  11199. }
  11200. function cartesianScale(vector, k) {
  11201. return [vector[0] * k, vector[1] * k, vector[2] * k];
  11202. }
  11203. // TODO return d
  11204. function cartesianNormalizeInPlace(d) {
  11205. var l = sqrt$1(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  11206. d[0] /= l, d[1] /= l, d[2] /= l;
  11207. }
  11208. var lambda0$1;
  11209. var phi0;
  11210. var lambda1;
  11211. var phi1;
  11212. var lambda2;
  11213. var lambda00$1;
  11214. var phi00$1;
  11215. var p0;
  11216. var deltaSum;
  11217. var ranges;
  11218. var range$1;
  11219. var boundsStream = {
  11220. point: boundsPoint,
  11221. lineStart: boundsLineStart,
  11222. lineEnd: boundsLineEnd,
  11223. polygonStart: function() {
  11224. boundsStream.point = boundsRingPoint;
  11225. boundsStream.lineStart = boundsRingStart;
  11226. boundsStream.lineEnd = boundsRingEnd;
  11227. deltaSum.reset();
  11228. areaStream.polygonStart();
  11229. },
  11230. polygonEnd: function() {
  11231. areaStream.polygonEnd();
  11232. boundsStream.point = boundsPoint;
  11233. boundsStream.lineStart = boundsLineStart;
  11234. boundsStream.lineEnd = boundsLineEnd;
  11235. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  11236. else if (deltaSum > epsilon$4) phi1 = 90;
  11237. else if (deltaSum < -epsilon$4) phi0 = -90;
  11238. range$1[0] = lambda0$1, range$1[1] = lambda1;
  11239. }
  11240. };
  11241. function boundsPoint(lambda, phi) {
  11242. ranges.push(range$1 = [lambda0$1 = lambda, lambda1 = lambda]);
  11243. if (phi < phi0) phi0 = phi;
  11244. if (phi > phi1) phi1 = phi;
  11245. }
  11246. function linePoint(lambda, phi) {
  11247. var p = cartesian([lambda * radians, phi * radians]);
  11248. if (p0) {
  11249. var normal = cartesianCross(p0, p),
  11250. equatorial = [normal[1], -normal[0], 0],
  11251. inflection = cartesianCross(equatorial, normal);
  11252. cartesianNormalizeInPlace(inflection);
  11253. inflection = spherical(inflection);
  11254. var delta = lambda - lambda2,
  11255. sign = delta > 0 ? 1 : -1,
  11256. lambdai = inflection[0] * degrees$1 * sign,
  11257. phii,
  11258. antimeridian = abs(delta) > 180;
  11259. if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  11260. phii = inflection[1] * degrees$1;
  11261. if (phii > phi1) phi1 = phii;
  11262. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  11263. phii = -inflection[1] * degrees$1;
  11264. if (phii < phi0) phi0 = phii;
  11265. } else {
  11266. if (phi < phi0) phi0 = phi;
  11267. if (phi > phi1) phi1 = phi;
  11268. }
  11269. if (antimeridian) {
  11270. if (lambda < lambda2) {
  11271. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  11272. } else {
  11273. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  11274. }
  11275. } else {
  11276. if (lambda1 >= lambda0$1) {
  11277. if (lambda < lambda0$1) lambda0$1 = lambda;
  11278. if (lambda > lambda1) lambda1 = lambda;
  11279. } else {
  11280. if (lambda > lambda2) {
  11281. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  11282. } else {
  11283. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  11284. }
  11285. }
  11286. }
  11287. } else {
  11288. boundsPoint(lambda, phi);
  11289. }
  11290. p0 = p, lambda2 = lambda;
  11291. }
  11292. function boundsLineStart() {
  11293. boundsStream.point = linePoint;
  11294. }
  11295. function boundsLineEnd() {
  11296. range$1[0] = lambda0$1, range$1[1] = lambda1;
  11297. boundsStream.point = boundsPoint;
  11298. p0 = null;
  11299. }
  11300. function boundsRingPoint(lambda, phi) {
  11301. if (p0) {
  11302. var delta = lambda - lambda2;
  11303. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  11304. } else {
  11305. lambda00$1 = lambda, phi00$1 = phi;
  11306. }
  11307. areaStream.point(lambda, phi);
  11308. linePoint(lambda, phi);
  11309. }
  11310. function boundsRingStart() {
  11311. areaStream.lineStart();
  11312. }
  11313. function boundsRingEnd() {
  11314. boundsRingPoint(lambda00$1, phi00$1);
  11315. areaStream.lineEnd();
  11316. if (abs(deltaSum) > epsilon$4) lambda0$1 = -(lambda1 = 180);
  11317. range$1[0] = lambda0$1, range$1[1] = lambda1;
  11318. p0 = null;
  11319. }
  11320. // Finds the left-right distance between two longitudes.
  11321. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  11322. // the distance between ±180° to be 360°.
  11323. function angle(lambda0, lambda1) {
  11324. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  11325. }
  11326. function rangeCompare(a, b) {
  11327. return a[0] - b[0];
  11328. }
  11329. function rangeContains(range, x) {
  11330. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  11331. }
  11332. function bounds(feature) {
  11333. var i, n, a, b, merged, deltaMax, delta;
  11334. if (deltaSum) deltaSum.reset();
  11335. else deltaSum = adder();
  11336. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  11337. ranges = [];
  11338. stream(feature, boundsStream);
  11339. // First, sort ranges by their minimum longitudes.
  11340. if (n = ranges.length) {
  11341. ranges.sort(rangeCompare);
  11342. // Then, merge any ranges that overlap.
  11343. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  11344. b = ranges[i];
  11345. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  11346. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  11347. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  11348. } else {
  11349. merged.push(a = b);
  11350. }
  11351. }
  11352. // Finally, find the largest gap between the merged ranges.
  11353. // The final bounding box will be the inverse of this gap.
  11354. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  11355. b = merged[i];
  11356. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  11357. }
  11358. }
  11359. ranges = range$1 = null;
  11360. return lambda0$1 === Infinity || phi0 === Infinity
  11361. ? [[NaN, NaN], [NaN, NaN]]
  11362. : [[lambda0$1, phi0], [lambda1, phi1]];
  11363. }
  11364. var W0;
  11365. var W1;
  11366. var X0;
  11367. var Y0;
  11368. var Z0;
  11369. var X1;
  11370. var Y1;
  11371. var Z1;
  11372. var X2;
  11373. var Y2;
  11374. var Z2;
  11375. var lambda00$2;
  11376. var phi00$2;
  11377. var x0;
  11378. var y0;
  11379. var z0;
  11380. // previous point
  11381. var centroidStream = {
  11382. sphere: noop$2,
  11383. point: centroidPoint,
  11384. lineStart: centroidLineStart,
  11385. lineEnd: centroidLineEnd,
  11386. polygonStart: function() {
  11387. centroidStream.lineStart = centroidRingStart;
  11388. centroidStream.lineEnd = centroidRingEnd;
  11389. },
  11390. polygonEnd: function() {
  11391. centroidStream.lineStart = centroidLineStart;
  11392. centroidStream.lineEnd = centroidLineEnd;
  11393. }
  11394. };
  11395. // Arithmetic mean of Cartesian vectors.
  11396. function centroidPoint(lambda, phi) {
  11397. lambda *= radians, phi *= radians;
  11398. var cosPhi = cos(phi);
  11399. centroidPointCartesian(cosPhi * cos(lambda), cosPhi * sin(lambda), sin(phi));
  11400. }
  11401. function centroidPointCartesian(x, y, z) {
  11402. ++W0;
  11403. X0 += (x - X0) / W0;
  11404. Y0 += (y - Y0) / W0;
  11405. Z0 += (z - Z0) / W0;
  11406. }
  11407. function centroidLineStart() {
  11408. centroidStream.point = centroidLinePointFirst;
  11409. }
  11410. function centroidLinePointFirst(lambda, phi) {
  11411. lambda *= radians, phi *= radians;
  11412. var cosPhi = cos(phi);
  11413. x0 = cosPhi * cos(lambda);
  11414. y0 = cosPhi * sin(lambda);
  11415. z0 = sin(phi);
  11416. centroidStream.point = centroidLinePoint;
  11417. centroidPointCartesian(x0, y0, z0);
  11418. }
  11419. function centroidLinePoint(lambda, phi) {
  11420. lambda *= radians, phi *= radians;
  11421. var cosPhi = cos(phi),
  11422. x = cosPhi * cos(lambda),
  11423. y = cosPhi * sin(lambda),
  11424. z = sin(phi),
  11425. w = atan2(sqrt$1((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
  11426. W1 += w;
  11427. X1 += w * (x0 + (x0 = x));
  11428. Y1 += w * (y0 + (y0 = y));
  11429. Z1 += w * (z0 + (z0 = z));
  11430. centroidPointCartesian(x0, y0, z0);
  11431. }
  11432. function centroidLineEnd() {
  11433. centroidStream.point = centroidPoint;
  11434. }
  11435. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  11436. // J. Applied Mechanics 42, 239 (1975).
  11437. function centroidRingStart() {
  11438. centroidStream.point = centroidRingPointFirst;
  11439. }
  11440. function centroidRingEnd() {
  11441. centroidRingPoint(lambda00$2, phi00$2);
  11442. centroidStream.point = centroidPoint;
  11443. }
  11444. function centroidRingPointFirst(lambda, phi) {
  11445. lambda00$2 = lambda, phi00$2 = phi;
  11446. lambda *= radians, phi *= radians;
  11447. centroidStream.point = centroidRingPoint;
  11448. var cosPhi = cos(phi);
  11449. x0 = cosPhi * cos(lambda);
  11450. y0 = cosPhi * sin(lambda);
  11451. z0 = sin(phi);
  11452. centroidPointCartesian(x0, y0, z0);
  11453. }
  11454. function centroidRingPoint(lambda, phi) {
  11455. lambda *= radians, phi *= radians;
  11456. var cosPhi = cos(phi),
  11457. x = cosPhi * cos(lambda),
  11458. y = cosPhi * sin(lambda),
  11459. z = sin(phi),
  11460. cx = y0 * z - z0 * y,
  11461. cy = z0 * x - x0 * z,
  11462. cz = x0 * y - y0 * x,
  11463. m = sqrt$1(cx * cx + cy * cy + cz * cz),
  11464. u = x0 * x + y0 * y + z0 * z,
  11465. v = m && -acos(u) / m, // area weight
  11466. w = atan2(m, u); // line weight
  11467. X2 += v * cx;
  11468. Y2 += v * cy;
  11469. Z2 += v * cz;
  11470. W1 += w;
  11471. X1 += w * (x0 + (x0 = x));
  11472. Y1 += w * (y0 + (y0 = y));
  11473. Z1 += w * (z0 + (z0 = z));
  11474. centroidPointCartesian(x0, y0, z0);
  11475. }
  11476. function centroid$1(object) {
  11477. W0 = W1 =
  11478. X0 = Y0 = Z0 =
  11479. X1 = Y1 = Z1 =
  11480. X2 = Y2 = Z2 = 0;
  11481. stream(object, centroidStream);
  11482. var x = X2,
  11483. y = Y2,
  11484. z = Z2,
  11485. m = x * x + y * y + z * z;
  11486. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  11487. if (m < epsilon2$2) {
  11488. x = X1, y = Y1, z = Z1;
  11489. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  11490. if (W1 < epsilon$4) x = X0, y = Y0, z = Z0;
  11491. m = x * x + y * y + z * z;
  11492. // If the feature still has an undefined ccentroid, then return.
  11493. if (m < epsilon2$2) return [NaN, NaN];
  11494. }
  11495. return [atan2(y, x) * degrees$1, asin$1(z / sqrt$1(m)) * degrees$1];
  11496. }
  11497. function constant$11(x) {
  11498. return function() {
  11499. return x;
  11500. };
  11501. }
  11502. function compose(a, b) {
  11503. function compose(x, y) {
  11504. return x = a(x, y), b(x[0], x[1]);
  11505. }
  11506. if (a.invert && b.invert) compose.invert = function(x, y) {
  11507. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  11508. };
  11509. return compose;
  11510. }
  11511. function rotationIdentity(lambda, phi) {
  11512. return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  11513. }
  11514. rotationIdentity.invert = rotationIdentity;
  11515. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  11516. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  11517. : rotationLambda(deltaLambda))
  11518. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  11519. : rotationIdentity);
  11520. }
  11521. function forwardRotationLambda(deltaLambda) {
  11522. return function(lambda, phi) {
  11523. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  11524. };
  11525. }
  11526. function rotationLambda(deltaLambda) {
  11527. var rotation = forwardRotationLambda(deltaLambda);
  11528. rotation.invert = forwardRotationLambda(-deltaLambda);
  11529. return rotation;
  11530. }
  11531. function rotationPhiGamma(deltaPhi, deltaGamma) {
  11532. var cosDeltaPhi = cos(deltaPhi),
  11533. sinDeltaPhi = sin(deltaPhi),
  11534. cosDeltaGamma = cos(deltaGamma),
  11535. sinDeltaGamma = sin(deltaGamma);
  11536. function rotation(lambda, phi) {
  11537. var cosPhi = cos(phi),
  11538. x = cos(lambda) * cosPhi,
  11539. y = sin(lambda) * cosPhi,
  11540. z = sin(phi),
  11541. k = z * cosDeltaPhi + x * sinDeltaPhi;
  11542. return [
  11543. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  11544. asin$1(k * cosDeltaGamma + y * sinDeltaGamma)
  11545. ];
  11546. }
  11547. rotation.invert = function(lambda, phi) {
  11548. var cosPhi = cos(phi),
  11549. x = cos(lambda) * cosPhi,
  11550. y = sin(lambda) * cosPhi,
  11551. z = sin(phi),
  11552. k = z * cosDeltaGamma - y * sinDeltaGamma;
  11553. return [
  11554. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  11555. asin$1(k * cosDeltaPhi - x * sinDeltaPhi)
  11556. ];
  11557. };
  11558. return rotation;
  11559. }
  11560. function rotation(rotate) {
  11561. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  11562. function forward(coordinates) {
  11563. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  11564. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  11565. }
  11566. forward.invert = function(coordinates) {
  11567. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  11568. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  11569. };
  11570. return forward;
  11571. }
  11572. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  11573. function circleStream(stream, radius, delta, direction, t0, t1) {
  11574. if (!delta) return;
  11575. var cosRadius = cos(radius),
  11576. sinRadius = sin(radius),
  11577. step = direction * delta;
  11578. if (t0 == null) {
  11579. t0 = radius + direction * tau$3;
  11580. t1 = radius - step / 2;
  11581. } else {
  11582. t0 = circleRadius(cosRadius, t0);
  11583. t1 = circleRadius(cosRadius, t1);
  11584. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  11585. }
  11586. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  11587. point = spherical([cosRadius, -sinRadius * cos(t), -sinRadius * sin(t)]);
  11588. stream.point(point[0], point[1]);
  11589. }
  11590. }
  11591. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  11592. function circleRadius(cosRadius, point) {
  11593. point = cartesian(point), point[0] -= cosRadius;
  11594. cartesianNormalizeInPlace(point);
  11595. var radius = acos(-point[1]);
  11596. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$4) % tau$3;
  11597. }
  11598. function circle$1() {
  11599. var center = constant$11([0, 0]),
  11600. radius = constant$11(90),
  11601. precision = constant$11(6),
  11602. ring,
  11603. rotate,
  11604. stream = {point: point};
  11605. function point(x, y) {
  11606. ring.push(x = rotate(x, y));
  11607. x[0] *= degrees$1, x[1] *= degrees$1;
  11608. }
  11609. function circle() {
  11610. var c = center.apply(this, arguments),
  11611. r = radius.apply(this, arguments) * radians,
  11612. p = precision.apply(this, arguments) * radians;
  11613. ring = [];
  11614. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  11615. circleStream(stream, r, p, 1);
  11616. c = {type: "Polygon", coordinates: [ring]};
  11617. ring = rotate = null;
  11618. return c;
  11619. }
  11620. circle.center = function(_) {
  11621. return arguments.length ? (center = typeof _ === "function" ? _ : constant$11([+_[0], +_[1]]), circle) : center;
  11622. };
  11623. circle.radius = function(_) {
  11624. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$11(+_), circle) : radius;
  11625. };
  11626. circle.precision = function(_) {
  11627. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$11(+_), circle) : precision;
  11628. };
  11629. return circle;
  11630. }
  11631. function clipBuffer() {
  11632. var lines = [],
  11633. line;
  11634. return {
  11635. point: function(x, y) {
  11636. line.push([x, y]);
  11637. },
  11638. lineStart: function() {
  11639. lines.push(line = []);
  11640. },
  11641. lineEnd: noop$2,
  11642. rejoin: function() {
  11643. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  11644. },
  11645. result: function() {
  11646. var result = lines;
  11647. lines = [];
  11648. line = null;
  11649. return result;
  11650. }
  11651. };
  11652. }
  11653. function clipLine(a, b, x0, y0, x1, y1) {
  11654. var ax = a[0],
  11655. ay = a[1],
  11656. bx = b[0],
  11657. by = b[1],
  11658. t0 = 0,
  11659. t1 = 1,
  11660. dx = bx - ax,
  11661. dy = by - ay,
  11662. r;
  11663. r = x0 - ax;
  11664. if (!dx && r > 0) return;
  11665. r /= dx;
  11666. if (dx < 0) {
  11667. if (r < t0) return;
  11668. if (r < t1) t1 = r;
  11669. } else if (dx > 0) {
  11670. if (r > t1) return;
  11671. if (r > t0) t0 = r;
  11672. }
  11673. r = x1 - ax;
  11674. if (!dx && r < 0) return;
  11675. r /= dx;
  11676. if (dx < 0) {
  11677. if (r > t1) return;
  11678. if (r > t0) t0 = r;
  11679. } else if (dx > 0) {
  11680. if (r < t0) return;
  11681. if (r < t1) t1 = r;
  11682. }
  11683. r = y0 - ay;
  11684. if (!dy && r > 0) return;
  11685. r /= dy;
  11686. if (dy < 0) {
  11687. if (r < t0) return;
  11688. if (r < t1) t1 = r;
  11689. } else if (dy > 0) {
  11690. if (r > t1) return;
  11691. if (r > t0) t0 = r;
  11692. }
  11693. r = y1 - ay;
  11694. if (!dy && r < 0) return;
  11695. r /= dy;
  11696. if (dy < 0) {
  11697. if (r > t1) return;
  11698. if (r > t0) t0 = r;
  11699. } else if (dy > 0) {
  11700. if (r < t0) return;
  11701. if (r < t1) t1 = r;
  11702. }
  11703. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  11704. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  11705. return true;
  11706. }
  11707. function pointEqual(a, b) {
  11708. return abs(a[0] - b[0]) < epsilon$4 && abs(a[1] - b[1]) < epsilon$4;
  11709. }
  11710. function Intersection(point, points, other, entry) {
  11711. this.x = point;
  11712. this.z = points;
  11713. this.o = other; // another intersection
  11714. this.e = entry; // is an entry?
  11715. this.v = false; // visited
  11716. this.n = this.p = null; // next & previous
  11717. }
  11718. // A generalized polygon clipping algorithm: given a polygon that has been cut
  11719. // into its visible line segments, and rejoins the segments by interpolating
  11720. // along the clip edge.
  11721. function clipPolygon(segments, compareIntersection, startInside, interpolate, stream) {
  11722. var subject = [],
  11723. clip = [],
  11724. i,
  11725. n;
  11726. segments.forEach(function(segment) {
  11727. if ((n = segment.length - 1) <= 0) return;
  11728. var n, p0 = segment[0], p1 = segment[n], x;
  11729. // If the first and last points of a segment are coincident, then treat as a
  11730. // closed ring. TODO if all rings are closed, then the winding order of the
  11731. // exterior ring should be checked.
  11732. if (pointEqual(p0, p1)) {
  11733. stream.lineStart();
  11734. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  11735. stream.lineEnd();
  11736. return;
  11737. }
  11738. subject.push(x = new Intersection(p0, segment, null, true));
  11739. clip.push(x.o = new Intersection(p0, null, x, false));
  11740. subject.push(x = new Intersection(p1, segment, null, false));
  11741. clip.push(x.o = new Intersection(p1, null, x, true));
  11742. });
  11743. if (!subject.length) return;
  11744. clip.sort(compareIntersection);
  11745. link$1(subject);
  11746. link$1(clip);
  11747. for (i = 0, n = clip.length; i < n; ++i) {
  11748. clip[i].e = startInside = !startInside;
  11749. }
  11750. var start = subject[0],
  11751. points,
  11752. point;
  11753. while (1) {
  11754. // Find first unvisited intersection.
  11755. var current = start,
  11756. isSubject = true;
  11757. while (current.v) if ((current = current.n) === start) return;
  11758. points = current.z;
  11759. stream.lineStart();
  11760. do {
  11761. current.v = current.o.v = true;
  11762. if (current.e) {
  11763. if (isSubject) {
  11764. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  11765. } else {
  11766. interpolate(current.x, current.n.x, 1, stream);
  11767. }
  11768. current = current.n;
  11769. } else {
  11770. if (isSubject) {
  11771. points = current.p.z;
  11772. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  11773. } else {
  11774. interpolate(current.x, current.p.x, -1, stream);
  11775. }
  11776. current = current.p;
  11777. }
  11778. current = current.o;
  11779. points = current.z;
  11780. isSubject = !isSubject;
  11781. } while (!current.v);
  11782. stream.lineEnd();
  11783. }
  11784. }
  11785. function link$1(array) {
  11786. if (!(n = array.length)) return;
  11787. var n,
  11788. i = 0,
  11789. a = array[0],
  11790. b;
  11791. while (++i < n) {
  11792. a.n = b = array[i];
  11793. b.p = a;
  11794. a = b;
  11795. }
  11796. a.n = b = array[0];
  11797. b.p = a;
  11798. }
  11799. var clipMax = 1e9;
  11800. var clipMin = -clipMax;
  11801. // TODO Use d3-polygon’s polygonContains here for the ring check?
  11802. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  11803. function clipExtent(x0, y0, x1, y1) {
  11804. function visible(x, y) {
  11805. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  11806. }
  11807. function interpolate(from, to, direction, stream) {
  11808. var a = 0, a1 = 0;
  11809. if (from == null
  11810. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  11811. || comparePoint(from, to) < 0 ^ direction > 0) {
  11812. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  11813. while ((a = (a + direction + 4) % 4) !== a1);
  11814. } else {
  11815. stream.point(to[0], to[1]);
  11816. }
  11817. }
  11818. function corner(p, direction) {
  11819. return abs(p[0] - x0) < epsilon$4 ? direction > 0 ? 0 : 3
  11820. : abs(p[0] - x1) < epsilon$4 ? direction > 0 ? 2 : 1
  11821. : abs(p[1] - y0) < epsilon$4 ? direction > 0 ? 1 : 0
  11822. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  11823. }
  11824. function compareIntersection(a, b) {
  11825. return comparePoint(a.x, b.x);
  11826. }
  11827. function comparePoint(a, b) {
  11828. var ca = corner(a, 1),
  11829. cb = corner(b, 1);
  11830. return ca !== cb ? ca - cb
  11831. : ca === 0 ? b[1] - a[1]
  11832. : ca === 1 ? a[0] - b[0]
  11833. : ca === 2 ? a[1] - b[1]
  11834. : b[0] - a[0];
  11835. }
  11836. return function(stream) {
  11837. var activeStream = stream,
  11838. bufferStream = clipBuffer(),
  11839. segments,
  11840. polygon,
  11841. ring,
  11842. x__, y__, v__, // first point
  11843. x_, y_, v_, // previous point
  11844. first,
  11845. clean;
  11846. var clipStream = {
  11847. point: point,
  11848. lineStart: lineStart,
  11849. lineEnd: lineEnd,
  11850. polygonStart: polygonStart,
  11851. polygonEnd: polygonEnd
  11852. };
  11853. function point(x, y) {
  11854. if (visible(x, y)) activeStream.point(x, y);
  11855. }
  11856. function polygonInside() {
  11857. var winding = 0;
  11858. for (var i = 0, n = polygon.length; i < n; ++i) {
  11859. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  11860. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  11861. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  11862. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  11863. }
  11864. }
  11865. return winding;
  11866. }
  11867. // Buffer geometry within a polygon and then clip it en masse.
  11868. function polygonStart() {
  11869. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  11870. }
  11871. function polygonEnd() {
  11872. var startInside = polygonInside(),
  11873. cleanInside = clean && startInside,
  11874. visible = (segments = merge(segments)).length;
  11875. if (cleanInside || visible) {
  11876. stream.polygonStart();
  11877. if (cleanInside) {
  11878. stream.lineStart();
  11879. interpolate(null, null, 1, stream);
  11880. stream.lineEnd();
  11881. }
  11882. if (visible) {
  11883. clipPolygon(segments, compareIntersection, startInside, interpolate, stream);
  11884. }
  11885. stream.polygonEnd();
  11886. }
  11887. activeStream = stream, segments = polygon = ring = null;
  11888. }
  11889. function lineStart() {
  11890. clipStream.point = linePoint;
  11891. if (polygon) polygon.push(ring = []);
  11892. first = true;
  11893. v_ = false;
  11894. x_ = y_ = NaN;
  11895. }
  11896. // TODO rather than special-case polygons, simply handle them separately.
  11897. // Ideally, coincident intersection points should be jittered to avoid
  11898. // clipping issues.
  11899. function lineEnd() {
  11900. if (segments) {
  11901. linePoint(x__, y__);
  11902. if (v__ && v_) bufferStream.rejoin();
  11903. segments.push(bufferStream.result());
  11904. }
  11905. clipStream.point = point;
  11906. if (v_) activeStream.lineEnd();
  11907. }
  11908. function linePoint(x, y) {
  11909. var v = visible(x, y);
  11910. if (polygon) ring.push([x, y]);
  11911. if (first) {
  11912. x__ = x, y__ = y, v__ = v;
  11913. first = false;
  11914. if (v) {
  11915. activeStream.lineStart();
  11916. activeStream.point(x, y);
  11917. }
  11918. } else {
  11919. if (v && v_) activeStream.point(x, y);
  11920. else {
  11921. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  11922. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  11923. if (clipLine(a, b, x0, y0, x1, y1)) {
  11924. if (!v_) {
  11925. activeStream.lineStart();
  11926. activeStream.point(a[0], a[1]);
  11927. }
  11928. activeStream.point(b[0], b[1]);
  11929. if (!v) activeStream.lineEnd();
  11930. clean = false;
  11931. } else if (v) {
  11932. activeStream.lineStart();
  11933. activeStream.point(x, y);
  11934. clean = false;
  11935. }
  11936. }
  11937. }
  11938. x_ = x, y_ = y, v_ = v;
  11939. }
  11940. return clipStream;
  11941. };
  11942. }
  11943. function extent$1() {
  11944. var x0 = 0,
  11945. y0 = 0,
  11946. x1 = 960,
  11947. y1 = 500,
  11948. cache,
  11949. cacheStream,
  11950. clip;
  11951. return clip = {
  11952. stream: function(stream) {
  11953. return cache && cacheStream === stream ? cache : cache = clipExtent(x0, y0, x1, y1)(cacheStream = stream);
  11954. },
  11955. extent: function(_) {
  11956. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  11957. }
  11958. };
  11959. }
  11960. var lengthSum;
  11961. var lambda0$2;
  11962. var sinPhi0$1;
  11963. var cosPhi0$1;
  11964. var lengthStream = {
  11965. sphere: noop$2,
  11966. point: noop$2,
  11967. lineStart: lengthLineStart,
  11968. lineEnd: noop$2,
  11969. polygonStart: noop$2,
  11970. polygonEnd: noop$2
  11971. };
  11972. function lengthLineStart() {
  11973. lengthStream.point = lengthPointFirst;
  11974. lengthStream.lineEnd = lengthLineEnd;
  11975. }
  11976. function lengthLineEnd() {
  11977. lengthStream.point = lengthStream.lineEnd = noop$2;
  11978. }
  11979. function lengthPointFirst(lambda, phi) {
  11980. lambda *= radians, phi *= radians;
  11981. lambda0$2 = lambda, sinPhi0$1 = sin(phi), cosPhi0$1 = cos(phi);
  11982. lengthStream.point = lengthPoint;
  11983. }
  11984. function lengthPoint(lambda, phi) {
  11985. lambda *= radians, phi *= radians;
  11986. var sinPhi = sin(phi),
  11987. cosPhi = cos(phi),
  11988. delta = abs(lambda - lambda0$2),
  11989. cosDelta = cos(delta),
  11990. sinDelta = sin(delta),
  11991. x = cosPhi * sinDelta,
  11992. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  11993. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  11994. lengthSum.add(atan2(sqrt$1(x * x + y * y), z));
  11995. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  11996. }
  11997. function length$2(object) {
  11998. if (lengthSum) lengthSum.reset();
  11999. else lengthSum = adder();
  12000. stream(object, lengthStream);
  12001. return +lengthSum;
  12002. }
  12003. var coordinates = [null, null];
  12004. var object$1 = {type: "LineString", coordinates: coordinates};
  12005. function distance(a, b) {
  12006. coordinates[0] = a;
  12007. coordinates[1] = b;
  12008. return length$2(object$1);
  12009. }
  12010. function graticuleX(y0, y1, dy) {
  12011. var y = range(y0, y1 - epsilon$4, dy).concat(y1);
  12012. return function(x) { return y.map(function(y) { return [x, y]; }); };
  12013. }
  12014. function graticuleY(x0, x1, dx) {
  12015. var x = range(x0, x1 - epsilon$4, dx).concat(x1);
  12016. return function(y) { return x.map(function(x) { return [x, y]; }); };
  12017. }
  12018. function graticule() {
  12019. var x1, x0, X1, X0,
  12020. y1, y0, Y1, Y0,
  12021. dx = 10, dy = dx, DX = 90, DY = 360,
  12022. x, y, X, Y,
  12023. precision = 2.5;
  12024. function graticule() {
  12025. return {type: "MultiLineString", coordinates: lines()};
  12026. }
  12027. function lines() {
  12028. return range(ceil(X0 / DX) * DX, X1, DX).map(X)
  12029. .concat(range(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  12030. .concat(range(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$4; }).map(x))
  12031. .concat(range(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$4; }).map(y));
  12032. }
  12033. graticule.lines = function() {
  12034. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  12035. };
  12036. graticule.outline = function() {
  12037. return {
  12038. type: "Polygon",
  12039. coordinates: [
  12040. X(X0).concat(
  12041. Y(Y1).slice(1),
  12042. X(X1).reverse().slice(1),
  12043. Y(Y0).reverse().slice(1))
  12044. ]
  12045. };
  12046. };
  12047. graticule.extent = function(_) {
  12048. if (!arguments.length) return graticule.extentMinor();
  12049. return graticule.extentMajor(_).extentMinor(_);
  12050. };
  12051. graticule.extentMajor = function(_) {
  12052. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  12053. X0 = +_[0][0], X1 = +_[1][0];
  12054. Y0 = +_[0][1], Y1 = +_[1][1];
  12055. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  12056. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  12057. return graticule.precision(precision);
  12058. };
  12059. graticule.extentMinor = function(_) {
  12060. if (!arguments.length) return [[x0, y0], [x1, y1]];
  12061. x0 = +_[0][0], x1 = +_[1][0];
  12062. y0 = +_[0][1], y1 = +_[1][1];
  12063. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  12064. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  12065. return graticule.precision(precision);
  12066. };
  12067. graticule.step = function(_) {
  12068. if (!arguments.length) return graticule.stepMinor();
  12069. return graticule.stepMajor(_).stepMinor(_);
  12070. };
  12071. graticule.stepMajor = function(_) {
  12072. if (!arguments.length) return [DX, DY];
  12073. DX = +_[0], DY = +_[1];
  12074. return graticule;
  12075. };
  12076. graticule.stepMinor = function(_) {
  12077. if (!arguments.length) return [dx, dy];
  12078. dx = +_[0], dy = +_[1];
  12079. return graticule;
  12080. };
  12081. graticule.precision = function(_) {
  12082. if (!arguments.length) return precision;
  12083. precision = +_;
  12084. x = graticuleX(y0, y1, 90);
  12085. y = graticuleY(x0, x1, precision);
  12086. X = graticuleX(Y0, Y1, 90);
  12087. Y = graticuleY(X0, X1, precision);
  12088. return graticule;
  12089. };
  12090. return graticule
  12091. .extentMajor([[-180, -90 + epsilon$4], [180, 90 - epsilon$4]])
  12092. .extentMinor([[-180, -80 - epsilon$4], [180, 80 + epsilon$4]]);
  12093. }
  12094. function interpolate$2(a, b) {
  12095. var x0 = a[0] * radians,
  12096. y0 = a[1] * radians,
  12097. x1 = b[0] * radians,
  12098. y1 = b[1] * radians,
  12099. cy0 = cos(y0),
  12100. sy0 = sin(y0),
  12101. cy1 = cos(y1),
  12102. sy1 = sin(y1),
  12103. kx0 = cy0 * cos(x0),
  12104. ky0 = cy0 * sin(x0),
  12105. kx1 = cy1 * cos(x1),
  12106. ky1 = cy1 * sin(x1),
  12107. d = 2 * asin$1(sqrt$1(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  12108. k = sin(d);
  12109. var interpolate = d ? function(t) {
  12110. var B = sin(t *= d) / k,
  12111. A = sin(d - t) / k,
  12112. x = A * kx0 + B * kx1,
  12113. y = A * ky0 + B * ky1,
  12114. z = A * sy0 + B * sy1;
  12115. return [
  12116. atan2(y, x) * degrees$1,
  12117. atan2(z, sqrt$1(x * x + y * y)) * degrees$1
  12118. ];
  12119. } : function() {
  12120. return [x0 * degrees$1, y0 * degrees$1];
  12121. };
  12122. interpolate.distance = d;
  12123. return interpolate;
  12124. }
  12125. function identity$7(x) {
  12126. return x;
  12127. }
  12128. var areaSum$1 = adder();
  12129. var areaRingSum$1 = adder();
  12130. var x00;
  12131. var y00;
  12132. var x0$1;
  12133. var y0$1;
  12134. var areaStream$1 = {
  12135. point: noop$2,
  12136. lineStart: noop$2,
  12137. lineEnd: noop$2,
  12138. polygonStart: function() {
  12139. areaStream$1.lineStart = areaRingStart$1;
  12140. areaStream$1.lineEnd = areaRingEnd$1;
  12141. },
  12142. polygonEnd: function() {
  12143. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  12144. areaSum$1.add(abs(areaRingSum$1));
  12145. areaRingSum$1.reset();
  12146. },
  12147. result: function() {
  12148. var area = areaSum$1 / 2;
  12149. areaSum$1.reset();
  12150. return area;
  12151. }
  12152. };
  12153. function areaRingStart$1() {
  12154. areaStream$1.point = areaPointFirst$1;
  12155. }
  12156. function areaPointFirst$1(x, y) {
  12157. areaStream$1.point = areaPoint$1;
  12158. x00 = x0$1 = x, y00 = y0$1 = y;
  12159. }
  12160. function areaPoint$1(x, y) {
  12161. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  12162. x0$1 = x, y0$1 = y;
  12163. }
  12164. function areaRingEnd$1() {
  12165. areaPoint$1(x00, y00);
  12166. }
  12167. var x0$2 = Infinity;
  12168. var y0$2 = x0$2;
  12169. var x1 = -x0$2;
  12170. var y1 = x1;
  12171. var boundsStream$1 = {
  12172. point: boundsPoint$1,
  12173. lineStart: noop$2,
  12174. lineEnd: noop$2,
  12175. polygonStart: noop$2,
  12176. polygonEnd: noop$2,
  12177. result: function() {
  12178. var bounds = [[x0$2, y0$2], [x1, y1]];
  12179. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  12180. return bounds;
  12181. }
  12182. };
  12183. function boundsPoint$1(x, y) {
  12184. if (x < x0$2) x0$2 = x;
  12185. if (x > x1) x1 = x;
  12186. if (y < y0$2) y0$2 = y;
  12187. if (y > y1) y1 = y;
  12188. }
  12189. var X0$1 = 0;
  12190. var Y0$1 = 0;
  12191. var Z0$1 = 0;
  12192. var X1$1 = 0;
  12193. var Y1$1 = 0;
  12194. var Z1$1 = 0;
  12195. var X2$1 = 0;
  12196. var Y2$1 = 0;
  12197. var Z2$1 = 0;
  12198. var x00$1;
  12199. var y00$1;
  12200. var x0$3;
  12201. var y0$3;
  12202. var centroidStream$1 = {
  12203. point: centroidPoint$1,
  12204. lineStart: centroidLineStart$1,
  12205. lineEnd: centroidLineEnd$1,
  12206. polygonStart: function() {
  12207. centroidStream$1.lineStart = centroidRingStart$1;
  12208. centroidStream$1.lineEnd = centroidRingEnd$1;
  12209. },
  12210. polygonEnd: function() {
  12211. centroidStream$1.point = centroidPoint$1;
  12212. centroidStream$1.lineStart = centroidLineStart$1;
  12213. centroidStream$1.lineEnd = centroidLineEnd$1;
  12214. },
  12215. result: function() {
  12216. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  12217. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  12218. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  12219. : [NaN, NaN];
  12220. X0$1 = Y0$1 = Z0$1 =
  12221. X1$1 = Y1$1 = Z1$1 =
  12222. X2$1 = Y2$1 = Z2$1 = 0;
  12223. return centroid;
  12224. }
  12225. };
  12226. function centroidPoint$1(x, y) {
  12227. X0$1 += x;
  12228. Y0$1 += y;
  12229. ++Z0$1;
  12230. }
  12231. function centroidLineStart$1() {
  12232. centroidStream$1.point = centroidPointFirstLine;
  12233. }
  12234. function centroidPointFirstLine(x, y) {
  12235. centroidStream$1.point = centroidPointLine;
  12236. centroidPoint$1(x0$3 = x, y0$3 = y);
  12237. }
  12238. function centroidPointLine(x, y) {
  12239. var dx = x - x0$3, dy = y - y0$3, z = sqrt$1(dx * dx + dy * dy);
  12240. X1$1 += z * (x0$3 + x) / 2;
  12241. Y1$1 += z * (y0$3 + y) / 2;
  12242. Z1$1 += z;
  12243. centroidPoint$1(x0$3 = x, y0$3 = y);
  12244. }
  12245. function centroidLineEnd$1() {
  12246. centroidStream$1.point = centroidPoint$1;
  12247. }
  12248. function centroidRingStart$1() {
  12249. centroidStream$1.point = centroidPointFirstRing;
  12250. }
  12251. function centroidRingEnd$1() {
  12252. centroidPointRing(x00$1, y00$1);
  12253. }
  12254. function centroidPointFirstRing(x, y) {
  12255. centroidStream$1.point = centroidPointRing;
  12256. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  12257. }
  12258. function centroidPointRing(x, y) {
  12259. var dx = x - x0$3,
  12260. dy = y - y0$3,
  12261. z = sqrt$1(dx * dx + dy * dy);
  12262. X1$1 += z * (x0$3 + x) / 2;
  12263. Y1$1 += z * (y0$3 + y) / 2;
  12264. Z1$1 += z;
  12265. z = y0$3 * x - x0$3 * y;
  12266. X2$1 += z * (x0$3 + x);
  12267. Y2$1 += z * (y0$3 + y);
  12268. Z2$1 += z * 3;
  12269. centroidPoint$1(x0$3 = x, y0$3 = y);
  12270. }
  12271. function PathContext(context) {
  12272. var pointRadius = 4.5;
  12273. var stream = {
  12274. point: point,
  12275. // While inside a line, override point to moveTo then lineTo.
  12276. lineStart: function() { stream.point = pointLineStart; },
  12277. lineEnd: lineEnd,
  12278. // While inside a polygon, override lineEnd to closePath.
  12279. polygonStart: function() { stream.lineEnd = lineEndPolygon; },
  12280. polygonEnd: function() { stream.lineEnd = lineEnd; stream.point = point; },
  12281. pointRadius: function(_) {
  12282. pointRadius = _;
  12283. return stream;
  12284. },
  12285. result: noop$2
  12286. };
  12287. function point(x, y) {
  12288. context.moveTo(x + pointRadius, y);
  12289. context.arc(x, y, pointRadius, 0, tau$3);
  12290. }
  12291. function pointLineStart(x, y) {
  12292. context.moveTo(x, y);
  12293. stream.point = pointLine;
  12294. }
  12295. function pointLine(x, y) {
  12296. context.lineTo(x, y);
  12297. }
  12298. function lineEnd() {
  12299. stream.point = point;
  12300. }
  12301. function lineEndPolygon() {
  12302. context.closePath();
  12303. }
  12304. return stream;
  12305. }
  12306. function PathString() {
  12307. var pointCircle = circle$2(4.5),
  12308. string = [];
  12309. var stream = {
  12310. point: point,
  12311. lineStart: lineStart,
  12312. lineEnd: lineEnd,
  12313. polygonStart: function() {
  12314. stream.lineEnd = lineEndPolygon;
  12315. },
  12316. polygonEnd: function() {
  12317. stream.lineEnd = lineEnd;
  12318. stream.point = point;
  12319. },
  12320. pointRadius: function(_) {
  12321. pointCircle = circle$2(_);
  12322. return stream;
  12323. },
  12324. result: function() {
  12325. if (string.length) {
  12326. var result = string.join("");
  12327. string = [];
  12328. return result;
  12329. }
  12330. }
  12331. };
  12332. function point(x, y) {
  12333. string.push("M", x, ",", y, pointCircle);
  12334. }
  12335. function pointLineStart(x, y) {
  12336. string.push("M", x, ",", y);
  12337. stream.point = pointLine;
  12338. }
  12339. function pointLine(x, y) {
  12340. string.push("L", x, ",", y);
  12341. }
  12342. function lineStart() {
  12343. stream.point = pointLineStart;
  12344. }
  12345. function lineEnd() {
  12346. stream.point = point;
  12347. }
  12348. function lineEndPolygon() {
  12349. string.push("Z");
  12350. }
  12351. return stream;
  12352. }
  12353. function circle$2(radius) {
  12354. return "m0," + radius
  12355. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  12356. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  12357. + "z";
  12358. }
  12359. function index$3() {
  12360. var pointRadius = 4.5,
  12361. projection,
  12362. projectionStream,
  12363. context,
  12364. contextStream;
  12365. function path(object) {
  12366. if (object) {
  12367. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  12368. stream(object, projectionStream(contextStream));
  12369. }
  12370. return contextStream.result();
  12371. }
  12372. path.area = function(object) {
  12373. stream(object, projectionStream(areaStream$1));
  12374. return areaStream$1.result();
  12375. };
  12376. path.bounds = function(object) {
  12377. stream(object, projectionStream(boundsStream$1));
  12378. return boundsStream$1.result();
  12379. };
  12380. path.centroid = function(object) {
  12381. stream(object, projectionStream(centroidStream$1));
  12382. return centroidStream$1.result();
  12383. };
  12384. path.projection = function(_) {
  12385. return arguments.length ? (projectionStream = (projection = _) == null ? identity$7 : _.stream, path) : projection;
  12386. };
  12387. path.context = function(_) {
  12388. if (!arguments.length) return context;
  12389. contextStream = (context = _) == null ? new PathString : new PathContext(_);
  12390. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  12391. return path;
  12392. };
  12393. path.pointRadius = function(_) {
  12394. if (!arguments.length) return pointRadius;
  12395. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  12396. return path;
  12397. };
  12398. return path.projection(null).context(null);
  12399. }
  12400. var sum$2 = adder();
  12401. function polygonContains(polygon, point) {
  12402. var lambda = point[0],
  12403. phi = point[1],
  12404. normal = [sin(lambda), -cos(lambda), 0],
  12405. angle = 0,
  12406. winding = 0;
  12407. for (var i = 0, n = polygon.length; i < n; ++i) {
  12408. if (!(m = (ring = polygon[i]).length)) continue;
  12409. var ring,
  12410. m,
  12411. point0 = ring[m - 1],
  12412. lambda0 = point0[0],
  12413. phi0 = point0[1] / 2 + quarterPi,
  12414. sinPhi0 = sin(phi0),
  12415. cosPhi0 = cos(phi0);
  12416. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  12417. var point1 = ring[j],
  12418. lambda1 = point1[0],
  12419. phi1 = point1[1] / 2 + quarterPi,
  12420. sinPhi1 = sin(phi1),
  12421. cosPhi1 = cos(phi1),
  12422. delta = lambda1 - lambda0,
  12423. sign = delta >= 0 ? 1 : -1,
  12424. absDelta = sign * delta,
  12425. antimeridian = absDelta > pi$3,
  12426. k = sinPhi0 * sinPhi1;
  12427. sum$2.add(atan2(k * sign * sin(absDelta), cosPhi0 * cosPhi1 + k * cos(absDelta)));
  12428. angle += antimeridian ? delta + sign * tau$3 : delta;
  12429. // Are the longitudes either side of the point’s meridian (lambda),
  12430. // and are the latitudes smaller than the parallel (phi)?
  12431. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  12432. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  12433. cartesianNormalizeInPlace(arc);
  12434. var intersection = cartesianCross(normal, arc);
  12435. cartesianNormalizeInPlace(intersection);
  12436. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]);
  12437. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  12438. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  12439. }
  12440. }
  12441. }
  12442. }
  12443. // First, determine whether the South pole is inside or outside:
  12444. //
  12445. // It is inside if:
  12446. // * the polygon winds around it in a clockwise direction.
  12447. // * the polygon does not (cumulatively) wind around it, but has a negative
  12448. // (counter-clockwise) area.
  12449. //
  12450. // Second, count the (signed) number of times a segment crosses a lambda
  12451. // from the point to the South pole. If it is zero, then the point is the
  12452. // same side as the South pole.
  12453. var contains = (angle < -epsilon$4 || angle < epsilon$4 && sum$2 < -epsilon$4) ^ (winding & 1);
  12454. sum$2.reset();
  12455. return contains;
  12456. }
  12457. function clip(pointVisible, clipLine, interpolate, start) {
  12458. return function(rotate, sink) {
  12459. var line = clipLine(sink),
  12460. rotatedStart = rotate.invert(start[0], start[1]),
  12461. ringBuffer = clipBuffer(),
  12462. ringSink = clipLine(ringBuffer),
  12463. polygonStarted = false,
  12464. polygon,
  12465. segments,
  12466. ring;
  12467. var clip = {
  12468. point: point,
  12469. lineStart: lineStart,
  12470. lineEnd: lineEnd,
  12471. polygonStart: function() {
  12472. clip.point = pointRing;
  12473. clip.lineStart = ringStart;
  12474. clip.lineEnd = ringEnd;
  12475. segments = [];
  12476. polygon = [];
  12477. },
  12478. polygonEnd: function() {
  12479. clip.point = point;
  12480. clip.lineStart = lineStart;
  12481. clip.lineEnd = lineEnd;
  12482. segments = merge(segments);
  12483. var startInside = polygonContains(polygon, rotatedStart);
  12484. if (segments.length) {
  12485. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  12486. clipPolygon(segments, compareIntersection, startInside, interpolate, sink);
  12487. } else if (startInside) {
  12488. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  12489. sink.lineStart();
  12490. interpolate(null, null, 1, sink);
  12491. sink.lineEnd();
  12492. }
  12493. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  12494. segments = polygon = null;
  12495. },
  12496. sphere: function() {
  12497. sink.polygonStart();
  12498. sink.lineStart();
  12499. interpolate(null, null, 1, sink);
  12500. sink.lineEnd();
  12501. sink.polygonEnd();
  12502. }
  12503. };
  12504. function point(lambda, phi) {
  12505. var point = rotate(lambda, phi);
  12506. if (pointVisible(lambda = point[0], phi = point[1])) sink.point(lambda, phi);
  12507. }
  12508. function pointLine(lambda, phi) {
  12509. var point = rotate(lambda, phi);
  12510. line.point(point[0], point[1]);
  12511. }
  12512. function lineStart() {
  12513. clip.point = pointLine;
  12514. line.lineStart();
  12515. }
  12516. function lineEnd() {
  12517. clip.point = point;
  12518. line.lineEnd();
  12519. }
  12520. function pointRing(lambda, phi) {
  12521. ring.push([lambda, phi]);
  12522. var point = rotate(lambda, phi);
  12523. ringSink.point(point[0], point[1]);
  12524. }
  12525. function ringStart() {
  12526. ringSink.lineStart();
  12527. ring = [];
  12528. }
  12529. function ringEnd() {
  12530. pointRing(ring[0][0], ring[0][1]);
  12531. ringSink.lineEnd();
  12532. var clean = ringSink.clean(),
  12533. ringSegments = ringBuffer.result(),
  12534. i, n = ringSegments.length, m,
  12535. segment,
  12536. point;
  12537. ring.pop();
  12538. polygon.push(ring);
  12539. ring = null;
  12540. if (!n) return;
  12541. // No intersections.
  12542. if (clean & 1) {
  12543. segment = ringSegments[0];
  12544. if ((m = segment.length - 1) > 0) {
  12545. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  12546. sink.lineStart();
  12547. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  12548. sink.lineEnd();
  12549. }
  12550. return;
  12551. }
  12552. // Rejoin connected segments.
  12553. // TODO reuse ringBuffer.rejoin()?
  12554. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  12555. segments.push(ringSegments.filter(validSegment));
  12556. }
  12557. return clip;
  12558. };
  12559. }
  12560. function validSegment(segment) {
  12561. return segment.length > 1;
  12562. }
  12563. // Intersections are sorted along the clip edge. For both antimeridian cutting
  12564. // and circle clipping, the same comparison is used.
  12565. function compareIntersection(a, b) {
  12566. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$4 : halfPi$2 - a[1])
  12567. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$4 : halfPi$2 - b[1]);
  12568. }
  12569. var clipAntimeridian = clip(
  12570. function() { return true; },
  12571. clipAntimeridianLine,
  12572. clipAntimeridianInterpolate,
  12573. [-pi$3, -halfPi$2]
  12574. );
  12575. // Takes a line and cuts into visible segments. Return values: 0 - there were
  12576. // intersections or the line was empty; 1 - no intersections; 2 - there were
  12577. // intersections, and the first and last segments should be rejoined.
  12578. function clipAntimeridianLine(stream) {
  12579. var lambda0 = NaN,
  12580. phi0 = NaN,
  12581. sign0 = NaN,
  12582. clean; // no intersections
  12583. return {
  12584. lineStart: function() {
  12585. stream.lineStart();
  12586. clean = 1;
  12587. },
  12588. point: function(lambda1, phi1) {
  12589. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  12590. delta = abs(lambda1 - lambda0);
  12591. if (abs(delta - pi$3) < epsilon$4) { // line crosses a pole
  12592. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  12593. stream.point(sign0, phi0);
  12594. stream.lineEnd();
  12595. stream.lineStart();
  12596. stream.point(sign1, phi0);
  12597. stream.point(lambda1, phi0);
  12598. clean = 0;
  12599. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  12600. if (abs(lambda0 - sign0) < epsilon$4) lambda0 -= sign0 * epsilon$4; // handle degeneracies
  12601. if (abs(lambda1 - sign1) < epsilon$4) lambda1 -= sign1 * epsilon$4;
  12602. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  12603. stream.point(sign0, phi0);
  12604. stream.lineEnd();
  12605. stream.lineStart();
  12606. stream.point(sign1, phi0);
  12607. clean = 0;
  12608. }
  12609. stream.point(lambda0 = lambda1, phi0 = phi1);
  12610. sign0 = sign1;
  12611. },
  12612. lineEnd: function() {
  12613. stream.lineEnd();
  12614. lambda0 = phi0 = NaN;
  12615. },
  12616. clean: function() {
  12617. return 2 - clean; // if intersections, rejoin first and last segments
  12618. }
  12619. };
  12620. }
  12621. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  12622. var cosPhi0,
  12623. cosPhi1,
  12624. sinLambda0Lambda1 = sin(lambda0 - lambda1);
  12625. return abs(sinLambda0Lambda1) > epsilon$4
  12626. ? atan((sin(phi0) * (cosPhi1 = cos(phi1)) * sin(lambda1)
  12627. - sin(phi1) * (cosPhi0 = cos(phi0)) * sin(lambda0))
  12628. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  12629. : (phi0 + phi1) / 2;
  12630. }
  12631. function clipAntimeridianInterpolate(from, to, direction, stream) {
  12632. var phi;
  12633. if (from == null) {
  12634. phi = direction * halfPi$2;
  12635. stream.point(-pi$3, phi);
  12636. stream.point(0, phi);
  12637. stream.point(pi$3, phi);
  12638. stream.point(pi$3, 0);
  12639. stream.point(pi$3, -phi);
  12640. stream.point(0, -phi);
  12641. stream.point(-pi$3, -phi);
  12642. stream.point(-pi$3, 0);
  12643. stream.point(-pi$3, phi);
  12644. } else if (abs(from[0] - to[0]) > epsilon$4) {
  12645. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  12646. phi = direction * lambda / 2;
  12647. stream.point(-lambda, phi);
  12648. stream.point(0, phi);
  12649. stream.point(lambda, phi);
  12650. } else {
  12651. stream.point(to[0], to[1]);
  12652. }
  12653. }
  12654. function clipCircle(radius, delta) {
  12655. var cr = cos(radius),
  12656. smallRadius = cr > 0,
  12657. notHemisphere = abs(cr) > epsilon$4; // TODO optimise for this common case
  12658. function interpolate(from, to, direction, stream) {
  12659. circleStream(stream, radius, delta, direction, from, to);
  12660. }
  12661. function visible(lambda, phi) {
  12662. return cos(lambda) * cos(phi) > cr;
  12663. }
  12664. // Takes a line and cuts into visible segments. Return values used for polygon
  12665. // clipping: 0 - there were intersections or the line was empty; 1 - no
  12666. // intersections 2 - there were intersections, and the first and last segments
  12667. // should be rejoined.
  12668. function clipLine(stream) {
  12669. var point0, // previous point
  12670. c0, // code for previous point
  12671. v0, // visibility of previous point
  12672. v00, // visibility of first point
  12673. clean; // no intersections
  12674. return {
  12675. lineStart: function() {
  12676. v00 = v0 = false;
  12677. clean = 1;
  12678. },
  12679. point: function(lambda, phi) {
  12680. var point1 = [lambda, phi],
  12681. point2,
  12682. v = visible(lambda, phi),
  12683. c = smallRadius
  12684. ? v ? 0 : code(lambda, phi)
  12685. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  12686. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  12687. // Handle degeneracies.
  12688. // TODO ignore if not clipping polygons.
  12689. if (v !== v0) {
  12690. point2 = intersect(point0, point1);
  12691. if (pointEqual(point0, point2) || pointEqual(point1, point2)) {
  12692. point1[0] += epsilon$4;
  12693. point1[1] += epsilon$4;
  12694. v = visible(point1[0], point1[1]);
  12695. }
  12696. }
  12697. if (v !== v0) {
  12698. clean = 0;
  12699. if (v) {
  12700. // outside going in
  12701. stream.lineStart();
  12702. point2 = intersect(point1, point0);
  12703. stream.point(point2[0], point2[1]);
  12704. } else {
  12705. // inside going out
  12706. point2 = intersect(point0, point1);
  12707. stream.point(point2[0], point2[1]);
  12708. stream.lineEnd();
  12709. }
  12710. point0 = point2;
  12711. } else if (notHemisphere && point0 && smallRadius ^ v) {
  12712. var t;
  12713. // If the codes for two points are different, or are both zero,
  12714. // and there this segment intersects with the small circle.
  12715. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  12716. clean = 0;
  12717. if (smallRadius) {
  12718. stream.lineStart();
  12719. stream.point(t[0][0], t[0][1]);
  12720. stream.point(t[1][0], t[1][1]);
  12721. stream.lineEnd();
  12722. } else {
  12723. stream.point(t[1][0], t[1][1]);
  12724. stream.lineEnd();
  12725. stream.lineStart();
  12726. stream.point(t[0][0], t[0][1]);
  12727. }
  12728. }
  12729. }
  12730. if (v && (!point0 || !pointEqual(point0, point1))) {
  12731. stream.point(point1[0], point1[1]);
  12732. }
  12733. point0 = point1, v0 = v, c0 = c;
  12734. },
  12735. lineEnd: function() {
  12736. if (v0) stream.lineEnd();
  12737. point0 = null;
  12738. },
  12739. // Rejoin first and last segments if there were intersections and the first
  12740. // and last points were visible.
  12741. clean: function() {
  12742. return clean | ((v00 && v0) << 1);
  12743. }
  12744. };
  12745. }
  12746. // Intersects the great circle between a and b with the clip circle.
  12747. function intersect(a, b, two) {
  12748. var pa = cartesian(a),
  12749. pb = cartesian(b);
  12750. // We have two planes, n1.p = d1 and n2.p = d2.
  12751. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  12752. var n1 = [1, 0, 0], // normal
  12753. n2 = cartesianCross(pa, pb),
  12754. n2n2 = cartesianDot(n2, n2),
  12755. n1n2 = n2[0], // cartesianDot(n1, n2),
  12756. determinant = n2n2 - n1n2 * n1n2;
  12757. // Two polar points.
  12758. if (!determinant) return !two && a;
  12759. var c1 = cr * n2n2 / determinant,
  12760. c2 = -cr * n1n2 / determinant,
  12761. n1xn2 = cartesianCross(n1, n2),
  12762. A = cartesianScale(n1, c1),
  12763. B = cartesianScale(n2, c2);
  12764. cartesianAddInPlace(A, B);
  12765. // Solve |p(t)|^2 = 1.
  12766. var u = n1xn2,
  12767. w = cartesianDot(A, u),
  12768. uu = cartesianDot(u, u),
  12769. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  12770. if (t2 < 0) return;
  12771. var t = sqrt$1(t2),
  12772. q = cartesianScale(u, (-w - t) / uu);
  12773. cartesianAddInPlace(q, A);
  12774. q = spherical(q);
  12775. if (!two) return q;
  12776. // Two intersection points.
  12777. var lambda0 = a[0],
  12778. lambda1 = b[0],
  12779. phi0 = a[1],
  12780. phi1 = b[1],
  12781. z;
  12782. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  12783. var delta = lambda1 - lambda0,
  12784. polar = abs(delta - pi$3) < epsilon$4,
  12785. meridian = polar || delta < epsilon$4;
  12786. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  12787. // Check that the first point is between a and b.
  12788. if (meridian
  12789. ? polar
  12790. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$4 ? phi0 : phi1)
  12791. : phi0 <= q[1] && q[1] <= phi1
  12792. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  12793. var q1 = cartesianScale(u, (-w + t) / uu);
  12794. cartesianAddInPlace(q1, A);
  12795. return [q, spherical(q1)];
  12796. }
  12797. }
  12798. // Generates a 4-bit vector representing the location of a point relative to
  12799. // the small circle's bounding box.
  12800. function code(lambda, phi) {
  12801. var r = smallRadius ? radius : pi$3 - radius,
  12802. code = 0;
  12803. if (lambda < -r) code |= 1; // left
  12804. else if (lambda > r) code |= 2; // right
  12805. if (phi < -r) code |= 4; // below
  12806. else if (phi > r) code |= 8; // above
  12807. return code;
  12808. }
  12809. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  12810. }
  12811. function transform$1(prototype) {
  12812. return {
  12813. stream: transform$2(prototype)
  12814. };
  12815. }
  12816. function transform$2(prototype) {
  12817. function T() {}
  12818. var p = T.prototype = Object.create(Transform$1.prototype);
  12819. for (var k in prototype) p[k] = prototype[k];
  12820. return function(stream) {
  12821. var t = new T;
  12822. t.stream = stream;
  12823. return t;
  12824. };
  12825. }
  12826. function Transform$1() {}
  12827. Transform$1.prototype = {
  12828. point: function(x, y) { this.stream.point(x, y); },
  12829. sphere: function() { this.stream.sphere(); },
  12830. lineStart: function() { this.stream.lineStart(); },
  12831. lineEnd: function() { this.stream.lineEnd(); },
  12832. polygonStart: function() { this.stream.polygonStart(); },
  12833. polygonEnd: function() { this.stream.polygonEnd(); }
  12834. };
  12835. var maxDepth = 16;
  12836. var cosMinDistance = cos(30 * radians);
  12837. // cos(minimum angular distance)
  12838. function resample(project, delta2) {
  12839. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  12840. }
  12841. function resampleNone(project) {
  12842. return transform$2({
  12843. point: function(x, y) {
  12844. x = project(x, y);
  12845. this.stream.point(x[0], x[1]);
  12846. }
  12847. });
  12848. }
  12849. function resample$1(project, delta2) {
  12850. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  12851. var dx = x1 - x0,
  12852. dy = y1 - y0,
  12853. d2 = dx * dx + dy * dy;
  12854. if (d2 > 4 * delta2 && depth--) {
  12855. var a = a0 + a1,
  12856. b = b0 + b1,
  12857. c = c0 + c1,
  12858. m = sqrt$1(a * a + b * b + c * c),
  12859. phi2 = asin$1(c /= m),
  12860. lambda2 = abs(abs(c) - 1) < epsilon$4 || abs(lambda0 - lambda1) < epsilon$4 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  12861. p = project(lambda2, phi2),
  12862. x2 = p[0],
  12863. y2 = p[1],
  12864. dx2 = x2 - x0,
  12865. dy2 = y2 - y0,
  12866. dz = dy * dx2 - dx * dy2;
  12867. if (dz * dz / d2 > delta2 // perpendicular projected distance
  12868. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  12869. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  12870. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  12871. stream.point(x2, y2);
  12872. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  12873. }
  12874. }
  12875. }
  12876. return function(stream) {
  12877. var lambda00, x00, y00, a00, b00, c00, // first point
  12878. lambda0, x0, y0, a0, b0, c0; // previous point
  12879. var resampleStream = {
  12880. point: point,
  12881. lineStart: lineStart,
  12882. lineEnd: lineEnd,
  12883. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  12884. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  12885. };
  12886. function point(x, y) {
  12887. x = project(x, y);
  12888. stream.point(x[0], x[1]);
  12889. }
  12890. function lineStart() {
  12891. x0 = NaN;
  12892. resampleStream.point = linePoint;
  12893. stream.lineStart();
  12894. }
  12895. function linePoint(lambda, phi) {
  12896. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  12897. 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);
  12898. stream.point(x0, y0);
  12899. }
  12900. function lineEnd() {
  12901. resampleStream.point = point;
  12902. stream.lineEnd();
  12903. }
  12904. function ringStart() {
  12905. lineStart();
  12906. resampleStream.point = ringPoint;
  12907. resampleStream.lineEnd = ringEnd;
  12908. }
  12909. function ringPoint(lambda, phi) {
  12910. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  12911. resampleStream.point = linePoint;
  12912. }
  12913. function ringEnd() {
  12914. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  12915. resampleStream.lineEnd = lineEnd;
  12916. lineEnd();
  12917. }
  12918. return resampleStream;
  12919. };
  12920. }
  12921. var transformRadians = transform$2({
  12922. point: function(x, y) {
  12923. this.stream.point(x * radians, y * radians);
  12924. }
  12925. });
  12926. function projection(project) {
  12927. return projectionMutator(function() { return project; })();
  12928. }
  12929. function projectionMutator(projectAt) {
  12930. var project,
  12931. k = 150, // scale
  12932. x = 480, y = 250, // translate
  12933. dx, dy, lambda = 0, phi = 0, // center
  12934. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
  12935. theta = null, preclip = clipAntimeridian, // clip angle
  12936. x0 = null, y0, x1, y1, postclip = identity$7, // clip extent
  12937. delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
  12938. cache,
  12939. cacheStream;
  12940. function projection(point) {
  12941. point = projectRotate(point[0] * radians, point[1] * radians);
  12942. return [point[0] * k + dx, dy - point[1] * k];
  12943. }
  12944. function invert(point) {
  12945. point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
  12946. return point && [point[0] * degrees$1, point[1] * degrees$1];
  12947. }
  12948. function projectTransform(x, y) {
  12949. return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
  12950. }
  12951. projection.stream = function(stream) {
  12952. return cache && cacheStream === stream ? cache : cache = transformRadians(preclip(rotate, projectResample(postclip(cacheStream = stream))));
  12953. };
  12954. projection.clipAngle = function(_) {
  12955. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians, 6 * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  12956. };
  12957. projection.clipExtent = function(_) {
  12958. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$7) : clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  12959. };
  12960. projection.scale = function(_) {
  12961. return arguments.length ? (k = +_, recenter()) : k;
  12962. };
  12963. projection.translate = function(_) {
  12964. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  12965. };
  12966. projection.center = function(_) {
  12967. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  12968. };
  12969. projection.rotate = function(_) {
  12970. 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];
  12971. };
  12972. projection.precision = function(_) {
  12973. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$1(delta2);
  12974. };
  12975. function recenter() {
  12976. projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
  12977. var center = project(lambda, phi);
  12978. dx = x - center[0] * k;
  12979. dy = y + center[1] * k;
  12980. return reset();
  12981. }
  12982. function reset() {
  12983. cache = cacheStream = null;
  12984. return projection;
  12985. }
  12986. return function() {
  12987. project = projectAt.apply(this, arguments);
  12988. projection.invert = project.invert && invert;
  12989. return recenter();
  12990. };
  12991. }
  12992. function conicProjection(projectAt) {
  12993. var phi0 = 0,
  12994. phi1 = pi$3 / 3,
  12995. m = projectionMutator(projectAt),
  12996. p = m(phi0, phi1);
  12997. p.parallels = function(_) {
  12998. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  12999. };
  13000. return p;
  13001. }
  13002. function conicEqualArea(y0, y1) {
  13003. var sy0 = sin(y0),
  13004. n = (sy0 + sin(y1)) / 2,
  13005. c = 1 + sy0 * (2 * n - sy0),
  13006. r0 = sqrt$1(c) / n;
  13007. function project(x, y) {
  13008. var r = sqrt$1(c - 2 * n * sin(y)) / n;
  13009. return [r * sin(x *= n), r0 - r * cos(x)];
  13010. }
  13011. project.invert = function(x, y) {
  13012. var r0y = r0 - y;
  13013. return [atan2(x, r0y) / n, asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  13014. };
  13015. return project;
  13016. }
  13017. function conicEqualArea$1() {
  13018. return conicProjection(conicEqualArea)
  13019. .scale(151)
  13020. .translate([480, 347]);
  13021. }
  13022. function albers() {
  13023. return conicEqualArea$1()
  13024. .parallels([29.5, 45.5])
  13025. .scale(1070)
  13026. .translate([480, 250])
  13027. .rotate([96, 0])
  13028. .center([-0.6, 38.7]);
  13029. }
  13030. // The projections must have mutually exclusive clip regions on the sphere,
  13031. // as this will avoid emitting interleaving lines and polygons.
  13032. function multiplex(streams) {
  13033. var n = streams.length;
  13034. return {
  13035. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  13036. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  13037. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  13038. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  13039. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  13040. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  13041. };
  13042. }
  13043. // A composite projection for the United States, configured by default for
  13044. // 960×500. Also works quite well at 960×600 with scale 1285. The set of
  13045. // standard parallels for each region comes from USGS, which is published here:
  13046. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  13047. function albersUsa() {
  13048. var cache,
  13049. cacheStream,
  13050. lower48 = albers(), lower48Point,
  13051. alaska = conicEqualArea$1().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  13052. hawaii = conicEqualArea$1().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  13053. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  13054. function albersUsa(coordinates) {
  13055. var x = coordinates[0], y = coordinates[1];
  13056. return point = null,
  13057. (lower48Point.point(x, y), point)
  13058. || (alaskaPoint.point(x, y), point)
  13059. || (hawaiiPoint.point(x, y), point);
  13060. }
  13061. albersUsa.invert = function(coordinates) {
  13062. var k = lower48.scale(),
  13063. t = lower48.translate(),
  13064. x = (coordinates[0] - t[0]) / k,
  13065. y = (coordinates[1] - t[1]) / k;
  13066. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  13067. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  13068. : lower48).invert(coordinates);
  13069. };
  13070. albersUsa.stream = function(stream) {
  13071. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  13072. };
  13073. albersUsa.precision = function(_) {
  13074. if (!arguments.length) return lower48.precision();
  13075. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  13076. return albersUsa;
  13077. };
  13078. albersUsa.scale = function(_) {
  13079. if (!arguments.length) return lower48.scale();
  13080. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  13081. return albersUsa.translate(lower48.translate());
  13082. };
  13083. albersUsa.translate = function(_) {
  13084. if (!arguments.length) return lower48.translate();
  13085. var k = lower48.scale(), x = +_[0], y = +_[1];
  13086. lower48Point = lower48
  13087. .translate(_)
  13088. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  13089. .stream(pointStream);
  13090. alaskaPoint = alaska
  13091. .translate([x - 0.307 * k, y + 0.201 * k])
  13092. .clipExtent([[x - 0.425 * k + epsilon$4, y + 0.120 * k + epsilon$4], [x - 0.214 * k - epsilon$4, y + 0.234 * k - epsilon$4]])
  13093. .stream(pointStream);
  13094. hawaiiPoint = hawaii
  13095. .translate([x - 0.205 * k, y + 0.212 * k])
  13096. .clipExtent([[x - 0.214 * k + epsilon$4, y + 0.166 * k + epsilon$4], [x - 0.115 * k - epsilon$4, y + 0.234 * k - epsilon$4]])
  13097. .stream(pointStream);
  13098. return albersUsa;
  13099. };
  13100. return albersUsa.scale(1070);
  13101. }
  13102. function azimuthal(scale) {
  13103. return function(x, y) {
  13104. var cx = cos(x),
  13105. cy = cos(y),
  13106. k = scale(cx * cy);
  13107. return [
  13108. k * cy * sin(x),
  13109. k * sin(y)
  13110. ];
  13111. }
  13112. }
  13113. function azimuthalInvert(angle) {
  13114. return function(x, y) {
  13115. var z = sqrt$1(x * x + y * y),
  13116. c = angle(z),
  13117. sc = sin(c),
  13118. cc = cos(c);
  13119. return [
  13120. atan2(x * sc, z * cc),
  13121. asin$1(z && y * sc / z)
  13122. ];
  13123. }
  13124. }
  13125. var azimuthalEqualArea = azimuthal(function(cxcy) {
  13126. return sqrt$1(2 / (1 + cxcy));
  13127. });
  13128. azimuthalEqualArea.invert = azimuthalInvert(function(z) {
  13129. return 2 * asin$1(z / 2);
  13130. });
  13131. function azimuthalEqualArea$1() {
  13132. return projection(azimuthalEqualArea)
  13133. .scale(120)
  13134. .clipAngle(180 - 1e-3);
  13135. }
  13136. var azimuthalEquidistant = azimuthal(function(c) {
  13137. return (c = acos(c)) && c / sin(c);
  13138. });
  13139. azimuthalEquidistant.invert = azimuthalInvert(function(z) {
  13140. return z;
  13141. });
  13142. function azimuthalEquidistant$1() {
  13143. return projection(azimuthalEquidistant)
  13144. .scale(480 / tau$3)
  13145. .clipAngle(180 - 1e-3);
  13146. }
  13147. function mercator(lambda, phi) {
  13148. return [lambda, log$1(tan((halfPi$2 + phi) / 2))];
  13149. }
  13150. mercator.invert = function(x, y) {
  13151. return [x, 2 * atan(exp(y)) - halfPi$2];
  13152. };
  13153. function mercator$1() {
  13154. return mercatorProjection(mercator);
  13155. }
  13156. function mercatorProjection(project) {
  13157. var m = projection(project),
  13158. scale = m.scale,
  13159. translate = m.translate,
  13160. clipExtent = m.clipExtent,
  13161. clipAuto;
  13162. m.scale = function(_) {
  13163. return arguments.length ? (scale(_), clipAuto && m.clipExtent(null), m) : scale();
  13164. };
  13165. m.translate = function(_) {
  13166. return arguments.length ? (translate(_), clipAuto && m.clipExtent(null), m) : translate();
  13167. };
  13168. m.clipExtent = function(_) {
  13169. if (!arguments.length) return clipAuto ? null : clipExtent();
  13170. if (clipAuto = _ == null) {
  13171. var k = pi$3 * scale(), t = translate();
  13172. _ = [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]];
  13173. }
  13174. clipExtent(_);
  13175. return m;
  13176. };
  13177. return m.clipExtent(null).scale(961 / tau$3);
  13178. }
  13179. function tany(y) {
  13180. return tan((halfPi$2 + y) / 2);
  13181. }
  13182. function conicConformal(y0, y1) {
  13183. var cy0 = cos(y0),
  13184. n = y0 === y1 ? sin(y0) : log$1(cy0 / cos(y1)) / log$1(tany(y1) / tany(y0)),
  13185. f = cy0 * pow$1(tany(y0), n) / n;
  13186. if (!n) return mercator;
  13187. function project(x, y) {
  13188. if (f > 0) { if (y < -halfPi$2 + epsilon$4) y = -halfPi$2 + epsilon$4; }
  13189. else { if (y > halfPi$2 - epsilon$4) y = halfPi$2 - epsilon$4; }
  13190. var r = f / pow$1(tany(y), n);
  13191. return [r * sin(n * x), f - r * cos(n * x)];
  13192. }
  13193. project.invert = function(x, y) {
  13194. var fy = f - y, r = sign$1(n) * sqrt$1(x * x + fy * fy);
  13195. return [atan2(x, fy) / n, 2 * atan(pow$1(f / r, 1 / n)) - halfPi$2];
  13196. };
  13197. return project;
  13198. }
  13199. function conicConformal$1() {
  13200. return conicProjection(conicConformal);
  13201. }
  13202. function equirectangular(lambda, phi) {
  13203. return [lambda, phi];
  13204. }
  13205. equirectangular.invert = equirectangular;
  13206. function equirectangular$1() {
  13207. return projection(equirectangular).scale(480 / pi$3);
  13208. }
  13209. function conicEquidistant(y0, y1) {
  13210. var cy0 = cos(y0),
  13211. n = y0 === y1 ? sin(y0) : (cy0 - cos(y1)) / (y1 - y0),
  13212. g = cy0 / n + y0;
  13213. if (abs(n) < epsilon$4) return equirectangular;
  13214. function project(x, y) {
  13215. var gy = g - y, nx = n * x;
  13216. return [gy * sin(nx), g - gy * cos(nx)];
  13217. }
  13218. project.invert = function(x, y) {
  13219. var gy = g - y;
  13220. return [atan2(x, gy) / n, g - sign$1(n) * sqrt$1(x * x + gy * gy)];
  13221. };
  13222. return project;
  13223. }
  13224. function conicEquidistant$1() {
  13225. return conicProjection(conicEquidistant)
  13226. .scale(128)
  13227. .translate([480, 280]);
  13228. }
  13229. function gnomonic(x, y) {
  13230. var cy = cos(y), k = cos(x) * cy;
  13231. return [cy * sin(x) / k, sin(y) / k];
  13232. }
  13233. gnomonic.invert = azimuthalInvert(atan);
  13234. function gnomonic$1() {
  13235. return projection(gnomonic)
  13236. .scale(139)
  13237. .clipAngle(60);
  13238. }
  13239. function orthographic(x, y) {
  13240. return [cos(y) * sin(x), sin(y)];
  13241. }
  13242. orthographic.invert = azimuthalInvert(asin$1);
  13243. function orthographic$1() {
  13244. return projection(orthographic)
  13245. .scale(240)
  13246. .clipAngle(90 + epsilon$4);
  13247. }
  13248. function stereographic(x, y) {
  13249. var cy = cos(y), k = 1 + cos(x) * cy;
  13250. return [cy * sin(x) / k, sin(y) / k];
  13251. }
  13252. stereographic.invert = azimuthalInvert(function(z) {
  13253. return 2 + atan(z);
  13254. });
  13255. function stereographic$1() {
  13256. return projection(stereographic)
  13257. .scale(240)
  13258. .clipAngle(142);
  13259. }
  13260. function transverseMercator(lambda, phi) {
  13261. return [log$1(tan((halfPi$2 + phi) / 2)), -lambda];
  13262. }
  13263. transverseMercator.invert = function(x, y) {
  13264. return [-y, 2 * atan(exp(x)) - halfPi$2];
  13265. };
  13266. function transverseMercator$1() {
  13267. var m = mercatorProjection(transverseMercator),
  13268. center = m.center,
  13269. rotate = m.rotate;
  13270. m.center = function(_) {
  13271. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  13272. };
  13273. m.rotate = function(_) {
  13274. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  13275. };
  13276. return rotate([0, 0, 90]);
  13277. }
  13278. exports.version = version;
  13279. exports.bisect = bisectRight;
  13280. exports.bisectRight = bisectRight;
  13281. exports.bisectLeft = bisectLeft;
  13282. exports.ascending = ascending;
  13283. exports.bisector = bisector;
  13284. exports.descending = descending;
  13285. exports.deviation = deviation;
  13286. exports.extent = extent;
  13287. exports.histogram = histogram;
  13288. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  13289. exports.thresholdScott = scott;
  13290. exports.thresholdSturges = sturges;
  13291. exports.max = max;
  13292. exports.mean = mean;
  13293. exports.median = median;
  13294. exports.merge = merge;
  13295. exports.min = min;
  13296. exports.pairs = pairs;
  13297. exports.permute = permute;
  13298. exports.quantile = threshold;
  13299. exports.range = range;
  13300. exports.scan = scan;
  13301. exports.shuffle = shuffle;
  13302. exports.sum = sum;
  13303. exports.ticks = ticks;
  13304. exports.tickStep = tickStep;
  13305. exports.transpose = transpose;
  13306. exports.variance = variance;
  13307. exports.zip = zip;
  13308. exports.entries = entries;
  13309. exports.keys = keys;
  13310. exports.values = values;
  13311. exports.map = map$1;
  13312. exports.set = set;
  13313. exports.nest = nest;
  13314. exports.randomUniform = uniform;
  13315. exports.randomNormal = normal;
  13316. exports.randomLogNormal = logNormal;
  13317. exports.randomBates = bates;
  13318. exports.randomIrwinHall = irwinHall;
  13319. exports.randomExponential = exponential;
  13320. exports.easeLinear = linear;
  13321. exports.easeQuad = quadInOut;
  13322. exports.easeQuadIn = quadIn;
  13323. exports.easeQuadOut = quadOut;
  13324. exports.easeQuadInOut = quadInOut;
  13325. exports.easeCubic = easeCubicInOut;
  13326. exports.easeCubicIn = cubicIn;
  13327. exports.easeCubicOut = cubicOut;
  13328. exports.easeCubicInOut = easeCubicInOut;
  13329. exports.easePoly = polyInOut;
  13330. exports.easePolyIn = polyIn;
  13331. exports.easePolyOut = polyOut;
  13332. exports.easePolyInOut = polyInOut;
  13333. exports.easeSin = sinInOut;
  13334. exports.easeSinIn = sinIn;
  13335. exports.easeSinOut = sinOut;
  13336. exports.easeSinInOut = sinInOut;
  13337. exports.easeExp = expInOut;
  13338. exports.easeExpIn = expIn;
  13339. exports.easeExpOut = expOut;
  13340. exports.easeExpInOut = expInOut;
  13341. exports.easeCircle = circleInOut;
  13342. exports.easeCircleIn = circleIn;
  13343. exports.easeCircleOut = circleOut;
  13344. exports.easeCircleInOut = circleInOut;
  13345. exports.easeBounce = bounceOut;
  13346. exports.easeBounceIn = bounceIn;
  13347. exports.easeBounceOut = bounceOut;
  13348. exports.easeBounceInOut = bounceInOut;
  13349. exports.easeBack = backInOut;
  13350. exports.easeBackIn = backIn;
  13351. exports.easeBackOut = backOut;
  13352. exports.easeBackInOut = backInOut;
  13353. exports.easeElastic = elasticOut;
  13354. exports.easeElasticIn = elasticIn;
  13355. exports.easeElasticOut = elasticOut;
  13356. exports.easeElasticInOut = elasticInOut;
  13357. exports.polygonArea = area;
  13358. exports.polygonCentroid = centroid;
  13359. exports.polygonHull = hull;
  13360. exports.polygonContains = contains;
  13361. exports.polygonLength = length$1;
  13362. exports.path = path;
  13363. exports.quadtree = quadtree;
  13364. exports.queue = queue;
  13365. exports.arc = arc;
  13366. exports.area = area$1;
  13367. exports.line = line;
  13368. exports.pie = pie;
  13369. exports.radialArea = radialArea;
  13370. exports.radialLine = radialLine$1;
  13371. exports.symbol = symbol;
  13372. exports.symbols = symbols;
  13373. exports.symbolCircle = circle;
  13374. exports.symbolCross = cross$1;
  13375. exports.symbolDiamond = diamond;
  13376. exports.symbolSquare = square;
  13377. exports.symbolStar = star;
  13378. exports.symbolTriangle = triangle;
  13379. exports.symbolWye = wye;
  13380. exports.curveBasisClosed = basisClosed;
  13381. exports.curveBasisOpen = basisOpen;
  13382. exports.curveBasis = basis;
  13383. exports.curveBundle = bundle;
  13384. exports.curveCardinalClosed = cardinalClosed;
  13385. exports.curveCardinalOpen = cardinalOpen;
  13386. exports.curveCardinal = cardinal;
  13387. exports.curveCatmullRomClosed = catmullRomClosed;
  13388. exports.curveCatmullRomOpen = catmullRomOpen;
  13389. exports.curveCatmullRom = catmullRom;
  13390. exports.curveLinearClosed = linearClosed;
  13391. exports.curveLinear = curveLinear;
  13392. exports.curveMonotoneX = monotoneX;
  13393. exports.curveMonotoneY = monotoneY;
  13394. exports.curveNatural = natural;
  13395. exports.curveStep = step;
  13396. exports.curveStepAfter = stepAfter;
  13397. exports.curveStepBefore = stepBefore;
  13398. exports.stack = stack;
  13399. exports.stackOffsetExpand = expand;
  13400. exports.stackOffsetNone = none;
  13401. exports.stackOffsetSilhouette = silhouette;
  13402. exports.stackOffsetWiggle = wiggle;
  13403. exports.stackOrderAscending = ascending$1;
  13404. exports.stackOrderDescending = descending$2;
  13405. exports.stackOrderInsideOut = insideOut;
  13406. exports.stackOrderNone = none$1;
  13407. exports.stackOrderReverse = reverse;
  13408. exports.color = color;
  13409. exports.rgb = colorRgb;
  13410. exports.hsl = colorHsl;
  13411. exports.lab = lab;
  13412. exports.hcl = colorHcl;
  13413. exports.cubehelix = cubehelix;
  13414. exports.interpolate = interpolate;
  13415. exports.interpolateArray = array$1;
  13416. exports.interpolateNumber = interpolateNumber;
  13417. exports.interpolateObject = object;
  13418. exports.interpolateRound = interpolateRound;
  13419. exports.interpolateString = interpolateString;
  13420. exports.interpolateTransformCss = interpolateTransform$1;
  13421. exports.interpolateTransformSvg = interpolateTransform$2;
  13422. exports.interpolateZoom = interpolateZoom;
  13423. exports.interpolateRgb = interpolateRgb;
  13424. exports.interpolateRgbBasis = rgbBasis;
  13425. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  13426. exports.interpolateHsl = hsl$1;
  13427. exports.interpolateHslLong = hslLong;
  13428. exports.interpolateLab = lab$1;
  13429. exports.interpolateHcl = hcl$1;
  13430. exports.interpolateHclLong = hclLong;
  13431. exports.interpolateCubehelix = cubehelix$2;
  13432. exports.interpolateCubehelixLong = interpolateCubehelixLong;
  13433. exports.interpolateBasis = basis$2;
  13434. exports.interpolateBasisClosed = basisClosed$1;
  13435. exports.quantize = quantize;
  13436. exports.dispatch = dispatch;
  13437. exports.dsvFormat = dsv;
  13438. exports.csvParse = csvParse;
  13439. exports.csvParseRows = csvParseRows;
  13440. exports.csvFormat = csvFormat;
  13441. exports.csvFormatRows = csvFormatRows;
  13442. exports.tsvParse = tsvParse;
  13443. exports.tsvParseRows = tsvParseRows;
  13444. exports.tsvFormat = tsvFormat;
  13445. exports.tsvFormatRows = tsvFormatRows;
  13446. exports.request = request;
  13447. exports.html = html;
  13448. exports.json = json;
  13449. exports.text = text;
  13450. exports.xml = xml;
  13451. exports.csv = csv$1;
  13452. exports.tsv = tsv$1;
  13453. exports.now = now;
  13454. exports.timer = timer;
  13455. exports.timerFlush = timerFlush;
  13456. exports.timeout = timeout$1;
  13457. exports.interval = interval$1;
  13458. exports.timeInterval = newInterval;
  13459. exports.timeMillisecond = millisecond;
  13460. exports.timeMilliseconds = milliseconds;
  13461. exports.timeSecond = second;
  13462. exports.timeSeconds = seconds;
  13463. exports.timeMinute = minute;
  13464. exports.timeMinutes = minutes;
  13465. exports.timeHour = hour;
  13466. exports.timeHours = hours;
  13467. exports.timeDay = day;
  13468. exports.timeDays = days;
  13469. exports.timeWeek = timeWeek;
  13470. exports.timeWeeks = sundays;
  13471. exports.timeSunday = timeWeek;
  13472. exports.timeSundays = sundays;
  13473. exports.timeMonday = timeMonday;
  13474. exports.timeMondays = mondays;
  13475. exports.timeTuesday = tuesday;
  13476. exports.timeTuesdays = tuesdays;
  13477. exports.timeWednesday = wednesday;
  13478. exports.timeWednesdays = wednesdays;
  13479. exports.timeThursday = thursday;
  13480. exports.timeThursdays = thursdays;
  13481. exports.timeFriday = friday;
  13482. exports.timeFridays = fridays;
  13483. exports.timeSaturday = saturday;
  13484. exports.timeSaturdays = saturdays;
  13485. exports.timeMonth = month;
  13486. exports.timeMonths = months;
  13487. exports.timeYear = year;
  13488. exports.timeYears = years;
  13489. exports.utcMillisecond = millisecond;
  13490. exports.utcMilliseconds = milliseconds;
  13491. exports.utcSecond = second;
  13492. exports.utcSeconds = seconds;
  13493. exports.utcMinute = utcMinute;
  13494. exports.utcMinutes = utcMinutes;
  13495. exports.utcHour = utcHour;
  13496. exports.utcHours = utcHours;
  13497. exports.utcDay = utcDay;
  13498. exports.utcDays = utcDays;
  13499. exports.utcWeek = utcWeek;
  13500. exports.utcWeeks = utcSundays;
  13501. exports.utcSunday = utcWeek;
  13502. exports.utcSundays = utcSundays;
  13503. exports.utcMonday = utcMonday;
  13504. exports.utcMondays = utcMondays;
  13505. exports.utcTuesday = utcTuesday;
  13506. exports.utcTuesdays = utcTuesdays;
  13507. exports.utcWednesday = utcWednesday;
  13508. exports.utcWednesdays = utcWednesdays;
  13509. exports.utcThursday = utcThursday;
  13510. exports.utcThursdays = utcThursdays;
  13511. exports.utcFriday = utcFriday;
  13512. exports.utcFridays = utcFridays;
  13513. exports.utcSaturday = utcSaturday;
  13514. exports.utcSaturdays = utcSaturdays;
  13515. exports.utcMonth = utcMonth;
  13516. exports.utcMonths = utcMonths;
  13517. exports.utcYear = utcYear;
  13518. exports.utcYears = utcYears;
  13519. exports.formatLocale = formatLocale;
  13520. exports.formatDefaultLocale = defaultLocale;
  13521. exports.formatSpecifier = formatSpecifier;
  13522. exports.precisionFixed = precisionFixed;
  13523. exports.precisionPrefix = precisionPrefix;
  13524. exports.precisionRound = precisionRound;
  13525. exports.isoFormat = formatIso;
  13526. exports.isoParse = parseIso;
  13527. exports.timeFormatLocale = formatLocale$1;
  13528. exports.timeFormatDefaultLocale = defaultLocale$1;
  13529. exports.scaleBand = band;
  13530. exports.scalePoint = point$4;
  13531. exports.scaleIdentity = identity$4;
  13532. exports.scaleLinear = linear$2;
  13533. exports.scaleLog = log;
  13534. exports.scaleOrdinal = ordinal;
  13535. exports.scaleImplicit = implicit;
  13536. exports.scalePow = pow;
  13537. exports.scaleSqrt = sqrt;
  13538. exports.scaleQuantile = quantile;
  13539. exports.scaleQuantize = quantize$1;
  13540. exports.scaleThreshold = threshold$1;
  13541. exports.scaleTime = time;
  13542. exports.scaleUtc = utcTime;
  13543. exports.schemeCategory10 = category10;
  13544. exports.schemeCategory20b = category20b;
  13545. exports.schemeCategory20c = category20c;
  13546. exports.schemeCategory20 = category20;
  13547. exports.scaleSequential = sequential;
  13548. exports.interpolateCubehelixDefault = cubehelix$3;
  13549. exports.interpolateRainbow = rainbow$1;
  13550. exports.interpolateWarm = warm;
  13551. exports.interpolateCool = cool;
  13552. exports.interpolateViridis = viridis;
  13553. exports.interpolateMagma = magma;
  13554. exports.interpolateInferno = inferno;
  13555. exports.interpolatePlasma = plasma;
  13556. exports.creator = creator;
  13557. exports.customEvent = customEvent;
  13558. exports.local = local;
  13559. exports.matcher = matcher$1;
  13560. exports.mouse = mouse;
  13561. exports.namespace = namespace;
  13562. exports.namespaces = namespaces;
  13563. exports.select = select;
  13564. exports.selectAll = selectAll;
  13565. exports.selection = selection;
  13566. exports.selector = selector;
  13567. exports.selectorAll = selectorAll;
  13568. exports.touch = touch;
  13569. exports.touches = touches;
  13570. exports.window = window;
  13571. exports.active = active;
  13572. exports.interrupt = interrupt;
  13573. exports.transition = transition;
  13574. exports.axisTop = axisTop;
  13575. exports.axisRight = axisRight;
  13576. exports.axisBottom = axisBottom;
  13577. exports.axisLeft = axisLeft;
  13578. exports.cluster = cluster;
  13579. exports.hierarchy = hierarchy;
  13580. exports.pack = index;
  13581. exports.packSiblings = siblings;
  13582. exports.packEnclose = enclose;
  13583. exports.partition = partition;
  13584. exports.stratify = stratify;
  13585. exports.tree = tree;
  13586. exports.treemap = index$1;
  13587. exports.treemapBinary = binary;
  13588. exports.treemapDice = treemapDice;
  13589. exports.treemapSlice = treemapSlice;
  13590. exports.treemapSliceDice = sliceDice;
  13591. exports.treemapSquarify = squarify;
  13592. exports.treemapResquarify = resquarify;
  13593. exports.forceCenter = center$1;
  13594. exports.forceCollide = collide;
  13595. exports.forceLink = link;
  13596. exports.forceManyBody = manyBody;
  13597. exports.forceSimulation = simulation;
  13598. exports.forceX = x$3;
  13599. exports.forceY = y$3;
  13600. exports.drag = drag;
  13601. exports.dragDisable = dragDisable;
  13602. exports.dragEnable = dragEnable;
  13603. exports.voronoi = voronoi;
  13604. exports.zoom = zoom;
  13605. exports.zoomIdentity = identity$6;
  13606. exports.zoomTransform = transform;
  13607. exports.brush = brush;
  13608. exports.brushX = brushX;
  13609. exports.brushY = brushY;
  13610. exports.brushSelection = brushSelection;
  13611. exports.geoArea = area$2;
  13612. exports.geoBounds = bounds;
  13613. exports.geoCentroid = centroid$1;
  13614. exports.geoCircle = circle$1;
  13615. exports.geoClipExtent = extent$1;
  13616. exports.geoDistance = distance;
  13617. exports.geoGraticule = graticule;
  13618. exports.geoInterpolate = interpolate$2;
  13619. exports.geoLength = length$2;
  13620. exports.geoPath = index$3;
  13621. exports.geoAlbers = albers;
  13622. exports.geoAlbersUsa = albersUsa;
  13623. exports.geoAzimuthalEqualArea = azimuthalEqualArea$1;
  13624. exports.geoAzimuthalEquidistant = azimuthalEquidistant$1;
  13625. exports.geoConicConformal = conicConformal$1;
  13626. exports.geoConicEqualArea = conicEqualArea$1;
  13627. exports.geoConicEquidistant = conicEquidistant$1;
  13628. exports.geoEquirectangular = equirectangular$1;
  13629. exports.geoGnomonic = gnomonic$1;
  13630. exports.geoProjection = projection;
  13631. exports.geoProjectionMutator = projectionMutator;
  13632. exports.geoMercator = mercator$1;
  13633. exports.geoOrthographic = orthographic$1;
  13634. exports.geoStereographic = stereographic$1;
  13635. exports.geoTransverseMercator = transverseMercator$1;
  13636. exports.geoRotation = rotation;
  13637. exports.geoStream = stream;
  13638. exports.geoTransform = transform$1;
  13639. Object.defineProperty(exports, '__esModule', { value: true });
  13640. }));