d3.js 439 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384
  1. // https://d3js.org Version 4.3.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.3.0";
  8. var ascending = function(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. };
  11. var bisector = function(compare) {
  12. if (compare.length === 1) compare = ascendingComparator(compare);
  13. return {
  14. left: function(a, x, lo, hi) {
  15. if (lo == null) lo = 0;
  16. if (hi == null) hi = a.length;
  17. while (lo < hi) {
  18. var mid = lo + hi >>> 1;
  19. if (compare(a[mid], x) < 0) lo = mid + 1;
  20. else hi = mid;
  21. }
  22. return lo;
  23. },
  24. right: function(a, x, lo, hi) {
  25. if (lo == null) lo = 0;
  26. if (hi == null) hi = a.length;
  27. while (lo < hi) {
  28. var mid = lo + hi >>> 1;
  29. if (compare(a[mid], x) > 0) hi = mid;
  30. else lo = mid + 1;
  31. }
  32. return lo;
  33. }
  34. };
  35. };
  36. function ascendingComparator(f) {
  37. return function(d, x) {
  38. return ascending(f(d), x);
  39. };
  40. }
  41. var ascendingBisect = bisector(ascending);
  42. var bisectRight = ascendingBisect.right;
  43. var bisectLeft = ascendingBisect.left;
  44. var descending = function(a, b) {
  45. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  46. };
  47. var number = function(x) {
  48. return x === null ? NaN : +x;
  49. };
  50. var variance = function(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. var deviation = function(array, f) {
  79. var v = variance(array, f);
  80. return v ? Math.sqrt(v) : v;
  81. };
  82. var extent = function(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. var constant$1 = function(x) {
  108. return function() {
  109. return x;
  110. };
  111. };
  112. var identity = function(x) {
  113. return x;
  114. };
  115. var range = function(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. var ticks = function(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. var sturges = function(values) {
  146. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  147. };
  148. var histogram = function() {
  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$1(_), histogram) : value;
  189. };
  190. histogram.domain = function(_) {
  191. return arguments.length ? (domain = typeof _ === "function" ? _ : constant$1([_[0], _[1]]), histogram) : domain;
  192. };
  193. histogram.thresholds = function(_) {
  194. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$1(slice.call(_)) : constant$1(_), histogram) : threshold;
  195. };
  196. return histogram;
  197. };
  198. var threshold = function(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. var freedmanDiaconis = function(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. var scott = function(values, min, max) {
  215. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  216. };
  217. var max = function(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. var mean = function(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. var median = function(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. var merge = function(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. var min = function(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. var pairs = function(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. var permute = function(array, indexes) {
  298. var i = indexes.length, permutes = new Array(i);
  299. while (i--) permutes[i] = array[indexes[i]];
  300. return permutes;
  301. };
  302. var scan = function(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. var shuffle = function(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. var sum = function(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. var transpose = function(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. var zip = function() {
  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. var nest = function() {
  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. var keys = function(map) {
  508. var keys = [];
  509. for (var key in map) keys.push(key);
  510. return keys;
  511. };
  512. var values = function(map) {
  513. var values = [];
  514. for (var key in map) values.push(map[key]);
  515. return values;
  516. };
  517. var entries = function(map) {
  518. var entries = [];
  519. for (var key in map) entries.push({key: key, value: map[key]});
  520. return entries;
  521. };
  522. var uniform = function(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. var normal = function(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. var logNormal = function() {
  549. var randomNormal = normal.apply(this, arguments);
  550. return function() {
  551. return Math.exp(randomNormal());
  552. };
  553. };
  554. var irwinHall = function(n) {
  555. return function() {
  556. for (var sum = 0, i = 0; i < n; ++i) sum += Math.random();
  557. return sum;
  558. };
  559. };
  560. var bates = function(n) {
  561. var randomIrwinHall = irwinHall(n);
  562. return function() {
  563. return randomIrwinHall() / n;
  564. };
  565. };
  566. var exponential = function(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 cubicInOut(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. var area = function(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. var centroid = function(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. var cross = function(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. var hull = function(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. var contains = function(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. var length$1 = function(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. var tree_add = function(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. var tree_cover = function(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. var tree_data = function() {
  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. var tree_extent = function(_) {
  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. var Quad = function(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. var tree_find = function(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. var tree_remove = function(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. var tree_root = function() {
  1215. return this._root;
  1216. };
  1217. var tree_size = function() {
  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. var tree_visit = function(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. var tree_visitAfter = function(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. var tree_x = function(_) {
  1261. return arguments.length ? (this._x = _, this) : this._x;
  1262. };
  1263. function defaultY(d) {
  1264. return d[1];
  1265. }
  1266. var tree_y = function(_) {
  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) {
  1364. try { start(q); } // let the current task complete
  1365. catch (e) {
  1366. if (q._tasks[q._ended + q._active - 1]) abort(q, e); // task errored synchronously
  1367. else if (!q._data) throw e; // await callback errored synchronously
  1368. }
  1369. }
  1370. }
  1371. function start(q) {
  1372. while (q._start = q._waiting && q._active < q._size) {
  1373. var i = q._ended + q._active,
  1374. t = q._tasks[i],
  1375. j = t.length - 1,
  1376. c = t[j];
  1377. t[j] = end(q, i);
  1378. --q._waiting, ++q._active;
  1379. t = c.apply(null, t);
  1380. if (!q._tasks[i]) continue; // task finished synchronously
  1381. q._tasks[i] = t || noabort;
  1382. }
  1383. }
  1384. function end(q, i) {
  1385. return function(e, r) {
  1386. if (!q._tasks[i]) return; // ignore multiple callbacks
  1387. --q._active, ++q._ended;
  1388. q._tasks[i] = null;
  1389. if (q._error != null) return; // ignore secondary errors
  1390. if (e != null) {
  1391. abort(q, e);
  1392. } else {
  1393. q._data[i] = r;
  1394. if (q._waiting) poke(q);
  1395. else maybeNotify(q);
  1396. }
  1397. };
  1398. }
  1399. function abort(q, e) {
  1400. var i = q._tasks.length, t;
  1401. q._error = e; // ignore active callbacks
  1402. q._data = undefined; // allow gc
  1403. q._waiting = NaN; // prevent starting
  1404. while (--i >= 0) {
  1405. if (t = q._tasks[i]) {
  1406. q._tasks[i] = null;
  1407. if (t.abort) {
  1408. try { t.abort(); }
  1409. catch (e) { /* ignore */ }
  1410. }
  1411. }
  1412. }
  1413. q._active = NaN; // allow notification
  1414. maybeNotify(q);
  1415. }
  1416. function maybeNotify(q) {
  1417. if (!q._active && q._call) {
  1418. var d = q._data;
  1419. q._data = undefined; // allow gc
  1420. q._call(q._error, d);
  1421. }
  1422. }
  1423. function queue(concurrency) {
  1424. return new Queue(arguments.length ? +concurrency : Infinity);
  1425. }
  1426. var constant$2 = function(x) {
  1427. return function constant() {
  1428. return x;
  1429. };
  1430. };
  1431. var epsilon$1 = 1e-12;
  1432. var pi$2 = Math.PI;
  1433. var halfPi$1 = pi$2 / 2;
  1434. var tau$2 = 2 * pi$2;
  1435. function arcInnerRadius(d) {
  1436. return d.innerRadius;
  1437. }
  1438. function arcOuterRadius(d) {
  1439. return d.outerRadius;
  1440. }
  1441. function arcStartAngle(d) {
  1442. return d.startAngle;
  1443. }
  1444. function arcEndAngle(d) {
  1445. return d.endAngle;
  1446. }
  1447. function arcPadAngle(d) {
  1448. return d && d.padAngle; // Note: optional!
  1449. }
  1450. function asin(x) {
  1451. return x >= 1 ? halfPi$1 : x <= -1 ? -halfPi$1 : Math.asin(x);
  1452. }
  1453. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  1454. var x10 = x1 - x0, y10 = y1 - y0,
  1455. x32 = x3 - x2, y32 = y3 - y2,
  1456. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
  1457. return [x0 + t * x10, y0 + t * y10];
  1458. }
  1459. // Compute perpendicular offset line of length rc.
  1460. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  1461. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  1462. var x01 = x0 - x1,
  1463. y01 = y0 - y1,
  1464. lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01),
  1465. ox = lo * y01,
  1466. oy = -lo * x01,
  1467. x11 = x0 + ox,
  1468. y11 = y0 + oy,
  1469. x10 = x1 + ox,
  1470. y10 = y1 + oy,
  1471. x00 = (x11 + x10) / 2,
  1472. y00 = (y11 + y10) / 2,
  1473. dx = x10 - x11,
  1474. dy = y10 - y11,
  1475. d2 = dx * dx + dy * dy,
  1476. r = r1 - rc,
  1477. D = x11 * y10 - x10 * y11,
  1478. d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)),
  1479. cx0 = (D * dy - dx * d) / d2,
  1480. cy0 = (-D * dx - dy * d) / d2,
  1481. cx1 = (D * dy + dx * d) / d2,
  1482. cy1 = (-D * dx + dy * d) / d2,
  1483. dx0 = cx0 - x00,
  1484. dy0 = cy0 - y00,
  1485. dx1 = cx1 - x00,
  1486. dy1 = cy1 - y00;
  1487. // Pick the closer of the two intersection points.
  1488. // TODO Is there a faster way to determine which intersection to use?
  1489. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  1490. return {
  1491. cx: cx0,
  1492. cy: cy0,
  1493. x01: -ox,
  1494. y01: -oy,
  1495. x11: cx0 * (r1 / r - 1),
  1496. y11: cy0 * (r1 / r - 1)
  1497. };
  1498. }
  1499. var arc = function() {
  1500. var innerRadius = arcInnerRadius,
  1501. outerRadius = arcOuterRadius,
  1502. cornerRadius = constant$2(0),
  1503. padRadius = null,
  1504. startAngle = arcStartAngle,
  1505. endAngle = arcEndAngle,
  1506. padAngle = arcPadAngle,
  1507. context = null;
  1508. function arc() {
  1509. var buffer,
  1510. r,
  1511. r0 = +innerRadius.apply(this, arguments),
  1512. r1 = +outerRadius.apply(this, arguments),
  1513. a0 = startAngle.apply(this, arguments) - halfPi$1,
  1514. a1 = endAngle.apply(this, arguments) - halfPi$1,
  1515. da = Math.abs(a1 - a0),
  1516. cw = a1 > a0;
  1517. if (!context) context = buffer = path();
  1518. // Ensure that the outer radius is always larger than the inner radius.
  1519. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  1520. // Is it a point?
  1521. if (!(r1 > epsilon$1)) context.moveTo(0, 0);
  1522. // Or is it a circle or annulus?
  1523. else if (da > tau$2 - epsilon$1) {
  1524. context.moveTo(r1 * Math.cos(a0), r1 * Math.sin(a0));
  1525. context.arc(0, 0, r1, a0, a1, !cw);
  1526. if (r0 > epsilon$1) {
  1527. context.moveTo(r0 * Math.cos(a1), r0 * Math.sin(a1));
  1528. context.arc(0, 0, r0, a1, a0, cw);
  1529. }
  1530. }
  1531. // Or is it a circular or annular sector?
  1532. else {
  1533. var a01 = a0,
  1534. a11 = a1,
  1535. a00 = a0,
  1536. a10 = a1,
  1537. da0 = da,
  1538. da1 = da,
  1539. ap = padAngle.apply(this, arguments) / 2,
  1540. rp = (ap > epsilon$1) && (padRadius ? +padRadius.apply(this, arguments) : Math.sqrt(r0 * r0 + r1 * r1)),
  1541. rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  1542. rc0 = rc,
  1543. rc1 = rc,
  1544. t0,
  1545. t1;
  1546. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  1547. if (rp > epsilon$1) {
  1548. var p0 = asin(rp / r0 * Math.sin(ap)),
  1549. p1 = asin(rp / r1 * Math.sin(ap));
  1550. if ((da0 -= p0 * 2) > epsilon$1) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  1551. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  1552. if ((da1 -= p1 * 2) > epsilon$1) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  1553. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  1554. }
  1555. var x01 = r1 * Math.cos(a01),
  1556. y01 = r1 * Math.sin(a01),
  1557. x10 = r0 * Math.cos(a10),
  1558. y10 = r0 * Math.sin(a10);
  1559. // Apply rounded corners?
  1560. if (rc > epsilon$1) {
  1561. var x11 = r1 * Math.cos(a11),
  1562. y11 = r1 * Math.sin(a11),
  1563. x00 = r0 * Math.cos(a00),
  1564. y00 = r0 * Math.sin(a00);
  1565. // Restrict the corner radius according to the sector angle.
  1566. if (da < pi$2) {
  1567. var oc = da0 > epsilon$1 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
  1568. ax = x01 - oc[0],
  1569. ay = y01 - oc[1],
  1570. bx = x11 - oc[0],
  1571. by = y11 - oc[1],
  1572. kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2),
  1573. lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
  1574. rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
  1575. rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
  1576. }
  1577. }
  1578. // Is the sector collapsed to a line?
  1579. if (!(da1 > epsilon$1)) context.moveTo(x01, y01);
  1580. // Does the sector’s outer ring have rounded corners?
  1581. else if (rc1 > epsilon$1) {
  1582. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  1583. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  1584. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  1585. // Have the corners merged?
  1586. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, Math.atan2(t0.y01, t0.x01), Math.atan2(t1.y01, t1.x01), !cw);
  1587. // Otherwise, draw the two corners and the ring.
  1588. else {
  1589. context.arc(t0.cx, t0.cy, rc1, Math.atan2(t0.y01, t0.x01), Math.atan2(t0.y11, t0.x11), !cw);
  1590. 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);
  1591. context.arc(t1.cx, t1.cy, rc1, Math.atan2(t1.y11, t1.x11), Math.atan2(t1.y01, t1.x01), !cw);
  1592. }
  1593. }
  1594. // Or is the outer ring just a circular arc?
  1595. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  1596. // Is there no inner ring, and it’s a circular sector?
  1597. // Or perhaps it’s an annular sector collapsed due to padding?
  1598. if (!(r0 > epsilon$1) || !(da0 > epsilon$1)) context.lineTo(x10, y10);
  1599. // Does the sector’s inner ring (or point) have rounded corners?
  1600. else if (rc0 > epsilon$1) {
  1601. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  1602. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  1603. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  1604. // Have the corners merged?
  1605. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, Math.atan2(t0.y01, t0.x01), Math.atan2(t1.y01, t1.x01), !cw);
  1606. // Otherwise, draw the two corners and the ring.
  1607. else {
  1608. context.arc(t0.cx, t0.cy, rc0, Math.atan2(t0.y01, t0.x01), Math.atan2(t0.y11, t0.x11), !cw);
  1609. 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);
  1610. context.arc(t1.cx, t1.cy, rc0, Math.atan2(t1.y11, t1.x11), Math.atan2(t1.y01, t1.x01), !cw);
  1611. }
  1612. }
  1613. // Or is the inner ring just a circular arc?
  1614. else context.arc(0, 0, r0, a10, a00, cw);
  1615. }
  1616. context.closePath();
  1617. if (buffer) return context = null, buffer + "" || null;
  1618. }
  1619. arc.centroid = function() {
  1620. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  1621. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$2 / 2;
  1622. return [Math.cos(a) * r, Math.sin(a) * r];
  1623. };
  1624. arc.innerRadius = function(_) {
  1625. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$2(+_), arc) : innerRadius;
  1626. };
  1627. arc.outerRadius = function(_) {
  1628. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$2(+_), arc) : outerRadius;
  1629. };
  1630. arc.cornerRadius = function(_) {
  1631. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$2(+_), arc) : cornerRadius;
  1632. };
  1633. arc.padRadius = function(_) {
  1634. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$2(+_), arc) : padRadius;
  1635. };
  1636. arc.startAngle = function(_) {
  1637. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$2(+_), arc) : startAngle;
  1638. };
  1639. arc.endAngle = function(_) {
  1640. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$2(+_), arc) : endAngle;
  1641. };
  1642. arc.padAngle = function(_) {
  1643. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$2(+_), arc) : padAngle;
  1644. };
  1645. arc.context = function(_) {
  1646. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  1647. };
  1648. return arc;
  1649. };
  1650. function Linear(context) {
  1651. this._context = context;
  1652. }
  1653. Linear.prototype = {
  1654. areaStart: function() {
  1655. this._line = 0;
  1656. },
  1657. areaEnd: function() {
  1658. this._line = NaN;
  1659. },
  1660. lineStart: function() {
  1661. this._point = 0;
  1662. },
  1663. lineEnd: function() {
  1664. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  1665. this._line = 1 - this._line;
  1666. },
  1667. point: function(x, y) {
  1668. x = +x, y = +y;
  1669. switch (this._point) {
  1670. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  1671. case 1: this._point = 2; // proceed
  1672. default: this._context.lineTo(x, y); break;
  1673. }
  1674. }
  1675. };
  1676. var curveLinear = function(context) {
  1677. return new Linear(context);
  1678. };
  1679. function x(p) {
  1680. return p[0];
  1681. }
  1682. function y(p) {
  1683. return p[1];
  1684. }
  1685. var line = function() {
  1686. var x$$1 = x,
  1687. y$$1 = y,
  1688. defined = constant$2(true),
  1689. context = null,
  1690. curve = curveLinear,
  1691. output = null;
  1692. function line(data) {
  1693. var i,
  1694. n = data.length,
  1695. d,
  1696. defined0 = false,
  1697. buffer;
  1698. if (context == null) output = curve(buffer = path());
  1699. for (i = 0; i <= n; ++i) {
  1700. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  1701. if (defined0 = !defined0) output.lineStart();
  1702. else output.lineEnd();
  1703. }
  1704. if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
  1705. }
  1706. if (buffer) return output = null, buffer + "" || null;
  1707. }
  1708. line.x = function(_) {
  1709. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$2(+_), line) : x$$1;
  1710. };
  1711. line.y = function(_) {
  1712. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$2(+_), line) : y$$1;
  1713. };
  1714. line.defined = function(_) {
  1715. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$2(!!_), line) : defined;
  1716. };
  1717. line.curve = function(_) {
  1718. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  1719. };
  1720. line.context = function(_) {
  1721. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  1722. };
  1723. return line;
  1724. };
  1725. var area$1 = function() {
  1726. var x0 = x,
  1727. x1 = null,
  1728. y0 = constant$2(0),
  1729. y1 = y,
  1730. defined = constant$2(true),
  1731. context = null,
  1732. curve = curveLinear,
  1733. output = null;
  1734. function area(data) {
  1735. var i,
  1736. j,
  1737. k,
  1738. n = data.length,
  1739. d,
  1740. defined0 = false,
  1741. buffer,
  1742. x0z = new Array(n),
  1743. y0z = new Array(n);
  1744. if (context == null) output = curve(buffer = path());
  1745. for (i = 0; i <= n; ++i) {
  1746. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  1747. if (defined0 = !defined0) {
  1748. j = i;
  1749. output.areaStart();
  1750. output.lineStart();
  1751. } else {
  1752. output.lineEnd();
  1753. output.lineStart();
  1754. for (k = i - 1; k >= j; --k) {
  1755. output.point(x0z[k], y0z[k]);
  1756. }
  1757. output.lineEnd();
  1758. output.areaEnd();
  1759. }
  1760. }
  1761. if (defined0) {
  1762. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  1763. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  1764. }
  1765. }
  1766. if (buffer) return output = null, buffer + "" || null;
  1767. }
  1768. function arealine() {
  1769. return line().defined(defined).curve(curve).context(context);
  1770. }
  1771. area.x = function(_) {
  1772. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$2(+_), x1 = null, area) : x0;
  1773. };
  1774. area.x0 = function(_) {
  1775. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$2(+_), area) : x0;
  1776. };
  1777. area.x1 = function(_) {
  1778. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$2(+_), area) : x1;
  1779. };
  1780. area.y = function(_) {
  1781. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$2(+_), y1 = null, area) : y0;
  1782. };
  1783. area.y0 = function(_) {
  1784. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$2(+_), area) : y0;
  1785. };
  1786. area.y1 = function(_) {
  1787. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$2(+_), area) : y1;
  1788. };
  1789. area.lineX0 =
  1790. area.lineY0 = function() {
  1791. return arealine().x(x0).y(y0);
  1792. };
  1793. area.lineY1 = function() {
  1794. return arealine().x(x0).y(y1);
  1795. };
  1796. area.lineX1 = function() {
  1797. return arealine().x(x1).y(y0);
  1798. };
  1799. area.defined = function(_) {
  1800. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$2(!!_), area) : defined;
  1801. };
  1802. area.curve = function(_) {
  1803. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  1804. };
  1805. area.context = function(_) {
  1806. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  1807. };
  1808. return area;
  1809. };
  1810. var descending$1 = function(a, b) {
  1811. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  1812. };
  1813. var identity$1 = function(d) {
  1814. return d;
  1815. };
  1816. var pie = function() {
  1817. var value = identity$1,
  1818. sortValues = descending$1,
  1819. sort = null,
  1820. startAngle = constant$2(0),
  1821. endAngle = constant$2(tau$2),
  1822. padAngle = constant$2(0);
  1823. function pie(data) {
  1824. var i,
  1825. n = data.length,
  1826. j,
  1827. k,
  1828. sum = 0,
  1829. index = new Array(n),
  1830. arcs = new Array(n),
  1831. a0 = +startAngle.apply(this, arguments),
  1832. da = Math.min(tau$2, Math.max(-tau$2, endAngle.apply(this, arguments) - a0)),
  1833. a1,
  1834. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  1835. pa = p * (da < 0 ? -1 : 1),
  1836. v;
  1837. for (i = 0; i < n; ++i) {
  1838. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  1839. sum += v;
  1840. }
  1841. }
  1842. // Optionally sort the arcs by previously-computed values or by data.
  1843. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  1844. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  1845. // Compute the arcs! They are stored in the original data's order.
  1846. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  1847. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  1848. data: data[j],
  1849. index: i,
  1850. value: v,
  1851. startAngle: a0,
  1852. endAngle: a1,
  1853. padAngle: p
  1854. };
  1855. }
  1856. return arcs;
  1857. }
  1858. pie.value = function(_) {
  1859. return arguments.length ? (value = typeof _ === "function" ? _ : constant$2(+_), pie) : value;
  1860. };
  1861. pie.sortValues = function(_) {
  1862. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  1863. };
  1864. pie.sort = function(_) {
  1865. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  1866. };
  1867. pie.startAngle = function(_) {
  1868. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$2(+_), pie) : startAngle;
  1869. };
  1870. pie.endAngle = function(_) {
  1871. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$2(+_), pie) : endAngle;
  1872. };
  1873. pie.padAngle = function(_) {
  1874. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$2(+_), pie) : padAngle;
  1875. };
  1876. return pie;
  1877. };
  1878. var curveRadialLinear = curveRadial(curveLinear);
  1879. function Radial(curve) {
  1880. this._curve = curve;
  1881. }
  1882. Radial.prototype = {
  1883. areaStart: function() {
  1884. this._curve.areaStart();
  1885. },
  1886. areaEnd: function() {
  1887. this._curve.areaEnd();
  1888. },
  1889. lineStart: function() {
  1890. this._curve.lineStart();
  1891. },
  1892. lineEnd: function() {
  1893. this._curve.lineEnd();
  1894. },
  1895. point: function(a, r) {
  1896. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  1897. }
  1898. };
  1899. function curveRadial(curve) {
  1900. function radial(context) {
  1901. return new Radial(curve(context));
  1902. }
  1903. radial._curve = curve;
  1904. return radial;
  1905. }
  1906. function radialLine(l) {
  1907. var c = l.curve;
  1908. l.angle = l.x, delete l.x;
  1909. l.radius = l.y, delete l.y;
  1910. l.curve = function(_) {
  1911. return arguments.length ? c(curveRadial(_)) : c()._curve;
  1912. };
  1913. return l;
  1914. }
  1915. var radialLine$1 = function() {
  1916. return radialLine(line().curve(curveRadialLinear));
  1917. };
  1918. var radialArea = function() {
  1919. var a = area$1().curve(curveRadialLinear),
  1920. c = a.curve,
  1921. x0 = a.lineX0,
  1922. x1 = a.lineX1,
  1923. y0 = a.lineY0,
  1924. y1 = a.lineY1;
  1925. a.angle = a.x, delete a.x;
  1926. a.startAngle = a.x0, delete a.x0;
  1927. a.endAngle = a.x1, delete a.x1;
  1928. a.radius = a.y, delete a.y;
  1929. a.innerRadius = a.y0, delete a.y0;
  1930. a.outerRadius = a.y1, delete a.y1;
  1931. a.lineStartAngle = function() { return radialLine(x0()); }, delete a.lineX0;
  1932. a.lineEndAngle = function() { return radialLine(x1()); }, delete a.lineX1;
  1933. a.lineInnerRadius = function() { return radialLine(y0()); }, delete a.lineY0;
  1934. a.lineOuterRadius = function() { return radialLine(y1()); }, delete a.lineY1;
  1935. a.curve = function(_) {
  1936. return arguments.length ? c(curveRadial(_)) : c()._curve;
  1937. };
  1938. return a;
  1939. };
  1940. var circle = {
  1941. draw: function(context, size) {
  1942. var r = Math.sqrt(size / pi$2);
  1943. context.moveTo(r, 0);
  1944. context.arc(0, 0, r, 0, tau$2);
  1945. }
  1946. };
  1947. var cross$1 = {
  1948. draw: function(context, size) {
  1949. var r = Math.sqrt(size / 5) / 2;
  1950. context.moveTo(-3 * r, -r);
  1951. context.lineTo(-r, -r);
  1952. context.lineTo(-r, -3 * r);
  1953. context.lineTo(r, -3 * r);
  1954. context.lineTo(r, -r);
  1955. context.lineTo(3 * r, -r);
  1956. context.lineTo(3 * r, r);
  1957. context.lineTo(r, r);
  1958. context.lineTo(r, 3 * r);
  1959. context.lineTo(-r, 3 * r);
  1960. context.lineTo(-r, r);
  1961. context.lineTo(-3 * r, r);
  1962. context.closePath();
  1963. }
  1964. };
  1965. var tan30 = Math.sqrt(1 / 3);
  1966. var tan30_2 = tan30 * 2;
  1967. var diamond = {
  1968. draw: function(context, size) {
  1969. var y = Math.sqrt(size / tan30_2),
  1970. x = y * tan30;
  1971. context.moveTo(0, -y);
  1972. context.lineTo(x, 0);
  1973. context.lineTo(0, y);
  1974. context.lineTo(-x, 0);
  1975. context.closePath();
  1976. }
  1977. };
  1978. var ka = 0.89081309152928522810;
  1979. var kr = Math.sin(pi$2 / 10) / Math.sin(7 * pi$2 / 10);
  1980. var kx = Math.sin(tau$2 / 10) * kr;
  1981. var ky = -Math.cos(tau$2 / 10) * kr;
  1982. var star = {
  1983. draw: function(context, size) {
  1984. var r = Math.sqrt(size * ka),
  1985. x = kx * r,
  1986. y = ky * r;
  1987. context.moveTo(0, -r);
  1988. context.lineTo(x, y);
  1989. for (var i = 1; i < 5; ++i) {
  1990. var a = tau$2 * i / 5,
  1991. c = Math.cos(a),
  1992. s = Math.sin(a);
  1993. context.lineTo(s * r, -c * r);
  1994. context.lineTo(c * x - s * y, s * x + c * y);
  1995. }
  1996. context.closePath();
  1997. }
  1998. };
  1999. var square = {
  2000. draw: function(context, size) {
  2001. var w = Math.sqrt(size),
  2002. x = -w / 2;
  2003. context.rect(x, x, w, w);
  2004. }
  2005. };
  2006. var sqrt3 = Math.sqrt(3);
  2007. var triangle = {
  2008. draw: function(context, size) {
  2009. var y = -Math.sqrt(size / (sqrt3 * 3));
  2010. context.moveTo(0, y * 2);
  2011. context.lineTo(-sqrt3 * y, -y);
  2012. context.lineTo(sqrt3 * y, -y);
  2013. context.closePath();
  2014. }
  2015. };
  2016. var c = -0.5;
  2017. var s = Math.sqrt(3) / 2;
  2018. var k = 1 / Math.sqrt(12);
  2019. var a = (k / 2 + 1) * 3;
  2020. var wye = {
  2021. draw: function(context, size) {
  2022. var r = Math.sqrt(size / a),
  2023. x0 = r / 2,
  2024. y0 = r * k,
  2025. x1 = x0,
  2026. y1 = r * k + r,
  2027. x2 = -x1,
  2028. y2 = y1;
  2029. context.moveTo(x0, y0);
  2030. context.lineTo(x1, y1);
  2031. context.lineTo(x2, y2);
  2032. context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
  2033. context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
  2034. context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
  2035. context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
  2036. context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
  2037. context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
  2038. context.closePath();
  2039. }
  2040. };
  2041. var symbols = [
  2042. circle,
  2043. cross$1,
  2044. diamond,
  2045. square,
  2046. star,
  2047. triangle,
  2048. wye
  2049. ];
  2050. var symbol = function() {
  2051. var type = constant$2(circle),
  2052. size = constant$2(64),
  2053. context = null;
  2054. function symbol() {
  2055. var buffer;
  2056. if (!context) context = buffer = path();
  2057. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  2058. if (buffer) return context = null, buffer + "" || null;
  2059. }
  2060. symbol.type = function(_) {
  2061. return arguments.length ? (type = typeof _ === "function" ? _ : constant$2(_), symbol) : type;
  2062. };
  2063. symbol.size = function(_) {
  2064. return arguments.length ? (size = typeof _ === "function" ? _ : constant$2(+_), symbol) : size;
  2065. };
  2066. symbol.context = function(_) {
  2067. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  2068. };
  2069. return symbol;
  2070. };
  2071. var noop = function() {};
  2072. function point(that, x, y) {
  2073. that._context.bezierCurveTo(
  2074. (2 * that._x0 + that._x1) / 3,
  2075. (2 * that._y0 + that._y1) / 3,
  2076. (that._x0 + 2 * that._x1) / 3,
  2077. (that._y0 + 2 * that._y1) / 3,
  2078. (that._x0 + 4 * that._x1 + x) / 6,
  2079. (that._y0 + 4 * that._y1 + y) / 6
  2080. );
  2081. }
  2082. function Basis(context) {
  2083. this._context = context;
  2084. }
  2085. Basis.prototype = {
  2086. areaStart: function() {
  2087. this._line = 0;
  2088. },
  2089. areaEnd: function() {
  2090. this._line = NaN;
  2091. },
  2092. lineStart: function() {
  2093. this._x0 = this._x1 =
  2094. this._y0 = this._y1 = NaN;
  2095. this._point = 0;
  2096. },
  2097. lineEnd: function() {
  2098. switch (this._point) {
  2099. case 3: point(this, this._x1, this._y1); // proceed
  2100. case 2: this._context.lineTo(this._x1, this._y1); break;
  2101. }
  2102. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  2103. this._line = 1 - this._line;
  2104. },
  2105. point: function(x, y) {
  2106. x = +x, y = +y;
  2107. switch (this._point) {
  2108. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  2109. case 1: this._point = 2; break;
  2110. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  2111. default: point(this, x, y); break;
  2112. }
  2113. this._x0 = this._x1, this._x1 = x;
  2114. this._y0 = this._y1, this._y1 = y;
  2115. }
  2116. };
  2117. var basis = function(context) {
  2118. return new Basis(context);
  2119. };
  2120. function BasisClosed(context) {
  2121. this._context = context;
  2122. }
  2123. BasisClosed.prototype = {
  2124. areaStart: noop,
  2125. areaEnd: noop,
  2126. lineStart: function() {
  2127. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  2128. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  2129. this._point = 0;
  2130. },
  2131. lineEnd: function() {
  2132. switch (this._point) {
  2133. case 1: {
  2134. this._context.moveTo(this._x2, this._y2);
  2135. this._context.closePath();
  2136. break;
  2137. }
  2138. case 2: {
  2139. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  2140. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  2141. this._context.closePath();
  2142. break;
  2143. }
  2144. case 3: {
  2145. this.point(this._x2, this._y2);
  2146. this.point(this._x3, this._y3);
  2147. this.point(this._x4, this._y4);
  2148. break;
  2149. }
  2150. }
  2151. },
  2152. point: function(x, y) {
  2153. x = +x, y = +y;
  2154. switch (this._point) {
  2155. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  2156. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  2157. 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;
  2158. default: point(this, x, y); break;
  2159. }
  2160. this._x0 = this._x1, this._x1 = x;
  2161. this._y0 = this._y1, this._y1 = y;
  2162. }
  2163. };
  2164. var basisClosed = function(context) {
  2165. return new BasisClosed(context);
  2166. };
  2167. function BasisOpen(context) {
  2168. this._context = context;
  2169. }
  2170. BasisOpen.prototype = {
  2171. areaStart: function() {
  2172. this._line = 0;
  2173. },
  2174. areaEnd: function() {
  2175. this._line = NaN;
  2176. },
  2177. lineStart: function() {
  2178. this._x0 = this._x1 =
  2179. this._y0 = this._y1 = NaN;
  2180. this._point = 0;
  2181. },
  2182. lineEnd: function() {
  2183. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  2184. this._line = 1 - this._line;
  2185. },
  2186. point: function(x, y) {
  2187. x = +x, y = +y;
  2188. switch (this._point) {
  2189. case 0: this._point = 1; break;
  2190. case 1: this._point = 2; break;
  2191. 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;
  2192. case 3: this._point = 4; // proceed
  2193. default: point(this, x, y); break;
  2194. }
  2195. this._x0 = this._x1, this._x1 = x;
  2196. this._y0 = this._y1, this._y1 = y;
  2197. }
  2198. };
  2199. var basisOpen = function(context) {
  2200. return new BasisOpen(context);
  2201. };
  2202. function Bundle(context, beta) {
  2203. this._basis = new Basis(context);
  2204. this._beta = beta;
  2205. }
  2206. Bundle.prototype = {
  2207. lineStart: function() {
  2208. this._x = [];
  2209. this._y = [];
  2210. this._basis.lineStart();
  2211. },
  2212. lineEnd: function() {
  2213. var x = this._x,
  2214. y = this._y,
  2215. j = x.length - 1;
  2216. if (j > 0) {
  2217. var x0 = x[0],
  2218. y0 = y[0],
  2219. dx = x[j] - x0,
  2220. dy = y[j] - y0,
  2221. i = -1,
  2222. t;
  2223. while (++i <= j) {
  2224. t = i / j;
  2225. this._basis.point(
  2226. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  2227. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  2228. );
  2229. }
  2230. }
  2231. this._x = this._y = null;
  2232. this._basis.lineEnd();
  2233. },
  2234. point: function(x, y) {
  2235. this._x.push(+x);
  2236. this._y.push(+y);
  2237. }
  2238. };
  2239. var bundle = (function custom(beta) {
  2240. function bundle(context) {
  2241. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  2242. }
  2243. bundle.beta = function(beta) {
  2244. return custom(+beta);
  2245. };
  2246. return bundle;
  2247. })(0.85);
  2248. function point$1(that, x, y) {
  2249. that._context.bezierCurveTo(
  2250. that._x1 + that._k * (that._x2 - that._x0),
  2251. that._y1 + that._k * (that._y2 - that._y0),
  2252. that._x2 + that._k * (that._x1 - x),
  2253. that._y2 + that._k * (that._y1 - y),
  2254. that._x2,
  2255. that._y2
  2256. );
  2257. }
  2258. function Cardinal(context, tension) {
  2259. this._context = context;
  2260. this._k = (1 - tension) / 6;
  2261. }
  2262. Cardinal.prototype = {
  2263. areaStart: function() {
  2264. this._line = 0;
  2265. },
  2266. areaEnd: function() {
  2267. this._line = NaN;
  2268. },
  2269. lineStart: function() {
  2270. this._x0 = this._x1 = this._x2 =
  2271. this._y0 = this._y1 = this._y2 = NaN;
  2272. this._point = 0;
  2273. },
  2274. lineEnd: function() {
  2275. switch (this._point) {
  2276. case 2: this._context.lineTo(this._x2, this._y2); break;
  2277. case 3: point$1(this, this._x1, this._y1); break;
  2278. }
  2279. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  2280. this._line = 1 - this._line;
  2281. },
  2282. point: function(x, y) {
  2283. x = +x, y = +y;
  2284. switch (this._point) {
  2285. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  2286. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  2287. case 2: this._point = 3; // proceed
  2288. default: point$1(this, x, y); break;
  2289. }
  2290. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2291. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2292. }
  2293. };
  2294. var cardinal = (function custom(tension) {
  2295. function cardinal(context) {
  2296. return new Cardinal(context, tension);
  2297. }
  2298. cardinal.tension = function(tension) {
  2299. return custom(+tension);
  2300. };
  2301. return cardinal;
  2302. })(0);
  2303. function CardinalClosed(context, tension) {
  2304. this._context = context;
  2305. this._k = (1 - tension) / 6;
  2306. }
  2307. CardinalClosed.prototype = {
  2308. areaStart: noop,
  2309. areaEnd: noop,
  2310. lineStart: function() {
  2311. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  2312. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  2313. this._point = 0;
  2314. },
  2315. lineEnd: function() {
  2316. switch (this._point) {
  2317. case 1: {
  2318. this._context.moveTo(this._x3, this._y3);
  2319. this._context.closePath();
  2320. break;
  2321. }
  2322. case 2: {
  2323. this._context.lineTo(this._x3, this._y3);
  2324. this._context.closePath();
  2325. break;
  2326. }
  2327. case 3: {
  2328. this.point(this._x3, this._y3);
  2329. this.point(this._x4, this._y4);
  2330. this.point(this._x5, this._y5);
  2331. break;
  2332. }
  2333. }
  2334. },
  2335. point: function(x, y) {
  2336. x = +x, y = +y;
  2337. switch (this._point) {
  2338. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  2339. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  2340. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  2341. default: point$1(this, x, y); break;
  2342. }
  2343. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2344. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2345. }
  2346. };
  2347. var cardinalClosed = (function custom(tension) {
  2348. function cardinal(context) {
  2349. return new CardinalClosed(context, tension);
  2350. }
  2351. cardinal.tension = function(tension) {
  2352. return custom(+tension);
  2353. };
  2354. return cardinal;
  2355. })(0);
  2356. function CardinalOpen(context, tension) {
  2357. this._context = context;
  2358. this._k = (1 - tension) / 6;
  2359. }
  2360. CardinalOpen.prototype = {
  2361. areaStart: function() {
  2362. this._line = 0;
  2363. },
  2364. areaEnd: function() {
  2365. this._line = NaN;
  2366. },
  2367. lineStart: function() {
  2368. this._x0 = this._x1 = this._x2 =
  2369. this._y0 = this._y1 = this._y2 = NaN;
  2370. this._point = 0;
  2371. },
  2372. lineEnd: function() {
  2373. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  2374. this._line = 1 - this._line;
  2375. },
  2376. point: function(x, y) {
  2377. x = +x, y = +y;
  2378. switch (this._point) {
  2379. case 0: this._point = 1; break;
  2380. case 1: this._point = 2; break;
  2381. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  2382. case 3: this._point = 4; // proceed
  2383. default: point$1(this, x, y); break;
  2384. }
  2385. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2386. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2387. }
  2388. };
  2389. var cardinalOpen = (function custom(tension) {
  2390. function cardinal(context) {
  2391. return new CardinalOpen(context, tension);
  2392. }
  2393. cardinal.tension = function(tension) {
  2394. return custom(+tension);
  2395. };
  2396. return cardinal;
  2397. })(0);
  2398. function point$2(that, x, y) {
  2399. var x1 = that._x1,
  2400. y1 = that._y1,
  2401. x2 = that._x2,
  2402. y2 = that._y2;
  2403. if (that._l01_a > epsilon$1) {
  2404. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  2405. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  2406. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  2407. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  2408. }
  2409. if (that._l23_a > epsilon$1) {
  2410. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  2411. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  2412. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  2413. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  2414. }
  2415. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  2416. }
  2417. function CatmullRom(context, alpha) {
  2418. this._context = context;
  2419. this._alpha = alpha;
  2420. }
  2421. CatmullRom.prototype = {
  2422. areaStart: function() {
  2423. this._line = 0;
  2424. },
  2425. areaEnd: function() {
  2426. this._line = NaN;
  2427. },
  2428. lineStart: function() {
  2429. this._x0 = this._x1 = this._x2 =
  2430. this._y0 = this._y1 = this._y2 = NaN;
  2431. this._l01_a = this._l12_a = this._l23_a =
  2432. this._l01_2a = this._l12_2a = this._l23_2a =
  2433. this._point = 0;
  2434. },
  2435. lineEnd: function() {
  2436. switch (this._point) {
  2437. case 2: this._context.lineTo(this._x2, this._y2); break;
  2438. case 3: this.point(this._x2, this._y2); break;
  2439. }
  2440. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  2441. this._line = 1 - this._line;
  2442. },
  2443. point: function(x, y) {
  2444. x = +x, y = +y;
  2445. if (this._point) {
  2446. var x23 = this._x2 - x,
  2447. y23 = this._y2 - y;
  2448. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  2449. }
  2450. switch (this._point) {
  2451. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  2452. case 1: this._point = 2; break;
  2453. case 2: this._point = 3; // proceed
  2454. default: point$2(this, x, y); break;
  2455. }
  2456. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  2457. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  2458. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2459. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2460. }
  2461. };
  2462. var catmullRom = (function custom(alpha) {
  2463. function catmullRom(context) {
  2464. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  2465. }
  2466. catmullRom.alpha = function(alpha) {
  2467. return custom(+alpha);
  2468. };
  2469. return catmullRom;
  2470. })(0.5);
  2471. function CatmullRomClosed(context, alpha) {
  2472. this._context = context;
  2473. this._alpha = alpha;
  2474. }
  2475. CatmullRomClosed.prototype = {
  2476. areaStart: noop,
  2477. areaEnd: noop,
  2478. lineStart: function() {
  2479. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  2480. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  2481. this._l01_a = this._l12_a = this._l23_a =
  2482. this._l01_2a = this._l12_2a = this._l23_2a =
  2483. this._point = 0;
  2484. },
  2485. lineEnd: function() {
  2486. switch (this._point) {
  2487. case 1: {
  2488. this._context.moveTo(this._x3, this._y3);
  2489. this._context.closePath();
  2490. break;
  2491. }
  2492. case 2: {
  2493. this._context.lineTo(this._x3, this._y3);
  2494. this._context.closePath();
  2495. break;
  2496. }
  2497. case 3: {
  2498. this.point(this._x3, this._y3);
  2499. this.point(this._x4, this._y4);
  2500. this.point(this._x5, this._y5);
  2501. break;
  2502. }
  2503. }
  2504. },
  2505. point: function(x, y) {
  2506. x = +x, y = +y;
  2507. if (this._point) {
  2508. var x23 = this._x2 - x,
  2509. y23 = this._y2 - y;
  2510. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  2511. }
  2512. switch (this._point) {
  2513. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  2514. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  2515. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  2516. default: point$2(this, x, y); break;
  2517. }
  2518. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  2519. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  2520. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2521. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2522. }
  2523. };
  2524. var catmullRomClosed = (function custom(alpha) {
  2525. function catmullRom(context) {
  2526. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  2527. }
  2528. catmullRom.alpha = function(alpha) {
  2529. return custom(+alpha);
  2530. };
  2531. return catmullRom;
  2532. })(0.5);
  2533. function CatmullRomOpen(context, alpha) {
  2534. this._context = context;
  2535. this._alpha = alpha;
  2536. }
  2537. CatmullRomOpen.prototype = {
  2538. areaStart: function() {
  2539. this._line = 0;
  2540. },
  2541. areaEnd: function() {
  2542. this._line = NaN;
  2543. },
  2544. lineStart: function() {
  2545. this._x0 = this._x1 = this._x2 =
  2546. this._y0 = this._y1 = this._y2 = NaN;
  2547. this._l01_a = this._l12_a = this._l23_a =
  2548. this._l01_2a = this._l12_2a = this._l23_2a =
  2549. this._point = 0;
  2550. },
  2551. lineEnd: function() {
  2552. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  2553. this._line = 1 - this._line;
  2554. },
  2555. point: function(x, y) {
  2556. x = +x, y = +y;
  2557. if (this._point) {
  2558. var x23 = this._x2 - x,
  2559. y23 = this._y2 - y;
  2560. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  2561. }
  2562. switch (this._point) {
  2563. case 0: this._point = 1; break;
  2564. case 1: this._point = 2; break;
  2565. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  2566. case 3: this._point = 4; // proceed
  2567. default: point$2(this, x, y); break;
  2568. }
  2569. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  2570. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  2571. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  2572. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  2573. }
  2574. };
  2575. var catmullRomOpen = (function custom(alpha) {
  2576. function catmullRom(context) {
  2577. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  2578. }
  2579. catmullRom.alpha = function(alpha) {
  2580. return custom(+alpha);
  2581. };
  2582. return catmullRom;
  2583. })(0.5);
  2584. function LinearClosed(context) {
  2585. this._context = context;
  2586. }
  2587. LinearClosed.prototype = {
  2588. areaStart: noop,
  2589. areaEnd: noop,
  2590. lineStart: function() {
  2591. this._point = 0;
  2592. },
  2593. lineEnd: function() {
  2594. if (this._point) this._context.closePath();
  2595. },
  2596. point: function(x, y) {
  2597. x = +x, y = +y;
  2598. if (this._point) this._context.lineTo(x, y);
  2599. else this._point = 1, this._context.moveTo(x, y);
  2600. }
  2601. };
  2602. var linearClosed = function(context) {
  2603. return new LinearClosed(context);
  2604. };
  2605. function sign(x) {
  2606. return x < 0 ? -1 : 1;
  2607. }
  2608. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  2609. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  2610. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  2611. // NOV(II), P. 443, 1990.
  2612. function slope3(that, x2, y2) {
  2613. var h0 = that._x1 - that._x0,
  2614. h1 = x2 - that._x1,
  2615. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  2616. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  2617. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  2618. return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  2619. }
  2620. // Calculate a one-sided slope.
  2621. function slope2(that, t) {
  2622. var h = that._x1 - that._x0;
  2623. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  2624. }
  2625. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  2626. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  2627. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  2628. function point$3(that, t0, t1) {
  2629. var x0 = that._x0,
  2630. y0 = that._y0,
  2631. x1 = that._x1,
  2632. y1 = that._y1,
  2633. dx = (x1 - x0) / 3;
  2634. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  2635. }
  2636. function MonotoneX(context) {
  2637. this._context = context;
  2638. }
  2639. MonotoneX.prototype = {
  2640. areaStart: function() {
  2641. this._line = 0;
  2642. },
  2643. areaEnd: function() {
  2644. this._line = NaN;
  2645. },
  2646. lineStart: function() {
  2647. this._x0 = this._x1 =
  2648. this._y0 = this._y1 =
  2649. this._t0 = NaN;
  2650. this._point = 0;
  2651. },
  2652. lineEnd: function() {
  2653. switch (this._point) {
  2654. case 2: this._context.lineTo(this._x1, this._y1); break;
  2655. case 3: point$3(this, this._t0, slope2(this, this._t0)); break;
  2656. }
  2657. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  2658. this._line = 1 - this._line;
  2659. },
  2660. point: function(x, y) {
  2661. var t1 = NaN;
  2662. x = +x, y = +y;
  2663. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  2664. switch (this._point) {
  2665. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  2666. case 1: this._point = 2; break;
  2667. case 2: this._point = 3; point$3(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  2668. default: point$3(this, this._t0, t1 = slope3(this, x, y)); break;
  2669. }
  2670. this._x0 = this._x1, this._x1 = x;
  2671. this._y0 = this._y1, this._y1 = y;
  2672. this._t0 = t1;
  2673. }
  2674. };
  2675. function MonotoneY(context) {
  2676. this._context = new ReflectContext(context);
  2677. }
  2678. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  2679. MonotoneX.prototype.point.call(this, y, x);
  2680. };
  2681. function ReflectContext(context) {
  2682. this._context = context;
  2683. }
  2684. ReflectContext.prototype = {
  2685. moveTo: function(x, y) { this._context.moveTo(y, x); },
  2686. closePath: function() { this._context.closePath(); },
  2687. lineTo: function(x, y) { this._context.lineTo(y, x); },
  2688. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  2689. };
  2690. function monotoneX(context) {
  2691. return new MonotoneX(context);
  2692. }
  2693. function monotoneY(context) {
  2694. return new MonotoneY(context);
  2695. }
  2696. function Natural(context) {
  2697. this._context = context;
  2698. }
  2699. Natural.prototype = {
  2700. areaStart: function() {
  2701. this._line = 0;
  2702. },
  2703. areaEnd: function() {
  2704. this._line = NaN;
  2705. },
  2706. lineStart: function() {
  2707. this._x = [];
  2708. this._y = [];
  2709. },
  2710. lineEnd: function() {
  2711. var x = this._x,
  2712. y = this._y,
  2713. n = x.length;
  2714. if (n) {
  2715. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  2716. if (n === 2) {
  2717. this._context.lineTo(x[1], y[1]);
  2718. } else {
  2719. var px = controlPoints(x),
  2720. py = controlPoints(y);
  2721. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  2722. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  2723. }
  2724. }
  2725. }
  2726. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  2727. this._line = 1 - this._line;
  2728. this._x = this._y = null;
  2729. },
  2730. point: function(x, y) {
  2731. this._x.push(+x);
  2732. this._y.push(+y);
  2733. }
  2734. };
  2735. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  2736. function controlPoints(x) {
  2737. var i,
  2738. n = x.length - 1,
  2739. m,
  2740. a = new Array(n),
  2741. b = new Array(n),
  2742. r = new Array(n);
  2743. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  2744. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  2745. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  2746. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  2747. a[n - 1] = r[n - 1] / b[n - 1];
  2748. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  2749. b[n - 1] = (x[n] + a[n - 1]) / 2;
  2750. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  2751. return [a, b];
  2752. }
  2753. var natural = function(context) {
  2754. return new Natural(context);
  2755. };
  2756. function Step(context, t) {
  2757. this._context = context;
  2758. this._t = t;
  2759. }
  2760. Step.prototype = {
  2761. areaStart: function() {
  2762. this._line = 0;
  2763. },
  2764. areaEnd: function() {
  2765. this._line = NaN;
  2766. },
  2767. lineStart: function() {
  2768. this._x = this._y = NaN;
  2769. this._point = 0;
  2770. },
  2771. lineEnd: function() {
  2772. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  2773. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  2774. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  2775. },
  2776. point: function(x, y) {
  2777. x = +x, y = +y;
  2778. switch (this._point) {
  2779. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  2780. case 1: this._point = 2; // proceed
  2781. default: {
  2782. if (this._t <= 0) {
  2783. this._context.lineTo(this._x, y);
  2784. this._context.lineTo(x, y);
  2785. } else {
  2786. var x1 = this._x * (1 - this._t) + x * this._t;
  2787. this._context.lineTo(x1, this._y);
  2788. this._context.lineTo(x1, y);
  2789. }
  2790. break;
  2791. }
  2792. }
  2793. this._x = x, this._y = y;
  2794. }
  2795. };
  2796. var step = function(context) {
  2797. return new Step(context, 0.5);
  2798. };
  2799. function stepBefore(context) {
  2800. return new Step(context, 0);
  2801. }
  2802. function stepAfter(context) {
  2803. return new Step(context, 1);
  2804. }
  2805. var slice$2 = Array.prototype.slice;
  2806. var none = function(series, order) {
  2807. if (!((n = series.length) > 1)) return;
  2808. for (var i = 1, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  2809. s0 = s1, s1 = series[order[i]];
  2810. for (var j = 0; j < m; ++j) {
  2811. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  2812. }
  2813. }
  2814. };
  2815. var none$1 = function(series) {
  2816. var n = series.length, o = new Array(n);
  2817. while (--n >= 0) o[n] = n;
  2818. return o;
  2819. };
  2820. function stackValue(d, key) {
  2821. return d[key];
  2822. }
  2823. var stack = function() {
  2824. var keys = constant$2([]),
  2825. order = none$1,
  2826. offset = none,
  2827. value = stackValue;
  2828. function stack(data) {
  2829. var kz = keys.apply(this, arguments),
  2830. i,
  2831. m = data.length,
  2832. n = kz.length,
  2833. sz = new Array(n),
  2834. oz;
  2835. for (i = 0; i < n; ++i) {
  2836. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  2837. si[j] = sij = [0, +value(data[j], ki, j, data)];
  2838. sij.data = data[j];
  2839. }
  2840. si.key = ki;
  2841. }
  2842. for (i = 0, oz = order(sz); i < n; ++i) {
  2843. sz[oz[i]].index = i;
  2844. }
  2845. offset(sz, oz);
  2846. return sz;
  2847. }
  2848. stack.keys = function(_) {
  2849. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$2(slice$2.call(_)), stack) : keys;
  2850. };
  2851. stack.value = function(_) {
  2852. return arguments.length ? (value = typeof _ === "function" ? _ : constant$2(+_), stack) : value;
  2853. };
  2854. stack.order = function(_) {
  2855. return arguments.length ? (order = _ == null ? none$1 : typeof _ === "function" ? _ : constant$2(slice$2.call(_)), stack) : order;
  2856. };
  2857. stack.offset = function(_) {
  2858. return arguments.length ? (offset = _ == null ? none : _, stack) : offset;
  2859. };
  2860. return stack;
  2861. };
  2862. var expand = function(series, order) {
  2863. if (!((n = series.length) > 0)) return;
  2864. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  2865. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  2866. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  2867. }
  2868. none(series, order);
  2869. };
  2870. var silhouette = function(series, order) {
  2871. if (!((n = series.length) > 0)) return;
  2872. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  2873. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  2874. s0[j][1] += s0[j][0] = -y / 2;
  2875. }
  2876. none(series, order);
  2877. };
  2878. var wiggle = function(series, order) {
  2879. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  2880. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  2881. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  2882. var si = series[order[i]],
  2883. sij0 = si[j][1] || 0,
  2884. sij1 = si[j - 1][1] || 0,
  2885. s3 = (sij0 - sij1) / 2;
  2886. for (var k = 0; k < i; ++k) {
  2887. var sk = series[order[k]],
  2888. skj0 = sk[j][1] || 0,
  2889. skj1 = sk[j - 1][1] || 0;
  2890. s3 += skj0 - skj1;
  2891. }
  2892. s1 += sij0, s2 += s3 * sij0;
  2893. }
  2894. s0[j - 1][1] += s0[j - 1][0] = y;
  2895. if (s1) y -= s2 / s1;
  2896. }
  2897. s0[j - 1][1] += s0[j - 1][0] = y;
  2898. none(series, order);
  2899. };
  2900. var ascending$1 = function(series) {
  2901. var sums = series.map(sum$1);
  2902. return none$1(series).sort(function(a, b) { return sums[a] - sums[b]; });
  2903. };
  2904. function sum$1(series) {
  2905. var s = 0, i = -1, n = series.length, v;
  2906. while (++i < n) if (v = +series[i][1]) s += v;
  2907. return s;
  2908. }
  2909. var descending$2 = function(series) {
  2910. return ascending$1(series).reverse();
  2911. };
  2912. var insideOut = function(series) {
  2913. var n = series.length,
  2914. i,
  2915. j,
  2916. sums = series.map(sum$1),
  2917. order = none$1(series).sort(function(a, b) { return sums[b] - sums[a]; }),
  2918. top = 0,
  2919. bottom = 0,
  2920. tops = [],
  2921. bottoms = [];
  2922. for (i = 0; i < n; ++i) {
  2923. j = order[i];
  2924. if (top < bottom) {
  2925. top += sums[j];
  2926. tops.push(j);
  2927. } else {
  2928. bottom += sums[j];
  2929. bottoms.push(j);
  2930. }
  2931. }
  2932. return bottoms.reverse().concat(tops);
  2933. };
  2934. var reverse = function(series) {
  2935. return none$1(series).reverse();
  2936. };
  2937. var define = function(constructor, factory, prototype) {
  2938. constructor.prototype = factory.prototype = prototype;
  2939. prototype.constructor = constructor;
  2940. };
  2941. function extend(parent, definition) {
  2942. var prototype = Object.create(parent.prototype);
  2943. for (var key in definition) prototype[key] = definition[key];
  2944. return prototype;
  2945. }
  2946. function Color() {}
  2947. var darker = 0.7;
  2948. var brighter = 1 / darker;
  2949. var reHex3 = /^#([0-9a-f]{3})$/;
  2950. var reHex6 = /^#([0-9a-f]{6})$/;
  2951. var reRgbInteger = /^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/;
  2952. var reRgbPercent = /^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
  2953. var reRgbaInteger = /^rgba\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
  2954. var reRgbaPercent = /^rgba\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
  2955. var reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
  2956. var reHslaPercent = /^hsla\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
  2957. var named = {
  2958. aliceblue: 0xf0f8ff,
  2959. antiquewhite: 0xfaebd7,
  2960. aqua: 0x00ffff,
  2961. aquamarine: 0x7fffd4,
  2962. azure: 0xf0ffff,
  2963. beige: 0xf5f5dc,
  2964. bisque: 0xffe4c4,
  2965. black: 0x000000,
  2966. blanchedalmond: 0xffebcd,
  2967. blue: 0x0000ff,
  2968. blueviolet: 0x8a2be2,
  2969. brown: 0xa52a2a,
  2970. burlywood: 0xdeb887,
  2971. cadetblue: 0x5f9ea0,
  2972. chartreuse: 0x7fff00,
  2973. chocolate: 0xd2691e,
  2974. coral: 0xff7f50,
  2975. cornflowerblue: 0x6495ed,
  2976. cornsilk: 0xfff8dc,
  2977. crimson: 0xdc143c,
  2978. cyan: 0x00ffff,
  2979. darkblue: 0x00008b,
  2980. darkcyan: 0x008b8b,
  2981. darkgoldenrod: 0xb8860b,
  2982. darkgray: 0xa9a9a9,
  2983. darkgreen: 0x006400,
  2984. darkgrey: 0xa9a9a9,
  2985. darkkhaki: 0xbdb76b,
  2986. darkmagenta: 0x8b008b,
  2987. darkolivegreen: 0x556b2f,
  2988. darkorange: 0xff8c00,
  2989. darkorchid: 0x9932cc,
  2990. darkred: 0x8b0000,
  2991. darksalmon: 0xe9967a,
  2992. darkseagreen: 0x8fbc8f,
  2993. darkslateblue: 0x483d8b,
  2994. darkslategray: 0x2f4f4f,
  2995. darkslategrey: 0x2f4f4f,
  2996. darkturquoise: 0x00ced1,
  2997. darkviolet: 0x9400d3,
  2998. deeppink: 0xff1493,
  2999. deepskyblue: 0x00bfff,
  3000. dimgray: 0x696969,
  3001. dimgrey: 0x696969,
  3002. dodgerblue: 0x1e90ff,
  3003. firebrick: 0xb22222,
  3004. floralwhite: 0xfffaf0,
  3005. forestgreen: 0x228b22,
  3006. fuchsia: 0xff00ff,
  3007. gainsboro: 0xdcdcdc,
  3008. ghostwhite: 0xf8f8ff,
  3009. gold: 0xffd700,
  3010. goldenrod: 0xdaa520,
  3011. gray: 0x808080,
  3012. green: 0x008000,
  3013. greenyellow: 0xadff2f,
  3014. grey: 0x808080,
  3015. honeydew: 0xf0fff0,
  3016. hotpink: 0xff69b4,
  3017. indianred: 0xcd5c5c,
  3018. indigo: 0x4b0082,
  3019. ivory: 0xfffff0,
  3020. khaki: 0xf0e68c,
  3021. lavender: 0xe6e6fa,
  3022. lavenderblush: 0xfff0f5,
  3023. lawngreen: 0x7cfc00,
  3024. lemonchiffon: 0xfffacd,
  3025. lightblue: 0xadd8e6,
  3026. lightcoral: 0xf08080,
  3027. lightcyan: 0xe0ffff,
  3028. lightgoldenrodyellow: 0xfafad2,
  3029. lightgray: 0xd3d3d3,
  3030. lightgreen: 0x90ee90,
  3031. lightgrey: 0xd3d3d3,
  3032. lightpink: 0xffb6c1,
  3033. lightsalmon: 0xffa07a,
  3034. lightseagreen: 0x20b2aa,
  3035. lightskyblue: 0x87cefa,
  3036. lightslategray: 0x778899,
  3037. lightslategrey: 0x778899,
  3038. lightsteelblue: 0xb0c4de,
  3039. lightyellow: 0xffffe0,
  3040. lime: 0x00ff00,
  3041. limegreen: 0x32cd32,
  3042. linen: 0xfaf0e6,
  3043. magenta: 0xff00ff,
  3044. maroon: 0x800000,
  3045. mediumaquamarine: 0x66cdaa,
  3046. mediumblue: 0x0000cd,
  3047. mediumorchid: 0xba55d3,
  3048. mediumpurple: 0x9370db,
  3049. mediumseagreen: 0x3cb371,
  3050. mediumslateblue: 0x7b68ee,
  3051. mediumspringgreen: 0x00fa9a,
  3052. mediumturquoise: 0x48d1cc,
  3053. mediumvioletred: 0xc71585,
  3054. midnightblue: 0x191970,
  3055. mintcream: 0xf5fffa,
  3056. mistyrose: 0xffe4e1,
  3057. moccasin: 0xffe4b5,
  3058. navajowhite: 0xffdead,
  3059. navy: 0x000080,
  3060. oldlace: 0xfdf5e6,
  3061. olive: 0x808000,
  3062. olivedrab: 0x6b8e23,
  3063. orange: 0xffa500,
  3064. orangered: 0xff4500,
  3065. orchid: 0xda70d6,
  3066. palegoldenrod: 0xeee8aa,
  3067. palegreen: 0x98fb98,
  3068. paleturquoise: 0xafeeee,
  3069. palevioletred: 0xdb7093,
  3070. papayawhip: 0xffefd5,
  3071. peachpuff: 0xffdab9,
  3072. peru: 0xcd853f,
  3073. pink: 0xffc0cb,
  3074. plum: 0xdda0dd,
  3075. powderblue: 0xb0e0e6,
  3076. purple: 0x800080,
  3077. rebeccapurple: 0x663399,
  3078. red: 0xff0000,
  3079. rosybrown: 0xbc8f8f,
  3080. royalblue: 0x4169e1,
  3081. saddlebrown: 0x8b4513,
  3082. salmon: 0xfa8072,
  3083. sandybrown: 0xf4a460,
  3084. seagreen: 0x2e8b57,
  3085. seashell: 0xfff5ee,
  3086. sienna: 0xa0522d,
  3087. silver: 0xc0c0c0,
  3088. skyblue: 0x87ceeb,
  3089. slateblue: 0x6a5acd,
  3090. slategray: 0x708090,
  3091. slategrey: 0x708090,
  3092. snow: 0xfffafa,
  3093. springgreen: 0x00ff7f,
  3094. steelblue: 0x4682b4,
  3095. tan: 0xd2b48c,
  3096. teal: 0x008080,
  3097. thistle: 0xd8bfd8,
  3098. tomato: 0xff6347,
  3099. turquoise: 0x40e0d0,
  3100. violet: 0xee82ee,
  3101. wheat: 0xf5deb3,
  3102. white: 0xffffff,
  3103. whitesmoke: 0xf5f5f5,
  3104. yellow: 0xffff00,
  3105. yellowgreen: 0x9acd32
  3106. };
  3107. define(Color, color, {
  3108. displayable: function() {
  3109. return this.rgb().displayable();
  3110. },
  3111. toString: function() {
  3112. return this.rgb() + "";
  3113. }
  3114. });
  3115. function color(format) {
  3116. var m;
  3117. format = (format + "").trim().toLowerCase();
  3118. 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
  3119. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  3120. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  3121. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  3122. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  3123. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  3124. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  3125. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  3126. : named.hasOwnProperty(format) ? rgbn(named[format])
  3127. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  3128. : null;
  3129. }
  3130. function rgbn(n) {
  3131. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  3132. }
  3133. function rgba(r, g, b, a) {
  3134. if (a <= 0) r = g = b = NaN;
  3135. return new Rgb(r, g, b, a);
  3136. }
  3137. function rgbConvert(o) {
  3138. if (!(o instanceof Color)) o = color(o);
  3139. if (!o) return new Rgb;
  3140. o = o.rgb();
  3141. return new Rgb(o.r, o.g, o.b, o.opacity);
  3142. }
  3143. function rgb(r, g, b, opacity) {
  3144. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  3145. }
  3146. function Rgb(r, g, b, opacity) {
  3147. this.r = +r;
  3148. this.g = +g;
  3149. this.b = +b;
  3150. this.opacity = +opacity;
  3151. }
  3152. define(Rgb, rgb, extend(Color, {
  3153. brighter: function(k) {
  3154. k = k == null ? brighter : Math.pow(brighter, k);
  3155. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  3156. },
  3157. darker: function(k) {
  3158. k = k == null ? darker : Math.pow(darker, k);
  3159. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  3160. },
  3161. rgb: function() {
  3162. return this;
  3163. },
  3164. displayable: function() {
  3165. return (0 <= this.r && this.r <= 255)
  3166. && (0 <= this.g && this.g <= 255)
  3167. && (0 <= this.b && this.b <= 255)
  3168. && (0 <= this.opacity && this.opacity <= 1);
  3169. },
  3170. toString: function() {
  3171. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  3172. return (a === 1 ? "rgb(" : "rgba(")
  3173. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  3174. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  3175. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  3176. + (a === 1 ? ")" : ", " + a + ")");
  3177. }
  3178. }));
  3179. function hsla(h, s, l, a) {
  3180. if (a <= 0) h = s = l = NaN;
  3181. else if (l <= 0 || l >= 1) h = s = NaN;
  3182. else if (s <= 0) h = NaN;
  3183. return new Hsl(h, s, l, a);
  3184. }
  3185. function hslConvert(o) {
  3186. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  3187. if (!(o instanceof Color)) o = color(o);
  3188. if (!o) return new Hsl;
  3189. if (o instanceof Hsl) return o;
  3190. o = o.rgb();
  3191. var r = o.r / 255,
  3192. g = o.g / 255,
  3193. b = o.b / 255,
  3194. min = Math.min(r, g, b),
  3195. max = Math.max(r, g, b),
  3196. h = NaN,
  3197. s = max - min,
  3198. l = (max + min) / 2;
  3199. if (s) {
  3200. if (r === max) h = (g - b) / s + (g < b) * 6;
  3201. else if (g === max) h = (b - r) / s + 2;
  3202. else h = (r - g) / s + 4;
  3203. s /= l < 0.5 ? max + min : 2 - max - min;
  3204. h *= 60;
  3205. } else {
  3206. s = l > 0 && l < 1 ? 0 : h;
  3207. }
  3208. return new Hsl(h, s, l, o.opacity);
  3209. }
  3210. function hsl(h, s, l, opacity) {
  3211. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  3212. }
  3213. function Hsl(h, s, l, opacity) {
  3214. this.h = +h;
  3215. this.s = +s;
  3216. this.l = +l;
  3217. this.opacity = +opacity;
  3218. }
  3219. define(Hsl, hsl, extend(Color, {
  3220. brighter: function(k) {
  3221. k = k == null ? brighter : Math.pow(brighter, k);
  3222. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  3223. },
  3224. darker: function(k) {
  3225. k = k == null ? darker : Math.pow(darker, k);
  3226. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  3227. },
  3228. rgb: function() {
  3229. var h = this.h % 360 + (this.h < 0) * 360,
  3230. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  3231. l = this.l,
  3232. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  3233. m1 = 2 * l - m2;
  3234. return new Rgb(
  3235. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  3236. hsl2rgb(h, m1, m2),
  3237. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  3238. this.opacity
  3239. );
  3240. },
  3241. displayable: function() {
  3242. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  3243. && (0 <= this.l && this.l <= 1)
  3244. && (0 <= this.opacity && this.opacity <= 1);
  3245. }
  3246. }));
  3247. /* From FvD 13.37, CSS Color Module Level 3 */
  3248. function hsl2rgb(h, m1, m2) {
  3249. return (h < 60 ? m1 + (m2 - m1) * h / 60
  3250. : h < 180 ? m2
  3251. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  3252. : m1) * 255;
  3253. }
  3254. var deg2rad = Math.PI / 180;
  3255. var rad2deg = 180 / Math.PI;
  3256. var Kn = 18;
  3257. var Xn = 0.950470;
  3258. var Yn = 1;
  3259. var Zn = 1.088830;
  3260. var t0 = 4 / 29;
  3261. var t1 = 6 / 29;
  3262. var t2 = 3 * t1 * t1;
  3263. var t3 = t1 * t1 * t1;
  3264. function labConvert(o) {
  3265. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  3266. if (o instanceof Hcl) {
  3267. var h = o.h * deg2rad;
  3268. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  3269. }
  3270. if (!(o instanceof Rgb)) o = rgbConvert(o);
  3271. var b = rgb2xyz(o.r),
  3272. a = rgb2xyz(o.g),
  3273. l = rgb2xyz(o.b),
  3274. x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
  3275. y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
  3276. z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
  3277. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  3278. }
  3279. function lab(l, a, b, opacity) {
  3280. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  3281. }
  3282. function Lab(l, a, b, opacity) {
  3283. this.l = +l;
  3284. this.a = +a;
  3285. this.b = +b;
  3286. this.opacity = +opacity;
  3287. }
  3288. define(Lab, lab, extend(Color, {
  3289. brighter: function(k) {
  3290. return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  3291. },
  3292. darker: function(k) {
  3293. return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
  3294. },
  3295. rgb: function() {
  3296. var y = (this.l + 16) / 116,
  3297. x = isNaN(this.a) ? y : y + this.a / 500,
  3298. z = isNaN(this.b) ? y : y - this.b / 200;
  3299. y = Yn * lab2xyz(y);
  3300. x = Xn * lab2xyz(x);
  3301. z = Zn * lab2xyz(z);
  3302. return new Rgb(
  3303. xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
  3304. xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
  3305. xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
  3306. this.opacity
  3307. );
  3308. }
  3309. }));
  3310. function xyz2lab(t) {
  3311. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  3312. }
  3313. function lab2xyz(t) {
  3314. return t > t1 ? t * t * t : t2 * (t - t0);
  3315. }
  3316. function xyz2rgb(x) {
  3317. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  3318. }
  3319. function rgb2xyz(x) {
  3320. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  3321. }
  3322. function hclConvert(o) {
  3323. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  3324. if (!(o instanceof Lab)) o = labConvert(o);
  3325. var h = Math.atan2(o.b, o.a) * rad2deg;
  3326. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  3327. }
  3328. function hcl(h, c, l, opacity) {
  3329. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  3330. }
  3331. function Hcl(h, c, l, opacity) {
  3332. this.h = +h;
  3333. this.c = +c;
  3334. this.l = +l;
  3335. this.opacity = +opacity;
  3336. }
  3337. define(Hcl, hcl, extend(Color, {
  3338. brighter: function(k) {
  3339. return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
  3340. },
  3341. darker: function(k) {
  3342. return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
  3343. },
  3344. rgb: function() {
  3345. return labConvert(this).rgb();
  3346. }
  3347. }));
  3348. var A = -0.14861;
  3349. var B = +1.78277;
  3350. var C = -0.29227;
  3351. var D = -0.90649;
  3352. var E = +1.97294;
  3353. var ED = E * D;
  3354. var EB = E * B;
  3355. var BC_DA = B * C - D * A;
  3356. function cubehelixConvert(o) {
  3357. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  3358. if (!(o instanceof Rgb)) o = rgbConvert(o);
  3359. var r = o.r / 255,
  3360. g = o.g / 255,
  3361. b = o.b / 255,
  3362. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  3363. bl = b - l,
  3364. k = (E * (g - l) - C * bl) / D,
  3365. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  3366. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  3367. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  3368. }
  3369. function cubehelix(h, s, l, opacity) {
  3370. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  3371. }
  3372. function Cubehelix(h, s, l, opacity) {
  3373. this.h = +h;
  3374. this.s = +s;
  3375. this.l = +l;
  3376. this.opacity = +opacity;
  3377. }
  3378. define(Cubehelix, cubehelix, extend(Color, {
  3379. brighter: function(k) {
  3380. k = k == null ? brighter : Math.pow(brighter, k);
  3381. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  3382. },
  3383. darker: function(k) {
  3384. k = k == null ? darker : Math.pow(darker, k);
  3385. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  3386. },
  3387. rgb: function() {
  3388. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  3389. l = +this.l,
  3390. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  3391. cosh = Math.cos(h),
  3392. sinh = Math.sin(h);
  3393. return new Rgb(
  3394. 255 * (l + a * (A * cosh + B * sinh)),
  3395. 255 * (l + a * (C * cosh + D * sinh)),
  3396. 255 * (l + a * (E * cosh)),
  3397. this.opacity
  3398. );
  3399. }
  3400. }));
  3401. function basis$1(t1, v0, v1, v2, v3) {
  3402. var t2 = t1 * t1, t3 = t2 * t1;
  3403. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  3404. + (4 - 6 * t2 + 3 * t3) * v1
  3405. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  3406. + t3 * v3) / 6;
  3407. }
  3408. var basis$2 = function(values) {
  3409. var n = values.length - 1;
  3410. return function(t) {
  3411. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  3412. v1 = values[i],
  3413. v2 = values[i + 1],
  3414. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  3415. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  3416. return basis$1((t - i / n) * n, v0, v1, v2, v3);
  3417. };
  3418. };
  3419. var basisClosed$1 = function(values) {
  3420. var n = values.length;
  3421. return function(t) {
  3422. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  3423. v0 = values[(i + n - 1) % n],
  3424. v1 = values[i % n],
  3425. v2 = values[(i + 1) % n],
  3426. v3 = values[(i + 2) % n];
  3427. return basis$1((t - i / n) * n, v0, v1, v2, v3);
  3428. };
  3429. };
  3430. var constant$3 = function(x) {
  3431. return function() {
  3432. return x;
  3433. };
  3434. };
  3435. function linear$1(a, d) {
  3436. return function(t) {
  3437. return a + t * d;
  3438. };
  3439. }
  3440. function exponential$1(a, b, y) {
  3441. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  3442. return Math.pow(a + t * b, y);
  3443. };
  3444. }
  3445. function hue(a, b) {
  3446. var d = b - a;
  3447. return d ? linear$1(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  3448. }
  3449. function gamma(y) {
  3450. return (y = +y) === 1 ? nogamma : function(a, b) {
  3451. return b - a ? exponential$1(a, b, y) : constant$3(isNaN(a) ? b : a);
  3452. };
  3453. }
  3454. function nogamma(a, b) {
  3455. var d = b - a;
  3456. return d ? linear$1(a, d) : constant$3(isNaN(a) ? b : a);
  3457. }
  3458. var interpolateRgb = (function rgbGamma(y) {
  3459. var color$$1 = gamma(y);
  3460. function rgb$$1(start, end) {
  3461. var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
  3462. g = color$$1(start.g, end.g),
  3463. b = color$$1(start.b, end.b),
  3464. opacity = color$$1(start.opacity, end.opacity);
  3465. return function(t) {
  3466. start.r = r(t);
  3467. start.g = g(t);
  3468. start.b = b(t);
  3469. start.opacity = opacity(t);
  3470. return start + "";
  3471. };
  3472. }
  3473. rgb$$1.gamma = rgbGamma;
  3474. return rgb$$1;
  3475. })(1);
  3476. function rgbSpline(spline) {
  3477. return function(colors) {
  3478. var n = colors.length,
  3479. r = new Array(n),
  3480. g = new Array(n),
  3481. b = new Array(n),
  3482. i, color$$1;
  3483. for (i = 0; i < n; ++i) {
  3484. color$$1 = rgb(colors[i]);
  3485. r[i] = color$$1.r || 0;
  3486. g[i] = color$$1.g || 0;
  3487. b[i] = color$$1.b || 0;
  3488. }
  3489. r = spline(r);
  3490. g = spline(g);
  3491. b = spline(b);
  3492. color$$1.opacity = 1;
  3493. return function(t) {
  3494. color$$1.r = r(t);
  3495. color$$1.g = g(t);
  3496. color$$1.b = b(t);
  3497. return color$$1 + "";
  3498. };
  3499. };
  3500. }
  3501. var rgbBasis = rgbSpline(basis$2);
  3502. var rgbBasisClosed = rgbSpline(basisClosed$1);
  3503. var array$1 = function(a, b) {
  3504. var nb = b ? b.length : 0,
  3505. na = a ? Math.min(nb, a.length) : 0,
  3506. x = new Array(nb),
  3507. c = new Array(nb),
  3508. i;
  3509. for (i = 0; i < na; ++i) x[i] = interpolate(a[i], b[i]);
  3510. for (; i < nb; ++i) c[i] = b[i];
  3511. return function(t) {
  3512. for (i = 0; i < na; ++i) c[i] = x[i](t);
  3513. return c;
  3514. };
  3515. };
  3516. var date = function(a, b) {
  3517. var d = new Date;
  3518. return a = +a, b -= a, function(t) {
  3519. return d.setTime(a + b * t), d;
  3520. };
  3521. };
  3522. var interpolateNumber = function(a, b) {
  3523. return a = +a, b -= a, function(t) {
  3524. return a + b * t;
  3525. };
  3526. };
  3527. var object = function(a, b) {
  3528. var i = {},
  3529. c = {},
  3530. k;
  3531. if (a === null || typeof a !== "object") a = {};
  3532. if (b === null || typeof b !== "object") b = {};
  3533. for (k in b) {
  3534. if (k in a) {
  3535. i[k] = interpolate(a[k], b[k]);
  3536. } else {
  3537. c[k] = b[k];
  3538. }
  3539. }
  3540. return function(t) {
  3541. for (k in i) c[k] = i[k](t);
  3542. return c;
  3543. };
  3544. };
  3545. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
  3546. var reB = new RegExp(reA.source, "g");
  3547. function zero(b) {
  3548. return function() {
  3549. return b;
  3550. };
  3551. }
  3552. function one(b) {
  3553. return function(t) {
  3554. return b(t) + "";
  3555. };
  3556. }
  3557. var interpolateString = function(a, b) {
  3558. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  3559. am, // current match in a
  3560. bm, // current match in b
  3561. bs, // string preceding current number in b, if any
  3562. i = -1, // index in s
  3563. s = [], // string constants and placeholders
  3564. q = []; // number interpolators
  3565. // Coerce inputs to strings.
  3566. a = a + "", b = b + "";
  3567. // Interpolate pairs of numbers in a & b.
  3568. while ((am = reA.exec(a))
  3569. && (bm = reB.exec(b))) {
  3570. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  3571. bs = b.slice(bi, bs);
  3572. if (s[i]) s[i] += bs; // coalesce with previous string
  3573. else s[++i] = bs;
  3574. }
  3575. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  3576. if (s[i]) s[i] += bm; // coalesce with previous string
  3577. else s[++i] = bm;
  3578. } else { // interpolate non-matching numbers
  3579. s[++i] = null;
  3580. q.push({i: i, x: interpolateNumber(am, bm)});
  3581. }
  3582. bi = reB.lastIndex;
  3583. }
  3584. // Add remains of b.
  3585. if (bi < b.length) {
  3586. bs = b.slice(bi);
  3587. if (s[i]) s[i] += bs; // coalesce with previous string
  3588. else s[++i] = bs;
  3589. }
  3590. // Special optimization for only a single match.
  3591. // Otherwise, interpolate each of the numbers and rejoin the string.
  3592. return s.length < 2 ? (q[0]
  3593. ? one(q[0].x)
  3594. : zero(b))
  3595. : (b = q.length, function(t) {
  3596. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  3597. return s.join("");
  3598. });
  3599. };
  3600. var interpolate = function(a, b) {
  3601. var t = typeof b, c;
  3602. return b == null || t === "boolean" ? constant$3(b)
  3603. : (t === "number" ? interpolateNumber
  3604. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  3605. : b instanceof color ? interpolateRgb
  3606. : b instanceof Date ? date
  3607. : Array.isArray(b) ? array$1
  3608. : isNaN(b) ? object
  3609. : interpolateNumber)(a, b);
  3610. };
  3611. var interpolateRound = function(a, b) {
  3612. return a = +a, b -= a, function(t) {
  3613. return Math.round(a + b * t);
  3614. };
  3615. };
  3616. var degrees = 180 / Math.PI;
  3617. var identity$2 = {
  3618. translateX: 0,
  3619. translateY: 0,
  3620. rotate: 0,
  3621. skewX: 0,
  3622. scaleX: 1,
  3623. scaleY: 1
  3624. };
  3625. var decompose = function(a, b, c, d, e, f) {
  3626. var scaleX, scaleY, skewX;
  3627. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  3628. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  3629. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  3630. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  3631. return {
  3632. translateX: e,
  3633. translateY: f,
  3634. rotate: Math.atan2(b, a) * degrees,
  3635. skewX: Math.atan(skewX) * degrees,
  3636. scaleX: scaleX,
  3637. scaleY: scaleY
  3638. };
  3639. };
  3640. var cssNode;
  3641. var cssRoot;
  3642. var cssView;
  3643. var svgNode;
  3644. function parseCss(value) {
  3645. if (value === "none") return identity$2;
  3646. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  3647. cssNode.style.transform = value;
  3648. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  3649. cssRoot.removeChild(cssNode);
  3650. value = value.slice(7, -1).split(",");
  3651. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  3652. }
  3653. function parseSvg(value) {
  3654. if (value == null) return identity$2;
  3655. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  3656. svgNode.setAttribute("transform", value);
  3657. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  3658. value = value.matrix;
  3659. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  3660. }
  3661. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  3662. function pop(s) {
  3663. return s.length ? s.pop() + " " : "";
  3664. }
  3665. function translate(xa, ya, xb, yb, s, q) {
  3666. if (xa !== xb || ya !== yb) {
  3667. var i = s.push("translate(", null, pxComma, null, pxParen);
  3668. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  3669. } else if (xb || yb) {
  3670. s.push("translate(" + xb + pxComma + yb + pxParen);
  3671. }
  3672. }
  3673. function rotate(a, b, s, q) {
  3674. if (a !== b) {
  3675. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  3676. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  3677. } else if (b) {
  3678. s.push(pop(s) + "rotate(" + b + degParen);
  3679. }
  3680. }
  3681. function skewX(a, b, s, q) {
  3682. if (a !== b) {
  3683. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  3684. } else if (b) {
  3685. s.push(pop(s) + "skewX(" + b + degParen);
  3686. }
  3687. }
  3688. function scale(xa, ya, xb, yb, s, q) {
  3689. if (xa !== xb || ya !== yb) {
  3690. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  3691. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  3692. } else if (xb !== 1 || yb !== 1) {
  3693. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  3694. }
  3695. }
  3696. return function(a, b) {
  3697. var s = [], // string constants and placeholders
  3698. q = []; // number interpolators
  3699. a = parse(a), b = parse(b);
  3700. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  3701. rotate(a.rotate, b.rotate, s, q);
  3702. skewX(a.skewX, b.skewX, s, q);
  3703. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  3704. a = b = null; // gc
  3705. return function(t) {
  3706. var i = -1, n = q.length, o;
  3707. while (++i < n) s[(o = q[i]).i] = o.x(t);
  3708. return s.join("");
  3709. };
  3710. };
  3711. }
  3712. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  3713. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  3714. var rho = Math.SQRT2;
  3715. var rho2 = 2;
  3716. var rho4 = 4;
  3717. var epsilon2 = 1e-12;
  3718. function cosh(x) {
  3719. return ((x = Math.exp(x)) + 1 / x) / 2;
  3720. }
  3721. function sinh(x) {
  3722. return ((x = Math.exp(x)) - 1 / x) / 2;
  3723. }
  3724. function tanh(x) {
  3725. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  3726. }
  3727. // p0 = [ux0, uy0, w0]
  3728. // p1 = [ux1, uy1, w1]
  3729. var interpolateZoom = function(p0, p1) {
  3730. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  3731. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  3732. dx = ux1 - ux0,
  3733. dy = uy1 - uy0,
  3734. d2 = dx * dx + dy * dy,
  3735. i,
  3736. S;
  3737. // Special case for u0 ≅ u1.
  3738. if (d2 < epsilon2) {
  3739. S = Math.log(w1 / w0) / rho;
  3740. i = function(t) {
  3741. return [
  3742. ux0 + t * dx,
  3743. uy0 + t * dy,
  3744. w0 * Math.exp(rho * t * S)
  3745. ];
  3746. };
  3747. }
  3748. // General case.
  3749. else {
  3750. var d1 = Math.sqrt(d2),
  3751. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  3752. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  3753. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  3754. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  3755. S = (r1 - r0) / rho;
  3756. i = function(t) {
  3757. var s = t * S,
  3758. coshr0 = cosh(r0),
  3759. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  3760. return [
  3761. ux0 + u * dx,
  3762. uy0 + u * dy,
  3763. w0 * coshr0 / cosh(rho * s + r0)
  3764. ];
  3765. };
  3766. }
  3767. i.duration = S * 1000;
  3768. return i;
  3769. };
  3770. function hsl$1(hue$$1) {
  3771. return function(start, end) {
  3772. var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
  3773. s = nogamma(start.s, end.s),
  3774. l = nogamma(start.l, end.l),
  3775. opacity = nogamma(start.opacity, end.opacity);
  3776. return function(t) {
  3777. start.h = h(t);
  3778. start.s = s(t);
  3779. start.l = l(t);
  3780. start.opacity = opacity(t);
  3781. return start + "";
  3782. };
  3783. }
  3784. }
  3785. var hsl$2 = hsl$1(hue);
  3786. var hslLong = hsl$1(nogamma);
  3787. function lab$1(start, end) {
  3788. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  3789. a = nogamma(start.a, end.a),
  3790. b = nogamma(start.b, end.b),
  3791. opacity = nogamma(start.opacity, end.opacity);
  3792. return function(t) {
  3793. start.l = l(t);
  3794. start.a = a(t);
  3795. start.b = b(t);
  3796. start.opacity = opacity(t);
  3797. return start + "";
  3798. };
  3799. }
  3800. function hcl$1(hue$$1) {
  3801. return function(start, end) {
  3802. var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
  3803. c = nogamma(start.c, end.c),
  3804. l = nogamma(start.l, end.l),
  3805. opacity = nogamma(start.opacity, end.opacity);
  3806. return function(t) {
  3807. start.h = h(t);
  3808. start.c = c(t);
  3809. start.l = l(t);
  3810. start.opacity = opacity(t);
  3811. return start + "";
  3812. };
  3813. }
  3814. }
  3815. var hcl$2 = hcl$1(hue);
  3816. var hclLong = hcl$1(nogamma);
  3817. function cubehelix$1(hue$$1) {
  3818. return (function cubehelixGamma(y) {
  3819. y = +y;
  3820. function cubehelix$$1(start, end) {
  3821. var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  3822. s = nogamma(start.s, end.s),
  3823. l = nogamma(start.l, end.l),
  3824. opacity = nogamma(start.opacity, end.opacity);
  3825. return function(t) {
  3826. start.h = h(t);
  3827. start.s = s(t);
  3828. start.l = l(Math.pow(t, y));
  3829. start.opacity = opacity(t);
  3830. return start + "";
  3831. };
  3832. }
  3833. cubehelix$$1.gamma = cubehelixGamma;
  3834. return cubehelix$$1;
  3835. })(1);
  3836. }
  3837. var cubehelix$2 = cubehelix$1(hue);
  3838. var cubehelixLong = cubehelix$1(nogamma);
  3839. var quantize = function(interpolator, n) {
  3840. var samples = new Array(n);
  3841. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  3842. return samples;
  3843. };
  3844. var noop$1 = {value: function() {}};
  3845. function dispatch() {
  3846. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  3847. if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
  3848. _[t] = [];
  3849. }
  3850. return new Dispatch(_);
  3851. }
  3852. function Dispatch(_) {
  3853. this._ = _;
  3854. }
  3855. function parseTypenames(typenames, types) {
  3856. return typenames.trim().split(/^|\s+/).map(function(t) {
  3857. var name = "", i = t.indexOf(".");
  3858. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  3859. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  3860. return {type: t, name: name};
  3861. });
  3862. }
  3863. Dispatch.prototype = dispatch.prototype = {
  3864. constructor: Dispatch,
  3865. on: function(typename, callback) {
  3866. var _ = this._,
  3867. T = parseTypenames(typename + "", _),
  3868. t,
  3869. i = -1,
  3870. n = T.length;
  3871. // If no callback was specified, return the callback of the given type and name.
  3872. if (arguments.length < 2) {
  3873. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  3874. return;
  3875. }
  3876. // If a type was specified, set the callback for the given type and name.
  3877. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  3878. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  3879. while (++i < n) {
  3880. if (t = (typename = T[i]).type) _[t] = set$2(_[t], typename.name, callback);
  3881. else if (callback == null) for (t in _) _[t] = set$2(_[t], typename.name, null);
  3882. }
  3883. return this;
  3884. },
  3885. copy: function() {
  3886. var copy = {}, _ = this._;
  3887. for (var t in _) copy[t] = _[t].slice();
  3888. return new Dispatch(copy);
  3889. },
  3890. call: function(type, that) {
  3891. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  3892. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  3893. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  3894. },
  3895. apply: function(type, that, args) {
  3896. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  3897. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  3898. }
  3899. };
  3900. function get(type, name) {
  3901. for (var i = 0, n = type.length, c; i < n; ++i) {
  3902. if ((c = type[i]).name === name) {
  3903. return c.value;
  3904. }
  3905. }
  3906. }
  3907. function set$2(type, name, callback) {
  3908. for (var i = 0, n = type.length; i < n; ++i) {
  3909. if (type[i].name === name) {
  3910. type[i] = noop$1, type = type.slice(0, i).concat(type.slice(i + 1));
  3911. break;
  3912. }
  3913. }
  3914. if (callback != null) type.push({name: name, value: callback});
  3915. return type;
  3916. }
  3917. function objectConverter(columns) {
  3918. return new Function("d", "return {" + columns.map(function(name, i) {
  3919. return JSON.stringify(name) + ": d[" + i + "]";
  3920. }).join(",") + "}");
  3921. }
  3922. function customConverter(columns, f) {
  3923. var object = objectConverter(columns);
  3924. return function(row, i) {
  3925. return f(object(row), i, columns);
  3926. };
  3927. }
  3928. // Compute unique columns in order of discovery.
  3929. function inferColumns(rows) {
  3930. var columnSet = Object.create(null),
  3931. columns = [];
  3932. rows.forEach(function(row) {
  3933. for (var column in row) {
  3934. if (!(column in columnSet)) {
  3935. columns.push(columnSet[column] = column);
  3936. }
  3937. }
  3938. });
  3939. return columns;
  3940. }
  3941. var dsv = function(delimiter) {
  3942. var reFormat = new RegExp("[\"" + delimiter + "\n]"),
  3943. delimiterCode = delimiter.charCodeAt(0);
  3944. function parse(text, f) {
  3945. var convert, columns, rows = parseRows(text, function(row, i) {
  3946. if (convert) return convert(row, i - 1);
  3947. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  3948. });
  3949. rows.columns = columns;
  3950. return rows;
  3951. }
  3952. function parseRows(text, f) {
  3953. var EOL = {}, // sentinel value for end-of-line
  3954. EOF = {}, // sentinel value for end-of-file
  3955. rows = [], // output rows
  3956. N = text.length,
  3957. I = 0, // current character index
  3958. n = 0, // the current line number
  3959. t, // the current token
  3960. eol; // is the current token followed by EOL?
  3961. function token() {
  3962. if (I >= N) return EOF; // special case: end of file
  3963. if (eol) return eol = false, EOL; // special case: end of line
  3964. // special case: quotes
  3965. var j = I, c;
  3966. if (text.charCodeAt(j) === 34) {
  3967. var i = j;
  3968. while (i++ < N) {
  3969. if (text.charCodeAt(i) === 34) {
  3970. if (text.charCodeAt(i + 1) !== 34) break;
  3971. ++i;
  3972. }
  3973. }
  3974. I = i + 2;
  3975. c = text.charCodeAt(i + 1);
  3976. if (c === 13) {
  3977. eol = true;
  3978. if (text.charCodeAt(i + 2) === 10) ++I;
  3979. } else if (c === 10) {
  3980. eol = true;
  3981. }
  3982. return text.slice(j + 1, i).replace(/""/g, "\"");
  3983. }
  3984. // common case: find next delimiter or newline
  3985. while (I < N) {
  3986. var k = 1;
  3987. c = text.charCodeAt(I++);
  3988. if (c === 10) eol = true; // \n
  3989. else if (c === 13) { eol = true; if (text.charCodeAt(I) === 10) ++I, ++k; } // \r|\r\n
  3990. else if (c !== delimiterCode) continue;
  3991. return text.slice(j, I - k);
  3992. }
  3993. // special case: last token before EOF
  3994. return text.slice(j);
  3995. }
  3996. while ((t = token()) !== EOF) {
  3997. var a = [];
  3998. while (t !== EOL && t !== EOF) {
  3999. a.push(t);
  4000. t = token();
  4001. }
  4002. if (f && (a = f(a, n++)) == null) continue;
  4003. rows.push(a);
  4004. }
  4005. return rows;
  4006. }
  4007. function format(rows, columns) {
  4008. if (columns == null) columns = inferColumns(rows);
  4009. return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
  4010. return columns.map(function(column) {
  4011. return formatValue(row[column]);
  4012. }).join(delimiter);
  4013. })).join("\n");
  4014. }
  4015. function formatRows(rows) {
  4016. return rows.map(formatRow).join("\n");
  4017. }
  4018. function formatRow(row) {
  4019. return row.map(formatValue).join(delimiter);
  4020. }
  4021. function formatValue(text) {
  4022. return text == null ? ""
  4023. : reFormat.test(text += "") ? "\"" + text.replace(/\"/g, "\"\"") + "\""
  4024. : text;
  4025. }
  4026. return {
  4027. parse: parse,
  4028. parseRows: parseRows,
  4029. format: format,
  4030. formatRows: formatRows
  4031. };
  4032. };
  4033. var csv = dsv(",");
  4034. var csvParse = csv.parse;
  4035. var csvParseRows = csv.parseRows;
  4036. var csvFormat = csv.format;
  4037. var csvFormatRows = csv.formatRows;
  4038. var tsv = dsv("\t");
  4039. var tsvParse = tsv.parse;
  4040. var tsvParseRows = tsv.parseRows;
  4041. var tsvFormat = tsv.format;
  4042. var tsvFormatRows = tsv.formatRows;
  4043. var request = function(url, callback) {
  4044. var request,
  4045. event = dispatch("beforesend", "progress", "load", "error"),
  4046. mimeType,
  4047. headers = map$1(),
  4048. xhr = new XMLHttpRequest,
  4049. user = null,
  4050. password = null,
  4051. response,
  4052. responseType,
  4053. timeout = 0;
  4054. // If IE does not support CORS, use XDomainRequest.
  4055. if (typeof XDomainRequest !== "undefined"
  4056. && !("withCredentials" in xhr)
  4057. && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
  4058. "onload" in xhr
  4059. ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
  4060. : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
  4061. function respond(o) {
  4062. var status = xhr.status, result;
  4063. if (!status && hasResponse(xhr)
  4064. || status >= 200 && status < 300
  4065. || status === 304) {
  4066. if (response) {
  4067. try {
  4068. result = response.call(request, xhr);
  4069. } catch (e) {
  4070. event.call("error", request, e);
  4071. return;
  4072. }
  4073. } else {
  4074. result = xhr;
  4075. }
  4076. event.call("load", request, result);
  4077. } else {
  4078. event.call("error", request, o);
  4079. }
  4080. }
  4081. xhr.onprogress = function(e) {
  4082. event.call("progress", request, e);
  4083. };
  4084. request = {
  4085. header: function(name, value) {
  4086. name = (name + "").toLowerCase();
  4087. if (arguments.length < 2) return headers.get(name);
  4088. if (value == null) headers.remove(name);
  4089. else headers.set(name, value + "");
  4090. return request;
  4091. },
  4092. // If mimeType is non-null and no Accept header is set, a default is used.
  4093. mimeType: function(value) {
  4094. if (!arguments.length) return mimeType;
  4095. mimeType = value == null ? null : value + "";
  4096. return request;
  4097. },
  4098. // Specifies what type the response value should take;
  4099. // for instance, arraybuffer, blob, document, or text.
  4100. responseType: function(value) {
  4101. if (!arguments.length) return responseType;
  4102. responseType = value;
  4103. return request;
  4104. },
  4105. timeout: function(value) {
  4106. if (!arguments.length) return timeout;
  4107. timeout = +value;
  4108. return request;
  4109. },
  4110. user: function(value) {
  4111. return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
  4112. },
  4113. password: function(value) {
  4114. return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
  4115. },
  4116. // Specify how to convert the response content to a specific type;
  4117. // changes the callback value on "load" events.
  4118. response: function(value) {
  4119. response = value;
  4120. return request;
  4121. },
  4122. // Alias for send("GET", …).
  4123. get: function(data, callback) {
  4124. return request.send("GET", data, callback);
  4125. },
  4126. // Alias for send("POST", …).
  4127. post: function(data, callback) {
  4128. return request.send("POST", data, callback);
  4129. },
  4130. // If callback is non-null, it will be used for error and load events.
  4131. send: function(method, data, callback) {
  4132. xhr.open(method, url, true, user, password);
  4133. if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
  4134. if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
  4135. if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
  4136. if (responseType != null) xhr.responseType = responseType;
  4137. if (timeout > 0) xhr.timeout = timeout;
  4138. if (callback == null && typeof data === "function") callback = data, data = null;
  4139. if (callback != null && callback.length === 1) callback = fixCallback(callback);
  4140. if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
  4141. event.call("beforesend", request, xhr);
  4142. xhr.send(data == null ? null : data);
  4143. return request;
  4144. },
  4145. abort: function() {
  4146. xhr.abort();
  4147. return request;
  4148. },
  4149. on: function() {
  4150. var value = event.on.apply(event, arguments);
  4151. return value === event ? request : value;
  4152. }
  4153. };
  4154. if (callback != null) {
  4155. if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
  4156. return request.get(callback);
  4157. }
  4158. return request;
  4159. };
  4160. function fixCallback(callback) {
  4161. return function(error, xhr) {
  4162. callback(error == null ? xhr : null);
  4163. };
  4164. }
  4165. function hasResponse(xhr) {
  4166. var type = xhr.responseType;
  4167. return type && type !== "text"
  4168. ? xhr.response // null on error
  4169. : xhr.responseText; // "" on error
  4170. }
  4171. var type = function(defaultMimeType, response) {
  4172. return function(url, callback) {
  4173. var r = request(url).mimeType(defaultMimeType).response(response);
  4174. if (callback != null) {
  4175. if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
  4176. return r.get(callback);
  4177. }
  4178. return r;
  4179. };
  4180. };
  4181. var html = type("text/html", function(xhr) {
  4182. return document.createRange().createContextualFragment(xhr.responseText);
  4183. });
  4184. var json = type("application/json", function(xhr) {
  4185. return JSON.parse(xhr.responseText);
  4186. });
  4187. var text = type("text/plain", function(xhr) {
  4188. return xhr.responseText;
  4189. });
  4190. var xml = type("application/xml", function(xhr) {
  4191. var xml = xhr.responseXML;
  4192. if (!xml) throw new Error("parse error");
  4193. return xml;
  4194. });
  4195. var dsv$1 = function(defaultMimeType, parse) {
  4196. return function(url, row, callback) {
  4197. if (arguments.length < 3) callback = row, row = null;
  4198. var r = request(url).mimeType(defaultMimeType);
  4199. r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
  4200. r.row(row);
  4201. return callback ? r.get(callback) : r;
  4202. };
  4203. };
  4204. function responseOf(parse, row) {
  4205. return function(request$$1) {
  4206. return parse(request$$1.responseText, row);
  4207. };
  4208. }
  4209. var csv$1 = dsv$1("text/csv", csvParse);
  4210. var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
  4211. var frame = 0;
  4212. var timeout = 0;
  4213. var interval = 0;
  4214. var pokeDelay = 1000;
  4215. var taskHead;
  4216. var taskTail;
  4217. var clockLast = 0;
  4218. var clockNow = 0;
  4219. var clockSkew = 0;
  4220. var clock = typeof performance === "object" && performance.now ? performance : Date;
  4221. var setFrame = typeof requestAnimationFrame === "function" ? requestAnimationFrame : function(f) { setTimeout(f, 17); };
  4222. function now() {
  4223. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  4224. }
  4225. function clearNow() {
  4226. clockNow = 0;
  4227. }
  4228. function Timer() {
  4229. this._call =
  4230. this._time =
  4231. this._next = null;
  4232. }
  4233. Timer.prototype = timer.prototype = {
  4234. constructor: Timer,
  4235. restart: function(callback, delay, time) {
  4236. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  4237. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  4238. if (!this._next && taskTail !== this) {
  4239. if (taskTail) taskTail._next = this;
  4240. else taskHead = this;
  4241. taskTail = this;
  4242. }
  4243. this._call = callback;
  4244. this._time = time;
  4245. sleep();
  4246. },
  4247. stop: function() {
  4248. if (this._call) {
  4249. this._call = null;
  4250. this._time = Infinity;
  4251. sleep();
  4252. }
  4253. }
  4254. };
  4255. function timer(callback, delay, time) {
  4256. var t = new Timer;
  4257. t.restart(callback, delay, time);
  4258. return t;
  4259. }
  4260. function timerFlush() {
  4261. now(); // Get the current time, if not already set.
  4262. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  4263. var t = taskHead, e;
  4264. while (t) {
  4265. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  4266. t = t._next;
  4267. }
  4268. --frame;
  4269. }
  4270. function wake() {
  4271. clockNow = (clockLast = clock.now()) + clockSkew;
  4272. frame = timeout = 0;
  4273. try {
  4274. timerFlush();
  4275. } finally {
  4276. frame = 0;
  4277. nap();
  4278. clockNow = 0;
  4279. }
  4280. }
  4281. function poke$1() {
  4282. var now = clock.now(), delay = now - clockLast;
  4283. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  4284. }
  4285. function nap() {
  4286. var t0, t1 = taskHead, t2, time = Infinity;
  4287. while (t1) {
  4288. if (t1._call) {
  4289. if (time > t1._time) time = t1._time;
  4290. t0 = t1, t1 = t1._next;
  4291. } else {
  4292. t2 = t1._next, t1._next = null;
  4293. t1 = t0 ? t0._next = t2 : taskHead = t2;
  4294. }
  4295. }
  4296. taskTail = t0;
  4297. sleep(time);
  4298. }
  4299. function sleep(time) {
  4300. if (frame) return; // Soonest alarm already set, or will be.
  4301. if (timeout) timeout = clearTimeout(timeout);
  4302. var delay = time - clockNow;
  4303. if (delay > 24) {
  4304. if (time < Infinity) timeout = setTimeout(wake, delay);
  4305. if (interval) interval = clearInterval(interval);
  4306. } else {
  4307. if (!interval) interval = setInterval(poke$1, pokeDelay);
  4308. frame = 1, setFrame(wake);
  4309. }
  4310. }
  4311. var timeout$1 = function(callback, delay, time) {
  4312. var t = new Timer;
  4313. delay = delay == null ? 0 : +delay;
  4314. t.restart(function(elapsed) {
  4315. t.stop();
  4316. callback(elapsed + delay);
  4317. }, delay, time);
  4318. return t;
  4319. };
  4320. var interval$1 = function(callback, delay, time) {
  4321. var t = new Timer, total = delay;
  4322. if (delay == null) return t.restart(callback, delay, time), t;
  4323. delay = +delay, time = time == null ? now() : +time;
  4324. t.restart(function tick(elapsed) {
  4325. elapsed += total;
  4326. t.restart(tick, total += delay, time);
  4327. callback(elapsed);
  4328. }, delay, time);
  4329. return t;
  4330. };
  4331. var t0$1 = new Date;
  4332. var t1$1 = new Date;
  4333. function newInterval(floori, offseti, count, field) {
  4334. function interval(date) {
  4335. return floori(date = new Date(+date)), date;
  4336. }
  4337. interval.floor = interval;
  4338. interval.ceil = function(date) {
  4339. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  4340. };
  4341. interval.round = function(date) {
  4342. var d0 = interval(date),
  4343. d1 = interval.ceil(date);
  4344. return date - d0 < d1 - date ? d0 : d1;
  4345. };
  4346. interval.offset = function(date, step) {
  4347. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  4348. };
  4349. interval.range = function(start, stop, step) {
  4350. var range = [];
  4351. start = interval.ceil(start);
  4352. step = step == null ? 1 : Math.floor(step);
  4353. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  4354. do range.push(new Date(+start)); while (offseti(start, step), floori(start), start < stop)
  4355. return range;
  4356. };
  4357. interval.filter = function(test) {
  4358. return newInterval(function(date) {
  4359. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  4360. }, function(date, step) {
  4361. if (date >= date) while (--step >= 0) while (offseti(date, 1), !test(date)) {} // eslint-disable-line no-empty
  4362. });
  4363. };
  4364. if (count) {
  4365. interval.count = function(start, end) {
  4366. t0$1.setTime(+start), t1$1.setTime(+end);
  4367. floori(t0$1), floori(t1$1);
  4368. return Math.floor(count(t0$1, t1$1));
  4369. };
  4370. interval.every = function(step) {
  4371. step = Math.floor(step);
  4372. return !isFinite(step) || !(step > 0) ? null
  4373. : !(step > 1) ? interval
  4374. : interval.filter(field
  4375. ? function(d) { return field(d) % step === 0; }
  4376. : function(d) { return interval.count(0, d) % step === 0; });
  4377. };
  4378. }
  4379. return interval;
  4380. }
  4381. var millisecond = newInterval(function() {
  4382. // noop
  4383. }, function(date, step) {
  4384. date.setTime(+date + step);
  4385. }, function(start, end) {
  4386. return end - start;
  4387. });
  4388. // An optimized implementation for this simple case.
  4389. millisecond.every = function(k) {
  4390. k = Math.floor(k);
  4391. if (!isFinite(k) || !(k > 0)) return null;
  4392. if (!(k > 1)) return millisecond;
  4393. return newInterval(function(date) {
  4394. date.setTime(Math.floor(date / k) * k);
  4395. }, function(date, step) {
  4396. date.setTime(+date + step * k);
  4397. }, function(start, end) {
  4398. return (end - start) / k;
  4399. });
  4400. };
  4401. var milliseconds = millisecond.range;
  4402. var durationSecond = 1e3;
  4403. var durationMinute = 6e4;
  4404. var durationHour = 36e5;
  4405. var durationDay = 864e5;
  4406. var durationWeek = 6048e5;
  4407. var second = newInterval(function(date) {
  4408. date.setTime(Math.floor(date / durationSecond) * durationSecond);
  4409. }, function(date, step) {
  4410. date.setTime(+date + step * durationSecond);
  4411. }, function(start, end) {
  4412. return (end - start) / durationSecond;
  4413. }, function(date) {
  4414. return date.getUTCSeconds();
  4415. });
  4416. var seconds = second.range;
  4417. var minute = newInterval(function(date) {
  4418. date.setTime(Math.floor(date / durationMinute) * durationMinute);
  4419. }, function(date, step) {
  4420. date.setTime(+date + step * durationMinute);
  4421. }, function(start, end) {
  4422. return (end - start) / durationMinute;
  4423. }, function(date) {
  4424. return date.getMinutes();
  4425. });
  4426. var minutes = minute.range;
  4427. var hour = newInterval(function(date) {
  4428. var offset = date.getTimezoneOffset() * durationMinute % durationHour;
  4429. if (offset < 0) offset += durationHour;
  4430. date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
  4431. }, function(date, step) {
  4432. date.setTime(+date + step * durationHour);
  4433. }, function(start, end) {
  4434. return (end - start) / durationHour;
  4435. }, function(date) {
  4436. return date.getHours();
  4437. });
  4438. var hours = hour.range;
  4439. var day = newInterval(function(date) {
  4440. date.setHours(0, 0, 0, 0);
  4441. }, function(date, step) {
  4442. date.setDate(date.getDate() + step);
  4443. }, function(start, end) {
  4444. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  4445. }, function(date) {
  4446. return date.getDate() - 1;
  4447. });
  4448. var days = day.range;
  4449. function weekday(i) {
  4450. return newInterval(function(date) {
  4451. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  4452. date.setHours(0, 0, 0, 0);
  4453. }, function(date, step) {
  4454. date.setDate(date.getDate() + step * 7);
  4455. }, function(start, end) {
  4456. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  4457. });
  4458. }
  4459. var sunday = weekday(0);
  4460. var monday = weekday(1);
  4461. var tuesday = weekday(2);
  4462. var wednesday = weekday(3);
  4463. var thursday = weekday(4);
  4464. var friday = weekday(5);
  4465. var saturday = weekday(6);
  4466. var sundays = sunday.range;
  4467. var mondays = monday.range;
  4468. var tuesdays = tuesday.range;
  4469. var wednesdays = wednesday.range;
  4470. var thursdays = thursday.range;
  4471. var fridays = friday.range;
  4472. var saturdays = saturday.range;
  4473. var month = newInterval(function(date) {
  4474. date.setDate(1);
  4475. date.setHours(0, 0, 0, 0);
  4476. }, function(date, step) {
  4477. date.setMonth(date.getMonth() + step);
  4478. }, function(start, end) {
  4479. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  4480. }, function(date) {
  4481. return date.getMonth();
  4482. });
  4483. var months = month.range;
  4484. var year = newInterval(function(date) {
  4485. date.setMonth(0, 1);
  4486. date.setHours(0, 0, 0, 0);
  4487. }, function(date, step) {
  4488. date.setFullYear(date.getFullYear() + step);
  4489. }, function(start, end) {
  4490. return end.getFullYear() - start.getFullYear();
  4491. }, function(date) {
  4492. return date.getFullYear();
  4493. });
  4494. // An optimized implementation for this simple case.
  4495. year.every = function(k) {
  4496. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  4497. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  4498. date.setMonth(0, 1);
  4499. date.setHours(0, 0, 0, 0);
  4500. }, function(date, step) {
  4501. date.setFullYear(date.getFullYear() + step * k);
  4502. });
  4503. };
  4504. var years = year.range;
  4505. var utcMinute = newInterval(function(date) {
  4506. date.setUTCSeconds(0, 0);
  4507. }, function(date, step) {
  4508. date.setTime(+date + step * durationMinute);
  4509. }, function(start, end) {
  4510. return (end - start) / durationMinute;
  4511. }, function(date) {
  4512. return date.getUTCMinutes();
  4513. });
  4514. var utcMinutes = utcMinute.range;
  4515. var utcHour = newInterval(function(date) {
  4516. date.setUTCMinutes(0, 0, 0);
  4517. }, function(date, step) {
  4518. date.setTime(+date + step * durationHour);
  4519. }, function(start, end) {
  4520. return (end - start) / durationHour;
  4521. }, function(date) {
  4522. return date.getUTCHours();
  4523. });
  4524. var utcHours = utcHour.range;
  4525. var utcDay = newInterval(function(date) {
  4526. date.setUTCHours(0, 0, 0, 0);
  4527. }, function(date, step) {
  4528. date.setUTCDate(date.getUTCDate() + step);
  4529. }, function(start, end) {
  4530. return (end - start) / durationDay;
  4531. }, function(date) {
  4532. return date.getUTCDate() - 1;
  4533. });
  4534. var utcDays = utcDay.range;
  4535. function utcWeekday(i) {
  4536. return newInterval(function(date) {
  4537. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  4538. date.setUTCHours(0, 0, 0, 0);
  4539. }, function(date, step) {
  4540. date.setUTCDate(date.getUTCDate() + step * 7);
  4541. }, function(start, end) {
  4542. return (end - start) / durationWeek;
  4543. });
  4544. }
  4545. var utcSunday = utcWeekday(0);
  4546. var utcMonday = utcWeekday(1);
  4547. var utcTuesday = utcWeekday(2);
  4548. var utcWednesday = utcWeekday(3);
  4549. var utcThursday = utcWeekday(4);
  4550. var utcFriday = utcWeekday(5);
  4551. var utcSaturday = utcWeekday(6);
  4552. var utcSundays = utcSunday.range;
  4553. var utcMondays = utcMonday.range;
  4554. var utcTuesdays = utcTuesday.range;
  4555. var utcWednesdays = utcWednesday.range;
  4556. var utcThursdays = utcThursday.range;
  4557. var utcFridays = utcFriday.range;
  4558. var utcSaturdays = utcSaturday.range;
  4559. var utcMonth = newInterval(function(date) {
  4560. date.setUTCDate(1);
  4561. date.setUTCHours(0, 0, 0, 0);
  4562. }, function(date, step) {
  4563. date.setUTCMonth(date.getUTCMonth() + step);
  4564. }, function(start, end) {
  4565. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  4566. }, function(date) {
  4567. return date.getUTCMonth();
  4568. });
  4569. var utcMonths = utcMonth.range;
  4570. var utcYear = newInterval(function(date) {
  4571. date.setUTCMonth(0, 1);
  4572. date.setUTCHours(0, 0, 0, 0);
  4573. }, function(date, step) {
  4574. date.setUTCFullYear(date.getUTCFullYear() + step);
  4575. }, function(start, end) {
  4576. return end.getUTCFullYear() - start.getUTCFullYear();
  4577. }, function(date) {
  4578. return date.getUTCFullYear();
  4579. });
  4580. // An optimized implementation for this simple case.
  4581. utcYear.every = function(k) {
  4582. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  4583. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  4584. date.setUTCMonth(0, 1);
  4585. date.setUTCHours(0, 0, 0, 0);
  4586. }, function(date, step) {
  4587. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  4588. });
  4589. };
  4590. var utcYears = utcYear.range;
  4591. // Computes the decimal coefficient and exponent of the specified number x with
  4592. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  4593. // For example, formatDecimal(1.23) returns ["123", 0].
  4594. var formatDecimal = function(x, p) {
  4595. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  4596. var i, coefficient = x.slice(0, i);
  4597. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  4598. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  4599. return [
  4600. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  4601. +x.slice(i + 1)
  4602. ];
  4603. };
  4604. var exponent$1 = function(x) {
  4605. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  4606. };
  4607. var formatGroup = function(grouping, thousands) {
  4608. return function(value, width) {
  4609. var i = value.length,
  4610. t = [],
  4611. j = 0,
  4612. g = grouping[0],
  4613. length = 0;
  4614. while (i > 0 && g > 0) {
  4615. if (length + g + 1 > width) g = Math.max(1, width - length);
  4616. t.push(value.substring(i -= g, i + g));
  4617. if ((length += g + 1) > width) break;
  4618. g = grouping[j = (j + 1) % grouping.length];
  4619. }
  4620. return t.reverse().join(thousands);
  4621. };
  4622. };
  4623. var formatDefault = function(x, p) {
  4624. x = x.toPrecision(p);
  4625. out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
  4626. switch (x[i]) {
  4627. case ".": i0 = i1 = i; break;
  4628. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  4629. case "e": break out;
  4630. default: if (i0 > 0) i0 = 0; break;
  4631. }
  4632. }
  4633. return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
  4634. };
  4635. var prefixExponent;
  4636. var formatPrefixAuto = function(x, p) {
  4637. var d = formatDecimal(x, p);
  4638. if (!d) return x + "";
  4639. var coefficient = d[0],
  4640. exponent = d[1],
  4641. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  4642. n = coefficient.length;
  4643. return i === n ? coefficient
  4644. : i > n ? coefficient + new Array(i - n + 1).join("0")
  4645. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  4646. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  4647. };
  4648. var formatRounded = function(x, p) {
  4649. var d = formatDecimal(x, p);
  4650. if (!d) return x + "";
  4651. var coefficient = d[0],
  4652. exponent = d[1];
  4653. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  4654. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  4655. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  4656. };
  4657. var formatTypes = {
  4658. "": formatDefault,
  4659. "%": function(x, p) { return (x * 100).toFixed(p); },
  4660. "b": function(x) { return Math.round(x).toString(2); },
  4661. "c": function(x) { return x + ""; },
  4662. "d": function(x) { return Math.round(x).toString(10); },
  4663. "e": function(x, p) { return x.toExponential(p); },
  4664. "f": function(x, p) { return x.toFixed(p); },
  4665. "g": function(x, p) { return x.toPrecision(p); },
  4666. "o": function(x) { return Math.round(x).toString(8); },
  4667. "p": function(x, p) { return formatRounded(x * 100, p); },
  4668. "r": formatRounded,
  4669. "s": formatPrefixAuto,
  4670. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  4671. "x": function(x) { return Math.round(x).toString(16); }
  4672. };
  4673. // [[fill]align][sign][symbol][0][width][,][.precision][type]
  4674. var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
  4675. var formatSpecifier = function(specifier) {
  4676. return new FormatSpecifier(specifier);
  4677. };
  4678. function FormatSpecifier(specifier) {
  4679. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  4680. var match,
  4681. fill = match[1] || " ",
  4682. align = match[2] || ">",
  4683. sign = match[3] || "-",
  4684. symbol = match[4] || "",
  4685. zero = !!match[5],
  4686. width = match[6] && +match[6],
  4687. comma = !!match[7],
  4688. precision = match[8] && +match[8].slice(1),
  4689. type = match[9] || "";
  4690. // The "n" type is an alias for ",g".
  4691. if (type === "n") comma = true, type = "g";
  4692. // Map invalid types to the default format.
  4693. else if (!formatTypes[type]) type = "";
  4694. // If zero fill is specified, padding goes after sign and before digits.
  4695. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  4696. this.fill = fill;
  4697. this.align = align;
  4698. this.sign = sign;
  4699. this.symbol = symbol;
  4700. this.zero = zero;
  4701. this.width = width;
  4702. this.comma = comma;
  4703. this.precision = precision;
  4704. this.type = type;
  4705. }
  4706. FormatSpecifier.prototype.toString = function() {
  4707. return this.fill
  4708. + this.align
  4709. + this.sign
  4710. + this.symbol
  4711. + (this.zero ? "0" : "")
  4712. + (this.width == null ? "" : Math.max(1, this.width | 0))
  4713. + (this.comma ? "," : "")
  4714. + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
  4715. + this.type;
  4716. };
  4717. var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  4718. function identity$3(x) {
  4719. return x;
  4720. }
  4721. var formatLocale = function(locale) {
  4722. var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
  4723. currency = locale.currency,
  4724. decimal = locale.decimal;
  4725. function newFormat(specifier) {
  4726. specifier = formatSpecifier(specifier);
  4727. var fill = specifier.fill,
  4728. align = specifier.align,
  4729. sign = specifier.sign,
  4730. symbol = specifier.symbol,
  4731. zero = specifier.zero,
  4732. width = specifier.width,
  4733. comma = specifier.comma,
  4734. precision = specifier.precision,
  4735. type = specifier.type;
  4736. // Compute the prefix and suffix.
  4737. // For SI-prefix, the suffix is lazily computed.
  4738. var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  4739. suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? "%" : "";
  4740. // What format function should we use?
  4741. // Is this an integer type?
  4742. // Can this type generate exponential notation?
  4743. var formatType = formatTypes[type],
  4744. maybeSuffix = !type || /[defgprs%]/.test(type);
  4745. // Set the default precision if not specified,
  4746. // or clamp the specified precision to the supported range.
  4747. // For significant precision, it must be in [1, 21].
  4748. // For fixed precision, it must be in [0, 20].
  4749. precision = precision == null ? (type ? 6 : 12)
  4750. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  4751. : Math.max(0, Math.min(20, precision));
  4752. function format(value) {
  4753. var valuePrefix = prefix,
  4754. valueSuffix = suffix,
  4755. i, n, c;
  4756. if (type === "c") {
  4757. valueSuffix = formatType(value) + valueSuffix;
  4758. value = "";
  4759. } else {
  4760. value = +value;
  4761. // Convert negative to positive, and compute the prefix.
  4762. // Note that -0 is not less than 0, but 1 / -0 is!
  4763. var valueNegative = (value < 0 || 1 / value < 0) && (value *= -1, true);
  4764. // Perform the initial formatting.
  4765. value = formatType(value, precision);
  4766. // If the original value was negative, it may be rounded to zero during
  4767. // formatting; treat this as (positive) zero.
  4768. if (valueNegative) {
  4769. i = -1, n = value.length;
  4770. valueNegative = false;
  4771. while (++i < n) {
  4772. if (c = value.charCodeAt(i), (48 < c && c < 58)
  4773. || (type === "x" && 96 < c && c < 103)
  4774. || (type === "X" && 64 < c && c < 71)) {
  4775. valueNegative = true;
  4776. break;
  4777. }
  4778. }
  4779. }
  4780. // Compute the prefix and suffix.
  4781. valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  4782. valueSuffix = valueSuffix + (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + (valueNegative && sign === "(" ? ")" : "");
  4783. // Break the formatted value into the integer “value” part that can be
  4784. // grouped, and fractional or exponential “suffix” part that is not.
  4785. if (maybeSuffix) {
  4786. i = -1, n = value.length;
  4787. while (++i < n) {
  4788. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  4789. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  4790. value = value.slice(0, i);
  4791. break;
  4792. }
  4793. }
  4794. }
  4795. }
  4796. // If the fill character is not "0", grouping is applied before padding.
  4797. if (comma && !zero) value = group(value, Infinity);
  4798. // Compute the padding.
  4799. var length = valuePrefix.length + value.length + valueSuffix.length,
  4800. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  4801. // If the fill character is "0", grouping is applied after padding.
  4802. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  4803. // Reconstruct the final output based on the desired alignment.
  4804. switch (align) {
  4805. case "<": return valuePrefix + value + valueSuffix + padding;
  4806. case "=": return valuePrefix + padding + value + valueSuffix;
  4807. case "^": return padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length);
  4808. }
  4809. return padding + valuePrefix + value + valueSuffix;
  4810. }
  4811. format.toString = function() {
  4812. return specifier + "";
  4813. };
  4814. return format;
  4815. }
  4816. function formatPrefix(specifier, value) {
  4817. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  4818. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  4819. k = Math.pow(10, -e),
  4820. prefix = prefixes[8 + e / 3];
  4821. return function(value) {
  4822. return f(k * value) + prefix;
  4823. };
  4824. }
  4825. return {
  4826. format: newFormat,
  4827. formatPrefix: formatPrefix
  4828. };
  4829. };
  4830. var locale$1;
  4831. defaultLocale({
  4832. decimal: ".",
  4833. thousands: ",",
  4834. grouping: [3],
  4835. currency: ["$", ""]
  4836. });
  4837. function defaultLocale(definition) {
  4838. locale$1 = formatLocale(definition);
  4839. exports.format = locale$1.format;
  4840. exports.formatPrefix = locale$1.formatPrefix;
  4841. return locale$1;
  4842. }
  4843. var precisionFixed = function(step) {
  4844. return Math.max(0, -exponent$1(Math.abs(step)));
  4845. };
  4846. var precisionPrefix = function(step, value) {
  4847. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  4848. };
  4849. var precisionRound = function(step, max) {
  4850. step = Math.abs(step), max = Math.abs(max) - step;
  4851. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  4852. };
  4853. function localDate(d) {
  4854. if (0 <= d.y && d.y < 100) {
  4855. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  4856. date.setFullYear(d.y);
  4857. return date;
  4858. }
  4859. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  4860. }
  4861. function utcDate(d) {
  4862. if (0 <= d.y && d.y < 100) {
  4863. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  4864. date.setUTCFullYear(d.y);
  4865. return date;
  4866. }
  4867. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  4868. }
  4869. function newYear(y) {
  4870. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  4871. }
  4872. function formatLocale$1(locale) {
  4873. var locale_dateTime = locale.dateTime,
  4874. locale_date = locale.date,
  4875. locale_time = locale.time,
  4876. locale_periods = locale.periods,
  4877. locale_weekdays = locale.days,
  4878. locale_shortWeekdays = locale.shortDays,
  4879. locale_months = locale.months,
  4880. locale_shortMonths = locale.shortMonths;
  4881. var periodRe = formatRe(locale_periods),
  4882. periodLookup = formatLookup(locale_periods),
  4883. weekdayRe = formatRe(locale_weekdays),
  4884. weekdayLookup = formatLookup(locale_weekdays),
  4885. shortWeekdayRe = formatRe(locale_shortWeekdays),
  4886. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  4887. monthRe = formatRe(locale_months),
  4888. monthLookup = formatLookup(locale_months),
  4889. shortMonthRe = formatRe(locale_shortMonths),
  4890. shortMonthLookup = formatLookup(locale_shortMonths);
  4891. var formats = {
  4892. "a": formatShortWeekday,
  4893. "A": formatWeekday,
  4894. "b": formatShortMonth,
  4895. "B": formatMonth,
  4896. "c": null,
  4897. "d": formatDayOfMonth,
  4898. "e": formatDayOfMonth,
  4899. "H": formatHour24,
  4900. "I": formatHour12,
  4901. "j": formatDayOfYear,
  4902. "L": formatMilliseconds,
  4903. "m": formatMonthNumber,
  4904. "M": formatMinutes,
  4905. "p": formatPeriod,
  4906. "S": formatSeconds,
  4907. "U": formatWeekNumberSunday,
  4908. "w": formatWeekdayNumber,
  4909. "W": formatWeekNumberMonday,
  4910. "x": null,
  4911. "X": null,
  4912. "y": formatYear,
  4913. "Y": formatFullYear,
  4914. "Z": formatZone,
  4915. "%": formatLiteralPercent
  4916. };
  4917. var utcFormats = {
  4918. "a": formatUTCShortWeekday,
  4919. "A": formatUTCWeekday,
  4920. "b": formatUTCShortMonth,
  4921. "B": formatUTCMonth,
  4922. "c": null,
  4923. "d": formatUTCDayOfMonth,
  4924. "e": formatUTCDayOfMonth,
  4925. "H": formatUTCHour24,
  4926. "I": formatUTCHour12,
  4927. "j": formatUTCDayOfYear,
  4928. "L": formatUTCMilliseconds,
  4929. "m": formatUTCMonthNumber,
  4930. "M": formatUTCMinutes,
  4931. "p": formatUTCPeriod,
  4932. "S": formatUTCSeconds,
  4933. "U": formatUTCWeekNumberSunday,
  4934. "w": formatUTCWeekdayNumber,
  4935. "W": formatUTCWeekNumberMonday,
  4936. "x": null,
  4937. "X": null,
  4938. "y": formatUTCYear,
  4939. "Y": formatUTCFullYear,
  4940. "Z": formatUTCZone,
  4941. "%": formatLiteralPercent
  4942. };
  4943. var parses = {
  4944. "a": parseShortWeekday,
  4945. "A": parseWeekday,
  4946. "b": parseShortMonth,
  4947. "B": parseMonth,
  4948. "c": parseLocaleDateTime,
  4949. "d": parseDayOfMonth,
  4950. "e": parseDayOfMonth,
  4951. "H": parseHour24,
  4952. "I": parseHour24,
  4953. "j": parseDayOfYear,
  4954. "L": parseMilliseconds,
  4955. "m": parseMonthNumber,
  4956. "M": parseMinutes,
  4957. "p": parsePeriod,
  4958. "S": parseSeconds,
  4959. "U": parseWeekNumberSunday,
  4960. "w": parseWeekdayNumber,
  4961. "W": parseWeekNumberMonday,
  4962. "x": parseLocaleDate,
  4963. "X": parseLocaleTime,
  4964. "y": parseYear,
  4965. "Y": parseFullYear,
  4966. "Z": parseZone,
  4967. "%": parseLiteralPercent
  4968. };
  4969. // These recursive directive definitions must be deferred.
  4970. formats.x = newFormat(locale_date, formats);
  4971. formats.X = newFormat(locale_time, formats);
  4972. formats.c = newFormat(locale_dateTime, formats);
  4973. utcFormats.x = newFormat(locale_date, utcFormats);
  4974. utcFormats.X = newFormat(locale_time, utcFormats);
  4975. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  4976. function newFormat(specifier, formats) {
  4977. return function(date) {
  4978. var string = [],
  4979. i = -1,
  4980. j = 0,
  4981. n = specifier.length,
  4982. c,
  4983. pad,
  4984. format;
  4985. if (!(date instanceof Date)) date = new Date(+date);
  4986. while (++i < n) {
  4987. if (specifier.charCodeAt(i) === 37) {
  4988. string.push(specifier.slice(j, i));
  4989. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  4990. else pad = c === "e" ? " " : "0";
  4991. if (format = formats[c]) c = format(date, pad);
  4992. string.push(c);
  4993. j = i + 1;
  4994. }
  4995. }
  4996. string.push(specifier.slice(j, i));
  4997. return string.join("");
  4998. };
  4999. }
  5000. function newParse(specifier, newDate) {
  5001. return function(string) {
  5002. var d = newYear(1900),
  5003. i = parseSpecifier(d, specifier, string += "", 0);
  5004. if (i != string.length) return null;
  5005. // The am-pm flag is 0 for AM, and 1 for PM.
  5006. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  5007. // Convert day-of-week and week-of-year to day-of-year.
  5008. if ("W" in d || "U" in d) {
  5009. if (!("w" in d)) d.w = "W" in d ? 1 : 0;
  5010. var day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  5011. d.m = 0;
  5012. d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$$1 + 5) % 7 : d.w + d.U * 7 - (day$$1 + 6) % 7;
  5013. }
  5014. // If a time zone is specified, all fields are interpreted as UTC and then
  5015. // offset according to the specified time zone.
  5016. if ("Z" in d) {
  5017. d.H += d.Z / 100 | 0;
  5018. d.M += d.Z % 100;
  5019. return utcDate(d);
  5020. }
  5021. // Otherwise, all fields are in local time.
  5022. return newDate(d);
  5023. };
  5024. }
  5025. function parseSpecifier(d, specifier, string, j) {
  5026. var i = 0,
  5027. n = specifier.length,
  5028. m = string.length,
  5029. c,
  5030. parse;
  5031. while (i < n) {
  5032. if (j >= m) return -1;
  5033. c = specifier.charCodeAt(i++);
  5034. if (c === 37) {
  5035. c = specifier.charAt(i++);
  5036. parse = parses[c in pads ? specifier.charAt(i++) : c];
  5037. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  5038. } else if (c != string.charCodeAt(j++)) {
  5039. return -1;
  5040. }
  5041. }
  5042. return j;
  5043. }
  5044. function parsePeriod(d, string, i) {
  5045. var n = periodRe.exec(string.slice(i));
  5046. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  5047. }
  5048. function parseShortWeekday(d, string, i) {
  5049. var n = shortWeekdayRe.exec(string.slice(i));
  5050. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  5051. }
  5052. function parseWeekday(d, string, i) {
  5053. var n = weekdayRe.exec(string.slice(i));
  5054. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  5055. }
  5056. function parseShortMonth(d, string, i) {
  5057. var n = shortMonthRe.exec(string.slice(i));
  5058. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  5059. }
  5060. function parseMonth(d, string, i) {
  5061. var n = monthRe.exec(string.slice(i));
  5062. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  5063. }
  5064. function parseLocaleDateTime(d, string, i) {
  5065. return parseSpecifier(d, locale_dateTime, string, i);
  5066. }
  5067. function parseLocaleDate(d, string, i) {
  5068. return parseSpecifier(d, locale_date, string, i);
  5069. }
  5070. function parseLocaleTime(d, string, i) {
  5071. return parseSpecifier(d, locale_time, string, i);
  5072. }
  5073. function formatShortWeekday(d) {
  5074. return locale_shortWeekdays[d.getDay()];
  5075. }
  5076. function formatWeekday(d) {
  5077. return locale_weekdays[d.getDay()];
  5078. }
  5079. function formatShortMonth(d) {
  5080. return locale_shortMonths[d.getMonth()];
  5081. }
  5082. function formatMonth(d) {
  5083. return locale_months[d.getMonth()];
  5084. }
  5085. function formatPeriod(d) {
  5086. return locale_periods[+(d.getHours() >= 12)];
  5087. }
  5088. function formatUTCShortWeekday(d) {
  5089. return locale_shortWeekdays[d.getUTCDay()];
  5090. }
  5091. function formatUTCWeekday(d) {
  5092. return locale_weekdays[d.getUTCDay()];
  5093. }
  5094. function formatUTCShortMonth(d) {
  5095. return locale_shortMonths[d.getUTCMonth()];
  5096. }
  5097. function formatUTCMonth(d) {
  5098. return locale_months[d.getUTCMonth()];
  5099. }
  5100. function formatUTCPeriod(d) {
  5101. return locale_periods[+(d.getUTCHours() >= 12)];
  5102. }
  5103. return {
  5104. format: function(specifier) {
  5105. var f = newFormat(specifier += "", formats);
  5106. f.toString = function() { return specifier; };
  5107. return f;
  5108. },
  5109. parse: function(specifier) {
  5110. var p = newParse(specifier += "", localDate);
  5111. p.toString = function() { return specifier; };
  5112. return p;
  5113. },
  5114. utcFormat: function(specifier) {
  5115. var f = newFormat(specifier += "", utcFormats);
  5116. f.toString = function() { return specifier; };
  5117. return f;
  5118. },
  5119. utcParse: function(specifier) {
  5120. var p = newParse(specifier, utcDate);
  5121. p.toString = function() { return specifier; };
  5122. return p;
  5123. }
  5124. };
  5125. }
  5126. var pads = {"-": "", "_": " ", "0": "0"};
  5127. var numberRe = /^\s*\d+/;
  5128. var percentRe = /^%/;
  5129. var requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  5130. function pad(value, fill, width) {
  5131. var sign = value < 0 ? "-" : "",
  5132. string = (sign ? -value : value) + "",
  5133. length = string.length;
  5134. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  5135. }
  5136. function requote(s) {
  5137. return s.replace(requoteRe, "\\$&");
  5138. }
  5139. function formatRe(names) {
  5140. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  5141. }
  5142. function formatLookup(names) {
  5143. var map = {}, i = -1, n = names.length;
  5144. while (++i < n) map[names[i].toLowerCase()] = i;
  5145. return map;
  5146. }
  5147. function parseWeekdayNumber(d, string, i) {
  5148. var n = numberRe.exec(string.slice(i, i + 1));
  5149. return n ? (d.w = +n[0], i + n[0].length) : -1;
  5150. }
  5151. function parseWeekNumberSunday(d, string, i) {
  5152. var n = numberRe.exec(string.slice(i));
  5153. return n ? (d.U = +n[0], i + n[0].length) : -1;
  5154. }
  5155. function parseWeekNumberMonday(d, string, i) {
  5156. var n = numberRe.exec(string.slice(i));
  5157. return n ? (d.W = +n[0], i + n[0].length) : -1;
  5158. }
  5159. function parseFullYear(d, string, i) {
  5160. var n = numberRe.exec(string.slice(i, i + 4));
  5161. return n ? (d.y = +n[0], i + n[0].length) : -1;
  5162. }
  5163. function parseYear(d, string, i) {
  5164. var n = numberRe.exec(string.slice(i, i + 2));
  5165. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  5166. }
  5167. function parseZone(d, string, i) {
  5168. var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6));
  5169. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  5170. }
  5171. function parseMonthNumber(d, string, i) {
  5172. var n = numberRe.exec(string.slice(i, i + 2));
  5173. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  5174. }
  5175. function parseDayOfMonth(d, string, i) {
  5176. var n = numberRe.exec(string.slice(i, i + 2));
  5177. return n ? (d.d = +n[0], i + n[0].length) : -1;
  5178. }
  5179. function parseDayOfYear(d, string, i) {
  5180. var n = numberRe.exec(string.slice(i, i + 3));
  5181. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  5182. }
  5183. function parseHour24(d, string, i) {
  5184. var n = numberRe.exec(string.slice(i, i + 2));
  5185. return n ? (d.H = +n[0], i + n[0].length) : -1;
  5186. }
  5187. function parseMinutes(d, string, i) {
  5188. var n = numberRe.exec(string.slice(i, i + 2));
  5189. return n ? (d.M = +n[0], i + n[0].length) : -1;
  5190. }
  5191. function parseSeconds(d, string, i) {
  5192. var n = numberRe.exec(string.slice(i, i + 2));
  5193. return n ? (d.S = +n[0], i + n[0].length) : -1;
  5194. }
  5195. function parseMilliseconds(d, string, i) {
  5196. var n = numberRe.exec(string.slice(i, i + 3));
  5197. return n ? (d.L = +n[0], i + n[0].length) : -1;
  5198. }
  5199. function parseLiteralPercent(d, string, i) {
  5200. var n = percentRe.exec(string.slice(i, i + 1));
  5201. return n ? i + n[0].length : -1;
  5202. }
  5203. function formatDayOfMonth(d, p) {
  5204. return pad(d.getDate(), p, 2);
  5205. }
  5206. function formatHour24(d, p) {
  5207. return pad(d.getHours(), p, 2);
  5208. }
  5209. function formatHour12(d, p) {
  5210. return pad(d.getHours() % 12 || 12, p, 2);
  5211. }
  5212. function formatDayOfYear(d, p) {
  5213. return pad(1 + day.count(year(d), d), p, 3);
  5214. }
  5215. function formatMilliseconds(d, p) {
  5216. return pad(d.getMilliseconds(), p, 3);
  5217. }
  5218. function formatMonthNumber(d, p) {
  5219. return pad(d.getMonth() + 1, p, 2);
  5220. }
  5221. function formatMinutes(d, p) {
  5222. return pad(d.getMinutes(), p, 2);
  5223. }
  5224. function formatSeconds(d, p) {
  5225. return pad(d.getSeconds(), p, 2);
  5226. }
  5227. function formatWeekNumberSunday(d, p) {
  5228. return pad(sunday.count(year(d), d), p, 2);
  5229. }
  5230. function formatWeekdayNumber(d) {
  5231. return d.getDay();
  5232. }
  5233. function formatWeekNumberMonday(d, p) {
  5234. return pad(monday.count(year(d), d), p, 2);
  5235. }
  5236. function formatYear(d, p) {
  5237. return pad(d.getFullYear() % 100, p, 2);
  5238. }
  5239. function formatFullYear(d, p) {
  5240. return pad(d.getFullYear() % 10000, p, 4);
  5241. }
  5242. function formatZone(d) {
  5243. var z = d.getTimezoneOffset();
  5244. return (z > 0 ? "-" : (z *= -1, "+"))
  5245. + pad(z / 60 | 0, "0", 2)
  5246. + pad(z % 60, "0", 2);
  5247. }
  5248. function formatUTCDayOfMonth(d, p) {
  5249. return pad(d.getUTCDate(), p, 2);
  5250. }
  5251. function formatUTCHour24(d, p) {
  5252. return pad(d.getUTCHours(), p, 2);
  5253. }
  5254. function formatUTCHour12(d, p) {
  5255. return pad(d.getUTCHours() % 12 || 12, p, 2);
  5256. }
  5257. function formatUTCDayOfYear(d, p) {
  5258. return pad(1 + utcDay.count(utcYear(d), d), p, 3);
  5259. }
  5260. function formatUTCMilliseconds(d, p) {
  5261. return pad(d.getUTCMilliseconds(), p, 3);
  5262. }
  5263. function formatUTCMonthNumber(d, p) {
  5264. return pad(d.getUTCMonth() + 1, p, 2);
  5265. }
  5266. function formatUTCMinutes(d, p) {
  5267. return pad(d.getUTCMinutes(), p, 2);
  5268. }
  5269. function formatUTCSeconds(d, p) {
  5270. return pad(d.getUTCSeconds(), p, 2);
  5271. }
  5272. function formatUTCWeekNumberSunday(d, p) {
  5273. return pad(utcSunday.count(utcYear(d), d), p, 2);
  5274. }
  5275. function formatUTCWeekdayNumber(d) {
  5276. return d.getUTCDay();
  5277. }
  5278. function formatUTCWeekNumberMonday(d, p) {
  5279. return pad(utcMonday.count(utcYear(d), d), p, 2);
  5280. }
  5281. function formatUTCYear(d, p) {
  5282. return pad(d.getUTCFullYear() % 100, p, 2);
  5283. }
  5284. function formatUTCFullYear(d, p) {
  5285. return pad(d.getUTCFullYear() % 10000, p, 4);
  5286. }
  5287. function formatUTCZone() {
  5288. return "+0000";
  5289. }
  5290. function formatLiteralPercent() {
  5291. return "%";
  5292. }
  5293. var locale$2;
  5294. defaultLocale$1({
  5295. dateTime: "%x, %X",
  5296. date: "%-m/%-d/%Y",
  5297. time: "%-I:%M:%S %p",
  5298. periods: ["AM", "PM"],
  5299. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  5300. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  5301. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  5302. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  5303. });
  5304. function defaultLocale$1(definition) {
  5305. locale$2 = formatLocale$1(definition);
  5306. exports.timeFormat = locale$2.format;
  5307. exports.timeParse = locale$2.parse;
  5308. exports.utcFormat = locale$2.utcFormat;
  5309. exports.utcParse = locale$2.utcParse;
  5310. return locale$2;
  5311. }
  5312. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  5313. function formatIsoNative(date) {
  5314. return date.toISOString();
  5315. }
  5316. var formatIso = Date.prototype.toISOString
  5317. ? formatIsoNative
  5318. : exports.utcFormat(isoSpecifier);
  5319. function parseIsoNative(string) {
  5320. var date = new Date(string);
  5321. return isNaN(date) ? null : date;
  5322. }
  5323. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  5324. ? parseIsoNative
  5325. : exports.utcParse(isoSpecifier);
  5326. var array$2 = Array.prototype;
  5327. var map$3 = array$2.map;
  5328. var slice$3 = array$2.slice;
  5329. var implicit = {name: "implicit"};
  5330. function ordinal(range) {
  5331. var index = map$1(),
  5332. domain = [],
  5333. unknown = implicit;
  5334. range = range == null ? [] : slice$3.call(range);
  5335. function scale(d) {
  5336. var key = d + "", i = index.get(key);
  5337. if (!i) {
  5338. if (unknown !== implicit) return unknown;
  5339. index.set(key, i = domain.push(d));
  5340. }
  5341. return range[(i - 1) % range.length];
  5342. }
  5343. scale.domain = function(_) {
  5344. if (!arguments.length) return domain.slice();
  5345. domain = [], index = map$1();
  5346. var i = -1, n = _.length, d, key;
  5347. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  5348. return scale;
  5349. };
  5350. scale.range = function(_) {
  5351. return arguments.length ? (range = slice$3.call(_), scale) : range.slice();
  5352. };
  5353. scale.unknown = function(_) {
  5354. return arguments.length ? (unknown = _, scale) : unknown;
  5355. };
  5356. scale.copy = function() {
  5357. return ordinal()
  5358. .domain(domain)
  5359. .range(range)
  5360. .unknown(unknown);
  5361. };
  5362. return scale;
  5363. }
  5364. function band() {
  5365. var scale = ordinal().unknown(undefined),
  5366. domain = scale.domain,
  5367. ordinalRange = scale.range,
  5368. range$$1 = [0, 1],
  5369. step,
  5370. bandwidth,
  5371. round = false,
  5372. paddingInner = 0,
  5373. paddingOuter = 0,
  5374. align = 0.5;
  5375. delete scale.unknown;
  5376. function rescale() {
  5377. var n = domain().length,
  5378. reverse = range$$1[1] < range$$1[0],
  5379. start = range$$1[reverse - 0],
  5380. stop = range$$1[1 - reverse];
  5381. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  5382. if (round) step = Math.floor(step);
  5383. start += (stop - start - step * (n - paddingInner)) * align;
  5384. bandwidth = step * (1 - paddingInner);
  5385. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  5386. var values = range(n).map(function(i) { return start + step * i; });
  5387. return ordinalRange(reverse ? values.reverse() : values);
  5388. }
  5389. scale.domain = function(_) {
  5390. return arguments.length ? (domain(_), rescale()) : domain();
  5391. };
  5392. scale.range = function(_) {
  5393. return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
  5394. };
  5395. scale.rangeRound = function(_) {
  5396. return range$$1 = [+_[0], +_[1]], round = true, rescale();
  5397. };
  5398. scale.bandwidth = function() {
  5399. return bandwidth;
  5400. };
  5401. scale.step = function() {
  5402. return step;
  5403. };
  5404. scale.round = function(_) {
  5405. return arguments.length ? (round = !!_, rescale()) : round;
  5406. };
  5407. scale.padding = function(_) {
  5408. return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  5409. };
  5410. scale.paddingInner = function(_) {
  5411. return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
  5412. };
  5413. scale.paddingOuter = function(_) {
  5414. return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
  5415. };
  5416. scale.align = function(_) {
  5417. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  5418. };
  5419. scale.copy = function() {
  5420. return band()
  5421. .domain(domain())
  5422. .range(range$$1)
  5423. .round(round)
  5424. .paddingInner(paddingInner)
  5425. .paddingOuter(paddingOuter)
  5426. .align(align);
  5427. };
  5428. return rescale();
  5429. }
  5430. function pointish(scale) {
  5431. var copy = scale.copy;
  5432. scale.padding = scale.paddingOuter;
  5433. delete scale.paddingInner;
  5434. delete scale.paddingOuter;
  5435. scale.copy = function() {
  5436. return pointish(copy());
  5437. };
  5438. return scale;
  5439. }
  5440. function point$4() {
  5441. return pointish(band().paddingInner(1));
  5442. }
  5443. var constant$4 = function(x) {
  5444. return function() {
  5445. return x;
  5446. };
  5447. };
  5448. var number$1 = function(x) {
  5449. return +x;
  5450. };
  5451. var unit = [0, 1];
  5452. function deinterpolateLinear(a, b) {
  5453. return (b -= (a = +a))
  5454. ? function(x) { return (x - a) / b; }
  5455. : constant$4(b);
  5456. }
  5457. function deinterpolateClamp(deinterpolate) {
  5458. return function(a, b) {
  5459. var d = deinterpolate(a = +a, b = +b);
  5460. return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
  5461. };
  5462. }
  5463. function reinterpolateClamp(reinterpolate) {
  5464. return function(a, b) {
  5465. var r = reinterpolate(a = +a, b = +b);
  5466. return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
  5467. };
  5468. }
  5469. function bimap(domain, range$$1, deinterpolate, reinterpolate) {
  5470. var d0 = domain[0], d1 = domain[1], r0 = range$$1[0], r1 = range$$1[1];
  5471. if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
  5472. else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
  5473. return function(x) { return r0(d0(x)); };
  5474. }
  5475. function polymap(domain, range$$1, deinterpolate, reinterpolate) {
  5476. var j = Math.min(domain.length, range$$1.length) - 1,
  5477. d = new Array(j),
  5478. r = new Array(j),
  5479. i = -1;
  5480. // Reverse descending domains.
  5481. if (domain[j] < domain[0]) {
  5482. domain = domain.slice().reverse();
  5483. range$$1 = range$$1.slice().reverse();
  5484. }
  5485. while (++i < j) {
  5486. d[i] = deinterpolate(domain[i], domain[i + 1]);
  5487. r[i] = reinterpolate(range$$1[i], range$$1[i + 1]);
  5488. }
  5489. return function(x) {
  5490. var i = bisectRight(domain, x, 1, j) - 1;
  5491. return r[i](d[i](x));
  5492. };
  5493. }
  5494. function copy(source, target) {
  5495. return target
  5496. .domain(source.domain())
  5497. .range(source.range())
  5498. .interpolate(source.interpolate())
  5499. .clamp(source.clamp());
  5500. }
  5501. // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  5502. // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
  5503. function continuous(deinterpolate, reinterpolate) {
  5504. var domain = unit,
  5505. range$$1 = unit,
  5506. interpolate$$1 = interpolate,
  5507. clamp = false,
  5508. piecewise,
  5509. output,
  5510. input;
  5511. function rescale() {
  5512. piecewise = Math.min(domain.length, range$$1.length) > 2 ? polymap : bimap;
  5513. output = input = null;
  5514. return scale;
  5515. }
  5516. function scale(x) {
  5517. return (output || (output = piecewise(domain, range$$1, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
  5518. }
  5519. scale.invert = function(y) {
  5520. return (input || (input = piecewise(range$$1, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
  5521. };
  5522. scale.domain = function(_) {
  5523. return arguments.length ? (domain = map$3.call(_, number$1), rescale()) : domain.slice();
  5524. };
  5525. scale.range = function(_) {
  5526. return arguments.length ? (range$$1 = slice$3.call(_), rescale()) : range$$1.slice();
  5527. };
  5528. scale.rangeRound = function(_) {
  5529. return range$$1 = slice$3.call(_), interpolate$$1 = interpolateRound, rescale();
  5530. };
  5531. scale.clamp = function(_) {
  5532. return arguments.length ? (clamp = !!_, rescale()) : clamp;
  5533. };
  5534. scale.interpolate = function(_) {
  5535. return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
  5536. };
  5537. return rescale();
  5538. }
  5539. var tickFormat = function(domain, count, specifier) {
  5540. var start = domain[0],
  5541. stop = domain[domain.length - 1],
  5542. step = tickStep(start, stop, count == null ? 10 : count),
  5543. precision;
  5544. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  5545. switch (specifier.type) {
  5546. case "s": {
  5547. var value = Math.max(Math.abs(start), Math.abs(stop));
  5548. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  5549. return exports.formatPrefix(specifier, value);
  5550. }
  5551. case "":
  5552. case "e":
  5553. case "g":
  5554. case "p":
  5555. case "r": {
  5556. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  5557. break;
  5558. }
  5559. case "f":
  5560. case "%": {
  5561. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  5562. break;
  5563. }
  5564. }
  5565. return exports.format(specifier);
  5566. };
  5567. function linearish(scale) {
  5568. var domain = scale.domain;
  5569. scale.ticks = function(count) {
  5570. var d = domain();
  5571. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  5572. };
  5573. scale.tickFormat = function(count, specifier) {
  5574. return tickFormat(domain(), count, specifier);
  5575. };
  5576. scale.nice = function(count) {
  5577. var d = domain(),
  5578. i = d.length - 1,
  5579. n = count == null ? 10 : count,
  5580. start = d[0],
  5581. stop = d[i],
  5582. step = tickStep(start, stop, n);
  5583. if (step) {
  5584. step = tickStep(Math.floor(start / step) * step, Math.ceil(stop / step) * step, n);
  5585. d[0] = Math.floor(start / step) * step;
  5586. d[i] = Math.ceil(stop / step) * step;
  5587. domain(d);
  5588. }
  5589. return scale;
  5590. };
  5591. return scale;
  5592. }
  5593. function linear$2() {
  5594. var scale = continuous(deinterpolateLinear, interpolateNumber);
  5595. scale.copy = function() {
  5596. return copy(scale, linear$2());
  5597. };
  5598. return linearish(scale);
  5599. }
  5600. function identity$4() {
  5601. var domain = [0, 1];
  5602. function scale(x) {
  5603. return +x;
  5604. }
  5605. scale.invert = scale;
  5606. scale.domain = scale.range = function(_) {
  5607. return arguments.length ? (domain = map$3.call(_, number$1), scale) : domain.slice();
  5608. };
  5609. scale.copy = function() {
  5610. return identity$4().domain(domain);
  5611. };
  5612. return linearish(scale);
  5613. }
  5614. var nice = function(domain, interval) {
  5615. domain = domain.slice();
  5616. var i0 = 0,
  5617. i1 = domain.length - 1,
  5618. x0 = domain[i0],
  5619. x1 = domain[i1],
  5620. t;
  5621. if (x1 < x0) {
  5622. t = i0, i0 = i1, i1 = t;
  5623. t = x0, x0 = x1, x1 = t;
  5624. }
  5625. domain[i0] = interval.floor(x0);
  5626. domain[i1] = interval.ceil(x1);
  5627. return domain;
  5628. };
  5629. function deinterpolate(a, b) {
  5630. return (b = Math.log(b / a))
  5631. ? function(x) { return Math.log(x / a) / b; }
  5632. : constant$4(b);
  5633. }
  5634. function reinterpolate(a, b) {
  5635. return a < 0
  5636. ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
  5637. : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
  5638. }
  5639. function pow10(x) {
  5640. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  5641. }
  5642. function powp(base) {
  5643. return base === 10 ? pow10
  5644. : base === Math.E ? Math.exp
  5645. : function(x) { return Math.pow(base, x); };
  5646. }
  5647. function logp(base) {
  5648. return base === Math.E ? Math.log
  5649. : base === 10 && Math.log10
  5650. || base === 2 && Math.log2
  5651. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  5652. }
  5653. function reflect(f) {
  5654. return function(x) {
  5655. return -f(-x);
  5656. };
  5657. }
  5658. function log() {
  5659. var scale = continuous(deinterpolate, reinterpolate).domain([1, 10]),
  5660. domain = scale.domain,
  5661. base = 10,
  5662. logs = logp(10),
  5663. pows = powp(10);
  5664. function rescale() {
  5665. logs = logp(base), pows = powp(base);
  5666. if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
  5667. return scale;
  5668. }
  5669. scale.base = function(_) {
  5670. return arguments.length ? (base = +_, rescale()) : base;
  5671. };
  5672. scale.domain = function(_) {
  5673. return arguments.length ? (domain(_), rescale()) : domain();
  5674. };
  5675. scale.ticks = function(count) {
  5676. var d = domain(),
  5677. u = d[0],
  5678. v = d[d.length - 1],
  5679. r;
  5680. if (r = v < u) i = u, u = v, v = i;
  5681. var i = logs(u),
  5682. j = logs(v),
  5683. p,
  5684. k,
  5685. t,
  5686. n = count == null ? 10 : +count,
  5687. z = [];
  5688. if (!(base % 1) && j - i < n) {
  5689. i = Math.round(i) - 1, j = Math.round(j) + 1;
  5690. if (u > 0) for (; i < j; ++i) {
  5691. for (k = 1, p = pows(i); k < base; ++k) {
  5692. t = p * k;
  5693. if (t < u) continue;
  5694. if (t > v) break;
  5695. z.push(t);
  5696. }
  5697. } else for (; i < j; ++i) {
  5698. for (k = base - 1, p = pows(i); k >= 1; --k) {
  5699. t = p * k;
  5700. if (t < u) continue;
  5701. if (t > v) break;
  5702. z.push(t);
  5703. }
  5704. }
  5705. } else {
  5706. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  5707. }
  5708. return r ? z.reverse() : z;
  5709. };
  5710. scale.tickFormat = function(count, specifier) {
  5711. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  5712. if (typeof specifier !== "function") specifier = exports.format(specifier);
  5713. if (count === Infinity) return specifier;
  5714. if (count == null) count = 10;
  5715. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  5716. return function(d) {
  5717. var i = d / pows(Math.round(logs(d)));
  5718. if (i * base < base - 0.5) i *= base;
  5719. return i <= k ? specifier(d) : "";
  5720. };
  5721. };
  5722. scale.nice = function() {
  5723. return domain(nice(domain(), {
  5724. floor: function(x) { return pows(Math.floor(logs(x))); },
  5725. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  5726. }));
  5727. };
  5728. scale.copy = function() {
  5729. return copy(scale, log().base(base));
  5730. };
  5731. return scale;
  5732. }
  5733. function raise(x, exponent) {
  5734. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  5735. }
  5736. function pow() {
  5737. var exponent = 1,
  5738. scale = continuous(deinterpolate, reinterpolate),
  5739. domain = scale.domain;
  5740. function deinterpolate(a, b) {
  5741. return (b = raise(b, exponent) - (a = raise(a, exponent)))
  5742. ? function(x) { return (raise(x, exponent) - a) / b; }
  5743. : constant$4(b);
  5744. }
  5745. function reinterpolate(a, b) {
  5746. b = raise(b, exponent) - (a = raise(a, exponent));
  5747. return function(t) { return raise(a + b * t, 1 / exponent); };
  5748. }
  5749. scale.exponent = function(_) {
  5750. return arguments.length ? (exponent = +_, domain(domain())) : exponent;
  5751. };
  5752. scale.copy = function() {
  5753. return copy(scale, pow().exponent(exponent));
  5754. };
  5755. return linearish(scale);
  5756. }
  5757. function sqrt() {
  5758. return pow().exponent(0.5);
  5759. }
  5760. function quantile$$1() {
  5761. var domain = [],
  5762. range$$1 = [],
  5763. thresholds = [];
  5764. function rescale() {
  5765. var i = 0, n = Math.max(1, range$$1.length);
  5766. thresholds = new Array(n - 1);
  5767. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  5768. return scale;
  5769. }
  5770. function scale(x) {
  5771. if (!isNaN(x = +x)) return range$$1[bisectRight(thresholds, x)];
  5772. }
  5773. scale.invertExtent = function(y) {
  5774. var i = range$$1.indexOf(y);
  5775. return i < 0 ? [NaN, NaN] : [
  5776. i > 0 ? thresholds[i - 1] : domain[0],
  5777. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  5778. ];
  5779. };
  5780. scale.domain = function(_) {
  5781. if (!arguments.length) return domain.slice();
  5782. domain = [];
  5783. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  5784. domain.sort(ascending);
  5785. return rescale();
  5786. };
  5787. scale.range = function(_) {
  5788. return arguments.length ? (range$$1 = slice$3.call(_), rescale()) : range$$1.slice();
  5789. };
  5790. scale.quantiles = function() {
  5791. return thresholds.slice();
  5792. };
  5793. scale.copy = function() {
  5794. return quantile$$1()
  5795. .domain(domain)
  5796. .range(range$$1);
  5797. };
  5798. return scale;
  5799. }
  5800. function quantize$1() {
  5801. var x0 = 0,
  5802. x1 = 1,
  5803. n = 1,
  5804. domain = [0.5],
  5805. range$$1 = [0, 1];
  5806. function scale(x) {
  5807. if (x <= x) return range$$1[bisectRight(domain, x, 0, n)];
  5808. }
  5809. function rescale() {
  5810. var i = -1;
  5811. domain = new Array(n);
  5812. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  5813. return scale;
  5814. }
  5815. scale.domain = function(_) {
  5816. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  5817. };
  5818. scale.range = function(_) {
  5819. return arguments.length ? (n = (range$$1 = slice$3.call(_)).length - 1, rescale()) : range$$1.slice();
  5820. };
  5821. scale.invertExtent = function(y) {
  5822. var i = range$$1.indexOf(y);
  5823. return i < 0 ? [NaN, NaN]
  5824. : i < 1 ? [x0, domain[0]]
  5825. : i >= n ? [domain[n - 1], x1]
  5826. : [domain[i - 1], domain[i]];
  5827. };
  5828. scale.copy = function() {
  5829. return quantize$1()
  5830. .domain([x0, x1])
  5831. .range(range$$1);
  5832. };
  5833. return linearish(scale);
  5834. }
  5835. function threshold$1() {
  5836. var domain = [0.5],
  5837. range$$1 = [0, 1],
  5838. n = 1;
  5839. function scale(x) {
  5840. if (x <= x) return range$$1[bisectRight(domain, x, 0, n)];
  5841. }
  5842. scale.domain = function(_) {
  5843. return arguments.length ? (domain = slice$3.call(_), n = Math.min(domain.length, range$$1.length - 1), scale) : domain.slice();
  5844. };
  5845. scale.range = function(_) {
  5846. return arguments.length ? (range$$1 = slice$3.call(_), n = Math.min(domain.length, range$$1.length - 1), scale) : range$$1.slice();
  5847. };
  5848. scale.invertExtent = function(y) {
  5849. var i = range$$1.indexOf(y);
  5850. return [domain[i - 1], domain[i]];
  5851. };
  5852. scale.copy = function() {
  5853. return threshold$1()
  5854. .domain(domain)
  5855. .range(range$$1);
  5856. };
  5857. return scale;
  5858. }
  5859. var durationSecond$1 = 1000;
  5860. var durationMinute$1 = durationSecond$1 * 60;
  5861. var durationHour$1 = durationMinute$1 * 60;
  5862. var durationDay$1 = durationHour$1 * 24;
  5863. var durationWeek$1 = durationDay$1 * 7;
  5864. var durationMonth = durationDay$1 * 30;
  5865. var durationYear = durationDay$1 * 365;
  5866. function date$1(t) {
  5867. return new Date(t);
  5868. }
  5869. function number$2(t) {
  5870. return t instanceof Date ? +t : +new Date(+t);
  5871. }
  5872. function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
  5873. var scale = continuous(deinterpolateLinear, interpolateNumber),
  5874. invert = scale.invert,
  5875. domain = scale.domain;
  5876. var formatMillisecond = format(".%L"),
  5877. formatSecond = format(":%S"),
  5878. formatMinute = format("%I:%M"),
  5879. formatHour = format("%I %p"),
  5880. formatDay = format("%a %d"),
  5881. formatWeek = format("%b %d"),
  5882. formatMonth = format("%B"),
  5883. formatYear = format("%Y");
  5884. var tickIntervals = [
  5885. [second$$1, 1, durationSecond$1],
  5886. [second$$1, 5, 5 * durationSecond$1],
  5887. [second$$1, 15, 15 * durationSecond$1],
  5888. [second$$1, 30, 30 * durationSecond$1],
  5889. [minute$$1, 1, durationMinute$1],
  5890. [minute$$1, 5, 5 * durationMinute$1],
  5891. [minute$$1, 15, 15 * durationMinute$1],
  5892. [minute$$1, 30, 30 * durationMinute$1],
  5893. [ hour$$1, 1, durationHour$1 ],
  5894. [ hour$$1, 3, 3 * durationHour$1 ],
  5895. [ hour$$1, 6, 6 * durationHour$1 ],
  5896. [ hour$$1, 12, 12 * durationHour$1 ],
  5897. [ day$$1, 1, durationDay$1 ],
  5898. [ day$$1, 2, 2 * durationDay$1 ],
  5899. [ week, 1, durationWeek$1 ],
  5900. [ month$$1, 1, durationMonth ],
  5901. [ month$$1, 3, 3 * durationMonth ],
  5902. [ year$$1, 1, durationYear ]
  5903. ];
  5904. function tickFormat(date) {
  5905. return (second$$1(date) < date ? formatMillisecond
  5906. : minute$$1(date) < date ? formatSecond
  5907. : hour$$1(date) < date ? formatMinute
  5908. : day$$1(date) < date ? formatHour
  5909. : month$$1(date) < date ? (week(date) < date ? formatDay : formatWeek)
  5910. : year$$1(date) < date ? formatMonth
  5911. : formatYear)(date);
  5912. }
  5913. function tickInterval(interval, start, stop, step) {
  5914. if (interval == null) interval = 10;
  5915. // If a desired tick count is specified, pick a reasonable tick interval
  5916. // based on the extent of the domain and a rough estimate of tick size.
  5917. // Otherwise, assume interval is already a time interval and use it.
  5918. if (typeof interval === "number") {
  5919. var target = Math.abs(stop - start) / interval,
  5920. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  5921. if (i === tickIntervals.length) {
  5922. step = tickStep(start / durationYear, stop / durationYear, interval);
  5923. interval = year$$1;
  5924. } else if (i) {
  5925. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  5926. step = i[1];
  5927. interval = i[0];
  5928. } else {
  5929. step = tickStep(start, stop, interval);
  5930. interval = millisecond$$1;
  5931. }
  5932. }
  5933. return step == null ? interval : interval.every(step);
  5934. }
  5935. scale.invert = function(y) {
  5936. return new Date(invert(y));
  5937. };
  5938. scale.domain = function(_) {
  5939. return arguments.length ? domain(map$3.call(_, number$2)) : domain().map(date$1);
  5940. };
  5941. scale.ticks = function(interval, step) {
  5942. var d = domain(),
  5943. t0 = d[0],
  5944. t1 = d[d.length - 1],
  5945. r = t1 < t0,
  5946. t;
  5947. if (r) t = t0, t0 = t1, t1 = t;
  5948. t = tickInterval(interval, t0, t1, step);
  5949. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  5950. return r ? t.reverse() : t;
  5951. };
  5952. scale.tickFormat = function(count, specifier) {
  5953. return specifier == null ? tickFormat : format(specifier);
  5954. };
  5955. scale.nice = function(interval, step) {
  5956. var d = domain();
  5957. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  5958. ? domain(nice(d, interval))
  5959. : scale;
  5960. };
  5961. scale.copy = function() {
  5962. return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
  5963. };
  5964. return scale;
  5965. }
  5966. var time = function() {
  5967. return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
  5968. };
  5969. var utcTime = function() {
  5970. return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
  5971. };
  5972. var colors = function(s) {
  5973. return s.match(/.{6}/g).map(function(x) {
  5974. return "#" + x;
  5975. });
  5976. };
  5977. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  5978. var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
  5979. var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
  5980. var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
  5981. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  5982. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  5983. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  5984. var rainbow = cubehelix();
  5985. var rainbow$1 = function(t) {
  5986. if (t < 0 || t > 1) t -= Math.floor(t);
  5987. var ts = Math.abs(t - 0.5);
  5988. rainbow.h = 360 * t - 100;
  5989. rainbow.s = 1.5 - 1.5 * ts;
  5990. rainbow.l = 0.8 - 0.9 * ts;
  5991. return rainbow + "";
  5992. };
  5993. function ramp(range) {
  5994. var n = range.length;
  5995. return function(t) {
  5996. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  5997. };
  5998. }
  5999. var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  6000. var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  6001. var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  6002. var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  6003. function sequential(interpolator) {
  6004. var x0 = 0,
  6005. x1 = 1,
  6006. clamp = false;
  6007. function scale(x) {
  6008. var t = (x - x0) / (x1 - x0);
  6009. return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
  6010. }
  6011. scale.domain = function(_) {
  6012. return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
  6013. };
  6014. scale.clamp = function(_) {
  6015. return arguments.length ? (clamp = !!_, scale) : clamp;
  6016. };
  6017. scale.interpolator = function(_) {
  6018. return arguments.length ? (interpolator = _, scale) : interpolator;
  6019. };
  6020. scale.copy = function() {
  6021. return sequential(interpolator).domain([x0, x1]).clamp(clamp);
  6022. };
  6023. return linearish(scale);
  6024. }
  6025. var xhtml = "http://www.w3.org/1999/xhtml";
  6026. var namespaces = {
  6027. svg: "http://www.w3.org/2000/svg",
  6028. xhtml: xhtml,
  6029. xlink: "http://www.w3.org/1999/xlink",
  6030. xml: "http://www.w3.org/XML/1998/namespace",
  6031. xmlns: "http://www.w3.org/2000/xmlns/"
  6032. };
  6033. var namespace = function(name) {
  6034. var prefix = name += "", i = prefix.indexOf(":");
  6035. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  6036. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  6037. };
  6038. function creatorInherit(name) {
  6039. return function() {
  6040. var document = this.ownerDocument,
  6041. uri = this.namespaceURI;
  6042. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  6043. ? document.createElement(name)
  6044. : document.createElementNS(uri, name);
  6045. };
  6046. }
  6047. function creatorFixed(fullname) {
  6048. return function() {
  6049. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  6050. };
  6051. }
  6052. var creator = function(name) {
  6053. var fullname = namespace(name);
  6054. return (fullname.local
  6055. ? creatorFixed
  6056. : creatorInherit)(fullname);
  6057. };
  6058. var nextId = 0;
  6059. function local() {
  6060. return new Local;
  6061. }
  6062. function Local() {
  6063. this._ = "@" + (++nextId).toString(36);
  6064. }
  6065. Local.prototype = local.prototype = {
  6066. constructor: Local,
  6067. get: function(node) {
  6068. var id = this._;
  6069. while (!(id in node)) if (!(node = node.parentNode)) return;
  6070. return node[id];
  6071. },
  6072. set: function(node, value) {
  6073. return node[this._] = value;
  6074. },
  6075. remove: function(node) {
  6076. return this._ in node && delete node[this._];
  6077. },
  6078. toString: function() {
  6079. return this._;
  6080. }
  6081. };
  6082. var matcher = function(selector) {
  6083. return function() {
  6084. return this.matches(selector);
  6085. };
  6086. };
  6087. if (typeof document !== "undefined") {
  6088. var element = document.documentElement;
  6089. if (!element.matches) {
  6090. var vendorMatches = element.webkitMatchesSelector
  6091. || element.msMatchesSelector
  6092. || element.mozMatchesSelector
  6093. || element.oMatchesSelector;
  6094. matcher = function(selector) {
  6095. return function() {
  6096. return vendorMatches.call(this, selector);
  6097. };
  6098. };
  6099. }
  6100. }
  6101. var matcher$1 = matcher;
  6102. var filterEvents = {};
  6103. exports.event = null;
  6104. if (typeof document !== "undefined") {
  6105. var element$1 = document.documentElement;
  6106. if (!("onmouseenter" in element$1)) {
  6107. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  6108. }
  6109. }
  6110. function filterContextListener(listener, index, group) {
  6111. listener = contextListener(listener, index, group);
  6112. return function(event) {
  6113. var related = event.relatedTarget;
  6114. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  6115. listener.call(this, event);
  6116. }
  6117. };
  6118. }
  6119. function contextListener(listener, index, group) {
  6120. return function(event1) {
  6121. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  6122. exports.event = event1;
  6123. try {
  6124. listener.call(this, this.__data__, index, group);
  6125. } finally {
  6126. exports.event = event0;
  6127. }
  6128. };
  6129. }
  6130. function parseTypenames$1(typenames) {
  6131. return typenames.trim().split(/^|\s+/).map(function(t) {
  6132. var name = "", i = t.indexOf(".");
  6133. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  6134. return {type: t, name: name};
  6135. });
  6136. }
  6137. function onRemove(typename) {
  6138. return function() {
  6139. var on = this.__on;
  6140. if (!on) return;
  6141. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  6142. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  6143. this.removeEventListener(o.type, o.listener, o.capture);
  6144. } else {
  6145. on[++i] = o;
  6146. }
  6147. }
  6148. if (++i) on.length = i;
  6149. else delete this.__on;
  6150. };
  6151. }
  6152. function onAdd(typename, value, capture) {
  6153. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  6154. return function(d, i, group) {
  6155. var on = this.__on, o, listener = wrap(value, i, group);
  6156. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  6157. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  6158. this.removeEventListener(o.type, o.listener, o.capture);
  6159. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  6160. o.value = value;
  6161. return;
  6162. }
  6163. }
  6164. this.addEventListener(typename.type, listener, capture);
  6165. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  6166. if (!on) this.__on = [o];
  6167. else on.push(o);
  6168. };
  6169. }
  6170. var selection_on = function(typename, value, capture) {
  6171. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  6172. if (arguments.length < 2) {
  6173. var on = this.node().__on;
  6174. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  6175. for (i = 0, o = on[j]; i < n; ++i) {
  6176. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  6177. return o.value;
  6178. }
  6179. }
  6180. }
  6181. return;
  6182. }
  6183. on = value ? onAdd : onRemove;
  6184. if (capture == null) capture = false;
  6185. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  6186. return this;
  6187. };
  6188. function customEvent(event1, listener, that, args) {
  6189. var event0 = exports.event;
  6190. event1.sourceEvent = exports.event;
  6191. exports.event = event1;
  6192. try {
  6193. return listener.apply(that, args);
  6194. } finally {
  6195. exports.event = event0;
  6196. }
  6197. }
  6198. var sourceEvent = function() {
  6199. var current = exports.event, source;
  6200. while (source = current.sourceEvent) current = source;
  6201. return current;
  6202. };
  6203. var point$5 = function(node, event) {
  6204. var svg = node.ownerSVGElement || node;
  6205. if (svg.createSVGPoint) {
  6206. var point = svg.createSVGPoint();
  6207. point.x = event.clientX, point.y = event.clientY;
  6208. point = point.matrixTransform(node.getScreenCTM().inverse());
  6209. return [point.x, point.y];
  6210. }
  6211. var rect = node.getBoundingClientRect();
  6212. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  6213. };
  6214. var mouse = function(node) {
  6215. var event = sourceEvent();
  6216. if (event.changedTouches) event = event.changedTouches[0];
  6217. return point$5(node, event);
  6218. };
  6219. function none$2() {}
  6220. var selector = function(selector) {
  6221. return selector == null ? none$2 : function() {
  6222. return this.querySelector(selector);
  6223. };
  6224. };
  6225. var selection_select = function(select) {
  6226. if (typeof select !== "function") select = selector(select);
  6227. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  6228. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  6229. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  6230. if ("__data__" in node) subnode.__data__ = node.__data__;
  6231. subgroup[i] = subnode;
  6232. }
  6233. }
  6234. }
  6235. return new Selection(subgroups, this._parents);
  6236. };
  6237. function empty() {
  6238. return [];
  6239. }
  6240. var selectorAll = function(selector) {
  6241. return selector == null ? empty : function() {
  6242. return this.querySelectorAll(selector);
  6243. };
  6244. };
  6245. var selection_selectAll = function(select) {
  6246. if (typeof select !== "function") select = selectorAll(select);
  6247. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  6248. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  6249. if (node = group[i]) {
  6250. subgroups.push(select.call(node, node.__data__, i, group));
  6251. parents.push(node);
  6252. }
  6253. }
  6254. }
  6255. return new Selection(subgroups, parents);
  6256. };
  6257. var selection_filter = function(match) {
  6258. if (typeof match !== "function") match = matcher$1(match);
  6259. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  6260. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  6261. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  6262. subgroup.push(node);
  6263. }
  6264. }
  6265. }
  6266. return new Selection(subgroups, this._parents);
  6267. };
  6268. var sparse = function(update) {
  6269. return new Array(update.length);
  6270. };
  6271. var selection_enter = function() {
  6272. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  6273. };
  6274. function EnterNode(parent, datum) {
  6275. this.ownerDocument = parent.ownerDocument;
  6276. this.namespaceURI = parent.namespaceURI;
  6277. this._next = null;
  6278. this._parent = parent;
  6279. this.__data__ = datum;
  6280. }
  6281. EnterNode.prototype = {
  6282. constructor: EnterNode,
  6283. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  6284. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  6285. querySelector: function(selector) { return this._parent.querySelector(selector); },
  6286. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  6287. };
  6288. var constant$5 = function(x) {
  6289. return function() {
  6290. return x;
  6291. };
  6292. };
  6293. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  6294. function bindIndex(parent, group, enter, update, exit, data) {
  6295. var i = 0,
  6296. node,
  6297. groupLength = group.length,
  6298. dataLength = data.length;
  6299. // Put any non-null nodes that fit into update.
  6300. // Put any null nodes into enter.
  6301. // Put any remaining data into enter.
  6302. for (; i < dataLength; ++i) {
  6303. if (node = group[i]) {
  6304. node.__data__ = data[i];
  6305. update[i] = node;
  6306. } else {
  6307. enter[i] = new EnterNode(parent, data[i]);
  6308. }
  6309. }
  6310. // Put any non-null nodes that don’t fit into exit.
  6311. for (; i < groupLength; ++i) {
  6312. if (node = group[i]) {
  6313. exit[i] = node;
  6314. }
  6315. }
  6316. }
  6317. function bindKey(parent, group, enter, update, exit, data, key) {
  6318. var i,
  6319. node,
  6320. nodeByKeyValue = {},
  6321. groupLength = group.length,
  6322. dataLength = data.length,
  6323. keyValues = new Array(groupLength),
  6324. keyValue;
  6325. // Compute the key for each node.
  6326. // If multiple nodes have the same key, the duplicates are added to exit.
  6327. for (i = 0; i < groupLength; ++i) {
  6328. if (node = group[i]) {
  6329. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  6330. if (keyValue in nodeByKeyValue) {
  6331. exit[i] = node;
  6332. } else {
  6333. nodeByKeyValue[keyValue] = node;
  6334. }
  6335. }
  6336. }
  6337. // Compute the key for each datum.
  6338. // If there a node associated with this key, join and add it to update.
  6339. // If there is not (or the key is a duplicate), add it to enter.
  6340. for (i = 0; i < dataLength; ++i) {
  6341. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  6342. if (node = nodeByKeyValue[keyValue]) {
  6343. update[i] = node;
  6344. node.__data__ = data[i];
  6345. nodeByKeyValue[keyValue] = null;
  6346. } else {
  6347. enter[i] = new EnterNode(parent, data[i]);
  6348. }
  6349. }
  6350. // Add any remaining nodes that were not bound to data to exit.
  6351. for (i = 0; i < groupLength; ++i) {
  6352. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  6353. exit[i] = node;
  6354. }
  6355. }
  6356. }
  6357. var selection_data = function(value, key) {
  6358. if (!value) {
  6359. data = new Array(this.size()), j = -1;
  6360. this.each(function(d) { data[++j] = d; });
  6361. return data;
  6362. }
  6363. var bind = key ? bindKey : bindIndex,
  6364. parents = this._parents,
  6365. groups = this._groups;
  6366. if (typeof value !== "function") value = constant$5(value);
  6367. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  6368. var parent = parents[j],
  6369. group = groups[j],
  6370. groupLength = group.length,
  6371. data = value.call(parent, parent && parent.__data__, j, parents),
  6372. dataLength = data.length,
  6373. enterGroup = enter[j] = new Array(dataLength),
  6374. updateGroup = update[j] = new Array(dataLength),
  6375. exitGroup = exit[j] = new Array(groupLength);
  6376. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  6377. // Now connect the enter nodes to their following update node, such that
  6378. // appendChild can insert the materialized enter node before this node,
  6379. // rather than at the end of the parent node.
  6380. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  6381. if (previous = enterGroup[i0]) {
  6382. if (i0 >= i1) i1 = i0 + 1;
  6383. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  6384. previous._next = next || null;
  6385. }
  6386. }
  6387. }
  6388. update = new Selection(update, parents);
  6389. update._enter = enter;
  6390. update._exit = exit;
  6391. return update;
  6392. };
  6393. var selection_exit = function() {
  6394. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  6395. };
  6396. var selection_merge = function(selection) {
  6397. 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) {
  6398. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  6399. if (node = group0[i] || group1[i]) {
  6400. merge[i] = node;
  6401. }
  6402. }
  6403. }
  6404. for (; j < m0; ++j) {
  6405. merges[j] = groups0[j];
  6406. }
  6407. return new Selection(merges, this._parents);
  6408. };
  6409. var selection_order = function() {
  6410. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  6411. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  6412. if (node = group[i]) {
  6413. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  6414. next = node;
  6415. }
  6416. }
  6417. }
  6418. return this;
  6419. };
  6420. var selection_sort = function(compare) {
  6421. if (!compare) compare = ascending$2;
  6422. function compareNode(a, b) {
  6423. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  6424. }
  6425. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  6426. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  6427. if (node = group[i]) {
  6428. sortgroup[i] = node;
  6429. }
  6430. }
  6431. sortgroup.sort(compareNode);
  6432. }
  6433. return new Selection(sortgroups, this._parents).order();
  6434. };
  6435. function ascending$2(a, b) {
  6436. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  6437. }
  6438. var selection_call = function() {
  6439. var callback = arguments[0];
  6440. arguments[0] = this;
  6441. callback.apply(null, arguments);
  6442. return this;
  6443. };
  6444. var selection_nodes = function() {
  6445. var nodes = new Array(this.size()), i = -1;
  6446. this.each(function() { nodes[++i] = this; });
  6447. return nodes;
  6448. };
  6449. var selection_node = function() {
  6450. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  6451. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  6452. var node = group[i];
  6453. if (node) return node;
  6454. }
  6455. }
  6456. return null;
  6457. };
  6458. var selection_size = function() {
  6459. var size = 0;
  6460. this.each(function() { ++size; });
  6461. return size;
  6462. };
  6463. var selection_empty = function() {
  6464. return !this.node();
  6465. };
  6466. var selection_each = function(callback) {
  6467. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  6468. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  6469. if (node = group[i]) callback.call(node, node.__data__, i, group);
  6470. }
  6471. }
  6472. return this;
  6473. };
  6474. function attrRemove(name) {
  6475. return function() {
  6476. this.removeAttribute(name);
  6477. };
  6478. }
  6479. function attrRemoveNS(fullname) {
  6480. return function() {
  6481. this.removeAttributeNS(fullname.space, fullname.local);
  6482. };
  6483. }
  6484. function attrConstant(name, value) {
  6485. return function() {
  6486. this.setAttribute(name, value);
  6487. };
  6488. }
  6489. function attrConstantNS(fullname, value) {
  6490. return function() {
  6491. this.setAttributeNS(fullname.space, fullname.local, value);
  6492. };
  6493. }
  6494. function attrFunction(name, value) {
  6495. return function() {
  6496. var v = value.apply(this, arguments);
  6497. if (v == null) this.removeAttribute(name);
  6498. else this.setAttribute(name, v);
  6499. };
  6500. }
  6501. function attrFunctionNS(fullname, value) {
  6502. return function() {
  6503. var v = value.apply(this, arguments);
  6504. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  6505. else this.setAttributeNS(fullname.space, fullname.local, v);
  6506. };
  6507. }
  6508. var selection_attr = function(name, value) {
  6509. var fullname = namespace(name);
  6510. if (arguments.length < 2) {
  6511. var node = this.node();
  6512. return fullname.local
  6513. ? node.getAttributeNS(fullname.space, fullname.local)
  6514. : node.getAttribute(fullname);
  6515. }
  6516. return this.each((value == null
  6517. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  6518. ? (fullname.local ? attrFunctionNS : attrFunction)
  6519. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  6520. };
  6521. var window = function(node) {
  6522. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  6523. || (node.document && node) // node is a Window
  6524. || node.defaultView; // node is a Document
  6525. };
  6526. function styleRemove(name) {
  6527. return function() {
  6528. this.style.removeProperty(name);
  6529. };
  6530. }
  6531. function styleConstant(name, value, priority) {
  6532. return function() {
  6533. this.style.setProperty(name, value, priority);
  6534. };
  6535. }
  6536. function styleFunction(name, value, priority) {
  6537. return function() {
  6538. var v = value.apply(this, arguments);
  6539. if (v == null) this.style.removeProperty(name);
  6540. else this.style.setProperty(name, v, priority);
  6541. };
  6542. }
  6543. var selection_style = function(name, value, priority) {
  6544. var node;
  6545. return arguments.length > 1
  6546. ? this.each((value == null
  6547. ? styleRemove : typeof value === "function"
  6548. ? styleFunction
  6549. : styleConstant)(name, value, priority == null ? "" : priority))
  6550. : window(node = this.node())
  6551. .getComputedStyle(node, null)
  6552. .getPropertyValue(name);
  6553. };
  6554. function propertyRemove(name) {
  6555. return function() {
  6556. delete this[name];
  6557. };
  6558. }
  6559. function propertyConstant(name, value) {
  6560. return function() {
  6561. this[name] = value;
  6562. };
  6563. }
  6564. function propertyFunction(name, value) {
  6565. return function() {
  6566. var v = value.apply(this, arguments);
  6567. if (v == null) delete this[name];
  6568. else this[name] = v;
  6569. };
  6570. }
  6571. var selection_property = function(name, value) {
  6572. return arguments.length > 1
  6573. ? this.each((value == null
  6574. ? propertyRemove : typeof value === "function"
  6575. ? propertyFunction
  6576. : propertyConstant)(name, value))
  6577. : this.node()[name];
  6578. };
  6579. function classArray(string) {
  6580. return string.trim().split(/^|\s+/);
  6581. }
  6582. function classList(node) {
  6583. return node.classList || new ClassList(node);
  6584. }
  6585. function ClassList(node) {
  6586. this._node = node;
  6587. this._names = classArray(node.getAttribute("class") || "");
  6588. }
  6589. ClassList.prototype = {
  6590. add: function(name) {
  6591. var i = this._names.indexOf(name);
  6592. if (i < 0) {
  6593. this._names.push(name);
  6594. this._node.setAttribute("class", this._names.join(" "));
  6595. }
  6596. },
  6597. remove: function(name) {
  6598. var i = this._names.indexOf(name);
  6599. if (i >= 0) {
  6600. this._names.splice(i, 1);
  6601. this._node.setAttribute("class", this._names.join(" "));
  6602. }
  6603. },
  6604. contains: function(name) {
  6605. return this._names.indexOf(name) >= 0;
  6606. }
  6607. };
  6608. function classedAdd(node, names) {
  6609. var list = classList(node), i = -1, n = names.length;
  6610. while (++i < n) list.add(names[i]);
  6611. }
  6612. function classedRemove(node, names) {
  6613. var list = classList(node), i = -1, n = names.length;
  6614. while (++i < n) list.remove(names[i]);
  6615. }
  6616. function classedTrue(names) {
  6617. return function() {
  6618. classedAdd(this, names);
  6619. };
  6620. }
  6621. function classedFalse(names) {
  6622. return function() {
  6623. classedRemove(this, names);
  6624. };
  6625. }
  6626. function classedFunction(names, value) {
  6627. return function() {
  6628. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  6629. };
  6630. }
  6631. var selection_classed = function(name, value) {
  6632. var names = classArray(name + "");
  6633. if (arguments.length < 2) {
  6634. var list = classList(this.node()), i = -1, n = names.length;
  6635. while (++i < n) if (!list.contains(names[i])) return false;
  6636. return true;
  6637. }
  6638. return this.each((typeof value === "function"
  6639. ? classedFunction : value
  6640. ? classedTrue
  6641. : classedFalse)(names, value));
  6642. };
  6643. function textRemove() {
  6644. this.textContent = "";
  6645. }
  6646. function textConstant(value) {
  6647. return function() {
  6648. this.textContent = value;
  6649. };
  6650. }
  6651. function textFunction(value) {
  6652. return function() {
  6653. var v = value.apply(this, arguments);
  6654. this.textContent = v == null ? "" : v;
  6655. };
  6656. }
  6657. var selection_text = function(value) {
  6658. return arguments.length
  6659. ? this.each(value == null
  6660. ? textRemove : (typeof value === "function"
  6661. ? textFunction
  6662. : textConstant)(value))
  6663. : this.node().textContent;
  6664. };
  6665. function htmlRemove() {
  6666. this.innerHTML = "";
  6667. }
  6668. function htmlConstant(value) {
  6669. return function() {
  6670. this.innerHTML = value;
  6671. };
  6672. }
  6673. function htmlFunction(value) {
  6674. return function() {
  6675. var v = value.apply(this, arguments);
  6676. this.innerHTML = v == null ? "" : v;
  6677. };
  6678. }
  6679. var selection_html = function(value) {
  6680. return arguments.length
  6681. ? this.each(value == null
  6682. ? htmlRemove : (typeof value === "function"
  6683. ? htmlFunction
  6684. : htmlConstant)(value))
  6685. : this.node().innerHTML;
  6686. };
  6687. function raise$1() {
  6688. if (this.nextSibling) this.parentNode.appendChild(this);
  6689. }
  6690. var selection_raise = function() {
  6691. return this.each(raise$1);
  6692. };
  6693. function lower() {
  6694. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  6695. }
  6696. var selection_lower = function() {
  6697. return this.each(lower);
  6698. };
  6699. var selection_append = function(name) {
  6700. var create = typeof name === "function" ? name : creator(name);
  6701. return this.select(function() {
  6702. return this.appendChild(create.apply(this, arguments));
  6703. });
  6704. };
  6705. function constantNull() {
  6706. return null;
  6707. }
  6708. var selection_insert = function(name, before) {
  6709. var create = typeof name === "function" ? name : creator(name),
  6710. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  6711. return this.select(function() {
  6712. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  6713. });
  6714. };
  6715. function remove() {
  6716. var parent = this.parentNode;
  6717. if (parent) parent.removeChild(this);
  6718. }
  6719. var selection_remove = function() {
  6720. return this.each(remove);
  6721. };
  6722. var selection_datum = function(value) {
  6723. return arguments.length
  6724. ? this.property("__data__", value)
  6725. : this.node().__data__;
  6726. };
  6727. function dispatchEvent(node, type, params) {
  6728. var window$$1 = window(node),
  6729. event = window$$1.CustomEvent;
  6730. if (event) {
  6731. event = new event(type, params);
  6732. } else {
  6733. event = window$$1.document.createEvent("Event");
  6734. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  6735. else event.initEvent(type, false, false);
  6736. }
  6737. node.dispatchEvent(event);
  6738. }
  6739. function dispatchConstant(type, params) {
  6740. return function() {
  6741. return dispatchEvent(this, type, params);
  6742. };
  6743. }
  6744. function dispatchFunction(type, params) {
  6745. return function() {
  6746. return dispatchEvent(this, type, params.apply(this, arguments));
  6747. };
  6748. }
  6749. var selection_dispatch = function(type, params) {
  6750. return this.each((typeof params === "function"
  6751. ? dispatchFunction
  6752. : dispatchConstant)(type, params));
  6753. };
  6754. var root = [null];
  6755. function Selection(groups, parents) {
  6756. this._groups = groups;
  6757. this._parents = parents;
  6758. }
  6759. function selection() {
  6760. return new Selection([[document.documentElement]], root);
  6761. }
  6762. Selection.prototype = selection.prototype = {
  6763. constructor: Selection,
  6764. select: selection_select,
  6765. selectAll: selection_selectAll,
  6766. filter: selection_filter,
  6767. data: selection_data,
  6768. enter: selection_enter,
  6769. exit: selection_exit,
  6770. merge: selection_merge,
  6771. order: selection_order,
  6772. sort: selection_sort,
  6773. call: selection_call,
  6774. nodes: selection_nodes,
  6775. node: selection_node,
  6776. size: selection_size,
  6777. empty: selection_empty,
  6778. each: selection_each,
  6779. attr: selection_attr,
  6780. style: selection_style,
  6781. property: selection_property,
  6782. classed: selection_classed,
  6783. text: selection_text,
  6784. html: selection_html,
  6785. raise: selection_raise,
  6786. lower: selection_lower,
  6787. append: selection_append,
  6788. insert: selection_insert,
  6789. remove: selection_remove,
  6790. datum: selection_datum,
  6791. on: selection_on,
  6792. dispatch: selection_dispatch
  6793. };
  6794. var select = function(selector) {
  6795. return typeof selector === "string"
  6796. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  6797. : new Selection([[selector]], root);
  6798. };
  6799. var selectAll = function(selector) {
  6800. return typeof selector === "string"
  6801. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  6802. : new Selection([selector == null ? [] : selector], root);
  6803. };
  6804. var touch = function(node, touches, identifier) {
  6805. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  6806. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  6807. if ((touch = touches[i]).identifier === identifier) {
  6808. return point$5(node, touch);
  6809. }
  6810. }
  6811. return null;
  6812. };
  6813. var touches = function(node, touches) {
  6814. if (touches == null) touches = sourceEvent().touches;
  6815. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  6816. points[i] = point$5(node, touches[i]);
  6817. }
  6818. return points;
  6819. };
  6820. var emptyOn = dispatch("start", "end", "interrupt");
  6821. var emptyTween = [];
  6822. var CREATED = 0;
  6823. var SCHEDULED = 1;
  6824. var STARTING = 2;
  6825. var STARTED = 3;
  6826. var RUNNING = 4;
  6827. var ENDING = 5;
  6828. var ENDED = 6;
  6829. var schedule = function(node, name, id, index, group, timing) {
  6830. var schedules = node.__transition;
  6831. if (!schedules) node.__transition = {};
  6832. else if (id in schedules) return;
  6833. create(node, id, {
  6834. name: name,
  6835. index: index, // For context during callback.
  6836. group: group, // For context during callback.
  6837. on: emptyOn,
  6838. tween: emptyTween,
  6839. time: timing.time,
  6840. delay: timing.delay,
  6841. duration: timing.duration,
  6842. ease: timing.ease,
  6843. timer: null,
  6844. state: CREATED
  6845. });
  6846. };
  6847. function init(node, id) {
  6848. var schedule = node.__transition;
  6849. if (!schedule || !(schedule = schedule[id]) || schedule.state > CREATED) throw new Error("too late");
  6850. return schedule;
  6851. }
  6852. function set$3(node, id) {
  6853. var schedule = node.__transition;
  6854. if (!schedule || !(schedule = schedule[id]) || schedule.state > STARTING) throw new Error("too late");
  6855. return schedule;
  6856. }
  6857. function get$1(node, id) {
  6858. var schedule = node.__transition;
  6859. if (!schedule || !(schedule = schedule[id])) throw new Error("too late");
  6860. return schedule;
  6861. }
  6862. function create(node, id, self) {
  6863. var schedules = node.__transition,
  6864. tween;
  6865. // Initialize the self timer when the transition is created.
  6866. // Note the actual delay is not known until the first callback!
  6867. schedules[id] = self;
  6868. self.timer = timer(schedule, 0, self.time);
  6869. function schedule(elapsed) {
  6870. self.state = SCHEDULED;
  6871. self.timer.restart(start, self.delay, self.time);
  6872. // If the elapsed delay is less than our first sleep, start immediately.
  6873. if (self.delay <= elapsed) start(elapsed - self.delay);
  6874. }
  6875. function start(elapsed) {
  6876. var i, j, n, o;
  6877. // If the state is not SCHEDULED, then we previously errored on start.
  6878. if (self.state !== SCHEDULED) return stop();
  6879. for (i in schedules) {
  6880. o = schedules[i];
  6881. if (o.name !== self.name) continue;
  6882. // While this element already has a starting transition during this frame,
  6883. // defer starting an interrupting transition until that transition has a
  6884. // chance to tick (and possibly end); see d3/d3-transition#54!
  6885. if (o.state === STARTED) return timeout$1(start);
  6886. // Interrupt the active transition, if any.
  6887. // Dispatch the interrupt event.
  6888. if (o.state === RUNNING) {
  6889. o.state = ENDED;
  6890. o.timer.stop();
  6891. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  6892. delete schedules[i];
  6893. }
  6894. // Cancel any pre-empted transitions. No interrupt event is dispatched
  6895. // because the cancelled transitions never started. Note that this also
  6896. // removes this transition from the pending list!
  6897. else if (+i < id) {
  6898. o.state = ENDED;
  6899. o.timer.stop();
  6900. delete schedules[i];
  6901. }
  6902. }
  6903. // Defer the first tick to end of the current frame; see d3/d3#1576.
  6904. // Note the transition may be canceled after start and before the first tick!
  6905. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  6906. // Assuming this is successful, subsequent callbacks go straight to tick.
  6907. timeout$1(function() {
  6908. if (self.state === STARTED) {
  6909. self.state = RUNNING;
  6910. self.timer.restart(tick, self.delay, self.time);
  6911. tick(elapsed);
  6912. }
  6913. });
  6914. // Dispatch the start event.
  6915. // Note this must be done before the tween are initialized.
  6916. self.state = STARTING;
  6917. self.on.call("start", node, node.__data__, self.index, self.group);
  6918. if (self.state !== STARTING) return; // interrupted
  6919. self.state = STARTED;
  6920. // Initialize the tween, deleting null tween.
  6921. tween = new Array(n = self.tween.length);
  6922. for (i = 0, j = -1; i < n; ++i) {
  6923. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  6924. tween[++j] = o;
  6925. }
  6926. }
  6927. tween.length = j + 1;
  6928. }
  6929. function tick(elapsed) {
  6930. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  6931. i = -1,
  6932. n = tween.length;
  6933. while (++i < n) {
  6934. tween[i].call(null, t);
  6935. }
  6936. // Dispatch the end event.
  6937. if (self.state === ENDING) {
  6938. self.on.call("end", node, node.__data__, self.index, self.group);
  6939. stop();
  6940. }
  6941. }
  6942. function stop() {
  6943. self.state = ENDED;
  6944. self.timer.stop();
  6945. delete schedules[id];
  6946. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  6947. delete node.__transition;
  6948. }
  6949. }
  6950. var interrupt = function(node, name) {
  6951. var schedules = node.__transition,
  6952. schedule,
  6953. active,
  6954. empty = true,
  6955. i;
  6956. if (!schedules) return;
  6957. name = name == null ? null : name + "";
  6958. for (i in schedules) {
  6959. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  6960. active = schedule.state > STARTING && schedule.state < ENDING;
  6961. schedule.state = ENDED;
  6962. schedule.timer.stop();
  6963. if (active) schedule.on.call("interrupt", node, node.__data__, schedule.index, schedule.group);
  6964. delete schedules[i];
  6965. }
  6966. if (empty) delete node.__transition;
  6967. };
  6968. var selection_interrupt = function(name) {
  6969. return this.each(function() {
  6970. interrupt(this, name);
  6971. });
  6972. };
  6973. function tweenRemove(id, name) {
  6974. var tween0, tween1;
  6975. return function() {
  6976. var schedule = set$3(this, id),
  6977. tween = schedule.tween;
  6978. // If this node shared tween with the previous node,
  6979. // just assign the updated shared tween and we’re done!
  6980. // Otherwise, copy-on-write.
  6981. if (tween !== tween0) {
  6982. tween1 = tween0 = tween;
  6983. for (var i = 0, n = tween1.length; i < n; ++i) {
  6984. if (tween1[i].name === name) {
  6985. tween1 = tween1.slice();
  6986. tween1.splice(i, 1);
  6987. break;
  6988. }
  6989. }
  6990. }
  6991. schedule.tween = tween1;
  6992. };
  6993. }
  6994. function tweenFunction(id, name, value) {
  6995. var tween0, tween1;
  6996. if (typeof value !== "function") throw new Error;
  6997. return function() {
  6998. var schedule = set$3(this, id),
  6999. tween = schedule.tween;
  7000. // If this node shared tween with the previous node,
  7001. // just assign the updated shared tween and we’re done!
  7002. // Otherwise, copy-on-write.
  7003. if (tween !== tween0) {
  7004. tween1 = (tween0 = tween).slice();
  7005. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  7006. if (tween1[i].name === name) {
  7007. tween1[i] = t;
  7008. break;
  7009. }
  7010. }
  7011. if (i === n) tween1.push(t);
  7012. }
  7013. schedule.tween = tween1;
  7014. };
  7015. }
  7016. var transition_tween = function(name, value) {
  7017. var id = this._id;
  7018. name += "";
  7019. if (arguments.length < 2) {
  7020. var tween = get$1(this.node(), id).tween;
  7021. for (var i = 0, n = tween.length, t; i < n; ++i) {
  7022. if ((t = tween[i]).name === name) {
  7023. return t.value;
  7024. }
  7025. }
  7026. return null;
  7027. }
  7028. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  7029. };
  7030. function tweenValue(transition, name, value) {
  7031. var id = transition._id;
  7032. transition.each(function() {
  7033. var schedule = set$3(this, id);
  7034. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  7035. });
  7036. return function(node) {
  7037. return get$1(node, id).value[name];
  7038. };
  7039. }
  7040. var interpolate$1 = function(a, b) {
  7041. var c;
  7042. return (typeof b === "number" ? interpolateNumber
  7043. : b instanceof color ? interpolateRgb
  7044. : (c = color(b)) ? (b = c, interpolateRgb)
  7045. : interpolateString)(a, b);
  7046. };
  7047. function attrRemove$1(name) {
  7048. return function() {
  7049. this.removeAttribute(name);
  7050. };
  7051. }
  7052. function attrRemoveNS$1(fullname) {
  7053. return function() {
  7054. this.removeAttributeNS(fullname.space, fullname.local);
  7055. };
  7056. }
  7057. function attrConstant$1(name, interpolate$$1, value1) {
  7058. var value00,
  7059. interpolate0;
  7060. return function() {
  7061. var value0 = this.getAttribute(name);
  7062. return value0 === value1 ? null
  7063. : value0 === value00 ? interpolate0
  7064. : interpolate0 = interpolate$$1(value00 = value0, value1);
  7065. };
  7066. }
  7067. function attrConstantNS$1(fullname, interpolate$$1, value1) {
  7068. var value00,
  7069. interpolate0;
  7070. return function() {
  7071. var value0 = this.getAttributeNS(fullname.space, fullname.local);
  7072. return value0 === value1 ? null
  7073. : value0 === value00 ? interpolate0
  7074. : interpolate0 = interpolate$$1(value00 = value0, value1);
  7075. };
  7076. }
  7077. function attrFunction$1(name, interpolate$$1, value) {
  7078. var value00,
  7079. value10,
  7080. interpolate0;
  7081. return function() {
  7082. var value0, value1 = value(this);
  7083. if (value1 == null) return void this.removeAttribute(name);
  7084. value0 = this.getAttribute(name);
  7085. return value0 === value1 ? null
  7086. : value0 === value00 && value1 === value10 ? interpolate0
  7087. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  7088. };
  7089. }
  7090. function attrFunctionNS$1(fullname, interpolate$$1, value) {
  7091. var value00,
  7092. value10,
  7093. interpolate0;
  7094. return function() {
  7095. var value0, value1 = value(this);
  7096. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  7097. value0 = this.getAttributeNS(fullname.space, fullname.local);
  7098. return value0 === value1 ? null
  7099. : value0 === value00 && value1 === value10 ? interpolate0
  7100. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  7101. };
  7102. }
  7103. var transition_attr = function(name, value) {
  7104. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$1;
  7105. return this.attrTween(name, typeof value === "function"
  7106. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  7107. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  7108. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
  7109. };
  7110. function attrTweenNS(fullname, value) {
  7111. function tween() {
  7112. var node = this, i = value.apply(node, arguments);
  7113. return i && function(t) {
  7114. node.setAttributeNS(fullname.space, fullname.local, i(t));
  7115. };
  7116. }
  7117. tween._value = value;
  7118. return tween;
  7119. }
  7120. function attrTween(name, value) {
  7121. function tween() {
  7122. var node = this, i = value.apply(node, arguments);
  7123. return i && function(t) {
  7124. node.setAttribute(name, i(t));
  7125. };
  7126. }
  7127. tween._value = value;
  7128. return tween;
  7129. }
  7130. var transition_attrTween = function(name, value) {
  7131. var key = "attr." + name;
  7132. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  7133. if (value == null) return this.tween(key, null);
  7134. if (typeof value !== "function") throw new Error;
  7135. var fullname = namespace(name);
  7136. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  7137. };
  7138. function delayFunction(id, value) {
  7139. return function() {
  7140. init(this, id).delay = +value.apply(this, arguments);
  7141. };
  7142. }
  7143. function delayConstant(id, value) {
  7144. return value = +value, function() {
  7145. init(this, id).delay = value;
  7146. };
  7147. }
  7148. var transition_delay = function(value) {
  7149. var id = this._id;
  7150. return arguments.length
  7151. ? this.each((typeof value === "function"
  7152. ? delayFunction
  7153. : delayConstant)(id, value))
  7154. : get$1(this.node(), id).delay;
  7155. };
  7156. function durationFunction(id, value) {
  7157. return function() {
  7158. set$3(this, id).duration = +value.apply(this, arguments);
  7159. };
  7160. }
  7161. function durationConstant(id, value) {
  7162. return value = +value, function() {
  7163. set$3(this, id).duration = value;
  7164. };
  7165. }
  7166. var transition_duration = function(value) {
  7167. var id = this._id;
  7168. return arguments.length
  7169. ? this.each((typeof value === "function"
  7170. ? durationFunction
  7171. : durationConstant)(id, value))
  7172. : get$1(this.node(), id).duration;
  7173. };
  7174. function easeConstant(id, value) {
  7175. if (typeof value !== "function") throw new Error;
  7176. return function() {
  7177. set$3(this, id).ease = value;
  7178. };
  7179. }
  7180. var transition_ease = function(value) {
  7181. var id = this._id;
  7182. return arguments.length
  7183. ? this.each(easeConstant(id, value))
  7184. : get$1(this.node(), id).ease;
  7185. };
  7186. var transition_filter = function(match) {
  7187. if (typeof match !== "function") match = matcher$1(match);
  7188. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  7189. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  7190. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  7191. subgroup.push(node);
  7192. }
  7193. }
  7194. }
  7195. return new Transition(subgroups, this._parents, this._name, this._id);
  7196. };
  7197. var transition_merge = function(transition) {
  7198. if (transition._id !== this._id) throw new Error;
  7199. 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) {
  7200. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  7201. if (node = group0[i] || group1[i]) {
  7202. merge[i] = node;
  7203. }
  7204. }
  7205. }
  7206. for (; j < m0; ++j) {
  7207. merges[j] = groups0[j];
  7208. }
  7209. return new Transition(merges, this._parents, this._name, this._id);
  7210. };
  7211. function start$1(name) {
  7212. return (name + "").trim().split(/^|\s+/).every(function(t) {
  7213. var i = t.indexOf(".");
  7214. if (i >= 0) t = t.slice(0, i);
  7215. return !t || t === "start";
  7216. });
  7217. }
  7218. function onFunction(id, name, listener) {
  7219. var on0, on1, sit = start$1(name) ? init : set$3;
  7220. return function() {
  7221. var schedule = sit(this, id),
  7222. on = schedule.on;
  7223. // If this node shared a dispatch with the previous node,
  7224. // just assign the updated shared dispatch and we’re done!
  7225. // Otherwise, copy-on-write.
  7226. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  7227. schedule.on = on1;
  7228. };
  7229. }
  7230. var transition_on = function(name, listener) {
  7231. var id = this._id;
  7232. return arguments.length < 2
  7233. ? get$1(this.node(), id).on.on(name)
  7234. : this.each(onFunction(id, name, listener));
  7235. };
  7236. function removeFunction(id) {
  7237. return function() {
  7238. var parent = this.parentNode;
  7239. for (var i in this.__transition) if (+i !== id) return;
  7240. if (parent) parent.removeChild(this);
  7241. };
  7242. }
  7243. var transition_remove = function() {
  7244. return this.on("end.remove", removeFunction(this._id));
  7245. };
  7246. var transition_select = function(select$$1) {
  7247. var name = this._name,
  7248. id = this._id;
  7249. if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
  7250. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  7251. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  7252. if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
  7253. if ("__data__" in node) subnode.__data__ = node.__data__;
  7254. subgroup[i] = subnode;
  7255. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  7256. }
  7257. }
  7258. }
  7259. return new Transition(subgroups, this._parents, name, id);
  7260. };
  7261. var transition_selectAll = function(select$$1) {
  7262. var name = this._name,
  7263. id = this._id;
  7264. if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
  7265. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  7266. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  7267. if (node = group[i]) {
  7268. for (var children = select$$1.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  7269. if (child = children[k]) {
  7270. schedule(child, name, id, k, children, inherit);
  7271. }
  7272. }
  7273. subgroups.push(children);
  7274. parents.push(node);
  7275. }
  7276. }
  7277. }
  7278. return new Transition(subgroups, parents, name, id);
  7279. };
  7280. var Selection$1 = selection.prototype.constructor;
  7281. var transition_selection = function() {
  7282. return new Selection$1(this._groups, this._parents);
  7283. };
  7284. function styleRemove$1(name, interpolate$$1) {
  7285. var value00,
  7286. value10,
  7287. interpolate0;
  7288. return function() {
  7289. var style = window(this).getComputedStyle(this, null),
  7290. value0 = style.getPropertyValue(name),
  7291. value1 = (this.style.removeProperty(name), style.getPropertyValue(name));
  7292. return value0 === value1 ? null
  7293. : value0 === value00 && value1 === value10 ? interpolate0
  7294. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  7295. };
  7296. }
  7297. function styleRemoveEnd(name) {
  7298. return function() {
  7299. this.style.removeProperty(name);
  7300. };
  7301. }
  7302. function styleConstant$1(name, interpolate$$1, value1) {
  7303. var value00,
  7304. interpolate0;
  7305. return function() {
  7306. var value0 = window(this).getComputedStyle(this, null).getPropertyValue(name);
  7307. return value0 === value1 ? null
  7308. : value0 === value00 ? interpolate0
  7309. : interpolate0 = interpolate$$1(value00 = value0, value1);
  7310. };
  7311. }
  7312. function styleFunction$1(name, interpolate$$1, value) {
  7313. var value00,
  7314. value10,
  7315. interpolate0;
  7316. return function() {
  7317. var style = window(this).getComputedStyle(this, null),
  7318. value0 = style.getPropertyValue(name),
  7319. value1 = value(this);
  7320. if (value1 == null) value1 = (this.style.removeProperty(name), style.getPropertyValue(name));
  7321. return value0 === value1 ? null
  7322. : value0 === value00 && value1 === value10 ? interpolate0
  7323. : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
  7324. };
  7325. }
  7326. var transition_style = function(name, value, priority) {
  7327. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1;
  7328. return value == null ? this
  7329. .styleTween(name, styleRemove$1(name, i))
  7330. .on("end.style." + name, styleRemoveEnd(name))
  7331. : this.styleTween(name, typeof value === "function"
  7332. ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
  7333. : styleConstant$1(name, i, value), priority);
  7334. };
  7335. function styleTween(name, value, priority) {
  7336. function tween() {
  7337. var node = this, i = value.apply(node, arguments);
  7338. return i && function(t) {
  7339. node.style.setProperty(name, i(t), priority);
  7340. };
  7341. }
  7342. tween._value = value;
  7343. return tween;
  7344. }
  7345. var transition_styleTween = function(name, value, priority) {
  7346. var key = "style." + (name += "");
  7347. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  7348. if (value == null) return this.tween(key, null);
  7349. if (typeof value !== "function") throw new Error;
  7350. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  7351. };
  7352. function textConstant$1(value) {
  7353. return function() {
  7354. this.textContent = value;
  7355. };
  7356. }
  7357. function textFunction$1(value) {
  7358. return function() {
  7359. var value1 = value(this);
  7360. this.textContent = value1 == null ? "" : value1;
  7361. };
  7362. }
  7363. var transition_text = function(value) {
  7364. return this.tween("text", typeof value === "function"
  7365. ? textFunction$1(tweenValue(this, "text", value))
  7366. : textConstant$1(value == null ? "" : value + ""));
  7367. };
  7368. var transition_transition = function() {
  7369. var name = this._name,
  7370. id0 = this._id,
  7371. id1 = newId();
  7372. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  7373. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  7374. if (node = group[i]) {
  7375. var inherit = get$1(node, id0);
  7376. schedule(node, name, id1, i, group, {
  7377. time: inherit.time + inherit.delay + inherit.duration,
  7378. delay: 0,
  7379. duration: inherit.duration,
  7380. ease: inherit.ease
  7381. });
  7382. }
  7383. }
  7384. }
  7385. return new Transition(groups, this._parents, name, id1);
  7386. };
  7387. var id = 0;
  7388. function Transition(groups, parents, name, id) {
  7389. this._groups = groups;
  7390. this._parents = parents;
  7391. this._name = name;
  7392. this._id = id;
  7393. }
  7394. function transition(name) {
  7395. return selection().transition(name);
  7396. }
  7397. function newId() {
  7398. return ++id;
  7399. }
  7400. var selection_prototype = selection.prototype;
  7401. Transition.prototype = transition.prototype = {
  7402. constructor: Transition,
  7403. select: transition_select,
  7404. selectAll: transition_selectAll,
  7405. filter: transition_filter,
  7406. merge: transition_merge,
  7407. selection: transition_selection,
  7408. transition: transition_transition,
  7409. call: selection_prototype.call,
  7410. nodes: selection_prototype.nodes,
  7411. node: selection_prototype.node,
  7412. size: selection_prototype.size,
  7413. empty: selection_prototype.empty,
  7414. each: selection_prototype.each,
  7415. on: transition_on,
  7416. attr: transition_attr,
  7417. attrTween: transition_attrTween,
  7418. style: transition_style,
  7419. styleTween: transition_styleTween,
  7420. text: transition_text,
  7421. remove: transition_remove,
  7422. tween: transition_tween,
  7423. delay: transition_delay,
  7424. duration: transition_duration,
  7425. ease: transition_ease
  7426. };
  7427. var defaultTiming = {
  7428. time: null, // Set on use.
  7429. delay: 0,
  7430. duration: 250,
  7431. ease: cubicInOut
  7432. };
  7433. function inherit(node, id) {
  7434. var timing;
  7435. while (!(timing = node.__transition) || !(timing = timing[id])) {
  7436. if (!(node = node.parentNode)) {
  7437. return defaultTiming.time = now(), defaultTiming;
  7438. }
  7439. }
  7440. return timing;
  7441. }
  7442. var selection_transition = function(name) {
  7443. var id,
  7444. timing;
  7445. if (name instanceof Transition) {
  7446. id = name._id, name = name._name;
  7447. } else {
  7448. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  7449. }
  7450. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  7451. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  7452. if (node = group[i]) {
  7453. schedule(node, name, id, i, group, timing || inherit(node, id));
  7454. }
  7455. }
  7456. }
  7457. return new Transition(groups, this._parents, name, id);
  7458. };
  7459. selection.prototype.interrupt = selection_interrupt;
  7460. selection.prototype.transition = selection_transition;
  7461. var root$1 = [null];
  7462. var active = function(node, name) {
  7463. var schedules = node.__transition,
  7464. schedule,
  7465. i;
  7466. if (schedules) {
  7467. name = name == null ? null : name + "";
  7468. for (i in schedules) {
  7469. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  7470. return new Transition([[node]], root$1, name, +i);
  7471. }
  7472. }
  7473. }
  7474. return null;
  7475. };
  7476. var slice$4 = Array.prototype.slice;
  7477. var identity$5 = function(x) {
  7478. return x;
  7479. };
  7480. var top = 1;
  7481. var right = 2;
  7482. var bottom = 3;
  7483. var left = 4;
  7484. var epsilon$2 = 1e-6;
  7485. function translateX(scale0, scale1, d) {
  7486. var x = scale0(d);
  7487. return "translate(" + (isFinite(x) ? x : scale1(d)) + ",0)";
  7488. }
  7489. function translateY(scale0, scale1, d) {
  7490. var y = scale0(d);
  7491. return "translate(0," + (isFinite(y) ? y : scale1(d)) + ")";
  7492. }
  7493. function center(scale) {
  7494. var offset = scale.bandwidth() / 2;
  7495. if (scale.round()) offset = Math.round(offset);
  7496. return function(d) {
  7497. return scale(d) + offset;
  7498. };
  7499. }
  7500. function entering() {
  7501. return !this.__axis;
  7502. }
  7503. function axis(orient, scale) {
  7504. var tickArguments = [],
  7505. tickValues = null,
  7506. tickFormat = null,
  7507. tickSizeInner = 6,
  7508. tickSizeOuter = 6,
  7509. tickPadding = 3;
  7510. function axis(context) {
  7511. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  7512. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$5) : tickFormat,
  7513. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  7514. transform = orient === top || orient === bottom ? translateX : translateY,
  7515. range = scale.range(),
  7516. range0 = range[0] + 0.5,
  7517. range1 = range[range.length - 1] + 0.5,
  7518. position = (scale.bandwidth ? center : identity$5)(scale.copy()),
  7519. selection = context.selection ? context.selection() : context,
  7520. path = selection.selectAll(".domain").data([null]),
  7521. tick = selection.selectAll(".tick").data(values, scale).order(),
  7522. tickExit = tick.exit(),
  7523. tickEnter = tick.enter().append("g").attr("class", "tick"),
  7524. line = tick.select("line"),
  7525. text = tick.select("text"),
  7526. k = orient === top || orient === left ? -1 : 1,
  7527. x, y = orient === left || orient === right ? (x = "x", "y") : (x = "y", "x");
  7528. path = path.merge(path.enter().insert("path", ".tick")
  7529. .attr("class", "domain")
  7530. .attr("stroke", "#000"));
  7531. tick = tick.merge(tickEnter);
  7532. line = line.merge(tickEnter.append("line")
  7533. .attr("stroke", "#000")
  7534. .attr(x + "2", k * tickSizeInner)
  7535. .attr(y + "1", 0.5)
  7536. .attr(y + "2", 0.5));
  7537. text = text.merge(tickEnter.append("text")
  7538. .attr("fill", "#000")
  7539. .attr(x, k * spacing)
  7540. .attr(y, 0.5)
  7541. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  7542. if (context !== selection) {
  7543. path = path.transition(context);
  7544. tick = tick.transition(context);
  7545. line = line.transition(context);
  7546. text = text.transition(context);
  7547. tickExit = tickExit.transition(context)
  7548. .attr("opacity", epsilon$2)
  7549. .attr("transform", function(d) { return transform(position, this.parentNode.__axis || position, d); });
  7550. tickEnter
  7551. .attr("opacity", epsilon$2)
  7552. .attr("transform", function(d) { return transform(this.parentNode.__axis || position, position, d); });
  7553. }
  7554. tickExit.remove();
  7555. path
  7556. .attr("d", orient === left || orient == right
  7557. ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
  7558. : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
  7559. tick
  7560. .attr("opacity", 1)
  7561. .attr("transform", function(d) { return transform(position, position, d); });
  7562. line
  7563. .attr(x + "2", k * tickSizeInner);
  7564. text
  7565. .attr(x, k * spacing)
  7566. .text(format);
  7567. selection.filter(entering)
  7568. .attr("fill", "none")
  7569. .attr("font-size", 10)
  7570. .attr("font-family", "sans-serif")
  7571. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  7572. selection
  7573. .each(function() { this.__axis = position; });
  7574. }
  7575. axis.scale = function(_) {
  7576. return arguments.length ? (scale = _, axis) : scale;
  7577. };
  7578. axis.ticks = function() {
  7579. return tickArguments = slice$4.call(arguments), axis;
  7580. };
  7581. axis.tickArguments = function(_) {
  7582. return arguments.length ? (tickArguments = _ == null ? [] : slice$4.call(_), axis) : tickArguments.slice();
  7583. };
  7584. axis.tickValues = function(_) {
  7585. return arguments.length ? (tickValues = _ == null ? null : slice$4.call(_), axis) : tickValues && tickValues.slice();
  7586. };
  7587. axis.tickFormat = function(_) {
  7588. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  7589. };
  7590. axis.tickSize = function(_) {
  7591. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  7592. };
  7593. axis.tickSizeInner = function(_) {
  7594. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  7595. };
  7596. axis.tickSizeOuter = function(_) {
  7597. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  7598. };
  7599. axis.tickPadding = function(_) {
  7600. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  7601. };
  7602. return axis;
  7603. }
  7604. function axisTop(scale) {
  7605. return axis(top, scale);
  7606. }
  7607. function axisRight(scale) {
  7608. return axis(right, scale);
  7609. }
  7610. function axisBottom(scale) {
  7611. return axis(bottom, scale);
  7612. }
  7613. function axisLeft(scale) {
  7614. return axis(left, scale);
  7615. }
  7616. function defaultSeparation(a, b) {
  7617. return a.parent === b.parent ? 1 : 2;
  7618. }
  7619. function meanX(children) {
  7620. return children.reduce(meanXReduce, 0) / children.length;
  7621. }
  7622. function meanXReduce(x, c) {
  7623. return x + c.x;
  7624. }
  7625. function maxY(children) {
  7626. return 1 + children.reduce(maxYReduce, 0);
  7627. }
  7628. function maxYReduce(y, c) {
  7629. return Math.max(y, c.y);
  7630. }
  7631. function leafLeft(node) {
  7632. var children;
  7633. while (children = node.children) node = children[0];
  7634. return node;
  7635. }
  7636. function leafRight(node) {
  7637. var children;
  7638. while (children = node.children) node = children[children.length - 1];
  7639. return node;
  7640. }
  7641. var cluster = function() {
  7642. var separation = defaultSeparation,
  7643. dx = 1,
  7644. dy = 1,
  7645. nodeSize = false;
  7646. function cluster(root) {
  7647. var previousNode,
  7648. x = 0;
  7649. // First walk, computing the initial x & y values.
  7650. root.eachAfter(function(node) {
  7651. var children = node.children;
  7652. if (children) {
  7653. node.x = meanX(children);
  7654. node.y = maxY(children);
  7655. } else {
  7656. node.x = previousNode ? x += separation(node, previousNode) : 0;
  7657. node.y = 0;
  7658. previousNode = node;
  7659. }
  7660. });
  7661. var left = leafLeft(root),
  7662. right = leafRight(root),
  7663. x0 = left.x - separation(left, right) / 2,
  7664. x1 = right.x + separation(right, left) / 2;
  7665. // Second walk, normalizing x & y to the desired size.
  7666. return root.eachAfter(nodeSize ? function(node) {
  7667. node.x = (node.x - root.x) * dx;
  7668. node.y = (root.y - node.y) * dy;
  7669. } : function(node) {
  7670. node.x = (node.x - x0) / (x1 - x0) * dx;
  7671. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  7672. });
  7673. }
  7674. cluster.separation = function(x) {
  7675. return arguments.length ? (separation = x, cluster) : separation;
  7676. };
  7677. cluster.size = function(x) {
  7678. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  7679. };
  7680. cluster.nodeSize = function(x) {
  7681. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  7682. };
  7683. return cluster;
  7684. };
  7685. var node_each = function(callback) {
  7686. var node = this, current, next = [node], children, i, n;
  7687. do {
  7688. current = next.reverse(), next = [];
  7689. while (node = current.pop()) {
  7690. callback(node), children = node.children;
  7691. if (children) for (i = 0, n = children.length; i < n; ++i) {
  7692. next.push(children[i]);
  7693. }
  7694. }
  7695. } while (next.length);
  7696. return this;
  7697. };
  7698. var node_eachBefore = function(callback) {
  7699. var node = this, nodes = [node], children, i;
  7700. while (node = nodes.pop()) {
  7701. callback(node), children = node.children;
  7702. if (children) for (i = children.length - 1; i >= 0; --i) {
  7703. nodes.push(children[i]);
  7704. }
  7705. }
  7706. return this;
  7707. };
  7708. var node_eachAfter = function(callback) {
  7709. var node = this, nodes = [node], next = [], children, i, n;
  7710. while (node = nodes.pop()) {
  7711. next.push(node), children = node.children;
  7712. if (children) for (i = 0, n = children.length; i < n; ++i) {
  7713. nodes.push(children[i]);
  7714. }
  7715. }
  7716. while (node = next.pop()) {
  7717. callback(node);
  7718. }
  7719. return this;
  7720. };
  7721. var node_sum = function(value) {
  7722. return this.eachAfter(function(node) {
  7723. var sum = +value(node.data) || 0,
  7724. children = node.children,
  7725. i = children && children.length;
  7726. while (--i >= 0) sum += children[i].value;
  7727. node.value = sum;
  7728. });
  7729. };
  7730. var node_sort = function(compare) {
  7731. return this.eachBefore(function(node) {
  7732. if (node.children) {
  7733. node.children.sort(compare);
  7734. }
  7735. });
  7736. };
  7737. var node_path = function(end) {
  7738. var start = this,
  7739. ancestor = leastCommonAncestor(start, end),
  7740. nodes = [start];
  7741. while (start !== ancestor) {
  7742. start = start.parent;
  7743. nodes.push(start);
  7744. }
  7745. var k = nodes.length;
  7746. while (end !== ancestor) {
  7747. nodes.splice(k, 0, end);
  7748. end = end.parent;
  7749. }
  7750. return nodes;
  7751. };
  7752. function leastCommonAncestor(a, b) {
  7753. if (a === b) return a;
  7754. var aNodes = a.ancestors(),
  7755. bNodes = b.ancestors(),
  7756. c = null;
  7757. a = aNodes.pop();
  7758. b = bNodes.pop();
  7759. while (a === b) {
  7760. c = a;
  7761. a = aNodes.pop();
  7762. b = bNodes.pop();
  7763. }
  7764. return c;
  7765. }
  7766. var node_ancestors = function() {
  7767. var node = this, nodes = [node];
  7768. while (node = node.parent) {
  7769. nodes.push(node);
  7770. }
  7771. return nodes;
  7772. };
  7773. var node_descendants = function() {
  7774. var nodes = [];
  7775. this.each(function(node) {
  7776. nodes.push(node);
  7777. });
  7778. return nodes;
  7779. };
  7780. var node_leaves = function() {
  7781. var leaves = [];
  7782. this.eachBefore(function(node) {
  7783. if (!node.children) {
  7784. leaves.push(node);
  7785. }
  7786. });
  7787. return leaves;
  7788. };
  7789. var node_links = function() {
  7790. var root = this, links = [];
  7791. root.each(function(node) {
  7792. if (node !== root) { // Don’t include the root’s parent, if any.
  7793. links.push({source: node.parent, target: node});
  7794. }
  7795. });
  7796. return links;
  7797. };
  7798. function hierarchy(data, children) {
  7799. var root = new Node(data),
  7800. valued = +data.value && (root.value = data.value),
  7801. node,
  7802. nodes = [root],
  7803. child,
  7804. childs,
  7805. i,
  7806. n;
  7807. if (children == null) children = defaultChildren;
  7808. while (node = nodes.pop()) {
  7809. if (valued) node.value = +node.data.value;
  7810. if ((childs = children(node.data)) && (n = childs.length)) {
  7811. node.children = new Array(n);
  7812. for (i = n - 1; i >= 0; --i) {
  7813. nodes.push(child = node.children[i] = new Node(childs[i]));
  7814. child.parent = node;
  7815. child.depth = node.depth + 1;
  7816. }
  7817. }
  7818. }
  7819. return root.eachBefore(computeHeight);
  7820. }
  7821. function node_copy() {
  7822. return hierarchy(this).eachBefore(copyData);
  7823. }
  7824. function defaultChildren(d) {
  7825. return d.children;
  7826. }
  7827. function copyData(node) {
  7828. node.data = node.data.data;
  7829. }
  7830. function computeHeight(node) {
  7831. var height = 0;
  7832. do node.height = height;
  7833. while ((node = node.parent) && (node.height < ++height));
  7834. }
  7835. function Node(data) {
  7836. this.data = data;
  7837. this.depth =
  7838. this.height = 0;
  7839. this.parent = null;
  7840. }
  7841. Node.prototype = hierarchy.prototype = {
  7842. constructor: Node,
  7843. each: node_each,
  7844. eachAfter: node_eachAfter,
  7845. eachBefore: node_eachBefore,
  7846. sum: node_sum,
  7847. sort: node_sort,
  7848. path: node_path,
  7849. ancestors: node_ancestors,
  7850. descendants: node_descendants,
  7851. leaves: node_leaves,
  7852. links: node_links,
  7853. copy: node_copy
  7854. };
  7855. function Node$2(value) {
  7856. this._ = value;
  7857. this.next = null;
  7858. }
  7859. var shuffle$1 = function(array) {
  7860. var i,
  7861. n = (array = array.slice()).length,
  7862. head = null,
  7863. node = head;
  7864. while (n) {
  7865. var next = new Node$2(array[n - 1]);
  7866. if (node) node = node.next = next;
  7867. else node = head = next;
  7868. array[i] = array[--n];
  7869. }
  7870. return {
  7871. head: head,
  7872. tail: node
  7873. };
  7874. };
  7875. var enclose = function(circles) {
  7876. return encloseN(shuffle$1(circles), []);
  7877. };
  7878. function encloses(a, b) {
  7879. var dx = b.x - a.x,
  7880. dy = b.y - a.y,
  7881. dr = a.r - b.r;
  7882. return dr * dr + 1e-6 > dx * dx + dy * dy;
  7883. }
  7884. // Returns the smallest circle that contains circles L and intersects circles B.
  7885. function encloseN(L, B) {
  7886. var circle,
  7887. l0 = null,
  7888. l1 = L.head,
  7889. l2,
  7890. p1;
  7891. switch (B.length) {
  7892. case 1: circle = enclose1(B[0]); break;
  7893. case 2: circle = enclose2(B[0], B[1]); break;
  7894. case 3: circle = enclose3(B[0], B[1], B[2]); break;
  7895. }
  7896. while (l1) {
  7897. p1 = l1._, l2 = l1.next;
  7898. if (!circle || !encloses(circle, p1)) {
  7899. // Temporarily truncate L before l1.
  7900. if (l0) L.tail = l0, l0.next = null;
  7901. else L.head = L.tail = null;
  7902. B.push(p1);
  7903. circle = encloseN(L, B); // Note: reorders L!
  7904. B.pop();
  7905. // Move l1 to the front of L and reconnect the truncated list L.
  7906. if (L.head) l1.next = L.head, L.head = l1;
  7907. else l1.next = null, L.head = L.tail = l1;
  7908. l0 = L.tail, l0.next = l2;
  7909. } else {
  7910. l0 = l1;
  7911. }
  7912. l1 = l2;
  7913. }
  7914. L.tail = l0;
  7915. return circle;
  7916. }
  7917. function enclose1(a) {
  7918. return {
  7919. x: a.x,
  7920. y: a.y,
  7921. r: a.r
  7922. };
  7923. }
  7924. function enclose2(a, b) {
  7925. var x1 = a.x, y1 = a.y, r1 = a.r,
  7926. x2 = b.x, y2 = b.y, r2 = b.r,
  7927. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  7928. l = Math.sqrt(x21 * x21 + y21 * y21);
  7929. return {
  7930. x: (x1 + x2 + x21 / l * r21) / 2,
  7931. y: (y1 + y2 + y21 / l * r21) / 2,
  7932. r: (l + r1 + r2) / 2
  7933. };
  7934. }
  7935. function enclose3(a, b, c) {
  7936. var x1 = a.x, y1 = a.y, r1 = a.r,
  7937. x2 = b.x, y2 = b.y, r2 = b.r,
  7938. x3 = c.x, y3 = c.y, r3 = c.r,
  7939. a2 = 2 * (x1 - x2),
  7940. b2 = 2 * (y1 - y2),
  7941. c2 = 2 * (r2 - r1),
  7942. d2 = x1 * x1 + y1 * y1 - r1 * r1 - x2 * x2 - y2 * y2 + r2 * r2,
  7943. a3 = 2 * (x1 - x3),
  7944. b3 = 2 * (y1 - y3),
  7945. c3 = 2 * (r3 - r1),
  7946. d3 = x1 * x1 + y1 * y1 - r1 * r1 - x3 * x3 - y3 * y3 + r3 * r3,
  7947. ab = a3 * b2 - a2 * b3,
  7948. xa = (b2 * d3 - b3 * d2) / ab - x1,
  7949. xb = (b3 * c2 - b2 * c3) / ab,
  7950. ya = (a3 * d2 - a2 * d3) / ab - y1,
  7951. yb = (a2 * c3 - a3 * c2) / ab,
  7952. A = xb * xb + yb * yb - 1,
  7953. B = 2 * (xa * xb + ya * yb + r1),
  7954. C = xa * xa + ya * ya - r1 * r1,
  7955. r = (-B - Math.sqrt(B * B - 4 * A * C)) / (2 * A);
  7956. return {
  7957. x: xa + xb * r + x1,
  7958. y: ya + yb * r + y1,
  7959. r: r
  7960. };
  7961. }
  7962. function place(a, b, c) {
  7963. var ax = a.x,
  7964. ay = a.y,
  7965. da = b.r + c.r,
  7966. db = a.r + c.r,
  7967. dx = b.x - ax,
  7968. dy = b.y - ay,
  7969. dc = dx * dx + dy * dy;
  7970. if (dc) {
  7971. var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
  7972. y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  7973. c.x = ax + x * dx + y * dy;
  7974. c.y = ay + x * dy - y * dx;
  7975. } else {
  7976. c.x = ax + db;
  7977. c.y = ay;
  7978. }
  7979. }
  7980. function intersects(a, b) {
  7981. var dx = b.x - a.x,
  7982. dy = b.y - a.y,
  7983. dr = a.r + b.r;
  7984. return dr * dr > dx * dx + dy * dy;
  7985. }
  7986. function distance2(circle, x, y) {
  7987. var dx = circle.x - x,
  7988. dy = circle.y - y;
  7989. return dx * dx + dy * dy;
  7990. }
  7991. function Node$1(circle) {
  7992. this._ = circle;
  7993. this.next = null;
  7994. this.previous = null;
  7995. }
  7996. function packEnclose(circles) {
  7997. if (!(n = circles.length)) return 0;
  7998. var a, b, c, n;
  7999. // Place the first circle.
  8000. a = circles[0], a.x = 0, a.y = 0;
  8001. if (!(n > 1)) return a.r;
  8002. // Place the second circle.
  8003. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  8004. if (!(n > 2)) return a.r + b.r;
  8005. // Place the third circle.
  8006. place(b, a, c = circles[2]);
  8007. // Initialize the weighted centroid.
  8008. var aa = a.r * a.r,
  8009. ba = b.r * b.r,
  8010. ca = c.r * c.r,
  8011. oa = aa + ba + ca,
  8012. ox = aa * a.x + ba * b.x + ca * c.x,
  8013. oy = aa * a.y + ba * b.y + ca * c.y,
  8014. cx, cy, i, j, k, sj, sk;
  8015. // Initialize the front-chain using the first three circles a, b and c.
  8016. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  8017. a.next = c.previous = b;
  8018. b.next = a.previous = c;
  8019. c.next = b.previous = a;
  8020. // Attempt to place each remaining circle…
  8021. pack: for (i = 3; i < n; ++i) {
  8022. place(a._, b._, c = circles[i]), c = new Node$1(c);
  8023. // If there are only three elements in the front-chain…
  8024. if ((k = a.previous) === (j = b.next)) {
  8025. // If the new circle intersects the third circle,
  8026. // rotate the front chain to try the next position.
  8027. if (intersects(j._, c._)) {
  8028. a = b, b = j, --i;
  8029. continue pack;
  8030. }
  8031. }
  8032. // Find the closest intersecting circle on the front-chain, if any.
  8033. else {
  8034. sj = j._.r, sk = k._.r;
  8035. do {
  8036. if (sj <= sk) {
  8037. if (intersects(j._, c._)) {
  8038. b = j, a.next = b, b.previous = a, --i;
  8039. continue pack;
  8040. }
  8041. j = j.next, sj += j._.r;
  8042. } else {
  8043. if (intersects(k._, c._)) {
  8044. a = k, a.next = b, b.previous = a, --i;
  8045. continue pack;
  8046. }
  8047. k = k.previous, sk += k._.r;
  8048. }
  8049. } while (j !== k.next);
  8050. }
  8051. // Success! Insert the new circle c between a and b.
  8052. c.previous = a, c.next = b, a.next = b.previous = b = c;
  8053. // Update the weighted centroid.
  8054. oa += ca = c._.r * c._.r;
  8055. ox += ca * c._.x;
  8056. oy += ca * c._.y;
  8057. // Compute the new closest circle a to centroid.
  8058. aa = distance2(a._, cx = ox / oa, cy = oy / oa);
  8059. while ((c = c.next) !== b) {
  8060. if ((ca = distance2(c._, cx, cy)) < aa) {
  8061. a = c, aa = ca;
  8062. }
  8063. }
  8064. b = a.next;
  8065. }
  8066. // Compute the enclosing circle of the front chain.
  8067. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  8068. // Translate the circles to put the enclosing circle around the origin.
  8069. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  8070. return c.r;
  8071. }
  8072. var siblings = function(circles) {
  8073. packEnclose(circles);
  8074. return circles;
  8075. };
  8076. function optional(f) {
  8077. return f == null ? null : required(f);
  8078. }
  8079. function required(f) {
  8080. if (typeof f !== "function") throw new Error;
  8081. return f;
  8082. }
  8083. function constantZero() {
  8084. return 0;
  8085. }
  8086. var constant$6 = function(x) {
  8087. return function() {
  8088. return x;
  8089. };
  8090. };
  8091. function defaultRadius(d) {
  8092. return Math.sqrt(d.value);
  8093. }
  8094. var index = function() {
  8095. var radius = null,
  8096. dx = 1,
  8097. dy = 1,
  8098. padding = constantZero;
  8099. function pack(root) {
  8100. root.x = dx / 2, root.y = dy / 2;
  8101. if (radius) {
  8102. root.eachBefore(radiusLeaf(radius))
  8103. .eachAfter(packChildren(padding, 0.5))
  8104. .eachBefore(translateChild(1));
  8105. } else {
  8106. root.eachBefore(radiusLeaf(defaultRadius))
  8107. .eachAfter(packChildren(constantZero, 1))
  8108. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  8109. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  8110. }
  8111. return root;
  8112. }
  8113. pack.radius = function(x) {
  8114. return arguments.length ? (radius = optional(x), pack) : radius;
  8115. };
  8116. pack.size = function(x) {
  8117. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  8118. };
  8119. pack.padding = function(x) {
  8120. return arguments.length ? (padding = typeof x === "function" ? x : constant$6(+x), pack) : padding;
  8121. };
  8122. return pack;
  8123. };
  8124. function radiusLeaf(radius) {
  8125. return function(node) {
  8126. if (!node.children) {
  8127. node.r = Math.max(0, +radius(node) || 0);
  8128. }
  8129. };
  8130. }
  8131. function packChildren(padding, k) {
  8132. return function(node) {
  8133. if (children = node.children) {
  8134. var children,
  8135. i,
  8136. n = children.length,
  8137. r = padding(node) * k || 0,
  8138. e;
  8139. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  8140. e = packEnclose(children);
  8141. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  8142. node.r = e + r;
  8143. }
  8144. };
  8145. }
  8146. function translateChild(k) {
  8147. return function(node) {
  8148. var parent = node.parent;
  8149. node.r *= k;
  8150. if (parent) {
  8151. node.x = parent.x + k * node.x;
  8152. node.y = parent.y + k * node.y;
  8153. }
  8154. };
  8155. }
  8156. var roundNode = function(node) {
  8157. node.x0 = Math.round(node.x0);
  8158. node.y0 = Math.round(node.y0);
  8159. node.x1 = Math.round(node.x1);
  8160. node.y1 = Math.round(node.y1);
  8161. };
  8162. var treemapDice = function(parent, x0, y0, x1, y1) {
  8163. var nodes = parent.children,
  8164. node,
  8165. i = -1,
  8166. n = nodes.length,
  8167. k = parent.value && (x1 - x0) / parent.value;
  8168. while (++i < n) {
  8169. node = nodes[i], node.y0 = y0, node.y1 = y1;
  8170. node.x0 = x0, node.x1 = x0 += node.value * k;
  8171. }
  8172. };
  8173. var partition = function() {
  8174. var dx = 1,
  8175. dy = 1,
  8176. padding = 0,
  8177. round = false;
  8178. function partition(root) {
  8179. var n = root.height + 1;
  8180. root.x0 =
  8181. root.y0 = padding;
  8182. root.x1 = dx;
  8183. root.y1 = dy / n;
  8184. root.eachBefore(positionNode(dy, n));
  8185. if (round) root.eachBefore(roundNode);
  8186. return root;
  8187. }
  8188. function positionNode(dy, n) {
  8189. return function(node) {
  8190. if (node.children) {
  8191. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  8192. }
  8193. var x0 = node.x0,
  8194. y0 = node.y0,
  8195. x1 = node.x1 - padding,
  8196. y1 = node.y1 - padding;
  8197. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  8198. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  8199. node.x0 = x0;
  8200. node.y0 = y0;
  8201. node.x1 = x1;
  8202. node.y1 = y1;
  8203. };
  8204. }
  8205. partition.round = function(x) {
  8206. return arguments.length ? (round = !!x, partition) : round;
  8207. };
  8208. partition.size = function(x) {
  8209. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  8210. };
  8211. partition.padding = function(x) {
  8212. return arguments.length ? (padding = +x, partition) : padding;
  8213. };
  8214. return partition;
  8215. };
  8216. var keyPrefix$1 = "$";
  8217. var preroot = {depth: -1};
  8218. var ambiguous = {};
  8219. function defaultId(d) {
  8220. return d.id;
  8221. }
  8222. function defaultParentId(d) {
  8223. return d.parentId;
  8224. }
  8225. var stratify = function() {
  8226. var id = defaultId,
  8227. parentId = defaultParentId;
  8228. function stratify(data) {
  8229. var d,
  8230. i,
  8231. n = data.length,
  8232. root,
  8233. parent,
  8234. node,
  8235. nodes = new Array(n),
  8236. nodeId,
  8237. nodeKey,
  8238. nodeByKey = {};
  8239. for (i = 0; i < n; ++i) {
  8240. d = data[i], node = nodes[i] = new Node(d);
  8241. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  8242. nodeKey = keyPrefix$1 + (node.id = nodeId);
  8243. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  8244. }
  8245. }
  8246. for (i = 0; i < n; ++i) {
  8247. node = nodes[i], nodeId = parentId(data[i], i, data);
  8248. if (nodeId == null || !(nodeId += "")) {
  8249. if (root) throw new Error("multiple roots");
  8250. root = node;
  8251. } else {
  8252. parent = nodeByKey[keyPrefix$1 + nodeId];
  8253. if (!parent) throw new Error("missing: " + nodeId);
  8254. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  8255. if (parent.children) parent.children.push(node);
  8256. else parent.children = [node];
  8257. node.parent = parent;
  8258. }
  8259. }
  8260. if (!root) throw new Error("no root");
  8261. root.parent = preroot;
  8262. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  8263. root.parent = null;
  8264. if (n > 0) throw new Error("cycle");
  8265. return root;
  8266. }
  8267. stratify.id = function(x) {
  8268. return arguments.length ? (id = required(x), stratify) : id;
  8269. };
  8270. stratify.parentId = function(x) {
  8271. return arguments.length ? (parentId = required(x), stratify) : parentId;
  8272. };
  8273. return stratify;
  8274. };
  8275. function defaultSeparation$1(a, b) {
  8276. return a.parent === b.parent ? 1 : 2;
  8277. }
  8278. // function radialSeparation(a, b) {
  8279. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  8280. // }
  8281. // This function is used to traverse the left contour of a subtree (or
  8282. // subforest). It returns the successor of v on this contour. This successor is
  8283. // either given by the leftmost child of v or by the thread of v. The function
  8284. // returns null if and only if v is on the highest level of its subtree.
  8285. function nextLeft(v) {
  8286. var children = v.children;
  8287. return children ? children[0] : v.t;
  8288. }
  8289. // This function works analogously to nextLeft.
  8290. function nextRight(v) {
  8291. var children = v.children;
  8292. return children ? children[children.length - 1] : v.t;
  8293. }
  8294. // Shifts the current subtree rooted at w+. This is done by increasing
  8295. // prelim(w+) and mod(w+) by shift.
  8296. function moveSubtree(wm, wp, shift) {
  8297. var change = shift / (wp.i - wm.i);
  8298. wp.c -= change;
  8299. wp.s += shift;
  8300. wm.c += change;
  8301. wp.z += shift;
  8302. wp.m += shift;
  8303. }
  8304. // All other shifts, applied to the smaller subtrees between w- and w+, are
  8305. // performed by this function. To prepare the shifts, we have to adjust
  8306. // change(w+), shift(w+), and change(w-).
  8307. function executeShifts(v) {
  8308. var shift = 0,
  8309. change = 0,
  8310. children = v.children,
  8311. i = children.length,
  8312. w;
  8313. while (--i >= 0) {
  8314. w = children[i];
  8315. w.z += shift;
  8316. w.m += shift;
  8317. shift += w.s + (change += w.c);
  8318. }
  8319. }
  8320. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  8321. // returns the specified (default) ancestor.
  8322. function nextAncestor(vim, v, ancestor) {
  8323. return vim.a.parent === v.parent ? vim.a : ancestor;
  8324. }
  8325. function TreeNode(node, i) {
  8326. this._ = node;
  8327. this.parent = null;
  8328. this.children = null;
  8329. this.A = null; // default ancestor
  8330. this.a = this; // ancestor
  8331. this.z = 0; // prelim
  8332. this.m = 0; // mod
  8333. this.c = 0; // change
  8334. this.s = 0; // shift
  8335. this.t = null; // thread
  8336. this.i = i; // number
  8337. }
  8338. TreeNode.prototype = Object.create(Node.prototype);
  8339. function treeRoot(root) {
  8340. var tree = new TreeNode(root, 0),
  8341. node,
  8342. nodes = [tree],
  8343. child,
  8344. children,
  8345. i,
  8346. n;
  8347. while (node = nodes.pop()) {
  8348. if (children = node._.children) {
  8349. node.children = new Array(n = children.length);
  8350. for (i = n - 1; i >= 0; --i) {
  8351. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  8352. child.parent = node;
  8353. }
  8354. }
  8355. }
  8356. (tree.parent = new TreeNode(null, 0)).children = [tree];
  8357. return tree;
  8358. }
  8359. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  8360. var tree = function() {
  8361. var separation = defaultSeparation$1,
  8362. dx = 1,
  8363. dy = 1,
  8364. nodeSize = null;
  8365. function tree(root) {
  8366. var t = treeRoot(root);
  8367. // Compute the layout using Buchheim et al.’s algorithm.
  8368. t.eachAfter(firstWalk), t.parent.m = -t.z;
  8369. t.eachBefore(secondWalk);
  8370. // If a fixed node size is specified, scale x and y.
  8371. if (nodeSize) root.eachBefore(sizeNode);
  8372. // If a fixed tree size is specified, scale x and y based on the extent.
  8373. // Compute the left-most, right-most, and depth-most nodes for extents.
  8374. else {
  8375. var left = root,
  8376. right = root,
  8377. bottom = root;
  8378. root.eachBefore(function(node) {
  8379. if (node.x < left.x) left = node;
  8380. if (node.x > right.x) right = node;
  8381. if (node.depth > bottom.depth) bottom = node;
  8382. });
  8383. var s = left === right ? 1 : separation(left, right) / 2,
  8384. tx = s - left.x,
  8385. kx = dx / (right.x + s + tx),
  8386. ky = dy / (bottom.depth || 1);
  8387. root.eachBefore(function(node) {
  8388. node.x = (node.x + tx) * kx;
  8389. node.y = node.depth * ky;
  8390. });
  8391. }
  8392. return root;
  8393. }
  8394. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  8395. // applied recursively to the children of v, as well as the function
  8396. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  8397. // node v is placed to the midpoint of its outermost children.
  8398. function firstWalk(v) {
  8399. var children = v.children,
  8400. siblings = v.parent.children,
  8401. w = v.i ? siblings[v.i - 1] : null;
  8402. if (children) {
  8403. executeShifts(v);
  8404. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  8405. if (w) {
  8406. v.z = w.z + separation(v._, w._);
  8407. v.m = v.z - midpoint;
  8408. } else {
  8409. v.z = midpoint;
  8410. }
  8411. } else if (w) {
  8412. v.z = w.z + separation(v._, w._);
  8413. }
  8414. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  8415. }
  8416. // Computes all real x-coordinates by summing up the modifiers recursively.
  8417. function secondWalk(v) {
  8418. v._.x = v.z + v.parent.m;
  8419. v.m += v.parent.m;
  8420. }
  8421. // The core of the algorithm. Here, a new subtree is combined with the
  8422. // previous subtrees. Threads are used to traverse the inside and outside
  8423. // contours of the left and right subtree up to the highest common level. The
  8424. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  8425. // superscript o means outside and i means inside, the subscript - means left
  8426. // subtree and + means right subtree. For summing up the modifiers along the
  8427. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  8428. // nodes of the inside contours conflict, we compute the left one of the
  8429. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  8430. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  8431. // Finally, we add a new thread (if necessary).
  8432. function apportion(v, w, ancestor) {
  8433. if (w) {
  8434. var vip = v,
  8435. vop = v,
  8436. vim = w,
  8437. vom = vip.parent.children[0],
  8438. sip = vip.m,
  8439. sop = vop.m,
  8440. sim = vim.m,
  8441. som = vom.m,
  8442. shift;
  8443. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  8444. vom = nextLeft(vom);
  8445. vop = nextRight(vop);
  8446. vop.a = v;
  8447. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  8448. if (shift > 0) {
  8449. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  8450. sip += shift;
  8451. sop += shift;
  8452. }
  8453. sim += vim.m;
  8454. sip += vip.m;
  8455. som += vom.m;
  8456. sop += vop.m;
  8457. }
  8458. if (vim && !nextRight(vop)) {
  8459. vop.t = vim;
  8460. vop.m += sim - sop;
  8461. }
  8462. if (vip && !nextLeft(vom)) {
  8463. vom.t = vip;
  8464. vom.m += sip - som;
  8465. ancestor = v;
  8466. }
  8467. }
  8468. return ancestor;
  8469. }
  8470. function sizeNode(node) {
  8471. node.x *= dx;
  8472. node.y = node.depth * dy;
  8473. }
  8474. tree.separation = function(x) {
  8475. return arguments.length ? (separation = x, tree) : separation;
  8476. };
  8477. tree.size = function(x) {
  8478. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  8479. };
  8480. tree.nodeSize = function(x) {
  8481. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  8482. };
  8483. return tree;
  8484. };
  8485. var treemapSlice = function(parent, x0, y0, x1, y1) {
  8486. var nodes = parent.children,
  8487. node,
  8488. i = -1,
  8489. n = nodes.length,
  8490. k = parent.value && (y1 - y0) / parent.value;
  8491. while (++i < n) {
  8492. node = nodes[i], node.x0 = x0, node.x1 = x1;
  8493. node.y0 = y0, node.y1 = y0 += node.value * k;
  8494. }
  8495. };
  8496. var phi = (1 + Math.sqrt(5)) / 2;
  8497. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  8498. var rows = [],
  8499. nodes = parent.children,
  8500. row,
  8501. nodeValue,
  8502. i0 = 0,
  8503. i1,
  8504. n = nodes.length,
  8505. dx, dy,
  8506. value = parent.value,
  8507. sumValue,
  8508. minValue,
  8509. maxValue,
  8510. newRatio,
  8511. minRatio,
  8512. alpha,
  8513. beta;
  8514. while (i0 < n) {
  8515. dx = x1 - x0, dy = y1 - y0;
  8516. minValue = maxValue = sumValue = nodes[i0].value;
  8517. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  8518. beta = sumValue * sumValue * alpha;
  8519. minRatio = Math.max(maxValue / beta, beta / minValue);
  8520. // Keep adding nodes while the aspect ratio maintains or improves.
  8521. for (i1 = i0 + 1; i1 < n; ++i1) {
  8522. sumValue += nodeValue = nodes[i1].value;
  8523. if (nodeValue < minValue) minValue = nodeValue;
  8524. if (nodeValue > maxValue) maxValue = nodeValue;
  8525. beta = sumValue * sumValue * alpha;
  8526. newRatio = Math.max(maxValue / beta, beta / minValue);
  8527. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  8528. minRatio = newRatio;
  8529. }
  8530. // Position and record the row orientation.
  8531. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  8532. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  8533. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  8534. value -= sumValue, i0 = i1;
  8535. }
  8536. return rows;
  8537. }
  8538. var squarify = (function custom(ratio) {
  8539. function squarify(parent, x0, y0, x1, y1) {
  8540. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  8541. }
  8542. squarify.ratio = function(x) {
  8543. return custom((x = +x) > 1 ? x : 1);
  8544. };
  8545. return squarify;
  8546. })(phi);
  8547. var index$1 = function() {
  8548. var tile = squarify,
  8549. round = false,
  8550. dx = 1,
  8551. dy = 1,
  8552. paddingStack = [0],
  8553. paddingInner = constantZero,
  8554. paddingTop = constantZero,
  8555. paddingRight = constantZero,
  8556. paddingBottom = constantZero,
  8557. paddingLeft = constantZero;
  8558. function treemap(root) {
  8559. root.x0 =
  8560. root.y0 = 0;
  8561. root.x1 = dx;
  8562. root.y1 = dy;
  8563. root.eachBefore(positionNode);
  8564. paddingStack = [0];
  8565. if (round) root.eachBefore(roundNode);
  8566. return root;
  8567. }
  8568. function positionNode(node) {
  8569. var p = paddingStack[node.depth],
  8570. x0 = node.x0 + p,
  8571. y0 = node.y0 + p,
  8572. x1 = node.x1 - p,
  8573. y1 = node.y1 - p;
  8574. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  8575. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  8576. node.x0 = x0;
  8577. node.y0 = y0;
  8578. node.x1 = x1;
  8579. node.y1 = y1;
  8580. if (node.children) {
  8581. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  8582. x0 += paddingLeft(node) - p;
  8583. y0 += paddingTop(node) - p;
  8584. x1 -= paddingRight(node) - p;
  8585. y1 -= paddingBottom(node) - p;
  8586. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  8587. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  8588. tile(node, x0, y0, x1, y1);
  8589. }
  8590. }
  8591. treemap.round = function(x) {
  8592. return arguments.length ? (round = !!x, treemap) : round;
  8593. };
  8594. treemap.size = function(x) {
  8595. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  8596. };
  8597. treemap.tile = function(x) {
  8598. return arguments.length ? (tile = required(x), treemap) : tile;
  8599. };
  8600. treemap.padding = function(x) {
  8601. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  8602. };
  8603. treemap.paddingInner = function(x) {
  8604. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$6(+x), treemap) : paddingInner;
  8605. };
  8606. treemap.paddingOuter = function(x) {
  8607. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  8608. };
  8609. treemap.paddingTop = function(x) {
  8610. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$6(+x), treemap) : paddingTop;
  8611. };
  8612. treemap.paddingRight = function(x) {
  8613. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$6(+x), treemap) : paddingRight;
  8614. };
  8615. treemap.paddingBottom = function(x) {
  8616. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$6(+x), treemap) : paddingBottom;
  8617. };
  8618. treemap.paddingLeft = function(x) {
  8619. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$6(+x), treemap) : paddingLeft;
  8620. };
  8621. return treemap;
  8622. };
  8623. var binary = function(parent, x0, y0, x1, y1) {
  8624. var nodes = parent.children,
  8625. i, n = nodes.length,
  8626. sum, sums = new Array(n + 1);
  8627. for (sums[0] = sum = i = 0; i < n; ++i) {
  8628. sums[i + 1] = sum += nodes[i].value;
  8629. }
  8630. partition(0, n, parent.value, x0, y0, x1, y1);
  8631. function partition(i, j, value, x0, y0, x1, y1) {
  8632. if (i >= j - 1) {
  8633. var node = nodes[i];
  8634. node.x0 = x0, node.y0 = y0;
  8635. node.x1 = x1, node.y1 = y1;
  8636. return;
  8637. }
  8638. var valueOffset = sums[i],
  8639. valueTarget = (value / 2) + valueOffset,
  8640. k = i + 1,
  8641. hi = j - 1;
  8642. while (k < hi) {
  8643. var mid = k + hi >>> 1;
  8644. if (sums[mid] < valueTarget) k = mid + 1;
  8645. else hi = mid;
  8646. }
  8647. var valueLeft = sums[k] - valueOffset,
  8648. valueRight = value - valueLeft;
  8649. if ((y1 - y0) > (x1 - x0)) {
  8650. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  8651. partition(i, k, valueLeft, x0, y0, x1, yk);
  8652. partition(k, j, valueRight, x0, yk, x1, y1);
  8653. } else {
  8654. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  8655. partition(i, k, valueLeft, x0, y0, xk, y1);
  8656. partition(k, j, valueRight, xk, y0, x1, y1);
  8657. }
  8658. }
  8659. };
  8660. var sliceDice = function(parent, x0, y0, x1, y1) {
  8661. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  8662. };
  8663. var resquarify = (function custom(ratio) {
  8664. function resquarify(parent, x0, y0, x1, y1) {
  8665. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  8666. var rows,
  8667. row,
  8668. nodes,
  8669. i,
  8670. j = -1,
  8671. n,
  8672. m = rows.length,
  8673. value = parent.value;
  8674. while (++j < m) {
  8675. row = rows[j], nodes = row.children;
  8676. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  8677. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  8678. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  8679. value -= row.value;
  8680. }
  8681. } else {
  8682. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  8683. rows.ratio = ratio;
  8684. }
  8685. }
  8686. resquarify.ratio = function(x) {
  8687. return custom((x = +x) > 1 ? x : 1);
  8688. };
  8689. return resquarify;
  8690. })(phi);
  8691. var center$1 = function(x, y) {
  8692. var nodes;
  8693. if (x == null) x = 0;
  8694. if (y == null) y = 0;
  8695. function force() {
  8696. var i,
  8697. n = nodes.length,
  8698. node,
  8699. sx = 0,
  8700. sy = 0;
  8701. for (i = 0; i < n; ++i) {
  8702. node = nodes[i], sx += node.x, sy += node.y;
  8703. }
  8704. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  8705. node = nodes[i], node.x -= sx, node.y -= sy;
  8706. }
  8707. }
  8708. force.initialize = function(_) {
  8709. nodes = _;
  8710. };
  8711. force.x = function(_) {
  8712. return arguments.length ? (x = +_, force) : x;
  8713. };
  8714. force.y = function(_) {
  8715. return arguments.length ? (y = +_, force) : y;
  8716. };
  8717. return force;
  8718. };
  8719. var constant$7 = function(x) {
  8720. return function() {
  8721. return x;
  8722. };
  8723. };
  8724. var jiggle = function() {
  8725. return (Math.random() - 0.5) * 1e-6;
  8726. };
  8727. function x$1(d) {
  8728. return d.x + d.vx;
  8729. }
  8730. function y$1(d) {
  8731. return d.y + d.vy;
  8732. }
  8733. var collide = function(radius) {
  8734. var nodes,
  8735. radii,
  8736. strength = 1,
  8737. iterations = 1;
  8738. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  8739. function force() {
  8740. var i, n = nodes.length,
  8741. tree,
  8742. node,
  8743. xi,
  8744. yi,
  8745. ri,
  8746. ri2;
  8747. for (var k = 0; k < iterations; ++k) {
  8748. tree = quadtree(nodes, x$1, y$1).visitAfter(prepare);
  8749. for (i = 0; i < n; ++i) {
  8750. node = nodes[i];
  8751. ri = radii[i], ri2 = ri * ri;
  8752. xi = node.x + node.vx;
  8753. yi = node.y + node.vy;
  8754. tree.visit(apply);
  8755. }
  8756. }
  8757. function apply(quad, x0, y0, x1, y1) {
  8758. var data = quad.data, rj = quad.r, r = ri + rj;
  8759. if (data) {
  8760. if (data.index > i) {
  8761. var x = xi - data.x - data.vx,
  8762. y = yi - data.y - data.vy,
  8763. l = x * x + y * y;
  8764. if (l < r * r) {
  8765. if (x === 0) x = jiggle(), l += x * x;
  8766. if (y === 0) y = jiggle(), l += y * y;
  8767. l = (r - (l = Math.sqrt(l))) / l * strength;
  8768. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  8769. node.vy += (y *= l) * r;
  8770. data.vx -= x * (r = 1 - r);
  8771. data.vy -= y * r;
  8772. }
  8773. }
  8774. return;
  8775. }
  8776. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  8777. }
  8778. }
  8779. function prepare(quad) {
  8780. if (quad.data) return quad.r = radii[quad.data.index];
  8781. for (var i = quad.r = 0; i < 4; ++i) {
  8782. if (quad[i] && quad[i].r > quad.r) {
  8783. quad.r = quad[i].r;
  8784. }
  8785. }
  8786. }
  8787. function initialize() {
  8788. if (!nodes) return;
  8789. var i, n = nodes.length;
  8790. radii = new Array(n);
  8791. for (i = 0; i < n; ++i) radii[i] = +radius(nodes[i], i, nodes);
  8792. }
  8793. force.initialize = function(_) {
  8794. nodes = _;
  8795. initialize();
  8796. };
  8797. force.iterations = function(_) {
  8798. return arguments.length ? (iterations = +_, force) : iterations;
  8799. };
  8800. force.strength = function(_) {
  8801. return arguments.length ? (strength = +_, force) : strength;
  8802. };
  8803. force.radius = function(_) {
  8804. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  8805. };
  8806. return force;
  8807. };
  8808. function index$2(d, i) {
  8809. return i;
  8810. }
  8811. function find(nodeById, nodeId) {
  8812. var node = nodeById.get(nodeId);
  8813. if (!node) throw new Error("missing: " + nodeId);
  8814. return node;
  8815. }
  8816. var link = function(links) {
  8817. var id = index$2,
  8818. strength = defaultStrength,
  8819. strengths,
  8820. distance = constant$7(30),
  8821. distances,
  8822. nodes,
  8823. count,
  8824. bias,
  8825. iterations = 1;
  8826. if (links == null) links = [];
  8827. function defaultStrength(link) {
  8828. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  8829. }
  8830. function force(alpha) {
  8831. for (var k = 0, n = links.length; k < iterations; ++k) {
  8832. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  8833. link = links[i], source = link.source, target = link.target;
  8834. x = target.x + target.vx - source.x - source.vx || jiggle();
  8835. y = target.y + target.vy - source.y - source.vy || jiggle();
  8836. l = Math.sqrt(x * x + y * y);
  8837. l = (l - distances[i]) / l * alpha * strengths[i];
  8838. x *= l, y *= l;
  8839. target.vx -= x * (b = bias[i]);
  8840. target.vy -= y * b;
  8841. source.vx += x * (b = 1 - b);
  8842. source.vy += y * b;
  8843. }
  8844. }
  8845. }
  8846. function initialize() {
  8847. if (!nodes) return;
  8848. var i,
  8849. n = nodes.length,
  8850. m = links.length,
  8851. nodeById = map$1(nodes, id),
  8852. link;
  8853. for (i = 0, count = new Array(n); i < n; ++i) {
  8854. count[i] = 0;
  8855. }
  8856. for (i = 0; i < m; ++i) {
  8857. link = links[i], link.index = i;
  8858. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  8859. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  8860. ++count[link.source.index], ++count[link.target.index];
  8861. }
  8862. for (i = 0, bias = new Array(m); i < m; ++i) {
  8863. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  8864. }
  8865. strengths = new Array(m), initializeStrength();
  8866. distances = new Array(m), initializeDistance();
  8867. }
  8868. function initializeStrength() {
  8869. if (!nodes) return;
  8870. for (var i = 0, n = links.length; i < n; ++i) {
  8871. strengths[i] = +strength(links[i], i, links);
  8872. }
  8873. }
  8874. function initializeDistance() {
  8875. if (!nodes) return;
  8876. for (var i = 0, n = links.length; i < n; ++i) {
  8877. distances[i] = +distance(links[i], i, links);
  8878. }
  8879. }
  8880. force.initialize = function(_) {
  8881. nodes = _;
  8882. initialize();
  8883. };
  8884. force.links = function(_) {
  8885. return arguments.length ? (links = _, initialize(), force) : links;
  8886. };
  8887. force.id = function(_) {
  8888. return arguments.length ? (id = _, force) : id;
  8889. };
  8890. force.iterations = function(_) {
  8891. return arguments.length ? (iterations = +_, force) : iterations;
  8892. };
  8893. force.strength = function(_) {
  8894. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  8895. };
  8896. force.distance = function(_) {
  8897. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  8898. };
  8899. return force;
  8900. };
  8901. function x$2(d) {
  8902. return d.x;
  8903. }
  8904. function y$2(d) {
  8905. return d.y;
  8906. }
  8907. var initialRadius = 10;
  8908. var initialAngle = Math.PI * (3 - Math.sqrt(5));
  8909. var simulation = function(nodes) {
  8910. var simulation,
  8911. alpha = 1,
  8912. alphaMin = 0.001,
  8913. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  8914. alphaTarget = 0,
  8915. velocityDecay = 0.6,
  8916. forces = map$1(),
  8917. stepper = timer(step),
  8918. event = dispatch("tick", "end");
  8919. if (nodes == null) nodes = [];
  8920. function step() {
  8921. tick();
  8922. event.call("tick", simulation);
  8923. if (alpha < alphaMin) {
  8924. stepper.stop();
  8925. event.call("end", simulation);
  8926. }
  8927. }
  8928. function tick() {
  8929. var i, n = nodes.length, node;
  8930. alpha += (alphaTarget - alpha) * alphaDecay;
  8931. forces.each(function(force) {
  8932. force(alpha);
  8933. });
  8934. for (i = 0; i < n; ++i) {
  8935. node = nodes[i];
  8936. if (node.fx == null) node.x += node.vx *= velocityDecay;
  8937. else node.x = node.fx, node.vx = 0;
  8938. if (node.fy == null) node.y += node.vy *= velocityDecay;
  8939. else node.y = node.fy, node.vy = 0;
  8940. }
  8941. }
  8942. function initializeNodes() {
  8943. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  8944. node = nodes[i], node.index = i;
  8945. if (isNaN(node.x) || isNaN(node.y)) {
  8946. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  8947. node.x = radius * Math.cos(angle);
  8948. node.y = radius * Math.sin(angle);
  8949. }
  8950. if (isNaN(node.vx) || isNaN(node.vy)) {
  8951. node.vx = node.vy = 0;
  8952. }
  8953. }
  8954. }
  8955. function initializeForce(force) {
  8956. if (force.initialize) force.initialize(nodes);
  8957. return force;
  8958. }
  8959. initializeNodes();
  8960. return simulation = {
  8961. tick: tick,
  8962. restart: function() {
  8963. return stepper.restart(step), simulation;
  8964. },
  8965. stop: function() {
  8966. return stepper.stop(), simulation;
  8967. },
  8968. nodes: function(_) {
  8969. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  8970. },
  8971. alpha: function(_) {
  8972. return arguments.length ? (alpha = +_, simulation) : alpha;
  8973. },
  8974. alphaMin: function(_) {
  8975. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  8976. },
  8977. alphaDecay: function(_) {
  8978. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  8979. },
  8980. alphaTarget: function(_) {
  8981. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  8982. },
  8983. velocityDecay: function(_) {
  8984. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  8985. },
  8986. force: function(name, _) {
  8987. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  8988. },
  8989. find: function(x, y, radius) {
  8990. var i = 0,
  8991. n = nodes.length,
  8992. dx,
  8993. dy,
  8994. d2,
  8995. node,
  8996. closest;
  8997. if (radius == null) radius = Infinity;
  8998. else radius *= radius;
  8999. for (i = 0; i < n; ++i) {
  9000. node = nodes[i];
  9001. dx = x - node.x;
  9002. dy = y - node.y;
  9003. d2 = dx * dx + dy * dy;
  9004. if (d2 < radius) closest = node, radius = d2;
  9005. }
  9006. return closest;
  9007. },
  9008. on: function(name, _) {
  9009. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  9010. }
  9011. };
  9012. };
  9013. var manyBody = function() {
  9014. var nodes,
  9015. node,
  9016. alpha,
  9017. strength = constant$7(-30),
  9018. strengths,
  9019. distanceMin2 = 1,
  9020. distanceMax2 = Infinity,
  9021. theta2 = 0.81;
  9022. function force(_) {
  9023. var i, n = nodes.length, tree = quadtree(nodes, x$2, y$2).visitAfter(accumulate);
  9024. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  9025. }
  9026. function initialize() {
  9027. if (!nodes) return;
  9028. var i, n = nodes.length;
  9029. strengths = new Array(n);
  9030. for (i = 0; i < n; ++i) strengths[i] = +strength(nodes[i], i, nodes);
  9031. }
  9032. function accumulate(quad) {
  9033. var strength = 0, q, c, x$$1, y$$1, i;
  9034. // For internal nodes, accumulate forces from child quadrants.
  9035. if (quad.length) {
  9036. for (x$$1 = y$$1 = i = 0; i < 4; ++i) {
  9037. if ((q = quad[i]) && (c = q.value)) {
  9038. strength += c, x$$1 += c * q.x, y$$1 += c * q.y;
  9039. }
  9040. }
  9041. quad.x = x$$1 / strength;
  9042. quad.y = y$$1 / strength;
  9043. }
  9044. // For leaf nodes, accumulate forces from coincident quadrants.
  9045. else {
  9046. q = quad;
  9047. q.x = q.data.x;
  9048. q.y = q.data.y;
  9049. do strength += strengths[q.data.index];
  9050. while (q = q.next);
  9051. }
  9052. quad.value = strength;
  9053. }
  9054. function apply(quad, x1, _, x2) {
  9055. if (!quad.value) return true;
  9056. var x$$1 = quad.x - node.x,
  9057. y$$1 = quad.y - node.y,
  9058. w = x2 - x1,
  9059. l = x$$1 * x$$1 + y$$1 * y$$1;
  9060. // Apply the Barnes-Hut approximation if possible.
  9061. // Limit forces for very close nodes; randomize direction if coincident.
  9062. if (w * w / theta2 < l) {
  9063. if (l < distanceMax2) {
  9064. if (x$$1 === 0) x$$1 = jiggle(), l += x$$1 * x$$1;
  9065. if (y$$1 === 0) y$$1 = jiggle(), l += y$$1 * y$$1;
  9066. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  9067. node.vx += x$$1 * quad.value * alpha / l;
  9068. node.vy += y$$1 * quad.value * alpha / l;
  9069. }
  9070. return true;
  9071. }
  9072. // Otherwise, process points directly.
  9073. else if (quad.length || l >= distanceMax2) return;
  9074. // Limit forces for very close nodes; randomize direction if coincident.
  9075. if (quad.data !== node || quad.next) {
  9076. if (x$$1 === 0) x$$1 = jiggle(), l += x$$1 * x$$1;
  9077. if (y$$1 === 0) y$$1 = jiggle(), l += y$$1 * y$$1;
  9078. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  9079. }
  9080. do if (quad.data !== node) {
  9081. w = strengths[quad.data.index] * alpha / l;
  9082. node.vx += x$$1 * w;
  9083. node.vy += y$$1 * w;
  9084. } while (quad = quad.next);
  9085. }
  9086. force.initialize = function(_) {
  9087. nodes = _;
  9088. initialize();
  9089. };
  9090. force.strength = function(_) {
  9091. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  9092. };
  9093. force.distanceMin = function(_) {
  9094. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  9095. };
  9096. force.distanceMax = function(_) {
  9097. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  9098. };
  9099. force.theta = function(_) {
  9100. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  9101. };
  9102. return force;
  9103. };
  9104. var x$3 = function(x) {
  9105. var strength = constant$7(0.1),
  9106. nodes,
  9107. strengths,
  9108. xz;
  9109. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  9110. function force(alpha) {
  9111. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  9112. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  9113. }
  9114. }
  9115. function initialize() {
  9116. if (!nodes) return;
  9117. var i, n = nodes.length;
  9118. strengths = new Array(n);
  9119. xz = new Array(n);
  9120. for (i = 0; i < n; ++i) {
  9121. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  9122. }
  9123. }
  9124. force.initialize = function(_) {
  9125. nodes = _;
  9126. initialize();
  9127. };
  9128. force.strength = function(_) {
  9129. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  9130. };
  9131. force.x = function(_) {
  9132. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  9133. };
  9134. return force;
  9135. };
  9136. var y$3 = function(y) {
  9137. var strength = constant$7(0.1),
  9138. nodes,
  9139. strengths,
  9140. yz;
  9141. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  9142. function force(alpha) {
  9143. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  9144. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  9145. }
  9146. }
  9147. function initialize() {
  9148. if (!nodes) return;
  9149. var i, n = nodes.length;
  9150. strengths = new Array(n);
  9151. yz = new Array(n);
  9152. for (i = 0; i < n; ++i) {
  9153. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  9154. }
  9155. }
  9156. force.initialize = function(_) {
  9157. nodes = _;
  9158. initialize();
  9159. };
  9160. force.strength = function(_) {
  9161. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  9162. };
  9163. force.y = function(_) {
  9164. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  9165. };
  9166. return force;
  9167. };
  9168. function nopropagation() {
  9169. exports.event.stopImmediatePropagation();
  9170. }
  9171. var noevent = function() {
  9172. exports.event.preventDefault();
  9173. exports.event.stopImmediatePropagation();
  9174. };
  9175. var dragDisable = function(view) {
  9176. var root = view.document.documentElement,
  9177. selection$$1 = select(view).on("dragstart.drag", noevent, true);
  9178. if ("onselectstart" in root) {
  9179. selection$$1.on("selectstart.drag", noevent, true);
  9180. } else {
  9181. root.__noselect = root.style.MozUserSelect;
  9182. root.style.MozUserSelect = "none";
  9183. }
  9184. };
  9185. function yesdrag(view, noclick) {
  9186. var root = view.document.documentElement,
  9187. selection$$1 = select(view).on("dragstart.drag", null);
  9188. if (noclick) {
  9189. selection$$1.on("click.drag", noevent, true);
  9190. setTimeout(function() { selection$$1.on("click.drag", null); }, 0);
  9191. }
  9192. if ("onselectstart" in root) {
  9193. selection$$1.on("selectstart.drag", null);
  9194. } else {
  9195. root.style.MozUserSelect = root.__noselect;
  9196. delete root.__noselect;
  9197. }
  9198. }
  9199. var constant$8 = function(x) {
  9200. return function() {
  9201. return x;
  9202. };
  9203. };
  9204. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  9205. this.target = target;
  9206. this.type = type;
  9207. this.subject = subject;
  9208. this.identifier = id;
  9209. this.active = active;
  9210. this.x = x;
  9211. this.y = y;
  9212. this.dx = dx;
  9213. this.dy = dy;
  9214. this._ = dispatch;
  9215. }
  9216. DragEvent.prototype.on = function() {
  9217. var value = this._.on.apply(this._, arguments);
  9218. return value === this._ ? this : value;
  9219. };
  9220. // Ignore right-click, since that should open the context menu.
  9221. function defaultFilter() {
  9222. return !exports.event.button;
  9223. }
  9224. function defaultContainer() {
  9225. return this.parentNode;
  9226. }
  9227. function defaultSubject(d) {
  9228. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  9229. }
  9230. var drag = function() {
  9231. var filter = defaultFilter,
  9232. container = defaultContainer,
  9233. subject = defaultSubject,
  9234. gestures = {},
  9235. listeners = dispatch("start", "drag", "end"),
  9236. active = 0,
  9237. mousemoving,
  9238. touchending;
  9239. function drag(selection$$1) {
  9240. selection$$1
  9241. .on("mousedown.drag", mousedowned)
  9242. .on("touchstart.drag", touchstarted)
  9243. .on("touchmove.drag", touchmoved)
  9244. .on("touchend.drag touchcancel.drag", touchended)
  9245. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  9246. }
  9247. function mousedowned() {
  9248. if (touchending || !filter.apply(this, arguments)) return;
  9249. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  9250. if (!gesture) return;
  9251. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  9252. dragDisable(exports.event.view);
  9253. nopropagation();
  9254. mousemoving = false;
  9255. gesture("start");
  9256. }
  9257. function mousemoved() {
  9258. noevent();
  9259. mousemoving = true;
  9260. gestures.mouse("drag");
  9261. }
  9262. function mouseupped() {
  9263. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  9264. yesdrag(exports.event.view, mousemoving);
  9265. noevent();
  9266. gestures.mouse("end");
  9267. }
  9268. function touchstarted() {
  9269. if (!filter.apply(this, arguments)) return;
  9270. var touches$$1 = exports.event.changedTouches,
  9271. c = container.apply(this, arguments),
  9272. n = touches$$1.length, i, gesture;
  9273. for (i = 0; i < n; ++i) {
  9274. if (gesture = beforestart(touches$$1[i].identifier, c, touch, this, arguments)) {
  9275. nopropagation();
  9276. gesture("start");
  9277. }
  9278. }
  9279. }
  9280. function touchmoved() {
  9281. var touches$$1 = exports.event.changedTouches,
  9282. n = touches$$1.length, i, gesture;
  9283. for (i = 0; i < n; ++i) {
  9284. if (gesture = gestures[touches$$1[i].identifier]) {
  9285. noevent();
  9286. gesture("drag");
  9287. }
  9288. }
  9289. }
  9290. function touchended() {
  9291. var touches$$1 = exports.event.changedTouches,
  9292. n = touches$$1.length, i, gesture;
  9293. if (touchending) clearTimeout(touchending);
  9294. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  9295. for (i = 0; i < n; ++i) {
  9296. if (gesture = gestures[touches$$1[i].identifier]) {
  9297. nopropagation();
  9298. gesture("end");
  9299. }
  9300. }
  9301. }
  9302. function beforestart(id, container, point, that, args) {
  9303. var p = point(container, id), s, dx, dy,
  9304. sublisteners = listeners.copy();
  9305. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  9306. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  9307. dx = s.x - p[0] || 0;
  9308. dy = s.y - p[1] || 0;
  9309. return true;
  9310. })) return;
  9311. return function gesture(type) {
  9312. var p0 = p, n;
  9313. switch (type) {
  9314. case "start": gestures[id] = gesture, n = active++; break;
  9315. case "end": delete gestures[id], --active; // nobreak
  9316. case "drag": p = point(container, id), n = active; break;
  9317. }
  9318. 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]);
  9319. };
  9320. }
  9321. drag.filter = function(_) {
  9322. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$8(!!_), drag) : filter;
  9323. };
  9324. drag.container = function(_) {
  9325. return arguments.length ? (container = typeof _ === "function" ? _ : constant$8(_), drag) : container;
  9326. };
  9327. drag.subject = function(_) {
  9328. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$8(_), drag) : subject;
  9329. };
  9330. drag.on = function() {
  9331. var value = listeners.on.apply(listeners, arguments);
  9332. return value === listeners ? drag : value;
  9333. };
  9334. return drag;
  9335. };
  9336. var constant$9 = function(x) {
  9337. return function() {
  9338. return x;
  9339. };
  9340. };
  9341. function x$4(d) {
  9342. return d[0];
  9343. }
  9344. function y$4(d) {
  9345. return d[1];
  9346. }
  9347. function RedBlackTree() {
  9348. this._ = null; // root node
  9349. }
  9350. function RedBlackNode(node) {
  9351. node.U = // parent node
  9352. node.C = // color - true for red, false for black
  9353. node.L = // left node
  9354. node.R = // right node
  9355. node.P = // previous node
  9356. node.N = null; // next node
  9357. }
  9358. RedBlackTree.prototype = {
  9359. constructor: RedBlackTree,
  9360. insert: function(after, node) {
  9361. var parent, grandpa, uncle;
  9362. if (after) {
  9363. node.P = after;
  9364. node.N = after.N;
  9365. if (after.N) after.N.P = node;
  9366. after.N = node;
  9367. if (after.R) {
  9368. after = after.R;
  9369. while (after.L) after = after.L;
  9370. after.L = node;
  9371. } else {
  9372. after.R = node;
  9373. }
  9374. parent = after;
  9375. } else if (this._) {
  9376. after = RedBlackFirst(this._);
  9377. node.P = null;
  9378. node.N = after;
  9379. after.P = after.L = node;
  9380. parent = after;
  9381. } else {
  9382. node.P = node.N = null;
  9383. this._ = node;
  9384. parent = null;
  9385. }
  9386. node.L = node.R = null;
  9387. node.U = parent;
  9388. node.C = true;
  9389. after = node;
  9390. while (parent && parent.C) {
  9391. grandpa = parent.U;
  9392. if (parent === grandpa.L) {
  9393. uncle = grandpa.R;
  9394. if (uncle && uncle.C) {
  9395. parent.C = uncle.C = false;
  9396. grandpa.C = true;
  9397. after = grandpa;
  9398. } else {
  9399. if (after === parent.R) {
  9400. RedBlackRotateLeft(this, parent);
  9401. after = parent;
  9402. parent = after.U;
  9403. }
  9404. parent.C = false;
  9405. grandpa.C = true;
  9406. RedBlackRotateRight(this, grandpa);
  9407. }
  9408. } else {
  9409. uncle = grandpa.L;
  9410. if (uncle && uncle.C) {
  9411. parent.C = uncle.C = false;
  9412. grandpa.C = true;
  9413. after = grandpa;
  9414. } else {
  9415. if (after === parent.L) {
  9416. RedBlackRotateRight(this, parent);
  9417. after = parent;
  9418. parent = after.U;
  9419. }
  9420. parent.C = false;
  9421. grandpa.C = true;
  9422. RedBlackRotateLeft(this, grandpa);
  9423. }
  9424. }
  9425. parent = after.U;
  9426. }
  9427. this._.C = false;
  9428. },
  9429. remove: function(node) {
  9430. if (node.N) node.N.P = node.P;
  9431. if (node.P) node.P.N = node.N;
  9432. node.N = node.P = null;
  9433. var parent = node.U,
  9434. sibling,
  9435. left = node.L,
  9436. right = node.R,
  9437. next,
  9438. red;
  9439. if (!left) next = right;
  9440. else if (!right) next = left;
  9441. else next = RedBlackFirst(right);
  9442. if (parent) {
  9443. if (parent.L === node) parent.L = next;
  9444. else parent.R = next;
  9445. } else {
  9446. this._ = next;
  9447. }
  9448. if (left && right) {
  9449. red = next.C;
  9450. next.C = node.C;
  9451. next.L = left;
  9452. left.U = next;
  9453. if (next !== right) {
  9454. parent = next.U;
  9455. next.U = node.U;
  9456. node = next.R;
  9457. parent.L = node;
  9458. next.R = right;
  9459. right.U = next;
  9460. } else {
  9461. next.U = parent;
  9462. parent = next;
  9463. node = next.R;
  9464. }
  9465. } else {
  9466. red = node.C;
  9467. node = next;
  9468. }
  9469. if (node) node.U = parent;
  9470. if (red) return;
  9471. if (node && node.C) { node.C = false; return; }
  9472. do {
  9473. if (node === this._) break;
  9474. if (node === parent.L) {
  9475. sibling = parent.R;
  9476. if (sibling.C) {
  9477. sibling.C = false;
  9478. parent.C = true;
  9479. RedBlackRotateLeft(this, parent);
  9480. sibling = parent.R;
  9481. }
  9482. if ((sibling.L && sibling.L.C)
  9483. || (sibling.R && sibling.R.C)) {
  9484. if (!sibling.R || !sibling.R.C) {
  9485. sibling.L.C = false;
  9486. sibling.C = true;
  9487. RedBlackRotateRight(this, sibling);
  9488. sibling = parent.R;
  9489. }
  9490. sibling.C = parent.C;
  9491. parent.C = sibling.R.C = false;
  9492. RedBlackRotateLeft(this, parent);
  9493. node = this._;
  9494. break;
  9495. }
  9496. } else {
  9497. sibling = parent.L;
  9498. if (sibling.C) {
  9499. sibling.C = false;
  9500. parent.C = true;
  9501. RedBlackRotateRight(this, parent);
  9502. sibling = parent.L;
  9503. }
  9504. if ((sibling.L && sibling.L.C)
  9505. || (sibling.R && sibling.R.C)) {
  9506. if (!sibling.L || !sibling.L.C) {
  9507. sibling.R.C = false;
  9508. sibling.C = true;
  9509. RedBlackRotateLeft(this, sibling);
  9510. sibling = parent.L;
  9511. }
  9512. sibling.C = parent.C;
  9513. parent.C = sibling.L.C = false;
  9514. RedBlackRotateRight(this, parent);
  9515. node = this._;
  9516. break;
  9517. }
  9518. }
  9519. sibling.C = true;
  9520. node = parent;
  9521. parent = parent.U;
  9522. } while (!node.C);
  9523. if (node) node.C = false;
  9524. }
  9525. };
  9526. function RedBlackRotateLeft(tree, node) {
  9527. var p = node,
  9528. q = node.R,
  9529. parent = p.U;
  9530. if (parent) {
  9531. if (parent.L === p) parent.L = q;
  9532. else parent.R = q;
  9533. } else {
  9534. tree._ = q;
  9535. }
  9536. q.U = parent;
  9537. p.U = q;
  9538. p.R = q.L;
  9539. if (p.R) p.R.U = p;
  9540. q.L = p;
  9541. }
  9542. function RedBlackRotateRight(tree, node) {
  9543. var p = node,
  9544. q = node.L,
  9545. parent = p.U;
  9546. if (parent) {
  9547. if (parent.L === p) parent.L = q;
  9548. else parent.R = q;
  9549. } else {
  9550. tree._ = q;
  9551. }
  9552. q.U = parent;
  9553. p.U = q;
  9554. p.L = q.R;
  9555. if (p.L) p.L.U = p;
  9556. q.R = p;
  9557. }
  9558. function RedBlackFirst(node) {
  9559. while (node.L) node = node.L;
  9560. return node;
  9561. }
  9562. function createEdge(left, right, v0, v1) {
  9563. var edge = [null, null],
  9564. index = edges.push(edge) - 1;
  9565. edge.left = left;
  9566. edge.right = right;
  9567. if (v0) setEdgeEnd(edge, left, right, v0);
  9568. if (v1) setEdgeEnd(edge, right, left, v1);
  9569. cells[left.index].halfedges.push(index);
  9570. cells[right.index].halfedges.push(index);
  9571. return edge;
  9572. }
  9573. function createBorderEdge(left, v0, v1) {
  9574. var edge = [v0, v1];
  9575. edge.left = left;
  9576. return edge;
  9577. }
  9578. function setEdgeEnd(edge, left, right, vertex) {
  9579. if (!edge[0] && !edge[1]) {
  9580. edge[0] = vertex;
  9581. edge.left = left;
  9582. edge.right = right;
  9583. } else if (edge.left === right) {
  9584. edge[1] = vertex;
  9585. } else {
  9586. edge[0] = vertex;
  9587. }
  9588. }
  9589. // Liang–Barsky line clipping.
  9590. function clipEdge(edge, x0, y0, x1, y1) {
  9591. var a = edge[0],
  9592. b = edge[1],
  9593. ax = a[0],
  9594. ay = a[1],
  9595. bx = b[0],
  9596. by = b[1],
  9597. t0 = 0,
  9598. t1 = 1,
  9599. dx = bx - ax,
  9600. dy = by - ay,
  9601. r;
  9602. r = x0 - ax;
  9603. if (!dx && r > 0) return;
  9604. r /= dx;
  9605. if (dx < 0) {
  9606. if (r < t0) return;
  9607. if (r < t1) t1 = r;
  9608. } else if (dx > 0) {
  9609. if (r > t1) return;
  9610. if (r > t0) t0 = r;
  9611. }
  9612. r = x1 - ax;
  9613. if (!dx && r < 0) return;
  9614. r /= dx;
  9615. if (dx < 0) {
  9616. if (r > t1) return;
  9617. if (r > t0) t0 = r;
  9618. } else if (dx > 0) {
  9619. if (r < t0) return;
  9620. if (r < t1) t1 = r;
  9621. }
  9622. r = y0 - ay;
  9623. if (!dy && r > 0) return;
  9624. r /= dy;
  9625. if (dy < 0) {
  9626. if (r < t0) return;
  9627. if (r < t1) t1 = r;
  9628. } else if (dy > 0) {
  9629. if (r > t1) return;
  9630. if (r > t0) t0 = r;
  9631. }
  9632. r = y1 - ay;
  9633. if (!dy && r < 0) return;
  9634. r /= dy;
  9635. if (dy < 0) {
  9636. if (r > t1) return;
  9637. if (r > t0) t0 = r;
  9638. } else if (dy > 0) {
  9639. if (r < t0) return;
  9640. if (r < t1) t1 = r;
  9641. }
  9642. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  9643. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  9644. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  9645. return true;
  9646. }
  9647. function connectEdge(edge, x0, y0, x1, y1) {
  9648. var v1 = edge[1];
  9649. if (v1) return true;
  9650. var v0 = edge[0],
  9651. left = edge.left,
  9652. right = edge.right,
  9653. lx = left[0],
  9654. ly = left[1],
  9655. rx = right[0],
  9656. ry = right[1],
  9657. fx = (lx + rx) / 2,
  9658. fy = (ly + ry) / 2,
  9659. fm,
  9660. fb;
  9661. if (ry === ly) {
  9662. if (fx < x0 || fx >= x1) return;
  9663. if (lx > rx) {
  9664. if (!v0) v0 = [fx, y0];
  9665. else if (v0[1] >= y1) return;
  9666. v1 = [fx, y1];
  9667. } else {
  9668. if (!v0) v0 = [fx, y1];
  9669. else if (v0[1] < y0) return;
  9670. v1 = [fx, y0];
  9671. }
  9672. } else {
  9673. fm = (lx - rx) / (ry - ly);
  9674. fb = fy - fm * fx;
  9675. if (fm < -1 || fm > 1) {
  9676. if (lx > rx) {
  9677. if (!v0) v0 = [(y0 - fb) / fm, y0];
  9678. else if (v0[1] >= y1) return;
  9679. v1 = [(y1 - fb) / fm, y1];
  9680. } else {
  9681. if (!v0) v0 = [(y1 - fb) / fm, y1];
  9682. else if (v0[1] < y0) return;
  9683. v1 = [(y0 - fb) / fm, y0];
  9684. }
  9685. } else {
  9686. if (ly < ry) {
  9687. if (!v0) v0 = [x0, fm * x0 + fb];
  9688. else if (v0[0] >= x1) return;
  9689. v1 = [x1, fm * x1 + fb];
  9690. } else {
  9691. if (!v0) v0 = [x1, fm * x1 + fb];
  9692. else if (v0[0] < x0) return;
  9693. v1 = [x0, fm * x0 + fb];
  9694. }
  9695. }
  9696. }
  9697. edge[0] = v0;
  9698. edge[1] = v1;
  9699. return true;
  9700. }
  9701. function clipEdges(x0, y0, x1, y1) {
  9702. var i = edges.length,
  9703. edge;
  9704. while (i--) {
  9705. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  9706. || !clipEdge(edge, x0, y0, x1, y1)
  9707. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$3
  9708. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$3)) {
  9709. delete edges[i];
  9710. }
  9711. }
  9712. }
  9713. function createCell(site) {
  9714. return cells[site.index] = {
  9715. site: site,
  9716. halfedges: []
  9717. };
  9718. }
  9719. function cellHalfedgeAngle(cell, edge) {
  9720. var site = cell.site,
  9721. va = edge.left,
  9722. vb = edge.right;
  9723. if (site === vb) vb = va, va = site;
  9724. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  9725. if (site === va) va = edge[1], vb = edge[0];
  9726. else va = edge[0], vb = edge[1];
  9727. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  9728. }
  9729. function cellHalfedgeStart(cell, edge) {
  9730. return edge[+(edge.left !== cell.site)];
  9731. }
  9732. function cellHalfedgeEnd(cell, edge) {
  9733. return edge[+(edge.left === cell.site)];
  9734. }
  9735. function sortCellHalfedges() {
  9736. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  9737. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  9738. var index = new Array(m),
  9739. array = new Array(m);
  9740. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  9741. index.sort(function(i, j) { return array[j] - array[i]; });
  9742. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  9743. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  9744. }
  9745. }
  9746. }
  9747. function clipCells(x0, y0, x1, y1) {
  9748. var nCells = cells.length,
  9749. iCell,
  9750. cell,
  9751. site,
  9752. iHalfedge,
  9753. halfedges,
  9754. nHalfedges,
  9755. start,
  9756. startX,
  9757. startY,
  9758. end,
  9759. endX,
  9760. endY,
  9761. cover = true;
  9762. for (iCell = 0; iCell < nCells; ++iCell) {
  9763. if (cell = cells[iCell]) {
  9764. site = cell.site;
  9765. halfedges = cell.halfedges;
  9766. iHalfedge = halfedges.length;
  9767. // Remove any dangling clipped edges.
  9768. while (iHalfedge--) {
  9769. if (!edges[halfedges[iHalfedge]]) {
  9770. halfedges.splice(iHalfedge, 1);
  9771. }
  9772. }
  9773. // Insert any border edges as necessary.
  9774. iHalfedge = 0, nHalfedges = halfedges.length;
  9775. while (iHalfedge < nHalfedges) {
  9776. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  9777. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  9778. if (Math.abs(endX - startX) > epsilon$3 || Math.abs(endY - startY) > epsilon$3) {
  9779. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  9780. Math.abs(endX - x0) < epsilon$3 && y1 - endY > epsilon$3 ? [x0, Math.abs(startX - x0) < epsilon$3 ? startY : y1]
  9781. : Math.abs(endY - y1) < epsilon$3 && x1 - endX > epsilon$3 ? [Math.abs(startY - y1) < epsilon$3 ? startX : x1, y1]
  9782. : Math.abs(endX - x1) < epsilon$3 && endY - y0 > epsilon$3 ? [x1, Math.abs(startX - x1) < epsilon$3 ? startY : y0]
  9783. : Math.abs(endY - y0) < epsilon$3 && endX - x0 > epsilon$3 ? [Math.abs(startY - y0) < epsilon$3 ? startX : x0, y0]
  9784. : null)) - 1);
  9785. ++nHalfedges;
  9786. }
  9787. }
  9788. if (nHalfedges) cover = false;
  9789. }
  9790. }
  9791. // If there weren’t any edges, have the closest site cover the extent.
  9792. // It doesn’t matter which corner of the extent we measure!
  9793. if (cover) {
  9794. var dx, dy, d2, dc = Infinity;
  9795. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  9796. if (cell = cells[iCell]) {
  9797. site = cell.site;
  9798. dx = site[0] - x0;
  9799. dy = site[1] - y0;
  9800. d2 = dx * dx + dy * dy;
  9801. if (d2 < dc) dc = d2, cover = cell;
  9802. }
  9803. }
  9804. if (cover) {
  9805. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  9806. cover.halfedges.push(
  9807. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  9808. edges.push(createBorderEdge(site, v01, v11)) - 1,
  9809. edges.push(createBorderEdge(site, v11, v10)) - 1,
  9810. edges.push(createBorderEdge(site, v10, v00)) - 1
  9811. );
  9812. }
  9813. }
  9814. // Lastly delete any cells with no edges; these were entirely clipped.
  9815. for (iCell = 0; iCell < nCells; ++iCell) {
  9816. if (cell = cells[iCell]) {
  9817. if (!cell.halfedges.length) {
  9818. delete cells[iCell];
  9819. }
  9820. }
  9821. }
  9822. }
  9823. var circlePool = [];
  9824. var firstCircle;
  9825. function Circle() {
  9826. RedBlackNode(this);
  9827. this.x =
  9828. this.y =
  9829. this.arc =
  9830. this.site =
  9831. this.cy = null;
  9832. }
  9833. function attachCircle(arc) {
  9834. var lArc = arc.P,
  9835. rArc = arc.N;
  9836. if (!lArc || !rArc) return;
  9837. var lSite = lArc.site,
  9838. cSite = arc.site,
  9839. rSite = rArc.site;
  9840. if (lSite === rSite) return;
  9841. var bx = cSite[0],
  9842. by = cSite[1],
  9843. ax = lSite[0] - bx,
  9844. ay = lSite[1] - by,
  9845. cx = rSite[0] - bx,
  9846. cy = rSite[1] - by;
  9847. var d = 2 * (ax * cy - ay * cx);
  9848. if (d >= -epsilon2$1) return;
  9849. var ha = ax * ax + ay * ay,
  9850. hc = cx * cx + cy * cy,
  9851. x = (cy * ha - ay * hc) / d,
  9852. y = (ax * hc - cx * ha) / d;
  9853. var circle = circlePool.pop() || new Circle;
  9854. circle.arc = arc;
  9855. circle.site = cSite;
  9856. circle.x = x + bx;
  9857. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  9858. arc.circle = circle;
  9859. var before = null,
  9860. node = circles._;
  9861. while (node) {
  9862. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  9863. if (node.L) node = node.L;
  9864. else { before = node.P; break; }
  9865. } else {
  9866. if (node.R) node = node.R;
  9867. else { before = node; break; }
  9868. }
  9869. }
  9870. circles.insert(before, circle);
  9871. if (!before) firstCircle = circle;
  9872. }
  9873. function detachCircle(arc) {
  9874. var circle = arc.circle;
  9875. if (circle) {
  9876. if (!circle.P) firstCircle = circle.N;
  9877. circles.remove(circle);
  9878. circlePool.push(circle);
  9879. RedBlackNode(circle);
  9880. arc.circle = null;
  9881. }
  9882. }
  9883. var beachPool = [];
  9884. function Beach() {
  9885. RedBlackNode(this);
  9886. this.edge =
  9887. this.site =
  9888. this.circle = null;
  9889. }
  9890. function createBeach(site) {
  9891. var beach = beachPool.pop() || new Beach;
  9892. beach.site = site;
  9893. return beach;
  9894. }
  9895. function detachBeach(beach) {
  9896. detachCircle(beach);
  9897. beaches.remove(beach);
  9898. beachPool.push(beach);
  9899. RedBlackNode(beach);
  9900. }
  9901. function removeBeach(beach) {
  9902. var circle = beach.circle,
  9903. x = circle.x,
  9904. y = circle.cy,
  9905. vertex = [x, y],
  9906. previous = beach.P,
  9907. next = beach.N,
  9908. disappearing = [beach];
  9909. detachBeach(beach);
  9910. var lArc = previous;
  9911. while (lArc.circle
  9912. && Math.abs(x - lArc.circle.x) < epsilon$3
  9913. && Math.abs(y - lArc.circle.cy) < epsilon$3) {
  9914. previous = lArc.P;
  9915. disappearing.unshift(lArc);
  9916. detachBeach(lArc);
  9917. lArc = previous;
  9918. }
  9919. disappearing.unshift(lArc);
  9920. detachCircle(lArc);
  9921. var rArc = next;
  9922. while (rArc.circle
  9923. && Math.abs(x - rArc.circle.x) < epsilon$3
  9924. && Math.abs(y - rArc.circle.cy) < epsilon$3) {
  9925. next = rArc.N;
  9926. disappearing.push(rArc);
  9927. detachBeach(rArc);
  9928. rArc = next;
  9929. }
  9930. disappearing.push(rArc);
  9931. detachCircle(rArc);
  9932. var nArcs = disappearing.length,
  9933. iArc;
  9934. for (iArc = 1; iArc < nArcs; ++iArc) {
  9935. rArc = disappearing[iArc];
  9936. lArc = disappearing[iArc - 1];
  9937. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  9938. }
  9939. lArc = disappearing[0];
  9940. rArc = disappearing[nArcs - 1];
  9941. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  9942. attachCircle(lArc);
  9943. attachCircle(rArc);
  9944. }
  9945. function addBeach(site) {
  9946. var x = site[0],
  9947. directrix = site[1],
  9948. lArc,
  9949. rArc,
  9950. dxl,
  9951. dxr,
  9952. node = beaches._;
  9953. while (node) {
  9954. dxl = leftBreakPoint(node, directrix) - x;
  9955. if (dxl > epsilon$3) node = node.L; else {
  9956. dxr = x - rightBreakPoint(node, directrix);
  9957. if (dxr > epsilon$3) {
  9958. if (!node.R) {
  9959. lArc = node;
  9960. break;
  9961. }
  9962. node = node.R;
  9963. } else {
  9964. if (dxl > -epsilon$3) {
  9965. lArc = node.P;
  9966. rArc = node;
  9967. } else if (dxr > -epsilon$3) {
  9968. lArc = node;
  9969. rArc = node.N;
  9970. } else {
  9971. lArc = rArc = node;
  9972. }
  9973. break;
  9974. }
  9975. }
  9976. }
  9977. createCell(site);
  9978. var newArc = createBeach(site);
  9979. beaches.insert(lArc, newArc);
  9980. if (!lArc && !rArc) return;
  9981. if (lArc === rArc) {
  9982. detachCircle(lArc);
  9983. rArc = createBeach(lArc.site);
  9984. beaches.insert(newArc, rArc);
  9985. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  9986. attachCircle(lArc);
  9987. attachCircle(rArc);
  9988. return;
  9989. }
  9990. if (!rArc) { // && lArc
  9991. newArc.edge = createEdge(lArc.site, newArc.site);
  9992. return;
  9993. }
  9994. // else lArc !== rArc
  9995. detachCircle(lArc);
  9996. detachCircle(rArc);
  9997. var lSite = lArc.site,
  9998. ax = lSite[0],
  9999. ay = lSite[1],
  10000. bx = site[0] - ax,
  10001. by = site[1] - ay,
  10002. rSite = rArc.site,
  10003. cx = rSite[0] - ax,
  10004. cy = rSite[1] - ay,
  10005. d = 2 * (bx * cy - by * cx),
  10006. hb = bx * bx + by * by,
  10007. hc = cx * cx + cy * cy,
  10008. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  10009. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  10010. newArc.edge = createEdge(lSite, site, null, vertex);
  10011. rArc.edge = createEdge(site, rSite, null, vertex);
  10012. attachCircle(lArc);
  10013. attachCircle(rArc);
  10014. }
  10015. function leftBreakPoint(arc, directrix) {
  10016. var site = arc.site,
  10017. rfocx = site[0],
  10018. rfocy = site[1],
  10019. pby2 = rfocy - directrix;
  10020. if (!pby2) return rfocx;
  10021. var lArc = arc.P;
  10022. if (!lArc) return -Infinity;
  10023. site = lArc.site;
  10024. var lfocx = site[0],
  10025. lfocy = site[1],
  10026. plby2 = lfocy - directrix;
  10027. if (!plby2) return lfocx;
  10028. var hl = lfocx - rfocx,
  10029. aby2 = 1 / pby2 - 1 / plby2,
  10030. b = hl / plby2;
  10031. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  10032. return (rfocx + lfocx) / 2;
  10033. }
  10034. function rightBreakPoint(arc, directrix) {
  10035. var rArc = arc.N;
  10036. if (rArc) return leftBreakPoint(rArc, directrix);
  10037. var site = arc.site;
  10038. return site[1] === directrix ? site[0] : Infinity;
  10039. }
  10040. var epsilon$3 = 1e-6;
  10041. var epsilon2$1 = 1e-12;
  10042. var beaches;
  10043. var cells;
  10044. var circles;
  10045. var edges;
  10046. function triangleArea(a, b, c) {
  10047. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  10048. }
  10049. function lexicographic(a, b) {
  10050. return b[1] - a[1]
  10051. || b[0] - a[0];
  10052. }
  10053. function Diagram(sites, extent) {
  10054. var site = sites.sort(lexicographic).pop(),
  10055. x,
  10056. y,
  10057. circle;
  10058. edges = [];
  10059. cells = new Array(sites.length);
  10060. beaches = new RedBlackTree;
  10061. circles = new RedBlackTree;
  10062. while (true) {
  10063. circle = firstCircle;
  10064. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  10065. if (site[0] !== x || site[1] !== y) {
  10066. addBeach(site);
  10067. x = site[0], y = site[1];
  10068. }
  10069. site = sites.pop();
  10070. } else if (circle) {
  10071. removeBeach(circle.arc);
  10072. } else {
  10073. break;
  10074. }
  10075. }
  10076. sortCellHalfedges();
  10077. if (extent) {
  10078. var x0 = +extent[0][0],
  10079. y0 = +extent[0][1],
  10080. x1 = +extent[1][0],
  10081. y1 = +extent[1][1];
  10082. clipEdges(x0, y0, x1, y1);
  10083. clipCells(x0, y0, x1, y1);
  10084. }
  10085. this.edges = edges;
  10086. this.cells = cells;
  10087. beaches =
  10088. circles =
  10089. edges =
  10090. cells = null;
  10091. }
  10092. Diagram.prototype = {
  10093. constructor: Diagram,
  10094. polygons: function() {
  10095. var edges = this.edges;
  10096. return this.cells.map(function(cell) {
  10097. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  10098. polygon.data = cell.site.data;
  10099. return polygon;
  10100. });
  10101. },
  10102. triangles: function() {
  10103. var triangles = [],
  10104. edges = this.edges;
  10105. this.cells.forEach(function(cell, i) {
  10106. var site = cell.site,
  10107. halfedges = cell.halfedges,
  10108. j = -1,
  10109. m = halfedges.length,
  10110. s0,
  10111. e1 = edges[halfedges[m - 1]],
  10112. s1 = e1.left === site ? e1.right : e1.left;
  10113. while (++j < m) {
  10114. s0 = s1;
  10115. e1 = edges[halfedges[j]];
  10116. s1 = e1.left === site ? e1.right : e1.left;
  10117. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  10118. triangles.push([site.data, s0.data, s1.data]);
  10119. }
  10120. }
  10121. });
  10122. return triangles;
  10123. },
  10124. links: function() {
  10125. return this.edges.filter(function(edge) {
  10126. return edge.right;
  10127. }).map(function(edge) {
  10128. return {
  10129. source: edge.left.data,
  10130. target: edge.right.data
  10131. };
  10132. });
  10133. },
  10134. find: function(x, y, radius) {
  10135. var that = this,
  10136. i0, i1 = that._found || 0,
  10137. cell = that.cells[i1] || that.cells[i1 = 0],
  10138. dx = x - cell.site[0],
  10139. dy = y - cell.site[1],
  10140. d2 = dx * dx + dy * dy;
  10141. do {
  10142. cell = that.cells[i0 = i1], i1 = null;
  10143. cell.halfedges.forEach(function(e) {
  10144. var edge = that.edges[e], v = edge.left;
  10145. if ((v === cell.site || !v) && !(v = edge.right)) return;
  10146. var vx = x - v[0],
  10147. vy = y - v[1],
  10148. v2 = vx * vx + vy * vy;
  10149. if (v2 < d2) d2 = v2, i1 = v.index;
  10150. });
  10151. } while (i1 !== null);
  10152. that._found = i0;
  10153. return radius == null || d2 <= radius * radius ? cell.site : null;
  10154. }
  10155. };
  10156. var voronoi = function() {
  10157. var x$$1 = x$4,
  10158. y$$1 = y$4,
  10159. extent = null;
  10160. function voronoi(data) {
  10161. return new Diagram(data.map(function(d, i) {
  10162. var s = [Math.round(x$$1(d, i, data) / epsilon$3) * epsilon$3, Math.round(y$$1(d, i, data) / epsilon$3) * epsilon$3];
  10163. s.index = i;
  10164. s.data = d;
  10165. return s;
  10166. }), extent);
  10167. }
  10168. voronoi.polygons = function(data) {
  10169. return voronoi(data).polygons();
  10170. };
  10171. voronoi.links = function(data) {
  10172. return voronoi(data).links();
  10173. };
  10174. voronoi.triangles = function(data) {
  10175. return voronoi(data).triangles();
  10176. };
  10177. voronoi.x = function(_) {
  10178. return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$9(+_), voronoi) : x$$1;
  10179. };
  10180. voronoi.y = function(_) {
  10181. return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$9(+_), voronoi) : y$$1;
  10182. };
  10183. voronoi.extent = function(_) {
  10184. 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]]];
  10185. };
  10186. voronoi.size = function(_) {
  10187. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  10188. };
  10189. return voronoi;
  10190. };
  10191. var constant$10 = function(x) {
  10192. return function() {
  10193. return x;
  10194. };
  10195. };
  10196. function ZoomEvent(target, type, transform) {
  10197. this.target = target;
  10198. this.type = type;
  10199. this.transform = transform;
  10200. }
  10201. function Transform(k, x, y) {
  10202. this.k = k;
  10203. this.x = x;
  10204. this.y = y;
  10205. }
  10206. Transform.prototype = {
  10207. constructor: Transform,
  10208. scale: function(k) {
  10209. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  10210. },
  10211. translate: function(x, y) {
  10212. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  10213. },
  10214. apply: function(point) {
  10215. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  10216. },
  10217. applyX: function(x) {
  10218. return x * this.k + this.x;
  10219. },
  10220. applyY: function(y) {
  10221. return y * this.k + this.y;
  10222. },
  10223. invert: function(location) {
  10224. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  10225. },
  10226. invertX: function(x) {
  10227. return (x - this.x) / this.k;
  10228. },
  10229. invertY: function(y) {
  10230. return (y - this.y) / this.k;
  10231. },
  10232. rescaleX: function(x) {
  10233. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  10234. },
  10235. rescaleY: function(y) {
  10236. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  10237. },
  10238. toString: function() {
  10239. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  10240. }
  10241. };
  10242. var identity$6 = new Transform(1, 0, 0);
  10243. transform.prototype = Transform.prototype;
  10244. function transform(node) {
  10245. return node.__zoom || identity$6;
  10246. }
  10247. function nopropagation$1() {
  10248. exports.event.stopImmediatePropagation();
  10249. }
  10250. var noevent$1 = function() {
  10251. exports.event.preventDefault();
  10252. exports.event.stopImmediatePropagation();
  10253. };
  10254. // Ignore right-click, since that should open the context menu.
  10255. function defaultFilter$1() {
  10256. return !exports.event.button;
  10257. }
  10258. function defaultExtent() {
  10259. var e = this, w, h;
  10260. if (e instanceof SVGElement) {
  10261. e = e.ownerSVGElement || e;
  10262. w = e.width.baseVal.value;
  10263. h = e.height.baseVal.value;
  10264. } else {
  10265. w = e.clientWidth;
  10266. h = e.clientHeight;
  10267. }
  10268. return [[0, 0], [w, h]];
  10269. }
  10270. function defaultTransform() {
  10271. return this.__zoom || identity$6;
  10272. }
  10273. var zoom = function() {
  10274. var filter = defaultFilter$1,
  10275. extent = defaultExtent,
  10276. k0 = 0,
  10277. k1 = Infinity,
  10278. x0 = -k1,
  10279. x1 = k1,
  10280. y0 = x0,
  10281. y1 = x1,
  10282. duration = 250,
  10283. gestures = [],
  10284. listeners = dispatch("start", "zoom", "end"),
  10285. touchstarting,
  10286. touchending,
  10287. touchDelay = 500,
  10288. wheelDelay = 150;
  10289. function zoom(selection$$1) {
  10290. selection$$1
  10291. .on("wheel.zoom", wheeled)
  10292. .on("mousedown.zoom", mousedowned)
  10293. .on("dblclick.zoom", dblclicked)
  10294. .on("touchstart.zoom", touchstarted)
  10295. .on("touchmove.zoom", touchmoved)
  10296. .on("touchend.zoom touchcancel.zoom", touchended)
  10297. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  10298. .property("__zoom", defaultTransform);
  10299. }
  10300. zoom.transform = function(collection, transform) {
  10301. var selection$$1 = collection.selection ? collection.selection() : collection;
  10302. selection$$1.property("__zoom", defaultTransform);
  10303. if (collection !== selection$$1) {
  10304. schedule(collection, transform);
  10305. } else {
  10306. selection$$1.interrupt().each(function() {
  10307. gesture(this, arguments)
  10308. .start()
  10309. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  10310. .end();
  10311. });
  10312. }
  10313. };
  10314. zoom.scaleBy = function(selection$$1, k) {
  10315. zoom.scaleTo(selection$$1, function() {
  10316. var k0 = this.__zoom.k,
  10317. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  10318. return k0 * k1;
  10319. });
  10320. };
  10321. zoom.scaleTo = function(selection$$1, k) {
  10322. zoom.transform(selection$$1, function() {
  10323. var e = extent.apply(this, arguments),
  10324. t0 = this.__zoom,
  10325. p0 = centroid(e),
  10326. p1 = t0.invert(p0),
  10327. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  10328. return constrain(translate(scale(t0, k1), p0, p1), e);
  10329. });
  10330. };
  10331. zoom.translateBy = function(selection$$1, x, y) {
  10332. zoom.transform(selection$$1, function() {
  10333. return constrain(this.__zoom.translate(
  10334. typeof x === "function" ? x.apply(this, arguments) : x,
  10335. typeof y === "function" ? y.apply(this, arguments) : y
  10336. ), extent.apply(this, arguments));
  10337. });
  10338. };
  10339. function scale(transform, k) {
  10340. k = Math.max(k0, Math.min(k1, k));
  10341. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  10342. }
  10343. function translate(transform, p0, p1) {
  10344. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  10345. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  10346. }
  10347. function constrain(transform, extent) {
  10348. var dx = Math.min(0, transform.invertX(extent[0][0]) - x0) || Math.max(0, transform.invertX(extent[1][0]) - x1),
  10349. dy = Math.min(0, transform.invertY(extent[0][1]) - y0) || Math.max(0, transform.invertY(extent[1][1]) - y1);
  10350. return dx || dy ? transform.translate(dx, dy) : transform;
  10351. }
  10352. function centroid(extent) {
  10353. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  10354. }
  10355. function schedule(transition$$1, transform, center) {
  10356. transition$$1
  10357. .on("start.zoom", function() { gesture(this, arguments).start(); })
  10358. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  10359. .tween("zoom", function() {
  10360. var that = this,
  10361. args = arguments,
  10362. g = gesture(that, args),
  10363. e = extent.apply(that, args),
  10364. p = center || centroid(e),
  10365. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  10366. a = that.__zoom,
  10367. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  10368. i = interpolateZoom(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  10369. return function(t) {
  10370. if (t === 1) t = b; // Avoid rounding error on end.
  10371. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  10372. g.zoom(null, t);
  10373. };
  10374. });
  10375. }
  10376. function gesture(that, args) {
  10377. for (var i = 0, n = gestures.length, g; i < n; ++i) {
  10378. if ((g = gestures[i]).that === that) {
  10379. return g;
  10380. }
  10381. }
  10382. return new Gesture(that, args);
  10383. }
  10384. function Gesture(that, args) {
  10385. this.that = that;
  10386. this.args = args;
  10387. this.index = -1;
  10388. this.active = 0;
  10389. this.extent = extent.apply(that, args);
  10390. }
  10391. Gesture.prototype = {
  10392. start: function() {
  10393. if (++this.active === 1) {
  10394. this.index = gestures.push(this) - 1;
  10395. this.emit("start");
  10396. }
  10397. return this;
  10398. },
  10399. zoom: function(key, transform) {
  10400. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  10401. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  10402. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  10403. this.that.__zoom = transform;
  10404. this.emit("zoom");
  10405. return this;
  10406. },
  10407. end: function() {
  10408. if (--this.active === 0) {
  10409. gestures.splice(this.index, 1);
  10410. this.index = -1;
  10411. this.emit("end");
  10412. }
  10413. return this;
  10414. },
  10415. emit: function(type) {
  10416. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  10417. }
  10418. };
  10419. function wheeled() {
  10420. if (!filter.apply(this, arguments)) return;
  10421. var g = gesture(this, arguments),
  10422. t = this.__zoom,
  10423. k = Math.max(k0, Math.min(k1, t.k * Math.pow(2, -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500))),
  10424. p = mouse(this);
  10425. // If the mouse is in the same location as before, reuse it.
  10426. // If there were recent wheel events, reset the wheel idle timeout.
  10427. if (g.wheel) {
  10428. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  10429. g.mouse[1] = t.invert(g.mouse[0] = p);
  10430. }
  10431. clearTimeout(g.wheel);
  10432. }
  10433. // If this wheel event won’t trigger a transform change, ignore it.
  10434. else if (t.k === k) return;
  10435. // Otherwise, capture the mouse point and location at the start.
  10436. else {
  10437. g.mouse = [p, t.invert(p)];
  10438. interrupt(this);
  10439. g.start();
  10440. }
  10441. noevent$1();
  10442. g.wheel = setTimeout(wheelidled, wheelDelay);
  10443. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent));
  10444. function wheelidled() {
  10445. g.wheel = null;
  10446. g.end();
  10447. }
  10448. }
  10449. function mousedowned() {
  10450. if (touchending || !filter.apply(this, arguments)) return;
  10451. var g = gesture(this, arguments),
  10452. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  10453. p = mouse(this);
  10454. dragDisable(exports.event.view);
  10455. nopropagation$1();
  10456. g.mouse = [p, this.__zoom.invert(p)];
  10457. interrupt(this);
  10458. g.start();
  10459. function mousemoved() {
  10460. noevent$1();
  10461. g.moved = true;
  10462. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent));
  10463. }
  10464. function mouseupped() {
  10465. v.on("mousemove.zoom mouseup.zoom", null);
  10466. yesdrag(exports.event.view, g.moved);
  10467. noevent$1();
  10468. g.end();
  10469. }
  10470. }
  10471. function dblclicked() {
  10472. if (!filter.apply(this, arguments)) return;
  10473. var t0 = this.__zoom,
  10474. p0 = mouse(this),
  10475. p1 = t0.invert(p0),
  10476. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  10477. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments));
  10478. noevent$1();
  10479. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  10480. else select(this).call(zoom.transform, t1);
  10481. }
  10482. function touchstarted() {
  10483. if (!filter.apply(this, arguments)) return;
  10484. var g = gesture(this, arguments),
  10485. touches$$1 = exports.event.changedTouches,
  10486. n = touches$$1.length, i, t, p;
  10487. nopropagation$1();
  10488. for (i = 0; i < n; ++i) {
  10489. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  10490. p = [p, this.__zoom.invert(p), t.identifier];
  10491. if (!g.touch0) g.touch0 = p;
  10492. else if (!g.touch1) g.touch1 = p;
  10493. }
  10494. if (touchstarting) {
  10495. touchstarting = clearTimeout(touchstarting);
  10496. if (!g.touch1) return g.end(), dblclicked.apply(this, arguments);
  10497. }
  10498. if (exports.event.touches.length === n) {
  10499. touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  10500. interrupt(this);
  10501. g.start();
  10502. }
  10503. }
  10504. function touchmoved() {
  10505. var g = gesture(this, arguments),
  10506. touches$$1 = exports.event.changedTouches,
  10507. n = touches$$1.length, i, t, p, l;
  10508. noevent$1();
  10509. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  10510. for (i = 0; i < n; ++i) {
  10511. t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
  10512. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  10513. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  10514. }
  10515. t = g.that.__zoom;
  10516. if (g.touch1) {
  10517. var p0 = g.touch0[0], l0 = g.touch0[1],
  10518. p1 = g.touch1[0], l1 = g.touch1[1],
  10519. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  10520. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  10521. t = scale(t, Math.sqrt(dp / dl));
  10522. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  10523. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  10524. }
  10525. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  10526. else return;
  10527. g.zoom("touch", constrain(translate(t, p, l), g.extent));
  10528. }
  10529. function touchended() {
  10530. var g = gesture(this, arguments),
  10531. touches$$1 = exports.event.changedTouches,
  10532. n = touches$$1.length, i, t;
  10533. nopropagation$1();
  10534. if (touchending) clearTimeout(touchending);
  10535. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  10536. for (i = 0; i < n; ++i) {
  10537. t = touches$$1[i];
  10538. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  10539. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  10540. }
  10541. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  10542. if (!g.touch0) g.end();
  10543. }
  10544. zoom.filter = function(_) {
  10545. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$10(!!_), zoom) : filter;
  10546. };
  10547. zoom.extent = function(_) {
  10548. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$10([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  10549. };
  10550. zoom.scaleExtent = function(_) {
  10551. return arguments.length ? (k0 = +_[0], k1 = +_[1], zoom) : [k0, k1];
  10552. };
  10553. zoom.translateExtent = function(_) {
  10554. return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], zoom) : [[x0, y0], [x1, y1]];
  10555. };
  10556. zoom.duration = function(_) {
  10557. return arguments.length ? (duration = +_, zoom) : duration;
  10558. };
  10559. zoom.on = function() {
  10560. var value = listeners.on.apply(listeners, arguments);
  10561. return value === listeners ? zoom : value;
  10562. };
  10563. return zoom;
  10564. };
  10565. var constant$11 = function(x) {
  10566. return function() {
  10567. return x;
  10568. };
  10569. };
  10570. var BrushEvent = function(target, type, selection) {
  10571. this.target = target;
  10572. this.type = type;
  10573. this.selection = selection;
  10574. };
  10575. function nopropagation$2() {
  10576. exports.event.stopImmediatePropagation();
  10577. }
  10578. var noevent$2 = function() {
  10579. exports.event.preventDefault();
  10580. exports.event.stopImmediatePropagation();
  10581. };
  10582. var MODE_DRAG = {name: "drag"};
  10583. var MODE_SPACE = {name: "space"};
  10584. var MODE_HANDLE = {name: "handle"};
  10585. var MODE_CENTER = {name: "center"};
  10586. var X = {
  10587. name: "x",
  10588. handles: ["e", "w"].map(type$1),
  10589. input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
  10590. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  10591. };
  10592. var Y = {
  10593. name: "y",
  10594. handles: ["n", "s"].map(type$1),
  10595. input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
  10596. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  10597. };
  10598. var XY = {
  10599. name: "xy",
  10600. handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type$1),
  10601. input: function(xy) { return xy; },
  10602. output: function(xy) { return xy; }
  10603. };
  10604. var cursors = {
  10605. overlay: "crosshair",
  10606. selection: "move",
  10607. n: "ns-resize",
  10608. e: "ew-resize",
  10609. s: "ns-resize",
  10610. w: "ew-resize",
  10611. nw: "nwse-resize",
  10612. ne: "nesw-resize",
  10613. se: "nwse-resize",
  10614. sw: "nesw-resize"
  10615. };
  10616. var flipX = {
  10617. e: "w",
  10618. w: "e",
  10619. nw: "ne",
  10620. ne: "nw",
  10621. se: "sw",
  10622. sw: "se"
  10623. };
  10624. var flipY = {
  10625. n: "s",
  10626. s: "n",
  10627. nw: "sw",
  10628. ne: "se",
  10629. se: "ne",
  10630. sw: "nw"
  10631. };
  10632. var signsX = {
  10633. overlay: +1,
  10634. selection: +1,
  10635. n: null,
  10636. e: +1,
  10637. s: null,
  10638. w: -1,
  10639. nw: -1,
  10640. ne: +1,
  10641. se: +1,
  10642. sw: -1
  10643. };
  10644. var signsY = {
  10645. overlay: +1,
  10646. selection: +1,
  10647. n: -1,
  10648. e: null,
  10649. s: +1,
  10650. w: null,
  10651. nw: -1,
  10652. ne: -1,
  10653. se: +1,
  10654. sw: +1
  10655. };
  10656. function type$1(t) {
  10657. return {type: t};
  10658. }
  10659. // Ignore right-click, since that should open the context menu.
  10660. function defaultFilter$2() {
  10661. return !exports.event.button;
  10662. }
  10663. function defaultExtent$1() {
  10664. var svg = this.ownerSVGElement || this;
  10665. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  10666. }
  10667. // Like d3.local, but with the name “__brush” rather than auto-generated.
  10668. function local$1(node) {
  10669. while (!node.__brush) if (!(node = node.parentNode)) return;
  10670. return node.__brush;
  10671. }
  10672. function empty$1(extent) {
  10673. return extent[0][0] === extent[1][0]
  10674. || extent[0][1] === extent[1][1];
  10675. }
  10676. function brushSelection(node) {
  10677. var state = node.__brush;
  10678. return state ? state.dim.output(state.selection) : null;
  10679. }
  10680. function brushX() {
  10681. return brush$1(X);
  10682. }
  10683. function brushY() {
  10684. return brush$1(Y);
  10685. }
  10686. var brush = function() {
  10687. return brush$1(XY);
  10688. };
  10689. function brush$1(dim) {
  10690. var extent = defaultExtent$1,
  10691. filter = defaultFilter$2,
  10692. listeners = dispatch(brush, "start", "brush", "end"),
  10693. handleSize = 6,
  10694. touchending;
  10695. function brush(group) {
  10696. var overlay = group
  10697. .property("__brush", initialize)
  10698. .selectAll(".overlay")
  10699. .data([type$1("overlay")]);
  10700. overlay.enter().append("rect")
  10701. .attr("class", "overlay")
  10702. .attr("pointer-events", "all")
  10703. .attr("cursor", cursors.overlay)
  10704. .merge(overlay)
  10705. .each(function() {
  10706. var extent = local$1(this).extent;
  10707. select(this)
  10708. .attr("x", extent[0][0])
  10709. .attr("y", extent[0][1])
  10710. .attr("width", extent[1][0] - extent[0][0])
  10711. .attr("height", extent[1][1] - extent[0][1]);
  10712. });
  10713. group.selectAll(".selection")
  10714. .data([type$1("selection")])
  10715. .enter().append("rect")
  10716. .attr("class", "selection")
  10717. .attr("cursor", cursors.selection)
  10718. .attr("fill", "#777")
  10719. .attr("fill-opacity", 0.3)
  10720. .attr("stroke", "#fff")
  10721. .attr("shape-rendering", "crispEdges");
  10722. var handle = group.selectAll(".handle")
  10723. .data(dim.handles, function(d) { return d.type; });
  10724. handle.exit().remove();
  10725. handle.enter().append("rect")
  10726. .attr("class", function(d) { return "handle handle--" + d.type; })
  10727. .attr("cursor", function(d) { return cursors[d.type]; });
  10728. group
  10729. .each(redraw)
  10730. .attr("fill", "none")
  10731. .attr("pointer-events", "all")
  10732. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
  10733. .on("mousedown.brush touchstart.brush", started);
  10734. }
  10735. brush.move = function(group, selection$$1) {
  10736. if (group.selection) {
  10737. group
  10738. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  10739. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  10740. .tween("brush", function() {
  10741. var that = this,
  10742. state = that.__brush,
  10743. emit = emitter(that, arguments),
  10744. selection0 = state.selection,
  10745. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
  10746. i = interpolate(selection0, selection1);
  10747. function tween(t) {
  10748. state.selection = t === 1 && empty$1(selection1) ? null : i(t);
  10749. redraw.call(that);
  10750. emit.brush();
  10751. }
  10752. return selection0 && selection1 ? tween : tween(1);
  10753. });
  10754. } else {
  10755. group
  10756. .each(function() {
  10757. var that = this,
  10758. args = arguments,
  10759. state = that.__brush,
  10760. selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
  10761. emit = emitter(that, args).beforestart();
  10762. interrupt(that);
  10763. state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
  10764. redraw.call(that);
  10765. emit.start().brush().end();
  10766. });
  10767. }
  10768. };
  10769. function redraw() {
  10770. var group = select(this),
  10771. selection$$1 = local$1(this).selection;
  10772. if (selection$$1) {
  10773. group.selectAll(".selection")
  10774. .style("display", null)
  10775. .attr("x", selection$$1[0][0])
  10776. .attr("y", selection$$1[0][1])
  10777. .attr("width", selection$$1[1][0] - selection$$1[0][0])
  10778. .attr("height", selection$$1[1][1] - selection$$1[0][1]);
  10779. group.selectAll(".handle")
  10780. .style("display", null)
  10781. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2; })
  10782. .attr("y", function(d) { return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2; })
  10783. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize; })
  10784. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize; });
  10785. }
  10786. else {
  10787. group.selectAll(".selection,.handle")
  10788. .style("display", "none")
  10789. .attr("x", null)
  10790. .attr("y", null)
  10791. .attr("width", null)
  10792. .attr("height", null);
  10793. }
  10794. }
  10795. function emitter(that, args) {
  10796. return that.__brush.emitter || new Emitter(that, args);
  10797. }
  10798. function Emitter(that, args) {
  10799. this.that = that;
  10800. this.args = args;
  10801. this.state = that.__brush;
  10802. this.active = 0;
  10803. }
  10804. Emitter.prototype = {
  10805. beforestart: function() {
  10806. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  10807. return this;
  10808. },
  10809. start: function() {
  10810. if (this.starting) this.starting = false, this.emit("start");
  10811. return this;
  10812. },
  10813. brush: function() {
  10814. this.emit("brush");
  10815. return this;
  10816. },
  10817. end: function() {
  10818. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  10819. return this;
  10820. },
  10821. emit: function(type) {
  10822. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  10823. }
  10824. };
  10825. function started() {
  10826. if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$2(); }
  10827. else if (touchending) return;
  10828. if (!filter.apply(this, arguments)) return;
  10829. var that = this,
  10830. type = exports.event.target.__data__.type,
  10831. mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  10832. signX = dim === Y ? null : signsX[type],
  10833. signY = dim === X ? null : signsY[type],
  10834. state = local$1(that),
  10835. extent = state.extent,
  10836. selection$$1 = state.selection,
  10837. W = extent[0][0], w0, w1,
  10838. N = extent[0][1], n0, n1,
  10839. E = extent[1][0], e0, e1,
  10840. S = extent[1][1], s0, s1,
  10841. dx,
  10842. dy,
  10843. moving,
  10844. shifting = signX && signY && exports.event.shiftKey,
  10845. lockX,
  10846. lockY,
  10847. point0 = mouse(that),
  10848. point = point0,
  10849. emit = emitter(that, arguments).beforestart();
  10850. if (type === "overlay") {
  10851. state.selection = selection$$1 = [
  10852. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  10853. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  10854. ];
  10855. } else {
  10856. w0 = selection$$1[0][0];
  10857. n0 = selection$$1[0][1];
  10858. e0 = selection$$1[1][0];
  10859. s0 = selection$$1[1][1];
  10860. }
  10861. w1 = w0;
  10862. n1 = n0;
  10863. e1 = e0;
  10864. s1 = s0;
  10865. var group = select(that)
  10866. .attr("pointer-events", "none");
  10867. var overlay = group.selectAll(".overlay")
  10868. .attr("cursor", cursors[type]);
  10869. if (exports.event.touches) {
  10870. group
  10871. .on("touchmove.brush", moved, true)
  10872. .on("touchend.brush touchcancel.brush", ended, true);
  10873. } else {
  10874. var view = select(exports.event.view)
  10875. .on("keydown.brush", keydowned, true)
  10876. .on("keyup.brush", keyupped, true)
  10877. .on("mousemove.brush", moved, true)
  10878. .on("mouseup.brush", ended, true);
  10879. dragDisable(exports.event.view);
  10880. }
  10881. nopropagation$2();
  10882. interrupt(that);
  10883. redraw.call(that);
  10884. emit.start();
  10885. function moved() {
  10886. var point1 = mouse(that);
  10887. if (shifting && !lockX && !lockY) {
  10888. if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
  10889. else lockX = true;
  10890. }
  10891. point = point1;
  10892. moving = true;
  10893. noevent$2();
  10894. move();
  10895. }
  10896. function move() {
  10897. var t;
  10898. dx = point[0] - point0[0];
  10899. dy = point[1] - point0[1];
  10900. switch (mode) {
  10901. case MODE_SPACE:
  10902. case MODE_DRAG: {
  10903. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  10904. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  10905. break;
  10906. }
  10907. case MODE_HANDLE: {
  10908. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  10909. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  10910. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  10911. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  10912. break;
  10913. }
  10914. case MODE_CENTER: {
  10915. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  10916. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  10917. break;
  10918. }
  10919. }
  10920. if (e1 < w1) {
  10921. signX *= -1;
  10922. t = w0, w0 = e0, e0 = t;
  10923. t = w1, w1 = e1, e1 = t;
  10924. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  10925. }
  10926. if (s1 < n1) {
  10927. signY *= -1;
  10928. t = n0, n0 = s0, s0 = t;
  10929. t = n1, n1 = s1, s1 = t;
  10930. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  10931. }
  10932. if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
  10933. if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
  10934. if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
  10935. if (selection$$1[0][0] !== w1
  10936. || selection$$1[0][1] !== n1
  10937. || selection$$1[1][0] !== e1
  10938. || selection$$1[1][1] !== s1) {
  10939. state.selection = [[w1, n1], [e1, s1]];
  10940. redraw.call(that);
  10941. emit.brush();
  10942. }
  10943. }
  10944. function ended() {
  10945. nopropagation$2();
  10946. if (exports.event.touches) {
  10947. if (exports.event.touches.length) return;
  10948. if (touchending) clearTimeout(touchending);
  10949. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  10950. group.on("touchmove.brush touchend.brush touchcancel.brush", null);
  10951. } else {
  10952. yesdrag(exports.event.view, moving);
  10953. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  10954. }
  10955. group.attr("pointer-events", "all");
  10956. overlay.attr("cursor", cursors.overlay);
  10957. if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
  10958. if (empty$1(selection$$1)) state.selection = null, redraw.call(that);
  10959. emit.end();
  10960. }
  10961. function keydowned() {
  10962. switch (exports.event.keyCode) {
  10963. case 16: { // SHIFT
  10964. shifting = signX && signY;
  10965. break;
  10966. }
  10967. case 18: { // ALT
  10968. if (mode === MODE_HANDLE) {
  10969. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  10970. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  10971. mode = MODE_CENTER;
  10972. move();
  10973. }
  10974. break;
  10975. }
  10976. case 32: { // SPACE; takes priority over ALT
  10977. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  10978. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  10979. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  10980. mode = MODE_SPACE;
  10981. overlay.attr("cursor", cursors.selection);
  10982. move();
  10983. }
  10984. break;
  10985. }
  10986. default: return;
  10987. }
  10988. noevent$2();
  10989. }
  10990. function keyupped() {
  10991. switch (exports.event.keyCode) {
  10992. case 16: { // SHIFT
  10993. if (shifting) {
  10994. lockX = lockY = shifting = false;
  10995. move();
  10996. }
  10997. break;
  10998. }
  10999. case 18: { // ALT
  11000. if (mode === MODE_CENTER) {
  11001. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  11002. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  11003. mode = MODE_HANDLE;
  11004. move();
  11005. }
  11006. break;
  11007. }
  11008. case 32: { // SPACE
  11009. if (mode === MODE_SPACE) {
  11010. if (exports.event.altKey) {
  11011. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  11012. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  11013. mode = MODE_CENTER;
  11014. } else {
  11015. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  11016. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  11017. mode = MODE_HANDLE;
  11018. }
  11019. overlay.attr("cursor", cursors[type]);
  11020. move();
  11021. }
  11022. break;
  11023. }
  11024. default: return;
  11025. }
  11026. noevent$2();
  11027. }
  11028. }
  11029. function initialize() {
  11030. var state = this.__brush || {selection: null};
  11031. state.extent = extent.apply(this, arguments);
  11032. state.dim = dim;
  11033. return state;
  11034. }
  11035. brush.extent = function(_) {
  11036. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$11([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
  11037. };
  11038. brush.filter = function(_) {
  11039. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$11(!!_), brush) : filter;
  11040. };
  11041. brush.handleSize = function(_) {
  11042. return arguments.length ? (handleSize = +_, brush) : handleSize;
  11043. };
  11044. brush.on = function() {
  11045. var value = listeners.on.apply(listeners, arguments);
  11046. return value === listeners ? brush : value;
  11047. };
  11048. return brush;
  11049. }
  11050. var cos = Math.cos;
  11051. var sin = Math.sin;
  11052. var pi$3 = Math.PI;
  11053. var halfPi$2 = pi$3 / 2;
  11054. var tau$3 = pi$3 * 2;
  11055. var max$1 = Math.max;
  11056. function compareValue(compare) {
  11057. return function(a, b) {
  11058. return compare(
  11059. a.source.value + a.target.value,
  11060. b.source.value + b.target.value
  11061. );
  11062. };
  11063. }
  11064. var chord = function() {
  11065. var padAngle = 0,
  11066. sortGroups = null,
  11067. sortSubgroups = null,
  11068. sortChords = null;
  11069. function chord(matrix) {
  11070. var n = matrix.length,
  11071. groupSums = [],
  11072. groupIndex = range(n),
  11073. subgroupIndex = [],
  11074. chords = [],
  11075. groups = chords.groups = new Array(n),
  11076. subgroups = new Array(n * n),
  11077. k,
  11078. x,
  11079. x0,
  11080. dx,
  11081. i,
  11082. j;
  11083. // Compute the sum.
  11084. k = 0, i = -1; while (++i < n) {
  11085. x = 0, j = -1; while (++j < n) {
  11086. x += matrix[i][j];
  11087. }
  11088. groupSums.push(x);
  11089. subgroupIndex.push(range(n));
  11090. k += x;
  11091. }
  11092. // Sort groups…
  11093. if (sortGroups) groupIndex.sort(function(a, b) {
  11094. return sortGroups(groupSums[a], groupSums[b]);
  11095. });
  11096. // Sort subgroups…
  11097. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  11098. d.sort(function(a, b) {
  11099. return sortSubgroups(matrix[i][a], matrix[i][b]);
  11100. });
  11101. });
  11102. // Convert the sum to scaling factor for [0, 2pi].
  11103. // TODO Allow start and end angle to be specified?
  11104. // TODO Allow padding to be specified as percentage?
  11105. k = max$1(0, tau$3 - padAngle * n) / k;
  11106. dx = k ? padAngle : tau$3 / n;
  11107. // Compute the start and end angle for each group and subgroup.
  11108. // Note: Opera has a bug reordering object literal properties!
  11109. x = 0, i = -1; while (++i < n) {
  11110. x0 = x, j = -1; while (++j < n) {
  11111. var di = groupIndex[i],
  11112. dj = subgroupIndex[di][j],
  11113. v = matrix[di][dj],
  11114. a0 = x,
  11115. a1 = x += v * k;
  11116. subgroups[dj * n + di] = {
  11117. index: di,
  11118. subindex: dj,
  11119. startAngle: a0,
  11120. endAngle: a1,
  11121. value: v
  11122. };
  11123. }
  11124. groups[di] = {
  11125. index: di,
  11126. startAngle: x0,
  11127. endAngle: x,
  11128. value: groupSums[di]
  11129. };
  11130. x += dx;
  11131. }
  11132. // Generate chords for each (non-empty) subgroup-subgroup link.
  11133. i = -1; while (++i < n) {
  11134. j = i - 1; while (++j < n) {
  11135. var source = subgroups[j * n + i],
  11136. target = subgroups[i * n + j];
  11137. if (source.value || target.value) {
  11138. chords.push(source.value < target.value
  11139. ? {source: target, target: source}
  11140. : {source: source, target: target});
  11141. }
  11142. }
  11143. }
  11144. return sortChords ? chords.sort(sortChords) : chords;
  11145. }
  11146. chord.padAngle = function(_) {
  11147. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  11148. };
  11149. chord.sortGroups = function(_) {
  11150. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  11151. };
  11152. chord.sortSubgroups = function(_) {
  11153. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  11154. };
  11155. chord.sortChords = function(_) {
  11156. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  11157. };
  11158. return chord;
  11159. };
  11160. var slice$5 = Array.prototype.slice;
  11161. var constant$12 = function(x) {
  11162. return function() {
  11163. return x;
  11164. };
  11165. };
  11166. function defaultSource(d) {
  11167. return d.source;
  11168. }
  11169. function defaultTarget(d) {
  11170. return d.target;
  11171. }
  11172. function defaultRadius$1(d) {
  11173. return d.radius;
  11174. }
  11175. function defaultStartAngle(d) {
  11176. return d.startAngle;
  11177. }
  11178. function defaultEndAngle(d) {
  11179. return d.endAngle;
  11180. }
  11181. var ribbon = function() {
  11182. var source = defaultSource,
  11183. target = defaultTarget,
  11184. radius = defaultRadius$1,
  11185. startAngle = defaultStartAngle,
  11186. endAngle = defaultEndAngle,
  11187. context = null;
  11188. function ribbon() {
  11189. var buffer,
  11190. argv = slice$5.call(arguments),
  11191. s = source.apply(this, argv),
  11192. t = target.apply(this, argv),
  11193. sr = +radius.apply(this, (argv[0] = s, argv)),
  11194. sa0 = startAngle.apply(this, argv) - halfPi$2,
  11195. sa1 = endAngle.apply(this, argv) - halfPi$2,
  11196. sx0 = sr * cos(sa0),
  11197. sy0 = sr * sin(sa0),
  11198. tr = +radius.apply(this, (argv[0] = t, argv)),
  11199. ta0 = startAngle.apply(this, argv) - halfPi$2,
  11200. ta1 = endAngle.apply(this, argv) - halfPi$2;
  11201. if (!context) context = buffer = path();
  11202. context.moveTo(sx0, sy0);
  11203. context.arc(0, 0, sr, sa0, sa1);
  11204. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  11205. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  11206. context.arc(0, 0, tr, ta0, ta1);
  11207. }
  11208. context.quadraticCurveTo(0, 0, sx0, sy0);
  11209. context.closePath();
  11210. if (buffer) return context = null, buffer + "" || null;
  11211. }
  11212. ribbon.radius = function(_) {
  11213. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$12(+_), ribbon) : radius;
  11214. };
  11215. ribbon.startAngle = function(_) {
  11216. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$12(+_), ribbon) : startAngle;
  11217. };
  11218. ribbon.endAngle = function(_) {
  11219. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$12(+_), ribbon) : endAngle;
  11220. };
  11221. ribbon.source = function(_) {
  11222. return arguments.length ? (source = _, ribbon) : source;
  11223. };
  11224. ribbon.target = function(_) {
  11225. return arguments.length ? (target = _, ribbon) : target;
  11226. };
  11227. ribbon.context = function(_) {
  11228. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  11229. };
  11230. return ribbon;
  11231. };
  11232. // Adds floating point numbers with twice the normal precision.
  11233. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  11234. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  11235. // 305–363 (1997).
  11236. // Code adapted from GeographicLib by Charles F. F. Karney,
  11237. // http://geographiclib.sourceforge.net/
  11238. var adder = function() {
  11239. return new Adder;
  11240. };
  11241. function Adder() {
  11242. this.reset();
  11243. }
  11244. Adder.prototype = {
  11245. constructor: Adder,
  11246. reset: function() {
  11247. this.s = // rounded value
  11248. this.t = 0; // exact error
  11249. },
  11250. add: function(y) {
  11251. add$1(temp, y, this.t);
  11252. add$1(this, temp.s, this.s);
  11253. if (this.s) this.t += temp.t;
  11254. else this.s = temp.t;
  11255. },
  11256. valueOf: function() {
  11257. return this.s;
  11258. }
  11259. };
  11260. var temp = new Adder;
  11261. function add$1(adder, a, b) {
  11262. var x = adder.s = a + b,
  11263. bv = x - a,
  11264. av = x - bv;
  11265. adder.t = (a - av) + (b - bv);
  11266. }
  11267. var epsilon$4 = 1e-6;
  11268. var epsilon2$2 = 1e-12;
  11269. var pi$4 = Math.PI;
  11270. var halfPi$3 = pi$4 / 2;
  11271. var quarterPi = pi$4 / 4;
  11272. var tau$4 = pi$4 * 2;
  11273. var degrees$1 = 180 / pi$4;
  11274. var radians = pi$4 / 180;
  11275. var abs = Math.abs;
  11276. var atan = Math.atan;
  11277. var atan2 = Math.atan2;
  11278. var cos$1 = Math.cos;
  11279. var ceil = Math.ceil;
  11280. var exp = Math.exp;
  11281. var log$1 = Math.log;
  11282. var pow$1 = Math.pow;
  11283. var sin$1 = Math.sin;
  11284. var sign$1 = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  11285. var sqrt$1 = Math.sqrt;
  11286. var tan = Math.tan;
  11287. function acos(x) {
  11288. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  11289. }
  11290. function asin$1(x) {
  11291. return x > 1 ? halfPi$3 : x < -1 ? -halfPi$3 : Math.asin(x);
  11292. }
  11293. function haversin(x) {
  11294. return (x = sin$1(x / 2)) * x;
  11295. }
  11296. function noop$2() {}
  11297. function streamGeometry(geometry, stream) {
  11298. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  11299. streamGeometryType[geometry.type](geometry, stream);
  11300. }
  11301. }
  11302. var streamObjectType = {
  11303. Feature: function(feature, stream) {
  11304. streamGeometry(feature.geometry, stream);
  11305. },
  11306. FeatureCollection: function(object, stream) {
  11307. var features = object.features, i = -1, n = features.length;
  11308. while (++i < n) streamGeometry(features[i].geometry, stream);
  11309. }
  11310. };
  11311. var streamGeometryType = {
  11312. Sphere: function(object, stream) {
  11313. stream.sphere();
  11314. },
  11315. Point: function(object, stream) {
  11316. object = object.coordinates;
  11317. stream.point(object[0], object[1], object[2]);
  11318. },
  11319. MultiPoint: function(object, stream) {
  11320. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  11321. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  11322. },
  11323. LineString: function(object, stream) {
  11324. streamLine(object.coordinates, stream, 0);
  11325. },
  11326. MultiLineString: function(object, stream) {
  11327. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  11328. while (++i < n) streamLine(coordinates[i], stream, 0);
  11329. },
  11330. Polygon: function(object, stream) {
  11331. streamPolygon(object.coordinates, stream);
  11332. },
  11333. MultiPolygon: function(object, stream) {
  11334. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  11335. while (++i < n) streamPolygon(coordinates[i], stream);
  11336. },
  11337. GeometryCollection: function(object, stream) {
  11338. var geometries = object.geometries, i = -1, n = geometries.length;
  11339. while (++i < n) streamGeometry(geometries[i], stream);
  11340. }
  11341. };
  11342. function streamLine(coordinates, stream, closed) {
  11343. var i = -1, n = coordinates.length - closed, coordinate;
  11344. stream.lineStart();
  11345. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  11346. stream.lineEnd();
  11347. }
  11348. function streamPolygon(coordinates, stream) {
  11349. var i = -1, n = coordinates.length;
  11350. stream.polygonStart();
  11351. while (++i < n) streamLine(coordinates[i], stream, 1);
  11352. stream.polygonEnd();
  11353. }
  11354. var geoStream = function(object, stream) {
  11355. if (object && streamObjectType.hasOwnProperty(object.type)) {
  11356. streamObjectType[object.type](object, stream);
  11357. } else {
  11358. streamGeometry(object, stream);
  11359. }
  11360. };
  11361. var areaRingSum = adder();
  11362. var areaSum = adder();
  11363. var lambda00;
  11364. var phi00;
  11365. var lambda0;
  11366. var cosPhi0;
  11367. var sinPhi0;
  11368. var areaStream = {
  11369. point: noop$2,
  11370. lineStart: noop$2,
  11371. lineEnd: noop$2,
  11372. polygonStart: function() {
  11373. areaRingSum.reset();
  11374. areaStream.lineStart = areaRingStart;
  11375. areaStream.lineEnd = areaRingEnd;
  11376. },
  11377. polygonEnd: function() {
  11378. var areaRing = +areaRingSum;
  11379. areaSum.add(areaRing < 0 ? tau$4 + areaRing : areaRing);
  11380. this.lineStart = this.lineEnd = this.point = noop$2;
  11381. },
  11382. sphere: function() {
  11383. areaSum.add(tau$4);
  11384. }
  11385. };
  11386. function areaRingStart() {
  11387. areaStream.point = areaPointFirst;
  11388. }
  11389. function areaRingEnd() {
  11390. areaPoint(lambda00, phi00);
  11391. }
  11392. function areaPointFirst(lambda, phi) {
  11393. areaStream.point = areaPoint;
  11394. lambda00 = lambda, phi00 = phi;
  11395. lambda *= radians, phi *= radians;
  11396. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  11397. }
  11398. function areaPoint(lambda, phi) {
  11399. lambda *= radians, phi *= radians;
  11400. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  11401. // Spherical excess E for a spherical triangle with vertices: south pole,
  11402. // previous point, current point. Uses a formula derived from Cagnoli’s
  11403. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  11404. var dLambda = lambda - lambda0,
  11405. sdLambda = dLambda >= 0 ? 1 : -1,
  11406. adLambda = sdLambda * dLambda,
  11407. cosPhi = cos$1(phi),
  11408. sinPhi = sin$1(phi),
  11409. k = sinPhi0 * sinPhi,
  11410. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  11411. v = k * sdLambda * sin$1(adLambda);
  11412. areaRingSum.add(atan2(v, u));
  11413. // Advance the previous points.
  11414. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  11415. }
  11416. var area$2 = function(object) {
  11417. areaSum.reset();
  11418. geoStream(object, areaStream);
  11419. return areaSum * 2;
  11420. };
  11421. function spherical(cartesian) {
  11422. return [atan2(cartesian[1], cartesian[0]), asin$1(cartesian[2])];
  11423. }
  11424. function cartesian(spherical) {
  11425. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  11426. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  11427. }
  11428. function cartesianDot(a, b) {
  11429. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  11430. }
  11431. function cartesianCross(a, b) {
  11432. 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]];
  11433. }
  11434. // TODO return a
  11435. function cartesianAddInPlace(a, b) {
  11436. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  11437. }
  11438. function cartesianScale(vector, k) {
  11439. return [vector[0] * k, vector[1] * k, vector[2] * k];
  11440. }
  11441. // TODO return d
  11442. function cartesianNormalizeInPlace(d) {
  11443. var l = sqrt$1(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  11444. d[0] /= l, d[1] /= l, d[2] /= l;
  11445. }
  11446. var lambda0$1;
  11447. var phi0;
  11448. var lambda1;
  11449. var phi1;
  11450. var lambda2;
  11451. var lambda00$1;
  11452. var phi00$1;
  11453. var p0;
  11454. var deltaSum = adder();
  11455. var ranges;
  11456. var range$1;
  11457. var boundsStream = {
  11458. point: boundsPoint,
  11459. lineStart: boundsLineStart,
  11460. lineEnd: boundsLineEnd,
  11461. polygonStart: function() {
  11462. boundsStream.point = boundsRingPoint;
  11463. boundsStream.lineStart = boundsRingStart;
  11464. boundsStream.lineEnd = boundsRingEnd;
  11465. deltaSum.reset();
  11466. areaStream.polygonStart();
  11467. },
  11468. polygonEnd: function() {
  11469. areaStream.polygonEnd();
  11470. boundsStream.point = boundsPoint;
  11471. boundsStream.lineStart = boundsLineStart;
  11472. boundsStream.lineEnd = boundsLineEnd;
  11473. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  11474. else if (deltaSum > epsilon$4) phi1 = 90;
  11475. else if (deltaSum < -epsilon$4) phi0 = -90;
  11476. range$1[0] = lambda0$1, range$1[1] = lambda1;
  11477. }
  11478. };
  11479. function boundsPoint(lambda, phi) {
  11480. ranges.push(range$1 = [lambda0$1 = lambda, lambda1 = lambda]);
  11481. if (phi < phi0) phi0 = phi;
  11482. if (phi > phi1) phi1 = phi;
  11483. }
  11484. function linePoint(lambda, phi) {
  11485. var p = cartesian([lambda * radians, phi * radians]);
  11486. if (p0) {
  11487. var normal = cartesianCross(p0, p),
  11488. equatorial = [normal[1], -normal[0], 0],
  11489. inflection = cartesianCross(equatorial, normal);
  11490. cartesianNormalizeInPlace(inflection);
  11491. inflection = spherical(inflection);
  11492. var delta = lambda - lambda2,
  11493. sign$$1 = delta > 0 ? 1 : -1,
  11494. lambdai = inflection[0] * degrees$1 * sign$$1,
  11495. phii,
  11496. antimeridian = abs(delta) > 180;
  11497. if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  11498. phii = inflection[1] * degrees$1;
  11499. if (phii > phi1) phi1 = phii;
  11500. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
  11501. phii = -inflection[1] * degrees$1;
  11502. if (phii < phi0) phi0 = phii;
  11503. } else {
  11504. if (phi < phi0) phi0 = phi;
  11505. if (phi > phi1) phi1 = phi;
  11506. }
  11507. if (antimeridian) {
  11508. if (lambda < lambda2) {
  11509. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  11510. } else {
  11511. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  11512. }
  11513. } else {
  11514. if (lambda1 >= lambda0$1) {
  11515. if (lambda < lambda0$1) lambda0$1 = lambda;
  11516. if (lambda > lambda1) lambda1 = lambda;
  11517. } else {
  11518. if (lambda > lambda2) {
  11519. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  11520. } else {
  11521. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  11522. }
  11523. }
  11524. }
  11525. } else {
  11526. boundsPoint(lambda, phi);
  11527. }
  11528. p0 = p, lambda2 = lambda;
  11529. }
  11530. function boundsLineStart() {
  11531. boundsStream.point = linePoint;
  11532. }
  11533. function boundsLineEnd() {
  11534. range$1[0] = lambda0$1, range$1[1] = lambda1;
  11535. boundsStream.point = boundsPoint;
  11536. p0 = null;
  11537. }
  11538. function boundsRingPoint(lambda, phi) {
  11539. if (p0) {
  11540. var delta = lambda - lambda2;
  11541. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  11542. } else {
  11543. lambda00$1 = lambda, phi00$1 = phi;
  11544. }
  11545. areaStream.point(lambda, phi);
  11546. linePoint(lambda, phi);
  11547. }
  11548. function boundsRingStart() {
  11549. areaStream.lineStart();
  11550. }
  11551. function boundsRingEnd() {
  11552. boundsRingPoint(lambda00$1, phi00$1);
  11553. areaStream.lineEnd();
  11554. if (abs(deltaSum) > epsilon$4) lambda0$1 = -(lambda1 = 180);
  11555. range$1[0] = lambda0$1, range$1[1] = lambda1;
  11556. p0 = null;
  11557. }
  11558. // Finds the left-right distance between two longitudes.
  11559. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  11560. // the distance between ±180° to be 360°.
  11561. function angle(lambda0, lambda1) {
  11562. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  11563. }
  11564. function rangeCompare(a, b) {
  11565. return a[0] - b[0];
  11566. }
  11567. function rangeContains(range, x) {
  11568. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  11569. }
  11570. var bounds = function(feature) {
  11571. var i, n, a, b, merged, deltaMax, delta;
  11572. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  11573. ranges = [];
  11574. geoStream(feature, boundsStream);
  11575. // First, sort ranges by their minimum longitudes.
  11576. if (n = ranges.length) {
  11577. ranges.sort(rangeCompare);
  11578. // Then, merge any ranges that overlap.
  11579. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  11580. b = ranges[i];
  11581. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  11582. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  11583. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  11584. } else {
  11585. merged.push(a = b);
  11586. }
  11587. }
  11588. // Finally, find the largest gap between the merged ranges.
  11589. // The final bounding box will be the inverse of this gap.
  11590. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  11591. b = merged[i];
  11592. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  11593. }
  11594. }
  11595. ranges = range$1 = null;
  11596. return lambda0$1 === Infinity || phi0 === Infinity
  11597. ? [[NaN, NaN], [NaN, NaN]]
  11598. : [[lambda0$1, phi0], [lambda1, phi1]];
  11599. };
  11600. var W0;
  11601. var W1;
  11602. var X0;
  11603. var Y0;
  11604. var Z0;
  11605. var X1;
  11606. var Y1;
  11607. var Z1;
  11608. var X2;
  11609. var Y2;
  11610. var Z2;
  11611. var lambda00$2;
  11612. var phi00$2;
  11613. var x0;
  11614. var y0;
  11615. var z0; // previous point
  11616. var centroidStream = {
  11617. sphere: noop$2,
  11618. point: centroidPoint,
  11619. lineStart: centroidLineStart,
  11620. lineEnd: centroidLineEnd,
  11621. polygonStart: function() {
  11622. centroidStream.lineStart = centroidRingStart;
  11623. centroidStream.lineEnd = centroidRingEnd;
  11624. },
  11625. polygonEnd: function() {
  11626. centroidStream.lineStart = centroidLineStart;
  11627. centroidStream.lineEnd = centroidLineEnd;
  11628. }
  11629. };
  11630. // Arithmetic mean of Cartesian vectors.
  11631. function centroidPoint(lambda, phi) {
  11632. lambda *= radians, phi *= radians;
  11633. var cosPhi = cos$1(phi);
  11634. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  11635. }
  11636. function centroidPointCartesian(x, y, z) {
  11637. ++W0;
  11638. X0 += (x - X0) / W0;
  11639. Y0 += (y - Y0) / W0;
  11640. Z0 += (z - Z0) / W0;
  11641. }
  11642. function centroidLineStart() {
  11643. centroidStream.point = centroidLinePointFirst;
  11644. }
  11645. function centroidLinePointFirst(lambda, phi) {
  11646. lambda *= radians, phi *= radians;
  11647. var cosPhi = cos$1(phi);
  11648. x0 = cosPhi * cos$1(lambda);
  11649. y0 = cosPhi * sin$1(lambda);
  11650. z0 = sin$1(phi);
  11651. centroidStream.point = centroidLinePoint;
  11652. centroidPointCartesian(x0, y0, z0);
  11653. }
  11654. function centroidLinePoint(lambda, phi) {
  11655. lambda *= radians, phi *= radians;
  11656. var cosPhi = cos$1(phi),
  11657. x = cosPhi * cos$1(lambda),
  11658. y = cosPhi * sin$1(lambda),
  11659. z = sin$1(phi),
  11660. 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);
  11661. W1 += w;
  11662. X1 += w * (x0 + (x0 = x));
  11663. Y1 += w * (y0 + (y0 = y));
  11664. Z1 += w * (z0 + (z0 = z));
  11665. centroidPointCartesian(x0, y0, z0);
  11666. }
  11667. function centroidLineEnd() {
  11668. centroidStream.point = centroidPoint;
  11669. }
  11670. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  11671. // J. Applied Mechanics 42, 239 (1975).
  11672. function centroidRingStart() {
  11673. centroidStream.point = centroidRingPointFirst;
  11674. }
  11675. function centroidRingEnd() {
  11676. centroidRingPoint(lambda00$2, phi00$2);
  11677. centroidStream.point = centroidPoint;
  11678. }
  11679. function centroidRingPointFirst(lambda, phi) {
  11680. lambda00$2 = lambda, phi00$2 = phi;
  11681. lambda *= radians, phi *= radians;
  11682. centroidStream.point = centroidRingPoint;
  11683. var cosPhi = cos$1(phi);
  11684. x0 = cosPhi * cos$1(lambda);
  11685. y0 = cosPhi * sin$1(lambda);
  11686. z0 = sin$1(phi);
  11687. centroidPointCartesian(x0, y0, z0);
  11688. }
  11689. function centroidRingPoint(lambda, phi) {
  11690. lambda *= radians, phi *= radians;
  11691. var cosPhi = cos$1(phi),
  11692. x = cosPhi * cos$1(lambda),
  11693. y = cosPhi * sin$1(lambda),
  11694. z = sin$1(phi),
  11695. cx = y0 * z - z0 * y,
  11696. cy = z0 * x - x0 * z,
  11697. cz = x0 * y - y0 * x,
  11698. m = sqrt$1(cx * cx + cy * cy + cz * cz),
  11699. u = x0 * x + y0 * y + z0 * z,
  11700. v = m && -acos(u) / m, // area weight
  11701. w = atan2(m, u); // line weight
  11702. X2 += v * cx;
  11703. Y2 += v * cy;
  11704. Z2 += v * cz;
  11705. W1 += w;
  11706. X1 += w * (x0 + (x0 = x));
  11707. Y1 += w * (y0 + (y0 = y));
  11708. Z1 += w * (z0 + (z0 = z));
  11709. centroidPointCartesian(x0, y0, z0);
  11710. }
  11711. var centroid$1 = function(object) {
  11712. W0 = W1 =
  11713. X0 = Y0 = Z0 =
  11714. X1 = Y1 = Z1 =
  11715. X2 = Y2 = Z2 = 0;
  11716. geoStream(object, centroidStream);
  11717. var x = X2,
  11718. y = Y2,
  11719. z = Z2,
  11720. m = x * x + y * y + z * z;
  11721. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  11722. if (m < epsilon2$2) {
  11723. x = X1, y = Y1, z = Z1;
  11724. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  11725. if (W1 < epsilon$4) x = X0, y = Y0, z = Z0;
  11726. m = x * x + y * y + z * z;
  11727. // If the feature still has an undefined ccentroid, then return.
  11728. if (m < epsilon2$2) return [NaN, NaN];
  11729. }
  11730. return [atan2(y, x) * degrees$1, asin$1(z / sqrt$1(m)) * degrees$1];
  11731. };
  11732. var constant$13 = function(x) {
  11733. return function() {
  11734. return x;
  11735. };
  11736. };
  11737. var compose = function(a, b) {
  11738. function compose(x, y) {
  11739. return x = a(x, y), b(x[0], x[1]);
  11740. }
  11741. if (a.invert && b.invert) compose.invert = function(x, y) {
  11742. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  11743. };
  11744. return compose;
  11745. };
  11746. function rotationIdentity(lambda, phi) {
  11747. return [lambda > pi$4 ? lambda - tau$4 : lambda < -pi$4 ? lambda + tau$4 : lambda, phi];
  11748. }
  11749. rotationIdentity.invert = rotationIdentity;
  11750. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  11751. return (deltaLambda %= tau$4) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  11752. : rotationLambda(deltaLambda))
  11753. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  11754. : rotationIdentity);
  11755. }
  11756. function forwardRotationLambda(deltaLambda) {
  11757. return function(lambda, phi) {
  11758. return lambda += deltaLambda, [lambda > pi$4 ? lambda - tau$4 : lambda < -pi$4 ? lambda + tau$4 : lambda, phi];
  11759. };
  11760. }
  11761. function rotationLambda(deltaLambda) {
  11762. var rotation = forwardRotationLambda(deltaLambda);
  11763. rotation.invert = forwardRotationLambda(-deltaLambda);
  11764. return rotation;
  11765. }
  11766. function rotationPhiGamma(deltaPhi, deltaGamma) {
  11767. var cosDeltaPhi = cos$1(deltaPhi),
  11768. sinDeltaPhi = sin$1(deltaPhi),
  11769. cosDeltaGamma = cos$1(deltaGamma),
  11770. sinDeltaGamma = sin$1(deltaGamma);
  11771. function rotation(lambda, phi) {
  11772. var cosPhi = cos$1(phi),
  11773. x = cos$1(lambda) * cosPhi,
  11774. y = sin$1(lambda) * cosPhi,
  11775. z = sin$1(phi),
  11776. k = z * cosDeltaPhi + x * sinDeltaPhi;
  11777. return [
  11778. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  11779. asin$1(k * cosDeltaGamma + y * sinDeltaGamma)
  11780. ];
  11781. }
  11782. rotation.invert = function(lambda, phi) {
  11783. var cosPhi = cos$1(phi),
  11784. x = cos$1(lambda) * cosPhi,
  11785. y = sin$1(lambda) * cosPhi,
  11786. z = sin$1(phi),
  11787. k = z * cosDeltaGamma - y * sinDeltaGamma;
  11788. return [
  11789. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  11790. asin$1(k * cosDeltaPhi - x * sinDeltaPhi)
  11791. ];
  11792. };
  11793. return rotation;
  11794. }
  11795. var rotation = function(rotate) {
  11796. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  11797. function forward(coordinates) {
  11798. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  11799. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  11800. }
  11801. forward.invert = function(coordinates) {
  11802. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  11803. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  11804. };
  11805. return forward;
  11806. };
  11807. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  11808. function circleStream(stream, radius, delta, direction, t0, t1) {
  11809. if (!delta) return;
  11810. var cosRadius = cos$1(radius),
  11811. sinRadius = sin$1(radius),
  11812. step = direction * delta;
  11813. if (t0 == null) {
  11814. t0 = radius + direction * tau$4;
  11815. t1 = radius - step / 2;
  11816. } else {
  11817. t0 = circleRadius(cosRadius, t0);
  11818. t1 = circleRadius(cosRadius, t1);
  11819. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$4;
  11820. }
  11821. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  11822. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  11823. stream.point(point[0], point[1]);
  11824. }
  11825. }
  11826. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  11827. function circleRadius(cosRadius, point) {
  11828. point = cartesian(point), point[0] -= cosRadius;
  11829. cartesianNormalizeInPlace(point);
  11830. var radius = acos(-point[1]);
  11831. return ((-point[2] < 0 ? -radius : radius) + tau$4 - epsilon$4) % tau$4;
  11832. }
  11833. var circle$1 = function() {
  11834. var center = constant$13([0, 0]),
  11835. radius = constant$13(90),
  11836. precision = constant$13(6),
  11837. ring,
  11838. rotate,
  11839. stream = {point: point};
  11840. function point(x, y) {
  11841. ring.push(x = rotate(x, y));
  11842. x[0] *= degrees$1, x[1] *= degrees$1;
  11843. }
  11844. function circle() {
  11845. var c = center.apply(this, arguments),
  11846. r = radius.apply(this, arguments) * radians,
  11847. p = precision.apply(this, arguments) * radians;
  11848. ring = [];
  11849. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  11850. circleStream(stream, r, p, 1);
  11851. c = {type: "Polygon", coordinates: [ring]};
  11852. ring = rotate = null;
  11853. return c;
  11854. }
  11855. circle.center = function(_) {
  11856. return arguments.length ? (center = typeof _ === "function" ? _ : constant$13([+_[0], +_[1]]), circle) : center;
  11857. };
  11858. circle.radius = function(_) {
  11859. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$13(+_), circle) : radius;
  11860. };
  11861. circle.precision = function(_) {
  11862. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$13(+_), circle) : precision;
  11863. };
  11864. return circle;
  11865. };
  11866. var clipBuffer = function() {
  11867. var lines = [],
  11868. line;
  11869. return {
  11870. point: function(x, y) {
  11871. line.push([x, y]);
  11872. },
  11873. lineStart: function() {
  11874. lines.push(line = []);
  11875. },
  11876. lineEnd: noop$2,
  11877. rejoin: function() {
  11878. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  11879. },
  11880. result: function() {
  11881. var result = lines;
  11882. lines = [];
  11883. line = null;
  11884. return result;
  11885. }
  11886. };
  11887. };
  11888. var clipLine = function(a, b, x0, y0, x1, y1) {
  11889. var ax = a[0],
  11890. ay = a[1],
  11891. bx = b[0],
  11892. by = b[1],
  11893. t0 = 0,
  11894. t1 = 1,
  11895. dx = bx - ax,
  11896. dy = by - ay,
  11897. r;
  11898. r = x0 - ax;
  11899. if (!dx && r > 0) return;
  11900. r /= dx;
  11901. if (dx < 0) {
  11902. if (r < t0) return;
  11903. if (r < t1) t1 = r;
  11904. } else if (dx > 0) {
  11905. if (r > t1) return;
  11906. if (r > t0) t0 = r;
  11907. }
  11908. r = x1 - ax;
  11909. if (!dx && r < 0) return;
  11910. r /= dx;
  11911. if (dx < 0) {
  11912. if (r > t1) return;
  11913. if (r > t0) t0 = r;
  11914. } else if (dx > 0) {
  11915. if (r < t0) return;
  11916. if (r < t1) t1 = r;
  11917. }
  11918. r = y0 - ay;
  11919. if (!dy && r > 0) return;
  11920. r /= dy;
  11921. if (dy < 0) {
  11922. if (r < t0) return;
  11923. if (r < t1) t1 = r;
  11924. } else if (dy > 0) {
  11925. if (r > t1) return;
  11926. if (r > t0) t0 = r;
  11927. }
  11928. r = y1 - ay;
  11929. if (!dy && r < 0) return;
  11930. r /= dy;
  11931. if (dy < 0) {
  11932. if (r > t1) return;
  11933. if (r > t0) t0 = r;
  11934. } else if (dy > 0) {
  11935. if (r < t0) return;
  11936. if (r < t1) t1 = r;
  11937. }
  11938. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  11939. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  11940. return true;
  11941. };
  11942. var pointEqual = function(a, b) {
  11943. return abs(a[0] - b[0]) < epsilon$4 && abs(a[1] - b[1]) < epsilon$4;
  11944. };
  11945. function Intersection(point, points, other, entry) {
  11946. this.x = point;
  11947. this.z = points;
  11948. this.o = other; // another intersection
  11949. this.e = entry; // is an entry?
  11950. this.v = false; // visited
  11951. this.n = this.p = null; // next & previous
  11952. }
  11953. // A generalized polygon clipping algorithm: given a polygon that has been cut
  11954. // into its visible line segments, and rejoins the segments by interpolating
  11955. // along the clip edge.
  11956. var clipPolygon = function(segments, compareIntersection, startInside, interpolate, stream) {
  11957. var subject = [],
  11958. clip = [],
  11959. i,
  11960. n;
  11961. segments.forEach(function(segment) {
  11962. if ((n = segment.length - 1) <= 0) return;
  11963. var n, p0 = segment[0], p1 = segment[n], x;
  11964. // If the first and last points of a segment are coincident, then treat as a
  11965. // closed ring. TODO if all rings are closed, then the winding order of the
  11966. // exterior ring should be checked.
  11967. if (pointEqual(p0, p1)) {
  11968. stream.lineStart();
  11969. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  11970. stream.lineEnd();
  11971. return;
  11972. }
  11973. subject.push(x = new Intersection(p0, segment, null, true));
  11974. clip.push(x.o = new Intersection(p0, null, x, false));
  11975. subject.push(x = new Intersection(p1, segment, null, false));
  11976. clip.push(x.o = new Intersection(p1, null, x, true));
  11977. });
  11978. if (!subject.length) return;
  11979. clip.sort(compareIntersection);
  11980. link$1(subject);
  11981. link$1(clip);
  11982. for (i = 0, n = clip.length; i < n; ++i) {
  11983. clip[i].e = startInside = !startInside;
  11984. }
  11985. var start = subject[0],
  11986. points,
  11987. point;
  11988. while (1) {
  11989. // Find first unvisited intersection.
  11990. var current = start,
  11991. isSubject = true;
  11992. while (current.v) if ((current = current.n) === start) return;
  11993. points = current.z;
  11994. stream.lineStart();
  11995. do {
  11996. current.v = current.o.v = true;
  11997. if (current.e) {
  11998. if (isSubject) {
  11999. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  12000. } else {
  12001. interpolate(current.x, current.n.x, 1, stream);
  12002. }
  12003. current = current.n;
  12004. } else {
  12005. if (isSubject) {
  12006. points = current.p.z;
  12007. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  12008. } else {
  12009. interpolate(current.x, current.p.x, -1, stream);
  12010. }
  12011. current = current.p;
  12012. }
  12013. current = current.o;
  12014. points = current.z;
  12015. isSubject = !isSubject;
  12016. } while (!current.v);
  12017. stream.lineEnd();
  12018. }
  12019. };
  12020. function link$1(array) {
  12021. if (!(n = array.length)) return;
  12022. var n,
  12023. i = 0,
  12024. a = array[0],
  12025. b;
  12026. while (++i < n) {
  12027. a.n = b = array[i];
  12028. b.p = a;
  12029. a = b;
  12030. }
  12031. a.n = b = array[0];
  12032. b.p = a;
  12033. }
  12034. var clipMax = 1e9;
  12035. var clipMin = -clipMax;
  12036. // TODO Use d3-polygon’s polygonContains here for the ring check?
  12037. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  12038. function clipExtent(x0, y0, x1, y1) {
  12039. function visible(x, y) {
  12040. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  12041. }
  12042. function interpolate(from, to, direction, stream) {
  12043. var a = 0, a1 = 0;
  12044. if (from == null
  12045. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  12046. || comparePoint(from, to) < 0 ^ direction > 0) {
  12047. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  12048. while ((a = (a + direction + 4) % 4) !== a1);
  12049. } else {
  12050. stream.point(to[0], to[1]);
  12051. }
  12052. }
  12053. function corner(p, direction) {
  12054. return abs(p[0] - x0) < epsilon$4 ? direction > 0 ? 0 : 3
  12055. : abs(p[0] - x1) < epsilon$4 ? direction > 0 ? 2 : 1
  12056. : abs(p[1] - y0) < epsilon$4 ? direction > 0 ? 1 : 0
  12057. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  12058. }
  12059. function compareIntersection(a, b) {
  12060. return comparePoint(a.x, b.x);
  12061. }
  12062. function comparePoint(a, b) {
  12063. var ca = corner(a, 1),
  12064. cb = corner(b, 1);
  12065. return ca !== cb ? ca - cb
  12066. : ca === 0 ? b[1] - a[1]
  12067. : ca === 1 ? a[0] - b[0]
  12068. : ca === 2 ? a[1] - b[1]
  12069. : b[0] - a[0];
  12070. }
  12071. return function(stream) {
  12072. var activeStream = stream,
  12073. bufferStream = clipBuffer(),
  12074. segments,
  12075. polygon,
  12076. ring,
  12077. x__, y__, v__, // first point
  12078. x_, y_, v_, // previous point
  12079. first,
  12080. clean;
  12081. var clipStream = {
  12082. point: point,
  12083. lineStart: lineStart,
  12084. lineEnd: lineEnd,
  12085. polygonStart: polygonStart,
  12086. polygonEnd: polygonEnd
  12087. };
  12088. function point(x, y) {
  12089. if (visible(x, y)) activeStream.point(x, y);
  12090. }
  12091. function polygonInside() {
  12092. var winding = 0;
  12093. for (var i = 0, n = polygon.length; i < n; ++i) {
  12094. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  12095. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  12096. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  12097. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  12098. }
  12099. }
  12100. return winding;
  12101. }
  12102. // Buffer geometry within a polygon and then clip it en masse.
  12103. function polygonStart() {
  12104. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  12105. }
  12106. function polygonEnd() {
  12107. var startInside = polygonInside(),
  12108. cleanInside = clean && startInside,
  12109. visible = (segments = merge(segments)).length;
  12110. if (cleanInside || visible) {
  12111. stream.polygonStart();
  12112. if (cleanInside) {
  12113. stream.lineStart();
  12114. interpolate(null, null, 1, stream);
  12115. stream.lineEnd();
  12116. }
  12117. if (visible) {
  12118. clipPolygon(segments, compareIntersection, startInside, interpolate, stream);
  12119. }
  12120. stream.polygonEnd();
  12121. }
  12122. activeStream = stream, segments = polygon = ring = null;
  12123. }
  12124. function lineStart() {
  12125. clipStream.point = linePoint;
  12126. if (polygon) polygon.push(ring = []);
  12127. first = true;
  12128. v_ = false;
  12129. x_ = y_ = NaN;
  12130. }
  12131. // TODO rather than special-case polygons, simply handle them separately.
  12132. // Ideally, coincident intersection points should be jittered to avoid
  12133. // clipping issues.
  12134. function lineEnd() {
  12135. if (segments) {
  12136. linePoint(x__, y__);
  12137. if (v__ && v_) bufferStream.rejoin();
  12138. segments.push(bufferStream.result());
  12139. }
  12140. clipStream.point = point;
  12141. if (v_) activeStream.lineEnd();
  12142. }
  12143. function linePoint(x, y) {
  12144. var v = visible(x, y);
  12145. if (polygon) ring.push([x, y]);
  12146. if (first) {
  12147. x__ = x, y__ = y, v__ = v;
  12148. first = false;
  12149. if (v) {
  12150. activeStream.lineStart();
  12151. activeStream.point(x, y);
  12152. }
  12153. } else {
  12154. if (v && v_) activeStream.point(x, y);
  12155. else {
  12156. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  12157. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  12158. if (clipLine(a, b, x0, y0, x1, y1)) {
  12159. if (!v_) {
  12160. activeStream.lineStart();
  12161. activeStream.point(a[0], a[1]);
  12162. }
  12163. activeStream.point(b[0], b[1]);
  12164. if (!v) activeStream.lineEnd();
  12165. clean = false;
  12166. } else if (v) {
  12167. activeStream.lineStart();
  12168. activeStream.point(x, y);
  12169. clean = false;
  12170. }
  12171. }
  12172. }
  12173. x_ = x, y_ = y, v_ = v;
  12174. }
  12175. return clipStream;
  12176. };
  12177. }
  12178. var extent$1 = function() {
  12179. var x0 = 0,
  12180. y0 = 0,
  12181. x1 = 960,
  12182. y1 = 500,
  12183. cache,
  12184. cacheStream,
  12185. clip;
  12186. return clip = {
  12187. stream: function(stream) {
  12188. return cache && cacheStream === stream ? cache : cache = clipExtent(x0, y0, x1, y1)(cacheStream = stream);
  12189. },
  12190. extent: function(_) {
  12191. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  12192. }
  12193. };
  12194. };
  12195. var lengthSum = adder();
  12196. var lambda0$2;
  12197. var sinPhi0$1;
  12198. var cosPhi0$1;
  12199. var lengthStream = {
  12200. sphere: noop$2,
  12201. point: noop$2,
  12202. lineStart: lengthLineStart,
  12203. lineEnd: noop$2,
  12204. polygonStart: noop$2,
  12205. polygonEnd: noop$2
  12206. };
  12207. function lengthLineStart() {
  12208. lengthStream.point = lengthPointFirst;
  12209. lengthStream.lineEnd = lengthLineEnd;
  12210. }
  12211. function lengthLineEnd() {
  12212. lengthStream.point = lengthStream.lineEnd = noop$2;
  12213. }
  12214. function lengthPointFirst(lambda, phi) {
  12215. lambda *= radians, phi *= radians;
  12216. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  12217. lengthStream.point = lengthPoint;
  12218. }
  12219. function lengthPoint(lambda, phi) {
  12220. lambda *= radians, phi *= radians;
  12221. var sinPhi = sin$1(phi),
  12222. cosPhi = cos$1(phi),
  12223. delta = abs(lambda - lambda0$2),
  12224. cosDelta = cos$1(delta),
  12225. sinDelta = sin$1(delta),
  12226. x = cosPhi * sinDelta,
  12227. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  12228. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  12229. lengthSum.add(atan2(sqrt$1(x * x + y * y), z));
  12230. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  12231. }
  12232. var length$2 = function(object) {
  12233. lengthSum.reset();
  12234. geoStream(object, lengthStream);
  12235. return +lengthSum;
  12236. };
  12237. var coordinates = [null, null];
  12238. var object$1 = {type: "LineString", coordinates: coordinates};
  12239. var distance = function(a, b) {
  12240. coordinates[0] = a;
  12241. coordinates[1] = b;
  12242. return length$2(object$1);
  12243. };
  12244. function graticuleX(y0, y1, dy) {
  12245. var y = range(y0, y1 - epsilon$4, dy).concat(y1);
  12246. return function(x) { return y.map(function(y) { return [x, y]; }); };
  12247. }
  12248. function graticuleY(x0, x1, dx) {
  12249. var x = range(x0, x1 - epsilon$4, dx).concat(x1);
  12250. return function(y) { return x.map(function(x) { return [x, y]; }); };
  12251. }
  12252. function graticule() {
  12253. var x1, x0, X1, X0,
  12254. y1, y0, Y1, Y0,
  12255. dx = 10, dy = dx, DX = 90, DY = 360,
  12256. x, y, X, Y,
  12257. precision = 2.5;
  12258. function graticule() {
  12259. return {type: "MultiLineString", coordinates: lines()};
  12260. }
  12261. function lines() {
  12262. return range(ceil(X0 / DX) * DX, X1, DX).map(X)
  12263. .concat(range(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  12264. .concat(range(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$4; }).map(x))
  12265. .concat(range(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$4; }).map(y));
  12266. }
  12267. graticule.lines = function() {
  12268. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  12269. };
  12270. graticule.outline = function() {
  12271. return {
  12272. type: "Polygon",
  12273. coordinates: [
  12274. X(X0).concat(
  12275. Y(Y1).slice(1),
  12276. X(X1).reverse().slice(1),
  12277. Y(Y0).reverse().slice(1))
  12278. ]
  12279. };
  12280. };
  12281. graticule.extent = function(_) {
  12282. if (!arguments.length) return graticule.extentMinor();
  12283. return graticule.extentMajor(_).extentMinor(_);
  12284. };
  12285. graticule.extentMajor = function(_) {
  12286. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  12287. X0 = +_[0][0], X1 = +_[1][0];
  12288. Y0 = +_[0][1], Y1 = +_[1][1];
  12289. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  12290. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  12291. return graticule.precision(precision);
  12292. };
  12293. graticule.extentMinor = function(_) {
  12294. if (!arguments.length) return [[x0, y0], [x1, y1]];
  12295. x0 = +_[0][0], x1 = +_[1][0];
  12296. y0 = +_[0][1], y1 = +_[1][1];
  12297. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  12298. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  12299. return graticule.precision(precision);
  12300. };
  12301. graticule.step = function(_) {
  12302. if (!arguments.length) return graticule.stepMinor();
  12303. return graticule.stepMajor(_).stepMinor(_);
  12304. };
  12305. graticule.stepMajor = function(_) {
  12306. if (!arguments.length) return [DX, DY];
  12307. DX = +_[0], DY = +_[1];
  12308. return graticule;
  12309. };
  12310. graticule.stepMinor = function(_) {
  12311. if (!arguments.length) return [dx, dy];
  12312. dx = +_[0], dy = +_[1];
  12313. return graticule;
  12314. };
  12315. graticule.precision = function(_) {
  12316. if (!arguments.length) return precision;
  12317. precision = +_;
  12318. x = graticuleX(y0, y1, 90);
  12319. y = graticuleY(x0, x1, precision);
  12320. X = graticuleX(Y0, Y1, 90);
  12321. Y = graticuleY(X0, X1, precision);
  12322. return graticule;
  12323. };
  12324. return graticule
  12325. .extentMajor([[-180, -90 + epsilon$4], [180, 90 - epsilon$4]])
  12326. .extentMinor([[-180, -80 - epsilon$4], [180, 80 + epsilon$4]]);
  12327. }
  12328. function graticule10() {
  12329. return graticule()();
  12330. }
  12331. var interpolate$2 = function(a, b) {
  12332. var x0 = a[0] * radians,
  12333. y0 = a[1] * radians,
  12334. x1 = b[0] * radians,
  12335. y1 = b[1] * radians,
  12336. cy0 = cos$1(y0),
  12337. sy0 = sin$1(y0),
  12338. cy1 = cos$1(y1),
  12339. sy1 = sin$1(y1),
  12340. kx0 = cy0 * cos$1(x0),
  12341. ky0 = cy0 * sin$1(x0),
  12342. kx1 = cy1 * cos$1(x1),
  12343. ky1 = cy1 * sin$1(x1),
  12344. d = 2 * asin$1(sqrt$1(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  12345. k = sin$1(d);
  12346. var interpolate = d ? function(t) {
  12347. var B = sin$1(t *= d) / k,
  12348. A = sin$1(d - t) / k,
  12349. x = A * kx0 + B * kx1,
  12350. y = A * ky0 + B * ky1,
  12351. z = A * sy0 + B * sy1;
  12352. return [
  12353. atan2(y, x) * degrees$1,
  12354. atan2(z, sqrt$1(x * x + y * y)) * degrees$1
  12355. ];
  12356. } : function() {
  12357. return [x0 * degrees$1, y0 * degrees$1];
  12358. };
  12359. interpolate.distance = d;
  12360. return interpolate;
  12361. };
  12362. var identity$7 = function(x) {
  12363. return x;
  12364. };
  12365. var areaSum$1 = adder();
  12366. var areaRingSum$1 = adder();
  12367. var x00;
  12368. var y00;
  12369. var x0$1;
  12370. var y0$1;
  12371. var areaStream$1 = {
  12372. point: noop$2,
  12373. lineStart: noop$2,
  12374. lineEnd: noop$2,
  12375. polygonStart: function() {
  12376. areaStream$1.lineStart = areaRingStart$1;
  12377. areaStream$1.lineEnd = areaRingEnd$1;
  12378. },
  12379. polygonEnd: function() {
  12380. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  12381. areaSum$1.add(abs(areaRingSum$1));
  12382. areaRingSum$1.reset();
  12383. },
  12384. result: function() {
  12385. var area = areaSum$1 / 2;
  12386. areaSum$1.reset();
  12387. return area;
  12388. }
  12389. };
  12390. function areaRingStart$1() {
  12391. areaStream$1.point = areaPointFirst$1;
  12392. }
  12393. function areaPointFirst$1(x, y) {
  12394. areaStream$1.point = areaPoint$1;
  12395. x00 = x0$1 = x, y00 = y0$1 = y;
  12396. }
  12397. function areaPoint$1(x, y) {
  12398. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  12399. x0$1 = x, y0$1 = y;
  12400. }
  12401. function areaRingEnd$1() {
  12402. areaPoint$1(x00, y00);
  12403. }
  12404. var x0$2 = Infinity;
  12405. var y0$2 = x0$2;
  12406. var x1 = -x0$2;
  12407. var y1 = x1;
  12408. var boundsStream$1 = {
  12409. point: boundsPoint$1,
  12410. lineStart: noop$2,
  12411. lineEnd: noop$2,
  12412. polygonStart: noop$2,
  12413. polygonEnd: noop$2,
  12414. result: function() {
  12415. var bounds = [[x0$2, y0$2], [x1, y1]];
  12416. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  12417. return bounds;
  12418. }
  12419. };
  12420. function boundsPoint$1(x, y) {
  12421. if (x < x0$2) x0$2 = x;
  12422. if (x > x1) x1 = x;
  12423. if (y < y0$2) y0$2 = y;
  12424. if (y > y1) y1 = y;
  12425. }
  12426. // TODO Enforce positive area for exterior, negative area for interior?
  12427. var X0$1 = 0;
  12428. var Y0$1 = 0;
  12429. var Z0$1 = 0;
  12430. var X1$1 = 0;
  12431. var Y1$1 = 0;
  12432. var Z1$1 = 0;
  12433. var X2$1 = 0;
  12434. var Y2$1 = 0;
  12435. var Z2$1 = 0;
  12436. var x00$1;
  12437. var y00$1;
  12438. var x0$3;
  12439. var y0$3;
  12440. var centroidStream$1 = {
  12441. point: centroidPoint$1,
  12442. lineStart: centroidLineStart$1,
  12443. lineEnd: centroidLineEnd$1,
  12444. polygonStart: function() {
  12445. centroidStream$1.lineStart = centroidRingStart$1;
  12446. centroidStream$1.lineEnd = centroidRingEnd$1;
  12447. },
  12448. polygonEnd: function() {
  12449. centroidStream$1.point = centroidPoint$1;
  12450. centroidStream$1.lineStart = centroidLineStart$1;
  12451. centroidStream$1.lineEnd = centroidLineEnd$1;
  12452. },
  12453. result: function() {
  12454. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  12455. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  12456. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  12457. : [NaN, NaN];
  12458. X0$1 = Y0$1 = Z0$1 =
  12459. X1$1 = Y1$1 = Z1$1 =
  12460. X2$1 = Y2$1 = Z2$1 = 0;
  12461. return centroid;
  12462. }
  12463. };
  12464. function centroidPoint$1(x, y) {
  12465. X0$1 += x;
  12466. Y0$1 += y;
  12467. ++Z0$1;
  12468. }
  12469. function centroidLineStart$1() {
  12470. centroidStream$1.point = centroidPointFirstLine;
  12471. }
  12472. function centroidPointFirstLine(x, y) {
  12473. centroidStream$1.point = centroidPointLine;
  12474. centroidPoint$1(x0$3 = x, y0$3 = y);
  12475. }
  12476. function centroidPointLine(x, y) {
  12477. var dx = x - x0$3, dy = y - y0$3, z = sqrt$1(dx * dx + dy * dy);
  12478. X1$1 += z * (x0$3 + x) / 2;
  12479. Y1$1 += z * (y0$3 + y) / 2;
  12480. Z1$1 += z;
  12481. centroidPoint$1(x0$3 = x, y0$3 = y);
  12482. }
  12483. function centroidLineEnd$1() {
  12484. centroidStream$1.point = centroidPoint$1;
  12485. }
  12486. function centroidRingStart$1() {
  12487. centroidStream$1.point = centroidPointFirstRing;
  12488. }
  12489. function centroidRingEnd$1() {
  12490. centroidPointRing(x00$1, y00$1);
  12491. }
  12492. function centroidPointFirstRing(x, y) {
  12493. centroidStream$1.point = centroidPointRing;
  12494. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  12495. }
  12496. function centroidPointRing(x, y) {
  12497. var dx = x - x0$3,
  12498. dy = y - y0$3,
  12499. z = sqrt$1(dx * dx + dy * dy);
  12500. X1$1 += z * (x0$3 + x) / 2;
  12501. Y1$1 += z * (y0$3 + y) / 2;
  12502. Z1$1 += z;
  12503. z = y0$3 * x - x0$3 * y;
  12504. X2$1 += z * (x0$3 + x);
  12505. Y2$1 += z * (y0$3 + y);
  12506. Z2$1 += z * 3;
  12507. centroidPoint$1(x0$3 = x, y0$3 = y);
  12508. }
  12509. function PathContext(context) {
  12510. this._context = context;
  12511. }
  12512. PathContext.prototype = {
  12513. _radius: 4.5,
  12514. pointRadius: function(_) {
  12515. return this._radius = _, this;
  12516. },
  12517. polygonStart: function() {
  12518. this._line = 0;
  12519. },
  12520. polygonEnd: function() {
  12521. this._line = NaN;
  12522. },
  12523. lineStart: function() {
  12524. this._point = 0;
  12525. },
  12526. lineEnd: function() {
  12527. if (this._line === 0) this._context.closePath();
  12528. this._point = NaN;
  12529. },
  12530. point: function(x, y) {
  12531. switch (this._point) {
  12532. case 0: {
  12533. this._context.moveTo(x, y);
  12534. this._point = 1;
  12535. break;
  12536. }
  12537. case 1: {
  12538. this._context.lineTo(x, y);
  12539. break;
  12540. }
  12541. default: {
  12542. this._context.moveTo(x + this._radius, y);
  12543. this._context.arc(x, y, this._radius, 0, tau$4);
  12544. break;
  12545. }
  12546. }
  12547. },
  12548. result: noop$2
  12549. };
  12550. function PathString() {
  12551. this._string = [];
  12552. }
  12553. PathString.prototype = {
  12554. _circle: circle$2(4.5),
  12555. pointRadius: function(_) {
  12556. return this._circle = circle$2(_), this;
  12557. },
  12558. polygonStart: function() {
  12559. this._line = 0;
  12560. },
  12561. polygonEnd: function() {
  12562. this._line = NaN;
  12563. },
  12564. lineStart: function() {
  12565. this._point = 0;
  12566. },
  12567. lineEnd: function() {
  12568. if (this._line === 0) this._string.push("Z");
  12569. this._point = NaN;
  12570. },
  12571. point: function(x, y) {
  12572. switch (this._point) {
  12573. case 0: {
  12574. this._string.push("M", x, ",", y);
  12575. this._point = 1;
  12576. break;
  12577. }
  12578. case 1: {
  12579. this._string.push("L", x, ",", y);
  12580. break;
  12581. }
  12582. default: {
  12583. this._string.push("M", x, ",", y, this._circle);
  12584. break;
  12585. }
  12586. }
  12587. },
  12588. result: function() {
  12589. if (this._string.length) {
  12590. var result = this._string.join("");
  12591. this._string = [];
  12592. return result;
  12593. }
  12594. }
  12595. };
  12596. function circle$2(radius) {
  12597. return "m0," + radius
  12598. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  12599. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  12600. + "z";
  12601. }
  12602. var index$3 = function(projection, context) {
  12603. var pointRadius = 4.5,
  12604. projectionStream,
  12605. contextStream;
  12606. function path(object) {
  12607. if (object) {
  12608. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  12609. geoStream(object, projectionStream(contextStream));
  12610. }
  12611. return contextStream.result();
  12612. }
  12613. path.area = function(object) {
  12614. geoStream(object, projectionStream(areaStream$1));
  12615. return areaStream$1.result();
  12616. };
  12617. path.bounds = function(object) {
  12618. geoStream(object, projectionStream(boundsStream$1));
  12619. return boundsStream$1.result();
  12620. };
  12621. path.centroid = function(object) {
  12622. geoStream(object, projectionStream(centroidStream$1));
  12623. return centroidStream$1.result();
  12624. };
  12625. path.projection = function(_) {
  12626. return arguments.length ? (projectionStream = (projection = _) == null ? identity$7 : _.stream, path) : projection;
  12627. };
  12628. path.context = function(_) {
  12629. if (!arguments.length) return context;
  12630. contextStream = (context = _) == null ? new PathString : new PathContext(_);
  12631. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  12632. return path;
  12633. };
  12634. path.pointRadius = function(_) {
  12635. if (!arguments.length) return pointRadius;
  12636. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  12637. return path;
  12638. };
  12639. return path.projection(projection).context(context);
  12640. };
  12641. var sum$2 = adder();
  12642. var polygonContains = function(polygon, point) {
  12643. var lambda = point[0],
  12644. phi = point[1],
  12645. normal = [sin$1(lambda), -cos$1(lambda), 0],
  12646. angle = 0,
  12647. winding = 0;
  12648. sum$2.reset();
  12649. for (var i = 0, n = polygon.length; i < n; ++i) {
  12650. if (!(m = (ring = polygon[i]).length)) continue;
  12651. var ring,
  12652. m,
  12653. point0 = ring[m - 1],
  12654. lambda0 = point0[0],
  12655. phi0 = point0[1] / 2 + quarterPi,
  12656. sinPhi0 = sin$1(phi0),
  12657. cosPhi0 = cos$1(phi0);
  12658. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  12659. var point1 = ring[j],
  12660. lambda1 = point1[0],
  12661. phi1 = point1[1] / 2 + quarterPi,
  12662. sinPhi1 = sin$1(phi1),
  12663. cosPhi1 = cos$1(phi1),
  12664. delta = lambda1 - lambda0,
  12665. sign$$1 = delta >= 0 ? 1 : -1,
  12666. absDelta = sign$$1 * delta,
  12667. antimeridian = absDelta > pi$4,
  12668. k = sinPhi0 * sinPhi1;
  12669. sum$2.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  12670. angle += antimeridian ? delta + sign$$1 * tau$4 : delta;
  12671. // Are the longitudes either side of the point’s meridian (lambda),
  12672. // and are the latitudes smaller than the parallel (phi)?
  12673. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  12674. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  12675. cartesianNormalizeInPlace(arc);
  12676. var intersection = cartesianCross(normal, arc);
  12677. cartesianNormalizeInPlace(intersection);
  12678. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]);
  12679. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  12680. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  12681. }
  12682. }
  12683. }
  12684. }
  12685. // First, determine whether the South pole is inside or outside:
  12686. //
  12687. // It is inside if:
  12688. // * the polygon winds around it in a clockwise direction.
  12689. // * the polygon does not (cumulatively) wind around it, but has a negative
  12690. // (counter-clockwise) area.
  12691. //
  12692. // Second, count the (signed) number of times a segment crosses a lambda
  12693. // from the point to the South pole. If it is zero, then the point is the
  12694. // same side as the South pole.
  12695. return (angle < -epsilon$4 || angle < epsilon$4 && sum$2 < -epsilon$4) ^ (winding & 1);
  12696. };
  12697. var clip = function(pointVisible, clipLine, interpolate, start) {
  12698. return function(rotate, sink) {
  12699. var line = clipLine(sink),
  12700. rotatedStart = rotate.invert(start[0], start[1]),
  12701. ringBuffer = clipBuffer(),
  12702. ringSink = clipLine(ringBuffer),
  12703. polygonStarted = false,
  12704. polygon,
  12705. segments,
  12706. ring;
  12707. var clip = {
  12708. point: point,
  12709. lineStart: lineStart,
  12710. lineEnd: lineEnd,
  12711. polygonStart: function() {
  12712. clip.point = pointRing;
  12713. clip.lineStart = ringStart;
  12714. clip.lineEnd = ringEnd;
  12715. segments = [];
  12716. polygon = [];
  12717. },
  12718. polygonEnd: function() {
  12719. clip.point = point;
  12720. clip.lineStart = lineStart;
  12721. clip.lineEnd = lineEnd;
  12722. segments = merge(segments);
  12723. var startInside = polygonContains(polygon, rotatedStart);
  12724. if (segments.length) {
  12725. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  12726. clipPolygon(segments, compareIntersection, startInside, interpolate, sink);
  12727. } else if (startInside) {
  12728. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  12729. sink.lineStart();
  12730. interpolate(null, null, 1, sink);
  12731. sink.lineEnd();
  12732. }
  12733. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  12734. segments = polygon = null;
  12735. },
  12736. sphere: function() {
  12737. sink.polygonStart();
  12738. sink.lineStart();
  12739. interpolate(null, null, 1, sink);
  12740. sink.lineEnd();
  12741. sink.polygonEnd();
  12742. }
  12743. };
  12744. function point(lambda, phi) {
  12745. var point = rotate(lambda, phi);
  12746. if (pointVisible(lambda = point[0], phi = point[1])) sink.point(lambda, phi);
  12747. }
  12748. function pointLine(lambda, phi) {
  12749. var point = rotate(lambda, phi);
  12750. line.point(point[0], point[1]);
  12751. }
  12752. function lineStart() {
  12753. clip.point = pointLine;
  12754. line.lineStart();
  12755. }
  12756. function lineEnd() {
  12757. clip.point = point;
  12758. line.lineEnd();
  12759. }
  12760. function pointRing(lambda, phi) {
  12761. ring.push([lambda, phi]);
  12762. var point = rotate(lambda, phi);
  12763. ringSink.point(point[0], point[1]);
  12764. }
  12765. function ringStart() {
  12766. ringSink.lineStart();
  12767. ring = [];
  12768. }
  12769. function ringEnd() {
  12770. pointRing(ring[0][0], ring[0][1]);
  12771. ringSink.lineEnd();
  12772. var clean = ringSink.clean(),
  12773. ringSegments = ringBuffer.result(),
  12774. i, n = ringSegments.length, m,
  12775. segment,
  12776. point;
  12777. ring.pop();
  12778. polygon.push(ring);
  12779. ring = null;
  12780. if (!n) return;
  12781. // No intersections.
  12782. if (clean & 1) {
  12783. segment = ringSegments[0];
  12784. if ((m = segment.length - 1) > 0) {
  12785. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  12786. sink.lineStart();
  12787. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  12788. sink.lineEnd();
  12789. }
  12790. return;
  12791. }
  12792. // Rejoin connected segments.
  12793. // TODO reuse ringBuffer.rejoin()?
  12794. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  12795. segments.push(ringSegments.filter(validSegment));
  12796. }
  12797. return clip;
  12798. };
  12799. };
  12800. function validSegment(segment) {
  12801. return segment.length > 1;
  12802. }
  12803. // Intersections are sorted along the clip edge. For both antimeridian cutting
  12804. // and circle clipping, the same comparison is used.
  12805. function compareIntersection(a, b) {
  12806. return ((a = a.x)[0] < 0 ? a[1] - halfPi$3 - epsilon$4 : halfPi$3 - a[1])
  12807. - ((b = b.x)[0] < 0 ? b[1] - halfPi$3 - epsilon$4 : halfPi$3 - b[1]);
  12808. }
  12809. var clipAntimeridian = clip(
  12810. function() { return true; },
  12811. clipAntimeridianLine,
  12812. clipAntimeridianInterpolate,
  12813. [-pi$4, -halfPi$3]
  12814. );
  12815. // Takes a line and cuts into visible segments. Return values: 0 - there were
  12816. // intersections or the line was empty; 1 - no intersections; 2 - there were
  12817. // intersections, and the first and last segments should be rejoined.
  12818. function clipAntimeridianLine(stream) {
  12819. var lambda0 = NaN,
  12820. phi0 = NaN,
  12821. sign0 = NaN,
  12822. clean; // no intersections
  12823. return {
  12824. lineStart: function() {
  12825. stream.lineStart();
  12826. clean = 1;
  12827. },
  12828. point: function(lambda1, phi1) {
  12829. var sign1 = lambda1 > 0 ? pi$4 : -pi$4,
  12830. delta = abs(lambda1 - lambda0);
  12831. if (abs(delta - pi$4) < epsilon$4) { // line crosses a pole
  12832. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$3 : -halfPi$3);
  12833. stream.point(sign0, phi0);
  12834. stream.lineEnd();
  12835. stream.lineStart();
  12836. stream.point(sign1, phi0);
  12837. stream.point(lambda1, phi0);
  12838. clean = 0;
  12839. } else if (sign0 !== sign1 && delta >= pi$4) { // line crosses antimeridian
  12840. if (abs(lambda0 - sign0) < epsilon$4) lambda0 -= sign0 * epsilon$4; // handle degeneracies
  12841. if (abs(lambda1 - sign1) < epsilon$4) lambda1 -= sign1 * epsilon$4;
  12842. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  12843. stream.point(sign0, phi0);
  12844. stream.lineEnd();
  12845. stream.lineStart();
  12846. stream.point(sign1, phi0);
  12847. clean = 0;
  12848. }
  12849. stream.point(lambda0 = lambda1, phi0 = phi1);
  12850. sign0 = sign1;
  12851. },
  12852. lineEnd: function() {
  12853. stream.lineEnd();
  12854. lambda0 = phi0 = NaN;
  12855. },
  12856. clean: function() {
  12857. return 2 - clean; // if intersections, rejoin first and last segments
  12858. }
  12859. };
  12860. }
  12861. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  12862. var cosPhi0,
  12863. cosPhi1,
  12864. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  12865. return abs(sinLambda0Lambda1) > epsilon$4
  12866. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  12867. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  12868. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  12869. : (phi0 + phi1) / 2;
  12870. }
  12871. function clipAntimeridianInterpolate(from, to, direction, stream) {
  12872. var phi;
  12873. if (from == null) {
  12874. phi = direction * halfPi$3;
  12875. stream.point(-pi$4, phi);
  12876. stream.point(0, phi);
  12877. stream.point(pi$4, phi);
  12878. stream.point(pi$4, 0);
  12879. stream.point(pi$4, -phi);
  12880. stream.point(0, -phi);
  12881. stream.point(-pi$4, -phi);
  12882. stream.point(-pi$4, 0);
  12883. stream.point(-pi$4, phi);
  12884. } else if (abs(from[0] - to[0]) > epsilon$4) {
  12885. var lambda = from[0] < to[0] ? pi$4 : -pi$4;
  12886. phi = direction * lambda / 2;
  12887. stream.point(-lambda, phi);
  12888. stream.point(0, phi);
  12889. stream.point(lambda, phi);
  12890. } else {
  12891. stream.point(to[0], to[1]);
  12892. }
  12893. }
  12894. var clipCircle = function(radius, delta) {
  12895. var cr = cos$1(radius),
  12896. smallRadius = cr > 0,
  12897. notHemisphere = abs(cr) > epsilon$4; // TODO optimise for this common case
  12898. function interpolate(from, to, direction, stream) {
  12899. circleStream(stream, radius, delta, direction, from, to);
  12900. }
  12901. function visible(lambda, phi) {
  12902. return cos$1(lambda) * cos$1(phi) > cr;
  12903. }
  12904. // Takes a line and cuts into visible segments. Return values used for polygon
  12905. // clipping: 0 - there were intersections or the line was empty; 1 - no
  12906. // intersections 2 - there were intersections, and the first and last segments
  12907. // should be rejoined.
  12908. function clipLine(stream) {
  12909. var point0, // previous point
  12910. c0, // code for previous point
  12911. v0, // visibility of previous point
  12912. v00, // visibility of first point
  12913. clean; // no intersections
  12914. return {
  12915. lineStart: function() {
  12916. v00 = v0 = false;
  12917. clean = 1;
  12918. },
  12919. point: function(lambda, phi) {
  12920. var point1 = [lambda, phi],
  12921. point2,
  12922. v = visible(lambda, phi),
  12923. c = smallRadius
  12924. ? v ? 0 : code(lambda, phi)
  12925. : v ? code(lambda + (lambda < 0 ? pi$4 : -pi$4), phi) : 0;
  12926. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  12927. // Handle degeneracies.
  12928. // TODO ignore if not clipping polygons.
  12929. if (v !== v0) {
  12930. point2 = intersect(point0, point1);
  12931. if (pointEqual(point0, point2) || pointEqual(point1, point2)) {
  12932. point1[0] += epsilon$4;
  12933. point1[1] += epsilon$4;
  12934. v = visible(point1[0], point1[1]);
  12935. }
  12936. }
  12937. if (v !== v0) {
  12938. clean = 0;
  12939. if (v) {
  12940. // outside going in
  12941. stream.lineStart();
  12942. point2 = intersect(point1, point0);
  12943. stream.point(point2[0], point2[1]);
  12944. } else {
  12945. // inside going out
  12946. point2 = intersect(point0, point1);
  12947. stream.point(point2[0], point2[1]);
  12948. stream.lineEnd();
  12949. }
  12950. point0 = point2;
  12951. } else if (notHemisphere && point0 && smallRadius ^ v) {
  12952. var t;
  12953. // If the codes for two points are different, or are both zero,
  12954. // and there this segment intersects with the small circle.
  12955. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  12956. clean = 0;
  12957. if (smallRadius) {
  12958. stream.lineStart();
  12959. stream.point(t[0][0], t[0][1]);
  12960. stream.point(t[1][0], t[1][1]);
  12961. stream.lineEnd();
  12962. } else {
  12963. stream.point(t[1][0], t[1][1]);
  12964. stream.lineEnd();
  12965. stream.lineStart();
  12966. stream.point(t[0][0], t[0][1]);
  12967. }
  12968. }
  12969. }
  12970. if (v && (!point0 || !pointEqual(point0, point1))) {
  12971. stream.point(point1[0], point1[1]);
  12972. }
  12973. point0 = point1, v0 = v, c0 = c;
  12974. },
  12975. lineEnd: function() {
  12976. if (v0) stream.lineEnd();
  12977. point0 = null;
  12978. },
  12979. // Rejoin first and last segments if there were intersections and the first
  12980. // and last points were visible.
  12981. clean: function() {
  12982. return clean | ((v00 && v0) << 1);
  12983. }
  12984. };
  12985. }
  12986. // Intersects the great circle between a and b with the clip circle.
  12987. function intersect(a, b, two) {
  12988. var pa = cartesian(a),
  12989. pb = cartesian(b);
  12990. // We have two planes, n1.p = d1 and n2.p = d2.
  12991. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  12992. var n1 = [1, 0, 0], // normal
  12993. n2 = cartesianCross(pa, pb),
  12994. n2n2 = cartesianDot(n2, n2),
  12995. n1n2 = n2[0], // cartesianDot(n1, n2),
  12996. determinant = n2n2 - n1n2 * n1n2;
  12997. // Two polar points.
  12998. if (!determinant) return !two && a;
  12999. var c1 = cr * n2n2 / determinant,
  13000. c2 = -cr * n1n2 / determinant,
  13001. n1xn2 = cartesianCross(n1, n2),
  13002. A = cartesianScale(n1, c1),
  13003. B = cartesianScale(n2, c2);
  13004. cartesianAddInPlace(A, B);
  13005. // Solve |p(t)|^2 = 1.
  13006. var u = n1xn2,
  13007. w = cartesianDot(A, u),
  13008. uu = cartesianDot(u, u),
  13009. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  13010. if (t2 < 0) return;
  13011. var t = sqrt$1(t2),
  13012. q = cartesianScale(u, (-w - t) / uu);
  13013. cartesianAddInPlace(q, A);
  13014. q = spherical(q);
  13015. if (!two) return q;
  13016. // Two intersection points.
  13017. var lambda0 = a[0],
  13018. lambda1 = b[0],
  13019. phi0 = a[1],
  13020. phi1 = b[1],
  13021. z;
  13022. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  13023. var delta = lambda1 - lambda0,
  13024. polar = abs(delta - pi$4) < epsilon$4,
  13025. meridian = polar || delta < epsilon$4;
  13026. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  13027. // Check that the first point is between a and b.
  13028. if (meridian
  13029. ? polar
  13030. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$4 ? phi0 : phi1)
  13031. : phi0 <= q[1] && q[1] <= phi1
  13032. : delta > pi$4 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  13033. var q1 = cartesianScale(u, (-w + t) / uu);
  13034. cartesianAddInPlace(q1, A);
  13035. return [q, spherical(q1)];
  13036. }
  13037. }
  13038. // Generates a 4-bit vector representing the location of a point relative to
  13039. // the small circle's bounding box.
  13040. function code(lambda, phi) {
  13041. var r = smallRadius ? radius : pi$4 - radius,
  13042. code = 0;
  13043. if (lambda < -r) code |= 1; // left
  13044. else if (lambda > r) code |= 2; // right
  13045. if (phi < -r) code |= 4; // below
  13046. else if (phi > r) code |= 8; // above
  13047. return code;
  13048. }
  13049. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$4, radius - pi$4]);
  13050. };
  13051. var transform$1 = function(methods) {
  13052. return {
  13053. stream: transformer(methods)
  13054. };
  13055. };
  13056. function transformer(methods) {
  13057. return function(stream) {
  13058. var s = new TransformStream;
  13059. for (var key in methods) s[key] = methods[key];
  13060. s.stream = stream;
  13061. return s;
  13062. };
  13063. }
  13064. function TransformStream() {}
  13065. TransformStream.prototype = {
  13066. constructor: TransformStream,
  13067. point: function(x, y) { this.stream.point(x, y); },
  13068. sphere: function() { this.stream.sphere(); },
  13069. lineStart: function() { this.stream.lineStart(); },
  13070. lineEnd: function() { this.stream.lineEnd(); },
  13071. polygonStart: function() { this.stream.polygonStart(); },
  13072. polygonEnd: function() { this.stream.polygonEnd(); }
  13073. };
  13074. function fitExtent(projection, extent, object) {
  13075. var w = extent[1][0] - extent[0][0],
  13076. h = extent[1][1] - extent[0][1],
  13077. clip = projection.clipExtent && projection.clipExtent();
  13078. projection
  13079. .scale(150)
  13080. .translate([0, 0]);
  13081. if (clip != null) projection.clipExtent(null);
  13082. geoStream(object, projection.stream(boundsStream$1));
  13083. var b = boundsStream$1.result(),
  13084. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  13085. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  13086. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  13087. if (clip != null) projection.clipExtent(clip);
  13088. return projection
  13089. .scale(k * 150)
  13090. .translate([x, y]);
  13091. }
  13092. function fitSize(projection, size, object) {
  13093. return fitExtent(projection, [[0, 0], size], object);
  13094. }
  13095. var maxDepth = 16;
  13096. var cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  13097. var resample = function(project, delta2) {
  13098. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  13099. };
  13100. function resampleNone(project) {
  13101. return transformer({
  13102. point: function(x, y) {
  13103. x = project(x, y);
  13104. this.stream.point(x[0], x[1]);
  13105. }
  13106. });
  13107. }
  13108. function resample$1(project, delta2) {
  13109. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  13110. var dx = x1 - x0,
  13111. dy = y1 - y0,
  13112. d2 = dx * dx + dy * dy;
  13113. if (d2 > 4 * delta2 && depth--) {
  13114. var a = a0 + a1,
  13115. b = b0 + b1,
  13116. c = c0 + c1,
  13117. m = sqrt$1(a * a + b * b + c * c),
  13118. phi2 = asin$1(c /= m),
  13119. lambda2 = abs(abs(c) - 1) < epsilon$4 || abs(lambda0 - lambda1) < epsilon$4 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  13120. p = project(lambda2, phi2),
  13121. x2 = p[0],
  13122. y2 = p[1],
  13123. dx2 = x2 - x0,
  13124. dy2 = y2 - y0,
  13125. dz = dy * dx2 - dx * dy2;
  13126. if (dz * dz / d2 > delta2 // perpendicular projected distance
  13127. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  13128. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  13129. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  13130. stream.point(x2, y2);
  13131. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  13132. }
  13133. }
  13134. }
  13135. return function(stream) {
  13136. var lambda00, x00, y00, a00, b00, c00, // first point
  13137. lambda0, x0, y0, a0, b0, c0; // previous point
  13138. var resampleStream = {
  13139. point: point,
  13140. lineStart: lineStart,
  13141. lineEnd: lineEnd,
  13142. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  13143. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  13144. };
  13145. function point(x, y) {
  13146. x = project(x, y);
  13147. stream.point(x[0], x[1]);
  13148. }
  13149. function lineStart() {
  13150. x0 = NaN;
  13151. resampleStream.point = linePoint;
  13152. stream.lineStart();
  13153. }
  13154. function linePoint(lambda, phi) {
  13155. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  13156. 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);
  13157. stream.point(x0, y0);
  13158. }
  13159. function lineEnd() {
  13160. resampleStream.point = point;
  13161. stream.lineEnd();
  13162. }
  13163. function ringStart() {
  13164. lineStart();
  13165. resampleStream.point = ringPoint;
  13166. resampleStream.lineEnd = ringEnd;
  13167. }
  13168. function ringPoint(lambda, phi) {
  13169. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  13170. resampleStream.point = linePoint;
  13171. }
  13172. function ringEnd() {
  13173. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  13174. resampleStream.lineEnd = lineEnd;
  13175. lineEnd();
  13176. }
  13177. return resampleStream;
  13178. };
  13179. }
  13180. var transformRadians = transformer({
  13181. point: function(x, y) {
  13182. this.stream.point(x * radians, y * radians);
  13183. }
  13184. });
  13185. function projection(project) {
  13186. return projectionMutator(function() { return project; })();
  13187. }
  13188. function projectionMutator(projectAt) {
  13189. var project,
  13190. k = 150, // scale
  13191. x = 480, y = 250, // translate
  13192. dx, dy, lambda = 0, phi = 0, // center
  13193. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
  13194. theta = null, preclip = clipAntimeridian, // clip angle
  13195. x0 = null, y0, x1, y1, postclip = identity$7, // clip extent
  13196. delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
  13197. cache,
  13198. cacheStream;
  13199. function projection(point) {
  13200. point = projectRotate(point[0] * radians, point[1] * radians);
  13201. return [point[0] * k + dx, dy - point[1] * k];
  13202. }
  13203. function invert(point) {
  13204. point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
  13205. return point && [point[0] * degrees$1, point[1] * degrees$1];
  13206. }
  13207. function projectTransform(x, y) {
  13208. return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
  13209. }
  13210. projection.stream = function(stream) {
  13211. return cache && cacheStream === stream ? cache : cache = transformRadians(preclip(rotate, projectResample(postclip(cacheStream = stream))));
  13212. };
  13213. projection.clipAngle = function(_) {
  13214. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians, 6 * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  13215. };
  13216. projection.clipExtent = function(_) {
  13217. 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]];
  13218. };
  13219. projection.scale = function(_) {
  13220. return arguments.length ? (k = +_, recenter()) : k;
  13221. };
  13222. projection.translate = function(_) {
  13223. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  13224. };
  13225. projection.center = function(_) {
  13226. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  13227. };
  13228. projection.rotate = function(_) {
  13229. 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];
  13230. };
  13231. projection.precision = function(_) {
  13232. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$1(delta2);
  13233. };
  13234. projection.fitExtent = function(extent, object) {
  13235. return fitExtent(projection, extent, object);
  13236. };
  13237. projection.fitSize = function(size, object) {
  13238. return fitSize(projection, size, object);
  13239. };
  13240. function recenter() {
  13241. projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
  13242. var center = project(lambda, phi);
  13243. dx = x - center[0] * k;
  13244. dy = y + center[1] * k;
  13245. return reset();
  13246. }
  13247. function reset() {
  13248. cache = cacheStream = null;
  13249. return projection;
  13250. }
  13251. return function() {
  13252. project = projectAt.apply(this, arguments);
  13253. projection.invert = project.invert && invert;
  13254. return recenter();
  13255. };
  13256. }
  13257. function conicProjection(projectAt) {
  13258. var phi0 = 0,
  13259. phi1 = pi$4 / 3,
  13260. m = projectionMutator(projectAt),
  13261. p = m(phi0, phi1);
  13262. p.parallels = function(_) {
  13263. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  13264. };
  13265. return p;
  13266. }
  13267. function cylindricalEqualAreaRaw(phi0) {
  13268. var cosPhi0 = cos$1(phi0);
  13269. function forward(lambda, phi) {
  13270. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  13271. }
  13272. forward.invert = function(x, y) {
  13273. return [x / cosPhi0, asin$1(y * cosPhi0)];
  13274. };
  13275. return forward;
  13276. }
  13277. function conicEqualAreaRaw(y0, y1) {
  13278. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  13279. // Are the parallels symmetrical around the Equator?
  13280. if (abs(n) < epsilon$4) return cylindricalEqualAreaRaw(y0);
  13281. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt$1(c) / n;
  13282. function project(x, y) {
  13283. var r = sqrt$1(c - 2 * n * sin$1(y)) / n;
  13284. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  13285. }
  13286. project.invert = function(x, y) {
  13287. var r0y = r0 - y;
  13288. return [atan2(x, abs(r0y)) / n * sign$1(r0y), asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  13289. };
  13290. return project;
  13291. }
  13292. var conicEqualArea = function() {
  13293. return conicProjection(conicEqualAreaRaw)
  13294. .scale(155.424)
  13295. .center([0, 33.6442]);
  13296. };
  13297. var albers = function() {
  13298. return conicEqualArea()
  13299. .parallels([29.5, 45.5])
  13300. .scale(1070)
  13301. .translate([480, 250])
  13302. .rotate([96, 0])
  13303. .center([-0.6, 38.7]);
  13304. };
  13305. // The projections must have mutually exclusive clip regions on the sphere,
  13306. // as this will avoid emitting interleaving lines and polygons.
  13307. function multiplex(streams) {
  13308. var n = streams.length;
  13309. return {
  13310. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  13311. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  13312. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  13313. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  13314. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  13315. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  13316. };
  13317. }
  13318. // A composite projection for the United States, configured by default for
  13319. // 960×500. The projection also works quite well at 960×600 if you change the
  13320. // scale to 1285 and adjust the translate accordingly. The set of standard
  13321. // parallels for each region comes from USGS, which is published here:
  13322. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  13323. var albersUsa = function() {
  13324. var cache,
  13325. cacheStream,
  13326. lower48 = albers(), lower48Point,
  13327. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  13328. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  13329. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  13330. function albersUsa(coordinates) {
  13331. var x = coordinates[0], y = coordinates[1];
  13332. return point = null,
  13333. (lower48Point.point(x, y), point)
  13334. || (alaskaPoint.point(x, y), point)
  13335. || (hawaiiPoint.point(x, y), point);
  13336. }
  13337. albersUsa.invert = function(coordinates) {
  13338. var k = lower48.scale(),
  13339. t = lower48.translate(),
  13340. x = (coordinates[0] - t[0]) / k,
  13341. y = (coordinates[1] - t[1]) / k;
  13342. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  13343. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  13344. : lower48).invert(coordinates);
  13345. };
  13346. albersUsa.stream = function(stream) {
  13347. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  13348. };
  13349. albersUsa.precision = function(_) {
  13350. if (!arguments.length) return lower48.precision();
  13351. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  13352. return reset();
  13353. };
  13354. albersUsa.scale = function(_) {
  13355. if (!arguments.length) return lower48.scale();
  13356. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  13357. return albersUsa.translate(lower48.translate());
  13358. };
  13359. albersUsa.translate = function(_) {
  13360. if (!arguments.length) return lower48.translate();
  13361. var k = lower48.scale(), x = +_[0], y = +_[1];
  13362. lower48Point = lower48
  13363. .translate(_)
  13364. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  13365. .stream(pointStream);
  13366. alaskaPoint = alaska
  13367. .translate([x - 0.307 * k, y + 0.201 * k])
  13368. .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]])
  13369. .stream(pointStream);
  13370. hawaiiPoint = hawaii
  13371. .translate([x - 0.205 * k, y + 0.212 * k])
  13372. .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]])
  13373. .stream(pointStream);
  13374. return reset();
  13375. };
  13376. albersUsa.fitExtent = function(extent, object) {
  13377. return fitExtent(albersUsa, extent, object);
  13378. };
  13379. albersUsa.fitSize = function(size, object) {
  13380. return fitSize(albersUsa, size, object);
  13381. };
  13382. function reset() {
  13383. cache = cacheStream = null;
  13384. return albersUsa;
  13385. }
  13386. return albersUsa.scale(1070);
  13387. };
  13388. function azimuthalRaw(scale) {
  13389. return function(x, y) {
  13390. var cx = cos$1(x),
  13391. cy = cos$1(y),
  13392. k = scale(cx * cy);
  13393. return [
  13394. k * cy * sin$1(x),
  13395. k * sin$1(y)
  13396. ];
  13397. }
  13398. }
  13399. function azimuthalInvert(angle) {
  13400. return function(x, y) {
  13401. var z = sqrt$1(x * x + y * y),
  13402. c = angle(z),
  13403. sc = sin$1(c),
  13404. cc = cos$1(c);
  13405. return [
  13406. atan2(x * sc, z * cc),
  13407. asin$1(z && y * sc / z)
  13408. ];
  13409. }
  13410. }
  13411. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  13412. return sqrt$1(2 / (1 + cxcy));
  13413. });
  13414. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  13415. return 2 * asin$1(z / 2);
  13416. });
  13417. var azimuthalEqualArea = function() {
  13418. return projection(azimuthalEqualAreaRaw)
  13419. .scale(124.75)
  13420. .clipAngle(180 - 1e-3);
  13421. };
  13422. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  13423. return (c = acos(c)) && c / sin$1(c);
  13424. });
  13425. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  13426. return z;
  13427. });
  13428. var azimuthalEquidistant = function() {
  13429. return projection(azimuthalEquidistantRaw)
  13430. .scale(79.4188)
  13431. .clipAngle(180 - 1e-3);
  13432. };
  13433. function mercatorRaw(lambda, phi) {
  13434. return [lambda, log$1(tan((halfPi$3 + phi) / 2))];
  13435. }
  13436. mercatorRaw.invert = function(x, y) {
  13437. return [x, 2 * atan(exp(y)) - halfPi$3];
  13438. };
  13439. var mercator = function() {
  13440. return mercatorProjection(mercatorRaw)
  13441. .scale(961 / tau$4);
  13442. };
  13443. function mercatorProjection(project) {
  13444. var m = projection(project),
  13445. scale = m.scale,
  13446. translate = m.translate,
  13447. clipExtent = m.clipExtent,
  13448. clipAuto;
  13449. m.scale = function(_) {
  13450. return arguments.length ? (scale(_), clipAuto && m.clipExtent(null), m) : scale();
  13451. };
  13452. m.translate = function(_) {
  13453. return arguments.length ? (translate(_), clipAuto && m.clipExtent(null), m) : translate();
  13454. };
  13455. m.clipExtent = function(_) {
  13456. if (!arguments.length) return clipAuto ? null : clipExtent();
  13457. if (clipAuto = _ == null) {
  13458. var k = pi$4 * scale(),
  13459. t = translate();
  13460. _ = [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]];
  13461. }
  13462. clipExtent(_);
  13463. return m;
  13464. };
  13465. return m.clipExtent(null);
  13466. }
  13467. function tany(y) {
  13468. return tan((halfPi$3 + y) / 2);
  13469. }
  13470. function conicConformalRaw(y0, y1) {
  13471. var cy0 = cos$1(y0),
  13472. n = y0 === y1 ? sin$1(y0) : log$1(cy0 / cos$1(y1)) / log$1(tany(y1) / tany(y0)),
  13473. f = cy0 * pow$1(tany(y0), n) / n;
  13474. if (!n) return mercatorRaw;
  13475. function project(x, y) {
  13476. if (f > 0) { if (y < -halfPi$3 + epsilon$4) y = -halfPi$3 + epsilon$4; }
  13477. else { if (y > halfPi$3 - epsilon$4) y = halfPi$3 - epsilon$4; }
  13478. var r = f / pow$1(tany(y), n);
  13479. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  13480. }
  13481. project.invert = function(x, y) {
  13482. var fy = f - y, r = sign$1(n) * sqrt$1(x * x + fy * fy);
  13483. return [atan2(x, abs(fy)) / n * sign$1(fy), 2 * atan(pow$1(f / r, 1 / n)) - halfPi$3];
  13484. };
  13485. return project;
  13486. }
  13487. var conicConformal = function() {
  13488. return conicProjection(conicConformalRaw)
  13489. .scale(109.5)
  13490. .parallels([30, 30]);
  13491. };
  13492. function equirectangularRaw(lambda, phi) {
  13493. return [lambda, phi];
  13494. }
  13495. equirectangularRaw.invert = equirectangularRaw;
  13496. var equirectangular = function() {
  13497. return projection(equirectangularRaw)
  13498. .scale(152.63);
  13499. };
  13500. function conicEquidistantRaw(y0, y1) {
  13501. var cy0 = cos$1(y0),
  13502. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  13503. g = cy0 / n + y0;
  13504. if (abs(n) < epsilon$4) return equirectangularRaw;
  13505. function project(x, y) {
  13506. var gy = g - y, nx = n * x;
  13507. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  13508. }
  13509. project.invert = function(x, y) {
  13510. var gy = g - y;
  13511. return [atan2(x, abs(gy)) / n * sign$1(gy), g - sign$1(n) * sqrt$1(x * x + gy * gy)];
  13512. };
  13513. return project;
  13514. }
  13515. var conicEquidistant = function() {
  13516. return conicProjection(conicEquidistantRaw)
  13517. .scale(131.154)
  13518. .center([0, 13.9389]);
  13519. };
  13520. function gnomonicRaw(x, y) {
  13521. var cy = cos$1(y), k = cos$1(x) * cy;
  13522. return [cy * sin$1(x) / k, sin$1(y) / k];
  13523. }
  13524. gnomonicRaw.invert = azimuthalInvert(atan);
  13525. var gnomonic = function() {
  13526. return projection(gnomonicRaw)
  13527. .scale(144.049)
  13528. .clipAngle(60);
  13529. };
  13530. function scaleTranslate(k, tx, ty) {
  13531. return k === 1 && tx === 0 && ty === 0 ? identity$7 : transformer({
  13532. point: function(x, y) {
  13533. this.stream.point(x * k + tx, y * k + ty);
  13534. }
  13535. });
  13536. }
  13537. var identity$8 = function() {
  13538. var k = 1, tx = 0, ty = 0, transform = identity$7, // scale and translate
  13539. x0 = null, y0, x1, y1, clip = identity$7, // clip extent
  13540. cache,
  13541. cacheStream,
  13542. projection;
  13543. function reset() {
  13544. cache = cacheStream = null;
  13545. return projection;
  13546. }
  13547. return projection = {
  13548. stream: function(stream) {
  13549. return cache && cacheStream === stream ? cache : cache = transform(clip(cacheStream = stream));
  13550. },
  13551. clipExtent: function(_) {
  13552. return arguments.length ? (clip = _ == 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]];
  13553. },
  13554. scale: function(_) {
  13555. return arguments.length ? (transform = scaleTranslate(k = +_, tx, ty), reset()) : k;
  13556. },
  13557. translate: function(_) {
  13558. return arguments.length ? (transform = scaleTranslate(k, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  13559. },
  13560. fitExtent: function(extent, object) {
  13561. return fitExtent(projection, extent, object);
  13562. },
  13563. fitSize: function(size, object) {
  13564. return fitSize(projection, size, object);
  13565. }
  13566. };
  13567. };
  13568. function orthographicRaw(x, y) {
  13569. return [cos$1(y) * sin$1(x), sin$1(y)];
  13570. }
  13571. orthographicRaw.invert = azimuthalInvert(asin$1);
  13572. var orthographic = function() {
  13573. return projection(orthographicRaw)
  13574. .scale(249.5)
  13575. .clipAngle(90 + epsilon$4);
  13576. };
  13577. function stereographicRaw(x, y) {
  13578. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  13579. return [cy * sin$1(x) / k, sin$1(y) / k];
  13580. }
  13581. stereographicRaw.invert = azimuthalInvert(function(z) {
  13582. return 2 * atan(z);
  13583. });
  13584. var stereographic = function() {
  13585. return projection(stereographicRaw)
  13586. .scale(250)
  13587. .clipAngle(142);
  13588. };
  13589. function transverseMercatorRaw(lambda, phi) {
  13590. return [log$1(tan((halfPi$3 + phi) / 2)), -lambda];
  13591. }
  13592. transverseMercatorRaw.invert = function(x, y) {
  13593. return [-y, 2 * atan(exp(x)) - halfPi$3];
  13594. };
  13595. var transverseMercator = function() {
  13596. var m = mercatorProjection(transverseMercatorRaw),
  13597. center = m.center,
  13598. rotate = m.rotate;
  13599. m.center = function(_) {
  13600. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  13601. };
  13602. m.rotate = function(_) {
  13603. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  13604. };
  13605. return rotate([0, 0, 90])
  13606. .scale(159.155);
  13607. };
  13608. exports.version = version;
  13609. exports.bisect = bisectRight;
  13610. exports.bisectRight = bisectRight;
  13611. exports.bisectLeft = bisectLeft;
  13612. exports.ascending = ascending;
  13613. exports.bisector = bisector;
  13614. exports.descending = descending;
  13615. exports.deviation = deviation;
  13616. exports.extent = extent;
  13617. exports.histogram = histogram;
  13618. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  13619. exports.thresholdScott = scott;
  13620. exports.thresholdSturges = sturges;
  13621. exports.max = max;
  13622. exports.mean = mean;
  13623. exports.median = median;
  13624. exports.merge = merge;
  13625. exports.min = min;
  13626. exports.pairs = pairs;
  13627. exports.permute = permute;
  13628. exports.quantile = threshold;
  13629. exports.range = range;
  13630. exports.scan = scan;
  13631. exports.shuffle = shuffle;
  13632. exports.sum = sum;
  13633. exports.ticks = ticks;
  13634. exports.tickStep = tickStep;
  13635. exports.transpose = transpose;
  13636. exports.variance = variance;
  13637. exports.zip = zip;
  13638. exports.entries = entries;
  13639. exports.keys = keys;
  13640. exports.values = values;
  13641. exports.map = map$1;
  13642. exports.set = set;
  13643. exports.nest = nest;
  13644. exports.randomUniform = uniform;
  13645. exports.randomNormal = normal;
  13646. exports.randomLogNormal = logNormal;
  13647. exports.randomBates = bates;
  13648. exports.randomIrwinHall = irwinHall;
  13649. exports.randomExponential = exponential;
  13650. exports.easeLinear = linear;
  13651. exports.easeQuad = quadInOut;
  13652. exports.easeQuadIn = quadIn;
  13653. exports.easeQuadOut = quadOut;
  13654. exports.easeQuadInOut = quadInOut;
  13655. exports.easeCubic = cubicInOut;
  13656. exports.easeCubicIn = cubicIn;
  13657. exports.easeCubicOut = cubicOut;
  13658. exports.easeCubicInOut = cubicInOut;
  13659. exports.easePoly = polyInOut;
  13660. exports.easePolyIn = polyIn;
  13661. exports.easePolyOut = polyOut;
  13662. exports.easePolyInOut = polyInOut;
  13663. exports.easeSin = sinInOut;
  13664. exports.easeSinIn = sinIn;
  13665. exports.easeSinOut = sinOut;
  13666. exports.easeSinInOut = sinInOut;
  13667. exports.easeExp = expInOut;
  13668. exports.easeExpIn = expIn;
  13669. exports.easeExpOut = expOut;
  13670. exports.easeExpInOut = expInOut;
  13671. exports.easeCircle = circleInOut;
  13672. exports.easeCircleIn = circleIn;
  13673. exports.easeCircleOut = circleOut;
  13674. exports.easeCircleInOut = circleInOut;
  13675. exports.easeBounce = bounceOut;
  13676. exports.easeBounceIn = bounceIn;
  13677. exports.easeBounceOut = bounceOut;
  13678. exports.easeBounceInOut = bounceInOut;
  13679. exports.easeBack = backInOut;
  13680. exports.easeBackIn = backIn;
  13681. exports.easeBackOut = backOut;
  13682. exports.easeBackInOut = backInOut;
  13683. exports.easeElastic = elasticOut;
  13684. exports.easeElasticIn = elasticIn;
  13685. exports.easeElasticOut = elasticOut;
  13686. exports.easeElasticInOut = elasticInOut;
  13687. exports.polygonArea = area;
  13688. exports.polygonCentroid = centroid;
  13689. exports.polygonHull = hull;
  13690. exports.polygonContains = contains;
  13691. exports.polygonLength = length$1;
  13692. exports.path = path;
  13693. exports.quadtree = quadtree;
  13694. exports.queue = queue;
  13695. exports.arc = arc;
  13696. exports.area = area$1;
  13697. exports.line = line;
  13698. exports.pie = pie;
  13699. exports.radialArea = radialArea;
  13700. exports.radialLine = radialLine$1;
  13701. exports.symbol = symbol;
  13702. exports.symbols = symbols;
  13703. exports.symbolCircle = circle;
  13704. exports.symbolCross = cross$1;
  13705. exports.symbolDiamond = diamond;
  13706. exports.symbolSquare = square;
  13707. exports.symbolStar = star;
  13708. exports.symbolTriangle = triangle;
  13709. exports.symbolWye = wye;
  13710. exports.curveBasisClosed = basisClosed;
  13711. exports.curveBasisOpen = basisOpen;
  13712. exports.curveBasis = basis;
  13713. exports.curveBundle = bundle;
  13714. exports.curveCardinalClosed = cardinalClosed;
  13715. exports.curveCardinalOpen = cardinalOpen;
  13716. exports.curveCardinal = cardinal;
  13717. exports.curveCatmullRomClosed = catmullRomClosed;
  13718. exports.curveCatmullRomOpen = catmullRomOpen;
  13719. exports.curveCatmullRom = catmullRom;
  13720. exports.curveLinearClosed = linearClosed;
  13721. exports.curveLinear = curveLinear;
  13722. exports.curveMonotoneX = monotoneX;
  13723. exports.curveMonotoneY = monotoneY;
  13724. exports.curveNatural = natural;
  13725. exports.curveStep = step;
  13726. exports.curveStepAfter = stepAfter;
  13727. exports.curveStepBefore = stepBefore;
  13728. exports.stack = stack;
  13729. exports.stackOffsetExpand = expand;
  13730. exports.stackOffsetNone = none;
  13731. exports.stackOffsetSilhouette = silhouette;
  13732. exports.stackOffsetWiggle = wiggle;
  13733. exports.stackOrderAscending = ascending$1;
  13734. exports.stackOrderDescending = descending$2;
  13735. exports.stackOrderInsideOut = insideOut;
  13736. exports.stackOrderNone = none$1;
  13737. exports.stackOrderReverse = reverse;
  13738. exports.color = color;
  13739. exports.rgb = rgb;
  13740. exports.hsl = hsl;
  13741. exports.lab = lab;
  13742. exports.hcl = hcl;
  13743. exports.cubehelix = cubehelix;
  13744. exports.interpolate = interpolate;
  13745. exports.interpolateArray = array$1;
  13746. exports.interpolateDate = date;
  13747. exports.interpolateNumber = interpolateNumber;
  13748. exports.interpolateObject = object;
  13749. exports.interpolateRound = interpolateRound;
  13750. exports.interpolateString = interpolateString;
  13751. exports.interpolateTransformCss = interpolateTransformCss;
  13752. exports.interpolateTransformSvg = interpolateTransformSvg;
  13753. exports.interpolateZoom = interpolateZoom;
  13754. exports.interpolateRgb = interpolateRgb;
  13755. exports.interpolateRgbBasis = rgbBasis;
  13756. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  13757. exports.interpolateHsl = hsl$2;
  13758. exports.interpolateHslLong = hslLong;
  13759. exports.interpolateLab = lab$1;
  13760. exports.interpolateHcl = hcl$2;
  13761. exports.interpolateHclLong = hclLong;
  13762. exports.interpolateCubehelix = cubehelix$2;
  13763. exports.interpolateCubehelixLong = cubehelixLong;
  13764. exports.interpolateBasis = basis$2;
  13765. exports.interpolateBasisClosed = basisClosed$1;
  13766. exports.quantize = quantize;
  13767. exports.dispatch = dispatch;
  13768. exports.dsvFormat = dsv;
  13769. exports.csvParse = csvParse;
  13770. exports.csvParseRows = csvParseRows;
  13771. exports.csvFormat = csvFormat;
  13772. exports.csvFormatRows = csvFormatRows;
  13773. exports.tsvParse = tsvParse;
  13774. exports.tsvParseRows = tsvParseRows;
  13775. exports.tsvFormat = tsvFormat;
  13776. exports.tsvFormatRows = tsvFormatRows;
  13777. exports.request = request;
  13778. exports.html = html;
  13779. exports.json = json;
  13780. exports.text = text;
  13781. exports.xml = xml;
  13782. exports.csv = csv$1;
  13783. exports.tsv = tsv$1;
  13784. exports.now = now;
  13785. exports.timer = timer;
  13786. exports.timerFlush = timerFlush;
  13787. exports.timeout = timeout$1;
  13788. exports.interval = interval$1;
  13789. exports.timeInterval = newInterval;
  13790. exports.timeMillisecond = millisecond;
  13791. exports.timeMilliseconds = milliseconds;
  13792. exports.timeSecond = second;
  13793. exports.timeSeconds = seconds;
  13794. exports.timeMinute = minute;
  13795. exports.timeMinutes = minutes;
  13796. exports.timeHour = hour;
  13797. exports.timeHours = hours;
  13798. exports.timeDay = day;
  13799. exports.timeDays = days;
  13800. exports.timeWeek = sunday;
  13801. exports.timeWeeks = sundays;
  13802. exports.timeSunday = sunday;
  13803. exports.timeSundays = sundays;
  13804. exports.timeMonday = monday;
  13805. exports.timeMondays = mondays;
  13806. exports.timeTuesday = tuesday;
  13807. exports.timeTuesdays = tuesdays;
  13808. exports.timeWednesday = wednesday;
  13809. exports.timeWednesdays = wednesdays;
  13810. exports.timeThursday = thursday;
  13811. exports.timeThursdays = thursdays;
  13812. exports.timeFriday = friday;
  13813. exports.timeFridays = fridays;
  13814. exports.timeSaturday = saturday;
  13815. exports.timeSaturdays = saturdays;
  13816. exports.timeMonth = month;
  13817. exports.timeMonths = months;
  13818. exports.timeYear = year;
  13819. exports.timeYears = years;
  13820. exports.utcMillisecond = millisecond;
  13821. exports.utcMilliseconds = milliseconds;
  13822. exports.utcSecond = second;
  13823. exports.utcSeconds = seconds;
  13824. exports.utcMinute = utcMinute;
  13825. exports.utcMinutes = utcMinutes;
  13826. exports.utcHour = utcHour;
  13827. exports.utcHours = utcHours;
  13828. exports.utcDay = utcDay;
  13829. exports.utcDays = utcDays;
  13830. exports.utcWeek = utcSunday;
  13831. exports.utcWeeks = utcSundays;
  13832. exports.utcSunday = utcSunday;
  13833. exports.utcSundays = utcSundays;
  13834. exports.utcMonday = utcMonday;
  13835. exports.utcMondays = utcMondays;
  13836. exports.utcTuesday = utcTuesday;
  13837. exports.utcTuesdays = utcTuesdays;
  13838. exports.utcWednesday = utcWednesday;
  13839. exports.utcWednesdays = utcWednesdays;
  13840. exports.utcThursday = utcThursday;
  13841. exports.utcThursdays = utcThursdays;
  13842. exports.utcFriday = utcFriday;
  13843. exports.utcFridays = utcFridays;
  13844. exports.utcSaturday = utcSaturday;
  13845. exports.utcSaturdays = utcSaturdays;
  13846. exports.utcMonth = utcMonth;
  13847. exports.utcMonths = utcMonths;
  13848. exports.utcYear = utcYear;
  13849. exports.utcYears = utcYears;
  13850. exports.formatLocale = formatLocale;
  13851. exports.formatDefaultLocale = defaultLocale;
  13852. exports.formatSpecifier = formatSpecifier;
  13853. exports.precisionFixed = precisionFixed;
  13854. exports.precisionPrefix = precisionPrefix;
  13855. exports.precisionRound = precisionRound;
  13856. exports.isoFormat = formatIso;
  13857. exports.isoParse = parseIso;
  13858. exports.timeFormatLocale = formatLocale$1;
  13859. exports.timeFormatDefaultLocale = defaultLocale$1;
  13860. exports.scaleBand = band;
  13861. exports.scalePoint = point$4;
  13862. exports.scaleIdentity = identity$4;
  13863. exports.scaleLinear = linear$2;
  13864. exports.scaleLog = log;
  13865. exports.scaleOrdinal = ordinal;
  13866. exports.scaleImplicit = implicit;
  13867. exports.scalePow = pow;
  13868. exports.scaleSqrt = sqrt;
  13869. exports.scaleQuantile = quantile$$1;
  13870. exports.scaleQuantize = quantize$1;
  13871. exports.scaleThreshold = threshold$1;
  13872. exports.scaleTime = time;
  13873. exports.scaleUtc = utcTime;
  13874. exports.schemeCategory10 = category10;
  13875. exports.schemeCategory20b = category20b;
  13876. exports.schemeCategory20c = category20c;
  13877. exports.schemeCategory20 = category20;
  13878. exports.scaleSequential = sequential;
  13879. exports.interpolateCubehelixDefault = cubehelix$3;
  13880. exports.interpolateRainbow = rainbow$1;
  13881. exports.interpolateWarm = warm;
  13882. exports.interpolateCool = cool;
  13883. exports.interpolateViridis = viridis;
  13884. exports.interpolateMagma = magma;
  13885. exports.interpolateInferno = inferno;
  13886. exports.interpolatePlasma = plasma;
  13887. exports.creator = creator;
  13888. exports.customEvent = customEvent;
  13889. exports.local = local;
  13890. exports.matcher = matcher$1;
  13891. exports.mouse = mouse;
  13892. exports.namespace = namespace;
  13893. exports.namespaces = namespaces;
  13894. exports.select = select;
  13895. exports.selectAll = selectAll;
  13896. exports.selection = selection;
  13897. exports.selector = selector;
  13898. exports.selectorAll = selectorAll;
  13899. exports.touch = touch;
  13900. exports.touches = touches;
  13901. exports.window = window;
  13902. exports.active = active;
  13903. exports.interrupt = interrupt;
  13904. exports.transition = transition;
  13905. exports.axisTop = axisTop;
  13906. exports.axisRight = axisRight;
  13907. exports.axisBottom = axisBottom;
  13908. exports.axisLeft = axisLeft;
  13909. exports.cluster = cluster;
  13910. exports.hierarchy = hierarchy;
  13911. exports.pack = index;
  13912. exports.packSiblings = siblings;
  13913. exports.packEnclose = enclose;
  13914. exports.partition = partition;
  13915. exports.stratify = stratify;
  13916. exports.tree = tree;
  13917. exports.treemap = index$1;
  13918. exports.treemapBinary = binary;
  13919. exports.treemapDice = treemapDice;
  13920. exports.treemapSlice = treemapSlice;
  13921. exports.treemapSliceDice = sliceDice;
  13922. exports.treemapSquarify = squarify;
  13923. exports.treemapResquarify = resquarify;
  13924. exports.forceCenter = center$1;
  13925. exports.forceCollide = collide;
  13926. exports.forceLink = link;
  13927. exports.forceManyBody = manyBody;
  13928. exports.forceSimulation = simulation;
  13929. exports.forceX = x$3;
  13930. exports.forceY = y$3;
  13931. exports.drag = drag;
  13932. exports.dragDisable = dragDisable;
  13933. exports.dragEnable = yesdrag;
  13934. exports.voronoi = voronoi;
  13935. exports.zoom = zoom;
  13936. exports.zoomIdentity = identity$6;
  13937. exports.zoomTransform = transform;
  13938. exports.brush = brush;
  13939. exports.brushX = brushX;
  13940. exports.brushY = brushY;
  13941. exports.brushSelection = brushSelection;
  13942. exports.chord = chord;
  13943. exports.ribbon = ribbon;
  13944. exports.geoAlbers = albers;
  13945. exports.geoAlbersUsa = albersUsa;
  13946. exports.geoArea = area$2;
  13947. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  13948. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  13949. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  13950. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  13951. exports.geoBounds = bounds;
  13952. exports.geoCentroid = centroid$1;
  13953. exports.geoCircle = circle$1;
  13954. exports.geoClipExtent = extent$1;
  13955. exports.geoConicConformal = conicConformal;
  13956. exports.geoConicConformalRaw = conicConformalRaw;
  13957. exports.geoConicEqualArea = conicEqualArea;
  13958. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  13959. exports.geoConicEquidistant = conicEquidistant;
  13960. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  13961. exports.geoDistance = distance;
  13962. exports.geoEquirectangular = equirectangular;
  13963. exports.geoEquirectangularRaw = equirectangularRaw;
  13964. exports.geoGnomonic = gnomonic;
  13965. exports.geoGnomonicRaw = gnomonicRaw;
  13966. exports.geoGraticule = graticule;
  13967. exports.geoGraticule10 = graticule10;
  13968. exports.geoIdentity = identity$8;
  13969. exports.geoInterpolate = interpolate$2;
  13970. exports.geoLength = length$2;
  13971. exports.geoMercator = mercator;
  13972. exports.geoMercatorRaw = mercatorRaw;
  13973. exports.geoOrthographic = orthographic;
  13974. exports.geoOrthographicRaw = orthographicRaw;
  13975. exports.geoPath = index$3;
  13976. exports.geoProjection = projection;
  13977. exports.geoProjectionMutator = projectionMutator;
  13978. exports.geoRotation = rotation;
  13979. exports.geoStereographic = stereographic;
  13980. exports.geoStereographicRaw = stereographicRaw;
  13981. exports.geoStream = geoStream;
  13982. exports.geoTransform = transform$1;
  13983. exports.geoTransverseMercator = transverseMercator;
  13984. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  13985. Object.defineProperty(exports, '__esModule', { value: true });
  13986. })));