d3.js 499 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428
  1. // https://d3js.org v5.12.0 Copyright 2019 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = global || self, factory(global.d3 = global.d3 || {}));
  6. }(this, function (exports) { 'use strict';
  7. var version = "5.12.0";
  8. function ascending(a, b) {
  9. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  10. }
  11. function bisector(compare) {
  12. if (compare.length === 1) compare = ascendingComparator(compare);
  13. return {
  14. left: function(a, x, lo, hi) {
  15. if (lo == null) lo = 0;
  16. if (hi == null) hi = a.length;
  17. while (lo < hi) {
  18. var mid = lo + hi >>> 1;
  19. if (compare(a[mid], x) < 0) lo = mid + 1;
  20. else hi = mid;
  21. }
  22. return lo;
  23. },
  24. right: function(a, x, lo, hi) {
  25. if (lo == null) lo = 0;
  26. if (hi == null) hi = a.length;
  27. while (lo < hi) {
  28. var mid = lo + hi >>> 1;
  29. if (compare(a[mid], x) > 0) hi = mid;
  30. else lo = mid + 1;
  31. }
  32. return lo;
  33. }
  34. };
  35. }
  36. function ascendingComparator(f) {
  37. return function(d, x) {
  38. return ascending(f(d), x);
  39. };
  40. }
  41. var ascendingBisect = bisector(ascending);
  42. var bisectRight = ascendingBisect.right;
  43. var bisectLeft = ascendingBisect.left;
  44. function pairs(array, f) {
  45. if (f == null) f = pair;
  46. var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
  47. while (i < n) pairs[i] = f(p, p = array[++i]);
  48. return pairs;
  49. }
  50. function pair(a, b) {
  51. return [a, b];
  52. }
  53. function cross(values0, values1, reduce) {
  54. var n0 = values0.length,
  55. n1 = values1.length,
  56. values = new Array(n0 * n1),
  57. i0,
  58. i1,
  59. i,
  60. value0;
  61. if (reduce == null) reduce = pair;
  62. for (i0 = i = 0; i0 < n0; ++i0) {
  63. for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
  64. values[i] = reduce(value0, values1[i1]);
  65. }
  66. }
  67. return values;
  68. }
  69. function descending(a, b) {
  70. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  71. }
  72. function number(x) {
  73. return x === null ? NaN : +x;
  74. }
  75. function variance(values, valueof) {
  76. var n = values.length,
  77. m = 0,
  78. i = -1,
  79. mean = 0,
  80. value,
  81. delta,
  82. sum = 0;
  83. if (valueof == null) {
  84. while (++i < n) {
  85. if (!isNaN(value = number(values[i]))) {
  86. delta = value - mean;
  87. mean += delta / ++m;
  88. sum += delta * (value - mean);
  89. }
  90. }
  91. }
  92. else {
  93. while (++i < n) {
  94. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  95. delta = value - mean;
  96. mean += delta / ++m;
  97. sum += delta * (value - mean);
  98. }
  99. }
  100. }
  101. if (m > 1) return sum / (m - 1);
  102. }
  103. function deviation(array, f) {
  104. var v = variance(array, f);
  105. return v ? Math.sqrt(v) : v;
  106. }
  107. function extent(values, valueof) {
  108. var n = values.length,
  109. i = -1,
  110. value,
  111. min,
  112. max;
  113. if (valueof == null) {
  114. while (++i < n) { // Find the first comparable value.
  115. if ((value = values[i]) != null && value >= value) {
  116. min = max = value;
  117. while (++i < n) { // Compare the remaining values.
  118. if ((value = values[i]) != null) {
  119. if (min > value) min = value;
  120. if (max < value) max = value;
  121. }
  122. }
  123. }
  124. }
  125. }
  126. else {
  127. while (++i < n) { // Find the first comparable value.
  128. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  129. min = max = value;
  130. while (++i < n) { // Compare the remaining values.
  131. if ((value = valueof(values[i], i, values)) != null) {
  132. if (min > value) min = value;
  133. if (max < value) max = value;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. return [min, max];
  140. }
  141. var array = Array.prototype;
  142. var slice = array.slice;
  143. var map = array.map;
  144. function constant(x) {
  145. return function() {
  146. return x;
  147. };
  148. }
  149. function identity(x) {
  150. return x;
  151. }
  152. function sequence(start, stop, step) {
  153. start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
  154. var i = -1,
  155. n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
  156. range = new Array(n);
  157. while (++i < n) {
  158. range[i] = start + i * step;
  159. }
  160. return range;
  161. }
  162. var e10 = Math.sqrt(50),
  163. e5 = Math.sqrt(10),
  164. e2 = Math.sqrt(2);
  165. function ticks(start, stop, count) {
  166. var reverse,
  167. i = -1,
  168. n,
  169. ticks,
  170. step;
  171. stop = +stop, start = +start, count = +count;
  172. if (start === stop && count > 0) return [start];
  173. if (reverse = stop < start) n = start, start = stop, stop = n;
  174. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
  175. if (step > 0) {
  176. start = Math.ceil(start / step);
  177. stop = Math.floor(stop / step);
  178. ticks = new Array(n = Math.ceil(stop - start + 1));
  179. while (++i < n) ticks[i] = (start + i) * step;
  180. } else {
  181. start = Math.floor(start * step);
  182. stop = Math.ceil(stop * step);
  183. ticks = new Array(n = Math.ceil(start - stop + 1));
  184. while (++i < n) ticks[i] = (start - i) / step;
  185. }
  186. if (reverse) ticks.reverse();
  187. return ticks;
  188. }
  189. function tickIncrement(start, stop, count) {
  190. var step = (stop - start) / Math.max(0, count),
  191. power = Math.floor(Math.log(step) / Math.LN10),
  192. error = step / Math.pow(10, power);
  193. return power >= 0
  194. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  195. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  196. }
  197. function tickStep(start, stop, count) {
  198. var step0 = Math.abs(stop - start) / Math.max(0, count),
  199. step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
  200. error = step0 / step1;
  201. if (error >= e10) step1 *= 10;
  202. else if (error >= e5) step1 *= 5;
  203. else if (error >= e2) step1 *= 2;
  204. return stop < start ? -step1 : step1;
  205. }
  206. function thresholdSturges(values) {
  207. return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
  208. }
  209. function histogram() {
  210. var value = identity,
  211. domain = extent,
  212. threshold = thresholdSturges;
  213. function histogram(data) {
  214. var i,
  215. n = data.length,
  216. x,
  217. values = new Array(n);
  218. for (i = 0; i < n; ++i) {
  219. values[i] = value(data[i], i, data);
  220. }
  221. var xz = domain(values),
  222. x0 = xz[0],
  223. x1 = xz[1],
  224. tz = threshold(values, x0, x1);
  225. // Convert number of thresholds into uniform thresholds.
  226. if (!Array.isArray(tz)) {
  227. tz = tickStep(x0, x1, tz);
  228. tz = sequence(Math.ceil(x0 / tz) * tz, x1, tz); // exclusive
  229. }
  230. // Remove any thresholds outside the domain.
  231. var m = tz.length;
  232. while (tz[0] <= x0) tz.shift(), --m;
  233. while (tz[m - 1] > x1) tz.pop(), --m;
  234. var bins = new Array(m + 1),
  235. bin;
  236. // Initialize bins.
  237. for (i = 0; i <= m; ++i) {
  238. bin = bins[i] = [];
  239. bin.x0 = i > 0 ? tz[i - 1] : x0;
  240. bin.x1 = i < m ? tz[i] : x1;
  241. }
  242. // Assign data to bins by value, ignoring any outside the domain.
  243. for (i = 0; i < n; ++i) {
  244. x = values[i];
  245. if (x0 <= x && x <= x1) {
  246. bins[bisectRight(tz, x, 0, m)].push(data[i]);
  247. }
  248. }
  249. return bins;
  250. }
  251. histogram.value = function(_) {
  252. return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
  253. };
  254. histogram.domain = function(_) {
  255. return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
  256. };
  257. histogram.thresholds = function(_) {
  258. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
  259. };
  260. return histogram;
  261. }
  262. function threshold(values, p, valueof) {
  263. if (valueof == null) valueof = number;
  264. if (!(n = values.length)) return;
  265. if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
  266. if (p >= 1) return +valueof(values[n - 1], n - 1, values);
  267. var n,
  268. i = (n - 1) * p,
  269. i0 = Math.floor(i),
  270. value0 = +valueof(values[i0], i0, values),
  271. value1 = +valueof(values[i0 + 1], i0 + 1, values);
  272. return value0 + (value1 - value0) * (i - i0);
  273. }
  274. function freedmanDiaconis(values, min, max) {
  275. values = map.call(values, number).sort(ascending);
  276. return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
  277. }
  278. function scott(values, min, max) {
  279. return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
  280. }
  281. function max(values, valueof) {
  282. var n = values.length,
  283. i = -1,
  284. value,
  285. max;
  286. if (valueof == null) {
  287. while (++i < n) { // Find the first comparable value.
  288. if ((value = values[i]) != null && value >= value) {
  289. max = value;
  290. while (++i < n) { // Compare the remaining values.
  291. if ((value = values[i]) != null && value > max) {
  292. max = value;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. else {
  299. while (++i < n) { // Find the first comparable value.
  300. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  301. max = value;
  302. while (++i < n) { // Compare the remaining values.
  303. if ((value = valueof(values[i], i, values)) != null && value > max) {
  304. max = value;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. return max;
  311. }
  312. function mean(values, valueof) {
  313. var n = values.length,
  314. m = n,
  315. i = -1,
  316. value,
  317. sum = 0;
  318. if (valueof == null) {
  319. while (++i < n) {
  320. if (!isNaN(value = number(values[i]))) sum += value;
  321. else --m;
  322. }
  323. }
  324. else {
  325. while (++i < n) {
  326. if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
  327. else --m;
  328. }
  329. }
  330. if (m) return sum / m;
  331. }
  332. function median(values, valueof) {
  333. var n = values.length,
  334. i = -1,
  335. value,
  336. numbers = [];
  337. if (valueof == null) {
  338. while (++i < n) {
  339. if (!isNaN(value = number(values[i]))) {
  340. numbers.push(value);
  341. }
  342. }
  343. }
  344. else {
  345. while (++i < n) {
  346. if (!isNaN(value = number(valueof(values[i], i, values)))) {
  347. numbers.push(value);
  348. }
  349. }
  350. }
  351. return threshold(numbers.sort(ascending), 0.5);
  352. }
  353. function merge(arrays) {
  354. var n = arrays.length,
  355. m,
  356. i = -1,
  357. j = 0,
  358. merged,
  359. array;
  360. while (++i < n) j += arrays[i].length;
  361. merged = new Array(j);
  362. while (--n >= 0) {
  363. array = arrays[n];
  364. m = array.length;
  365. while (--m >= 0) {
  366. merged[--j] = array[m];
  367. }
  368. }
  369. return merged;
  370. }
  371. function min(values, valueof) {
  372. var n = values.length,
  373. i = -1,
  374. value,
  375. min;
  376. if (valueof == null) {
  377. while (++i < n) { // Find the first comparable value.
  378. if ((value = values[i]) != null && value >= value) {
  379. min = value;
  380. while (++i < n) { // Compare the remaining values.
  381. if ((value = values[i]) != null && min > value) {
  382. min = value;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. else {
  389. while (++i < n) { // Find the first comparable value.
  390. if ((value = valueof(values[i], i, values)) != null && value >= value) {
  391. min = value;
  392. while (++i < n) { // Compare the remaining values.
  393. if ((value = valueof(values[i], i, values)) != null && min > value) {
  394. min = value;
  395. }
  396. }
  397. }
  398. }
  399. }
  400. return min;
  401. }
  402. function permute(array, indexes) {
  403. var i = indexes.length, permutes = new Array(i);
  404. while (i--) permutes[i] = array[indexes[i]];
  405. return permutes;
  406. }
  407. function scan(values, compare) {
  408. if (!(n = values.length)) return;
  409. var n,
  410. i = 0,
  411. j = 0,
  412. xi,
  413. xj = values[j];
  414. if (compare == null) compare = ascending;
  415. while (++i < n) {
  416. if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
  417. xj = xi, j = i;
  418. }
  419. }
  420. if (compare(xj, xj) === 0) return j;
  421. }
  422. function shuffle(array, i0, i1) {
  423. var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
  424. t,
  425. i;
  426. while (m) {
  427. i = Math.random() * m-- | 0;
  428. t = array[m + i0];
  429. array[m + i0] = array[i + i0];
  430. array[i + i0] = t;
  431. }
  432. return array;
  433. }
  434. function sum(values, valueof) {
  435. var n = values.length,
  436. i = -1,
  437. value,
  438. sum = 0;
  439. if (valueof == null) {
  440. while (++i < n) {
  441. if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
  442. }
  443. }
  444. else {
  445. while (++i < n) {
  446. if (value = +valueof(values[i], i, values)) sum += value;
  447. }
  448. }
  449. return sum;
  450. }
  451. function transpose(matrix) {
  452. if (!(n = matrix.length)) return [];
  453. for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
  454. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
  455. row[j] = matrix[j][i];
  456. }
  457. }
  458. return transpose;
  459. }
  460. function length(d) {
  461. return d.length;
  462. }
  463. function zip() {
  464. return transpose(arguments);
  465. }
  466. var slice$1 = Array.prototype.slice;
  467. function identity$1(x) {
  468. return x;
  469. }
  470. var top = 1,
  471. right = 2,
  472. bottom = 3,
  473. left = 4,
  474. epsilon = 1e-6;
  475. function translateX(x) {
  476. return "translate(" + (x + 0.5) + ",0)";
  477. }
  478. function translateY(y) {
  479. return "translate(0," + (y + 0.5) + ")";
  480. }
  481. function number$1(scale) {
  482. return function(d) {
  483. return +scale(d);
  484. };
  485. }
  486. function center(scale) {
  487. var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
  488. if (scale.round()) offset = Math.round(offset);
  489. return function(d) {
  490. return +scale(d) + offset;
  491. };
  492. }
  493. function entering() {
  494. return !this.__axis;
  495. }
  496. function axis(orient, scale) {
  497. var tickArguments = [],
  498. tickValues = null,
  499. tickFormat = null,
  500. tickSizeInner = 6,
  501. tickSizeOuter = 6,
  502. tickPadding = 3,
  503. k = orient === top || orient === left ? -1 : 1,
  504. x = orient === left || orient === right ? "x" : "y",
  505. transform = orient === top || orient === bottom ? translateX : translateY;
  506. function axis(context) {
  507. var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
  508. format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
  509. spacing = Math.max(tickSizeInner, 0) + tickPadding,
  510. range = scale.range(),
  511. range0 = +range[0] + 0.5,
  512. range1 = +range[range.length - 1] + 0.5,
  513. position = (scale.bandwidth ? center : number$1)(scale.copy()),
  514. selection = context.selection ? context.selection() : context,
  515. path = selection.selectAll(".domain").data([null]),
  516. tick = selection.selectAll(".tick").data(values, scale).order(),
  517. tickExit = tick.exit(),
  518. tickEnter = tick.enter().append("g").attr("class", "tick"),
  519. line = tick.select("line"),
  520. text = tick.select("text");
  521. path = path.merge(path.enter().insert("path", ".tick")
  522. .attr("class", "domain")
  523. .attr("stroke", "currentColor"));
  524. tick = tick.merge(tickEnter);
  525. line = line.merge(tickEnter.append("line")
  526. .attr("stroke", "currentColor")
  527. .attr(x + "2", k * tickSizeInner));
  528. text = text.merge(tickEnter.append("text")
  529. .attr("fill", "currentColor")
  530. .attr(x, k * spacing)
  531. .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
  532. if (context !== selection) {
  533. path = path.transition(context);
  534. tick = tick.transition(context);
  535. line = line.transition(context);
  536. text = text.transition(context);
  537. tickExit = tickExit.transition(context)
  538. .attr("opacity", epsilon)
  539. .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
  540. tickEnter
  541. .attr("opacity", epsilon)
  542. .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
  543. }
  544. tickExit.remove();
  545. path
  546. .attr("d", orient === left || orient == right
  547. ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter : "M0.5," + range0 + "V" + range1)
  548. : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + ",0.5H" + range1));
  549. tick
  550. .attr("opacity", 1)
  551. .attr("transform", function(d) { return transform(position(d)); });
  552. line
  553. .attr(x + "2", k * tickSizeInner);
  554. text
  555. .attr(x, k * spacing)
  556. .text(format);
  557. selection.filter(entering)
  558. .attr("fill", "none")
  559. .attr("font-size", 10)
  560. .attr("font-family", "sans-serif")
  561. .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
  562. selection
  563. .each(function() { this.__axis = position; });
  564. }
  565. axis.scale = function(_) {
  566. return arguments.length ? (scale = _, axis) : scale;
  567. };
  568. axis.ticks = function() {
  569. return tickArguments = slice$1.call(arguments), axis;
  570. };
  571. axis.tickArguments = function(_) {
  572. return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
  573. };
  574. axis.tickValues = function(_) {
  575. return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
  576. };
  577. axis.tickFormat = function(_) {
  578. return arguments.length ? (tickFormat = _, axis) : tickFormat;
  579. };
  580. axis.tickSize = function(_) {
  581. return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
  582. };
  583. axis.tickSizeInner = function(_) {
  584. return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
  585. };
  586. axis.tickSizeOuter = function(_) {
  587. return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
  588. };
  589. axis.tickPadding = function(_) {
  590. return arguments.length ? (tickPadding = +_, axis) : tickPadding;
  591. };
  592. return axis;
  593. }
  594. function axisTop(scale) {
  595. return axis(top, scale);
  596. }
  597. function axisRight(scale) {
  598. return axis(right, scale);
  599. }
  600. function axisBottom(scale) {
  601. return axis(bottom, scale);
  602. }
  603. function axisLeft(scale) {
  604. return axis(left, scale);
  605. }
  606. var noop = {value: function() {}};
  607. function dispatch() {
  608. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  609. if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
  610. _[t] = [];
  611. }
  612. return new Dispatch(_);
  613. }
  614. function Dispatch(_) {
  615. this._ = _;
  616. }
  617. function parseTypenames(typenames, types) {
  618. return typenames.trim().split(/^|\s+/).map(function(t) {
  619. var name = "", i = t.indexOf(".");
  620. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  621. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  622. return {type: t, name: name};
  623. });
  624. }
  625. Dispatch.prototype = dispatch.prototype = {
  626. constructor: Dispatch,
  627. on: function(typename, callback) {
  628. var _ = this._,
  629. T = parseTypenames(typename + "", _),
  630. t,
  631. i = -1,
  632. n = T.length;
  633. // If no callback was specified, return the callback of the given type and name.
  634. if (arguments.length < 2) {
  635. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  636. return;
  637. }
  638. // If a type was specified, set the callback for the given type and name.
  639. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  640. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  641. while (++i < n) {
  642. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  643. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  644. }
  645. return this;
  646. },
  647. copy: function() {
  648. var copy = {}, _ = this._;
  649. for (var t in _) copy[t] = _[t].slice();
  650. return new Dispatch(copy);
  651. },
  652. call: function(type, that) {
  653. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  654. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  655. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  656. },
  657. apply: function(type, that, args) {
  658. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  659. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  660. }
  661. };
  662. function get(type, name) {
  663. for (var i = 0, n = type.length, c; i < n; ++i) {
  664. if ((c = type[i]).name === name) {
  665. return c.value;
  666. }
  667. }
  668. }
  669. function set(type, name, callback) {
  670. for (var i = 0, n = type.length; i < n; ++i) {
  671. if (type[i].name === name) {
  672. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  673. break;
  674. }
  675. }
  676. if (callback != null) type.push({name: name, value: callback});
  677. return type;
  678. }
  679. var xhtml = "http://www.w3.org/1999/xhtml";
  680. var namespaces = {
  681. svg: "http://www.w3.org/2000/svg",
  682. xhtml: xhtml,
  683. xlink: "http://www.w3.org/1999/xlink",
  684. xml: "http://www.w3.org/XML/1998/namespace",
  685. xmlns: "http://www.w3.org/2000/xmlns/"
  686. };
  687. function namespace(name) {
  688. var prefix = name += "", i = prefix.indexOf(":");
  689. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  690. return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
  691. }
  692. function creatorInherit(name) {
  693. return function() {
  694. var document = this.ownerDocument,
  695. uri = this.namespaceURI;
  696. return uri === xhtml && document.documentElement.namespaceURI === xhtml
  697. ? document.createElement(name)
  698. : document.createElementNS(uri, name);
  699. };
  700. }
  701. function creatorFixed(fullname) {
  702. return function() {
  703. return this.ownerDocument.createElementNS(fullname.space, fullname.local);
  704. };
  705. }
  706. function creator(name) {
  707. var fullname = namespace(name);
  708. return (fullname.local
  709. ? creatorFixed
  710. : creatorInherit)(fullname);
  711. }
  712. function none() {}
  713. function selector(selector) {
  714. return selector == null ? none : function() {
  715. return this.querySelector(selector);
  716. };
  717. }
  718. function selection_select(select) {
  719. if (typeof select !== "function") select = selector(select);
  720. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  721. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  722. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  723. if ("__data__" in node) subnode.__data__ = node.__data__;
  724. subgroup[i] = subnode;
  725. }
  726. }
  727. }
  728. return new Selection(subgroups, this._parents);
  729. }
  730. function empty() {
  731. return [];
  732. }
  733. function selectorAll(selector) {
  734. return selector == null ? empty : function() {
  735. return this.querySelectorAll(selector);
  736. };
  737. }
  738. function selection_selectAll(select) {
  739. if (typeof select !== "function") select = selectorAll(select);
  740. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  741. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  742. if (node = group[i]) {
  743. subgroups.push(select.call(node, node.__data__, i, group));
  744. parents.push(node);
  745. }
  746. }
  747. }
  748. return new Selection(subgroups, parents);
  749. }
  750. function matcher(selector) {
  751. return function() {
  752. return this.matches(selector);
  753. };
  754. }
  755. function selection_filter(match) {
  756. if (typeof match !== "function") match = matcher(match);
  757. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  758. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  759. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  760. subgroup.push(node);
  761. }
  762. }
  763. }
  764. return new Selection(subgroups, this._parents);
  765. }
  766. function sparse(update) {
  767. return new Array(update.length);
  768. }
  769. function selection_enter() {
  770. return new Selection(this._enter || this._groups.map(sparse), this._parents);
  771. }
  772. function EnterNode(parent, datum) {
  773. this.ownerDocument = parent.ownerDocument;
  774. this.namespaceURI = parent.namespaceURI;
  775. this._next = null;
  776. this._parent = parent;
  777. this.__data__ = datum;
  778. }
  779. EnterNode.prototype = {
  780. constructor: EnterNode,
  781. appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
  782. insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
  783. querySelector: function(selector) { return this._parent.querySelector(selector); },
  784. querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
  785. };
  786. function constant$1(x) {
  787. return function() {
  788. return x;
  789. };
  790. }
  791. var keyPrefix = "$"; // Protect against keys like “__proto__”.
  792. function bindIndex(parent, group, enter, update, exit, data) {
  793. var i = 0,
  794. node,
  795. groupLength = group.length,
  796. dataLength = data.length;
  797. // Put any non-null nodes that fit into update.
  798. // Put any null nodes into enter.
  799. // Put any remaining data into enter.
  800. for (; i < dataLength; ++i) {
  801. if (node = group[i]) {
  802. node.__data__ = data[i];
  803. update[i] = node;
  804. } else {
  805. enter[i] = new EnterNode(parent, data[i]);
  806. }
  807. }
  808. // Put any non-null nodes that don’t fit into exit.
  809. for (; i < groupLength; ++i) {
  810. if (node = group[i]) {
  811. exit[i] = node;
  812. }
  813. }
  814. }
  815. function bindKey(parent, group, enter, update, exit, data, key) {
  816. var i,
  817. node,
  818. nodeByKeyValue = {},
  819. groupLength = group.length,
  820. dataLength = data.length,
  821. keyValues = new Array(groupLength),
  822. keyValue;
  823. // Compute the key for each node.
  824. // If multiple nodes have the same key, the duplicates are added to exit.
  825. for (i = 0; i < groupLength; ++i) {
  826. if (node = group[i]) {
  827. keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
  828. if (keyValue in nodeByKeyValue) {
  829. exit[i] = node;
  830. } else {
  831. nodeByKeyValue[keyValue] = node;
  832. }
  833. }
  834. }
  835. // Compute the key for each datum.
  836. // If there a node associated with this key, join and add it to update.
  837. // If there is not (or the key is a duplicate), add it to enter.
  838. for (i = 0; i < dataLength; ++i) {
  839. keyValue = keyPrefix + key.call(parent, data[i], i, data);
  840. if (node = nodeByKeyValue[keyValue]) {
  841. update[i] = node;
  842. node.__data__ = data[i];
  843. nodeByKeyValue[keyValue] = null;
  844. } else {
  845. enter[i] = new EnterNode(parent, data[i]);
  846. }
  847. }
  848. // Add any remaining nodes that were not bound to data to exit.
  849. for (i = 0; i < groupLength; ++i) {
  850. if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
  851. exit[i] = node;
  852. }
  853. }
  854. }
  855. function selection_data(value, key) {
  856. if (!value) {
  857. data = new Array(this.size()), j = -1;
  858. this.each(function(d) { data[++j] = d; });
  859. return data;
  860. }
  861. var bind = key ? bindKey : bindIndex,
  862. parents = this._parents,
  863. groups = this._groups;
  864. if (typeof value !== "function") value = constant$1(value);
  865. for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
  866. var parent = parents[j],
  867. group = groups[j],
  868. groupLength = group.length,
  869. data = value.call(parent, parent && parent.__data__, j, parents),
  870. dataLength = data.length,
  871. enterGroup = enter[j] = new Array(dataLength),
  872. updateGroup = update[j] = new Array(dataLength),
  873. exitGroup = exit[j] = new Array(groupLength);
  874. bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
  875. // Now connect the enter nodes to their following update node, such that
  876. // appendChild can insert the materialized enter node before this node,
  877. // rather than at the end of the parent node.
  878. for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
  879. if (previous = enterGroup[i0]) {
  880. if (i0 >= i1) i1 = i0 + 1;
  881. while (!(next = updateGroup[i1]) && ++i1 < dataLength);
  882. previous._next = next || null;
  883. }
  884. }
  885. }
  886. update = new Selection(update, parents);
  887. update._enter = enter;
  888. update._exit = exit;
  889. return update;
  890. }
  891. function selection_exit() {
  892. return new Selection(this._exit || this._groups.map(sparse), this._parents);
  893. }
  894. function selection_join(onenter, onupdate, onexit) {
  895. var enter = this.enter(), update = this, exit = this.exit();
  896. enter = typeof onenter === "function" ? onenter(enter) : enter.append(onenter + "");
  897. if (onupdate != null) update = onupdate(update);
  898. if (onexit == null) exit.remove(); else onexit(exit);
  899. return enter && update ? enter.merge(update).order() : update;
  900. }
  901. function selection_merge(selection) {
  902. for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
  903. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  904. if (node = group0[i] || group1[i]) {
  905. merge[i] = node;
  906. }
  907. }
  908. }
  909. for (; j < m0; ++j) {
  910. merges[j] = groups0[j];
  911. }
  912. return new Selection(merges, this._parents);
  913. }
  914. function selection_order() {
  915. for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
  916. for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
  917. if (node = group[i]) {
  918. if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
  919. next = node;
  920. }
  921. }
  922. }
  923. return this;
  924. }
  925. function selection_sort(compare) {
  926. if (!compare) compare = ascending$1;
  927. function compareNode(a, b) {
  928. return a && b ? compare(a.__data__, b.__data__) : !a - !b;
  929. }
  930. for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
  931. for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
  932. if (node = group[i]) {
  933. sortgroup[i] = node;
  934. }
  935. }
  936. sortgroup.sort(compareNode);
  937. }
  938. return new Selection(sortgroups, this._parents).order();
  939. }
  940. function ascending$1(a, b) {
  941. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  942. }
  943. function selection_call() {
  944. var callback = arguments[0];
  945. arguments[0] = this;
  946. callback.apply(null, arguments);
  947. return this;
  948. }
  949. function selection_nodes() {
  950. var nodes = new Array(this.size()), i = -1;
  951. this.each(function() { nodes[++i] = this; });
  952. return nodes;
  953. }
  954. function selection_node() {
  955. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  956. for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
  957. var node = group[i];
  958. if (node) return node;
  959. }
  960. }
  961. return null;
  962. }
  963. function selection_size() {
  964. var size = 0;
  965. this.each(function() { ++size; });
  966. return size;
  967. }
  968. function selection_empty() {
  969. return !this.node();
  970. }
  971. function selection_each(callback) {
  972. for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
  973. for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
  974. if (node = group[i]) callback.call(node, node.__data__, i, group);
  975. }
  976. }
  977. return this;
  978. }
  979. function attrRemove(name) {
  980. return function() {
  981. this.removeAttribute(name);
  982. };
  983. }
  984. function attrRemoveNS(fullname) {
  985. return function() {
  986. this.removeAttributeNS(fullname.space, fullname.local);
  987. };
  988. }
  989. function attrConstant(name, value) {
  990. return function() {
  991. this.setAttribute(name, value);
  992. };
  993. }
  994. function attrConstantNS(fullname, value) {
  995. return function() {
  996. this.setAttributeNS(fullname.space, fullname.local, value);
  997. };
  998. }
  999. function attrFunction(name, value) {
  1000. return function() {
  1001. var v = value.apply(this, arguments);
  1002. if (v == null) this.removeAttribute(name);
  1003. else this.setAttribute(name, v);
  1004. };
  1005. }
  1006. function attrFunctionNS(fullname, value) {
  1007. return function() {
  1008. var v = value.apply(this, arguments);
  1009. if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
  1010. else this.setAttributeNS(fullname.space, fullname.local, v);
  1011. };
  1012. }
  1013. function selection_attr(name, value) {
  1014. var fullname = namespace(name);
  1015. if (arguments.length < 2) {
  1016. var node = this.node();
  1017. return fullname.local
  1018. ? node.getAttributeNS(fullname.space, fullname.local)
  1019. : node.getAttribute(fullname);
  1020. }
  1021. return this.each((value == null
  1022. ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
  1023. ? (fullname.local ? attrFunctionNS : attrFunction)
  1024. : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
  1025. }
  1026. function defaultView(node) {
  1027. return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
  1028. || (node.document && node) // node is a Window
  1029. || node.defaultView; // node is a Document
  1030. }
  1031. function styleRemove(name) {
  1032. return function() {
  1033. this.style.removeProperty(name);
  1034. };
  1035. }
  1036. function styleConstant(name, value, priority) {
  1037. return function() {
  1038. this.style.setProperty(name, value, priority);
  1039. };
  1040. }
  1041. function styleFunction(name, value, priority) {
  1042. return function() {
  1043. var v = value.apply(this, arguments);
  1044. if (v == null) this.style.removeProperty(name);
  1045. else this.style.setProperty(name, v, priority);
  1046. };
  1047. }
  1048. function selection_style(name, value, priority) {
  1049. return arguments.length > 1
  1050. ? this.each((value == null
  1051. ? styleRemove : typeof value === "function"
  1052. ? styleFunction
  1053. : styleConstant)(name, value, priority == null ? "" : priority))
  1054. : styleValue(this.node(), name);
  1055. }
  1056. function styleValue(node, name) {
  1057. return node.style.getPropertyValue(name)
  1058. || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
  1059. }
  1060. function propertyRemove(name) {
  1061. return function() {
  1062. delete this[name];
  1063. };
  1064. }
  1065. function propertyConstant(name, value) {
  1066. return function() {
  1067. this[name] = value;
  1068. };
  1069. }
  1070. function propertyFunction(name, value) {
  1071. return function() {
  1072. var v = value.apply(this, arguments);
  1073. if (v == null) delete this[name];
  1074. else this[name] = v;
  1075. };
  1076. }
  1077. function selection_property(name, value) {
  1078. return arguments.length > 1
  1079. ? this.each((value == null
  1080. ? propertyRemove : typeof value === "function"
  1081. ? propertyFunction
  1082. : propertyConstant)(name, value))
  1083. : this.node()[name];
  1084. }
  1085. function classArray(string) {
  1086. return string.trim().split(/^|\s+/);
  1087. }
  1088. function classList(node) {
  1089. return node.classList || new ClassList(node);
  1090. }
  1091. function ClassList(node) {
  1092. this._node = node;
  1093. this._names = classArray(node.getAttribute("class") || "");
  1094. }
  1095. ClassList.prototype = {
  1096. add: function(name) {
  1097. var i = this._names.indexOf(name);
  1098. if (i < 0) {
  1099. this._names.push(name);
  1100. this._node.setAttribute("class", this._names.join(" "));
  1101. }
  1102. },
  1103. remove: function(name) {
  1104. var i = this._names.indexOf(name);
  1105. if (i >= 0) {
  1106. this._names.splice(i, 1);
  1107. this._node.setAttribute("class", this._names.join(" "));
  1108. }
  1109. },
  1110. contains: function(name) {
  1111. return this._names.indexOf(name) >= 0;
  1112. }
  1113. };
  1114. function classedAdd(node, names) {
  1115. var list = classList(node), i = -1, n = names.length;
  1116. while (++i < n) list.add(names[i]);
  1117. }
  1118. function classedRemove(node, names) {
  1119. var list = classList(node), i = -1, n = names.length;
  1120. while (++i < n) list.remove(names[i]);
  1121. }
  1122. function classedTrue(names) {
  1123. return function() {
  1124. classedAdd(this, names);
  1125. };
  1126. }
  1127. function classedFalse(names) {
  1128. return function() {
  1129. classedRemove(this, names);
  1130. };
  1131. }
  1132. function classedFunction(names, value) {
  1133. return function() {
  1134. (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
  1135. };
  1136. }
  1137. function selection_classed(name, value) {
  1138. var names = classArray(name + "");
  1139. if (arguments.length < 2) {
  1140. var list = classList(this.node()), i = -1, n = names.length;
  1141. while (++i < n) if (!list.contains(names[i])) return false;
  1142. return true;
  1143. }
  1144. return this.each((typeof value === "function"
  1145. ? classedFunction : value
  1146. ? classedTrue
  1147. : classedFalse)(names, value));
  1148. }
  1149. function textRemove() {
  1150. this.textContent = "";
  1151. }
  1152. function textConstant(value) {
  1153. return function() {
  1154. this.textContent = value;
  1155. };
  1156. }
  1157. function textFunction(value) {
  1158. return function() {
  1159. var v = value.apply(this, arguments);
  1160. this.textContent = v == null ? "" : v;
  1161. };
  1162. }
  1163. function selection_text(value) {
  1164. return arguments.length
  1165. ? this.each(value == null
  1166. ? textRemove : (typeof value === "function"
  1167. ? textFunction
  1168. : textConstant)(value))
  1169. : this.node().textContent;
  1170. }
  1171. function htmlRemove() {
  1172. this.innerHTML = "";
  1173. }
  1174. function htmlConstant(value) {
  1175. return function() {
  1176. this.innerHTML = value;
  1177. };
  1178. }
  1179. function htmlFunction(value) {
  1180. return function() {
  1181. var v = value.apply(this, arguments);
  1182. this.innerHTML = v == null ? "" : v;
  1183. };
  1184. }
  1185. function selection_html(value) {
  1186. return arguments.length
  1187. ? this.each(value == null
  1188. ? htmlRemove : (typeof value === "function"
  1189. ? htmlFunction
  1190. : htmlConstant)(value))
  1191. : this.node().innerHTML;
  1192. }
  1193. function raise() {
  1194. if (this.nextSibling) this.parentNode.appendChild(this);
  1195. }
  1196. function selection_raise() {
  1197. return this.each(raise);
  1198. }
  1199. function lower() {
  1200. if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
  1201. }
  1202. function selection_lower() {
  1203. return this.each(lower);
  1204. }
  1205. function selection_append(name) {
  1206. var create = typeof name === "function" ? name : creator(name);
  1207. return this.select(function() {
  1208. return this.appendChild(create.apply(this, arguments));
  1209. });
  1210. }
  1211. function constantNull() {
  1212. return null;
  1213. }
  1214. function selection_insert(name, before) {
  1215. var create = typeof name === "function" ? name : creator(name),
  1216. select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
  1217. return this.select(function() {
  1218. return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
  1219. });
  1220. }
  1221. function remove() {
  1222. var parent = this.parentNode;
  1223. if (parent) parent.removeChild(this);
  1224. }
  1225. function selection_remove() {
  1226. return this.each(remove);
  1227. }
  1228. function selection_cloneShallow() {
  1229. return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
  1230. }
  1231. function selection_cloneDeep() {
  1232. return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
  1233. }
  1234. function selection_clone(deep) {
  1235. return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
  1236. }
  1237. function selection_datum(value) {
  1238. return arguments.length
  1239. ? this.property("__data__", value)
  1240. : this.node().__data__;
  1241. }
  1242. var filterEvents = {};
  1243. exports.event = null;
  1244. if (typeof document !== "undefined") {
  1245. var element = document.documentElement;
  1246. if (!("onmouseenter" in element)) {
  1247. filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
  1248. }
  1249. }
  1250. function filterContextListener(listener, index, group) {
  1251. listener = contextListener(listener, index, group);
  1252. return function(event) {
  1253. var related = event.relatedTarget;
  1254. if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
  1255. listener.call(this, event);
  1256. }
  1257. };
  1258. }
  1259. function contextListener(listener, index, group) {
  1260. return function(event1) {
  1261. var event0 = exports.event; // Events can be reentrant (e.g., focus).
  1262. exports.event = event1;
  1263. try {
  1264. listener.call(this, this.__data__, index, group);
  1265. } finally {
  1266. exports.event = event0;
  1267. }
  1268. };
  1269. }
  1270. function parseTypenames$1(typenames) {
  1271. return typenames.trim().split(/^|\s+/).map(function(t) {
  1272. var name = "", i = t.indexOf(".");
  1273. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  1274. return {type: t, name: name};
  1275. });
  1276. }
  1277. function onRemove(typename) {
  1278. return function() {
  1279. var on = this.__on;
  1280. if (!on) return;
  1281. for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
  1282. if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
  1283. this.removeEventListener(o.type, o.listener, o.capture);
  1284. } else {
  1285. on[++i] = o;
  1286. }
  1287. }
  1288. if (++i) on.length = i;
  1289. else delete this.__on;
  1290. };
  1291. }
  1292. function onAdd(typename, value, capture) {
  1293. var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
  1294. return function(d, i, group) {
  1295. var on = this.__on, o, listener = wrap(value, i, group);
  1296. if (on) for (var j = 0, m = on.length; j < m; ++j) {
  1297. if ((o = on[j]).type === typename.type && o.name === typename.name) {
  1298. this.removeEventListener(o.type, o.listener, o.capture);
  1299. this.addEventListener(o.type, o.listener = listener, o.capture = capture);
  1300. o.value = value;
  1301. return;
  1302. }
  1303. }
  1304. this.addEventListener(typename.type, listener, capture);
  1305. o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
  1306. if (!on) this.__on = [o];
  1307. else on.push(o);
  1308. };
  1309. }
  1310. function selection_on(typename, value, capture) {
  1311. var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
  1312. if (arguments.length < 2) {
  1313. var on = this.node().__on;
  1314. if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
  1315. for (i = 0, o = on[j]; i < n; ++i) {
  1316. if ((t = typenames[i]).type === o.type && t.name === o.name) {
  1317. return o.value;
  1318. }
  1319. }
  1320. }
  1321. return;
  1322. }
  1323. on = value ? onAdd : onRemove;
  1324. if (capture == null) capture = false;
  1325. for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
  1326. return this;
  1327. }
  1328. function customEvent(event1, listener, that, args) {
  1329. var event0 = exports.event;
  1330. event1.sourceEvent = exports.event;
  1331. exports.event = event1;
  1332. try {
  1333. return listener.apply(that, args);
  1334. } finally {
  1335. exports.event = event0;
  1336. }
  1337. }
  1338. function dispatchEvent(node, type, params) {
  1339. var window = defaultView(node),
  1340. event = window.CustomEvent;
  1341. if (typeof event === "function") {
  1342. event = new event(type, params);
  1343. } else {
  1344. event = window.document.createEvent("Event");
  1345. if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
  1346. else event.initEvent(type, false, false);
  1347. }
  1348. node.dispatchEvent(event);
  1349. }
  1350. function dispatchConstant(type, params) {
  1351. return function() {
  1352. return dispatchEvent(this, type, params);
  1353. };
  1354. }
  1355. function dispatchFunction(type, params) {
  1356. return function() {
  1357. return dispatchEvent(this, type, params.apply(this, arguments));
  1358. };
  1359. }
  1360. function selection_dispatch(type, params) {
  1361. return this.each((typeof params === "function"
  1362. ? dispatchFunction
  1363. : dispatchConstant)(type, params));
  1364. }
  1365. var root = [null];
  1366. function Selection(groups, parents) {
  1367. this._groups = groups;
  1368. this._parents = parents;
  1369. }
  1370. function selection() {
  1371. return new Selection([[document.documentElement]], root);
  1372. }
  1373. Selection.prototype = selection.prototype = {
  1374. constructor: Selection,
  1375. select: selection_select,
  1376. selectAll: selection_selectAll,
  1377. filter: selection_filter,
  1378. data: selection_data,
  1379. enter: selection_enter,
  1380. exit: selection_exit,
  1381. join: selection_join,
  1382. merge: selection_merge,
  1383. order: selection_order,
  1384. sort: selection_sort,
  1385. call: selection_call,
  1386. nodes: selection_nodes,
  1387. node: selection_node,
  1388. size: selection_size,
  1389. empty: selection_empty,
  1390. each: selection_each,
  1391. attr: selection_attr,
  1392. style: selection_style,
  1393. property: selection_property,
  1394. classed: selection_classed,
  1395. text: selection_text,
  1396. html: selection_html,
  1397. raise: selection_raise,
  1398. lower: selection_lower,
  1399. append: selection_append,
  1400. insert: selection_insert,
  1401. remove: selection_remove,
  1402. clone: selection_clone,
  1403. datum: selection_datum,
  1404. on: selection_on,
  1405. dispatch: selection_dispatch
  1406. };
  1407. function select(selector) {
  1408. return typeof selector === "string"
  1409. ? new Selection([[document.querySelector(selector)]], [document.documentElement])
  1410. : new Selection([[selector]], root);
  1411. }
  1412. function create(name) {
  1413. return select(creator(name).call(document.documentElement));
  1414. }
  1415. var nextId = 0;
  1416. function local() {
  1417. return new Local;
  1418. }
  1419. function Local() {
  1420. this._ = "@" + (++nextId).toString(36);
  1421. }
  1422. Local.prototype = local.prototype = {
  1423. constructor: Local,
  1424. get: function(node) {
  1425. var id = this._;
  1426. while (!(id in node)) if (!(node = node.parentNode)) return;
  1427. return node[id];
  1428. },
  1429. set: function(node, value) {
  1430. return node[this._] = value;
  1431. },
  1432. remove: function(node) {
  1433. return this._ in node && delete node[this._];
  1434. },
  1435. toString: function() {
  1436. return this._;
  1437. }
  1438. };
  1439. function sourceEvent() {
  1440. var current = exports.event, source;
  1441. while (source = current.sourceEvent) current = source;
  1442. return current;
  1443. }
  1444. function point(node, event) {
  1445. var svg = node.ownerSVGElement || node;
  1446. if (svg.createSVGPoint) {
  1447. var point = svg.createSVGPoint();
  1448. point.x = event.clientX, point.y = event.clientY;
  1449. point = point.matrixTransform(node.getScreenCTM().inverse());
  1450. return [point.x, point.y];
  1451. }
  1452. var rect = node.getBoundingClientRect();
  1453. return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
  1454. }
  1455. function mouse(node) {
  1456. var event = sourceEvent();
  1457. if (event.changedTouches) event = event.changedTouches[0];
  1458. return point(node, event);
  1459. }
  1460. function selectAll(selector) {
  1461. return typeof selector === "string"
  1462. ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
  1463. : new Selection([selector == null ? [] : selector], root);
  1464. }
  1465. function touch(node, touches, identifier) {
  1466. if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
  1467. for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
  1468. if ((touch = touches[i]).identifier === identifier) {
  1469. return point(node, touch);
  1470. }
  1471. }
  1472. return null;
  1473. }
  1474. function touches(node, touches) {
  1475. if (touches == null) touches = sourceEvent().touches;
  1476. for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
  1477. points[i] = point(node, touches[i]);
  1478. }
  1479. return points;
  1480. }
  1481. function nopropagation() {
  1482. exports.event.stopImmediatePropagation();
  1483. }
  1484. function noevent() {
  1485. exports.event.preventDefault();
  1486. exports.event.stopImmediatePropagation();
  1487. }
  1488. function dragDisable(view) {
  1489. var root = view.document.documentElement,
  1490. selection = select(view).on("dragstart.drag", noevent, true);
  1491. if ("onselectstart" in root) {
  1492. selection.on("selectstart.drag", noevent, true);
  1493. } else {
  1494. root.__noselect = root.style.MozUserSelect;
  1495. root.style.MozUserSelect = "none";
  1496. }
  1497. }
  1498. function yesdrag(view, noclick) {
  1499. var root = view.document.documentElement,
  1500. selection = select(view).on("dragstart.drag", null);
  1501. if (noclick) {
  1502. selection.on("click.drag", noevent, true);
  1503. setTimeout(function() { selection.on("click.drag", null); }, 0);
  1504. }
  1505. if ("onselectstart" in root) {
  1506. selection.on("selectstart.drag", null);
  1507. } else {
  1508. root.style.MozUserSelect = root.__noselect;
  1509. delete root.__noselect;
  1510. }
  1511. }
  1512. function constant$2(x) {
  1513. return function() {
  1514. return x;
  1515. };
  1516. }
  1517. function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
  1518. this.target = target;
  1519. this.type = type;
  1520. this.subject = subject;
  1521. this.identifier = id;
  1522. this.active = active;
  1523. this.x = x;
  1524. this.y = y;
  1525. this.dx = dx;
  1526. this.dy = dy;
  1527. this._ = dispatch;
  1528. }
  1529. DragEvent.prototype.on = function() {
  1530. var value = this._.on.apply(this._, arguments);
  1531. return value === this._ ? this : value;
  1532. };
  1533. // Ignore right-click, since that should open the context menu.
  1534. function defaultFilter() {
  1535. return !exports.event.ctrlKey && !exports.event.button;
  1536. }
  1537. function defaultContainer() {
  1538. return this.parentNode;
  1539. }
  1540. function defaultSubject(d) {
  1541. return d == null ? {x: exports.event.x, y: exports.event.y} : d;
  1542. }
  1543. function defaultTouchable() {
  1544. return navigator.maxTouchPoints || ("ontouchstart" in this);
  1545. }
  1546. function drag() {
  1547. var filter = defaultFilter,
  1548. container = defaultContainer,
  1549. subject = defaultSubject,
  1550. touchable = defaultTouchable,
  1551. gestures = {},
  1552. listeners = dispatch("start", "drag", "end"),
  1553. active = 0,
  1554. mousedownx,
  1555. mousedowny,
  1556. mousemoving,
  1557. touchending,
  1558. clickDistance2 = 0;
  1559. function drag(selection) {
  1560. selection
  1561. .on("mousedown.drag", mousedowned)
  1562. .filter(touchable)
  1563. .on("touchstart.drag", touchstarted)
  1564. .on("touchmove.drag", touchmoved)
  1565. .on("touchend.drag touchcancel.drag", touchended)
  1566. .style("touch-action", "none")
  1567. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  1568. }
  1569. function mousedowned() {
  1570. if (touchending || !filter.apply(this, arguments)) return;
  1571. var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
  1572. if (!gesture) return;
  1573. select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
  1574. dragDisable(exports.event.view);
  1575. nopropagation();
  1576. mousemoving = false;
  1577. mousedownx = exports.event.clientX;
  1578. mousedowny = exports.event.clientY;
  1579. gesture("start");
  1580. }
  1581. function mousemoved() {
  1582. noevent();
  1583. if (!mousemoving) {
  1584. var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
  1585. mousemoving = dx * dx + dy * dy > clickDistance2;
  1586. }
  1587. gestures.mouse("drag");
  1588. }
  1589. function mouseupped() {
  1590. select(exports.event.view).on("mousemove.drag mouseup.drag", null);
  1591. yesdrag(exports.event.view, mousemoving);
  1592. noevent();
  1593. gestures.mouse("end");
  1594. }
  1595. function touchstarted() {
  1596. if (!filter.apply(this, arguments)) return;
  1597. var touches = exports.event.changedTouches,
  1598. c = container.apply(this, arguments),
  1599. n = touches.length, i, gesture;
  1600. for (i = 0; i < n; ++i) {
  1601. if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
  1602. nopropagation();
  1603. gesture("start");
  1604. }
  1605. }
  1606. }
  1607. function touchmoved() {
  1608. var touches = exports.event.changedTouches,
  1609. n = touches.length, i, gesture;
  1610. for (i = 0; i < n; ++i) {
  1611. if (gesture = gestures[touches[i].identifier]) {
  1612. noevent();
  1613. gesture("drag");
  1614. }
  1615. }
  1616. }
  1617. function touchended() {
  1618. var touches = exports.event.changedTouches,
  1619. n = touches.length, i, gesture;
  1620. if (touchending) clearTimeout(touchending);
  1621. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  1622. for (i = 0; i < n; ++i) {
  1623. if (gesture = gestures[touches[i].identifier]) {
  1624. nopropagation();
  1625. gesture("end");
  1626. }
  1627. }
  1628. }
  1629. function beforestart(id, container, point, that, args) {
  1630. var p = point(container, id), s, dx, dy,
  1631. sublisteners = listeners.copy();
  1632. if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
  1633. if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
  1634. dx = s.x - p[0] || 0;
  1635. dy = s.y - p[1] || 0;
  1636. return true;
  1637. })) return;
  1638. return function gesture(type) {
  1639. var p0 = p, n;
  1640. switch (type) {
  1641. case "start": gestures[id] = gesture, n = active++; break;
  1642. case "end": delete gestures[id], --active; // nobreak
  1643. case "drag": p = point(container, id), n = active; break;
  1644. }
  1645. 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]);
  1646. };
  1647. }
  1648. drag.filter = function(_) {
  1649. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
  1650. };
  1651. drag.container = function(_) {
  1652. return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
  1653. };
  1654. drag.subject = function(_) {
  1655. return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
  1656. };
  1657. drag.touchable = function(_) {
  1658. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
  1659. };
  1660. drag.on = function() {
  1661. var value = listeners.on.apply(listeners, arguments);
  1662. return value === listeners ? drag : value;
  1663. };
  1664. drag.clickDistance = function(_) {
  1665. return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
  1666. };
  1667. return drag;
  1668. }
  1669. function define(constructor, factory, prototype) {
  1670. constructor.prototype = factory.prototype = prototype;
  1671. prototype.constructor = constructor;
  1672. }
  1673. function extend(parent, definition) {
  1674. var prototype = Object.create(parent.prototype);
  1675. for (var key in definition) prototype[key] = definition[key];
  1676. return prototype;
  1677. }
  1678. function Color() {}
  1679. var darker = 0.7;
  1680. var brighter = 1 / darker;
  1681. var reI = "\\s*([+-]?\\d+)\\s*",
  1682. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  1683. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  1684. reHex3 = /^#([0-9a-f]{3})$/,
  1685. reHex6 = /^#([0-9a-f]{6})$/,
  1686. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  1687. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  1688. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  1689. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  1690. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  1691. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  1692. var named = {
  1693. aliceblue: 0xf0f8ff,
  1694. antiquewhite: 0xfaebd7,
  1695. aqua: 0x00ffff,
  1696. aquamarine: 0x7fffd4,
  1697. azure: 0xf0ffff,
  1698. beige: 0xf5f5dc,
  1699. bisque: 0xffe4c4,
  1700. black: 0x000000,
  1701. blanchedalmond: 0xffebcd,
  1702. blue: 0x0000ff,
  1703. blueviolet: 0x8a2be2,
  1704. brown: 0xa52a2a,
  1705. burlywood: 0xdeb887,
  1706. cadetblue: 0x5f9ea0,
  1707. chartreuse: 0x7fff00,
  1708. chocolate: 0xd2691e,
  1709. coral: 0xff7f50,
  1710. cornflowerblue: 0x6495ed,
  1711. cornsilk: 0xfff8dc,
  1712. crimson: 0xdc143c,
  1713. cyan: 0x00ffff,
  1714. darkblue: 0x00008b,
  1715. darkcyan: 0x008b8b,
  1716. darkgoldenrod: 0xb8860b,
  1717. darkgray: 0xa9a9a9,
  1718. darkgreen: 0x006400,
  1719. darkgrey: 0xa9a9a9,
  1720. darkkhaki: 0xbdb76b,
  1721. darkmagenta: 0x8b008b,
  1722. darkolivegreen: 0x556b2f,
  1723. darkorange: 0xff8c00,
  1724. darkorchid: 0x9932cc,
  1725. darkred: 0x8b0000,
  1726. darksalmon: 0xe9967a,
  1727. darkseagreen: 0x8fbc8f,
  1728. darkslateblue: 0x483d8b,
  1729. darkslategray: 0x2f4f4f,
  1730. darkslategrey: 0x2f4f4f,
  1731. darkturquoise: 0x00ced1,
  1732. darkviolet: 0x9400d3,
  1733. deeppink: 0xff1493,
  1734. deepskyblue: 0x00bfff,
  1735. dimgray: 0x696969,
  1736. dimgrey: 0x696969,
  1737. dodgerblue: 0x1e90ff,
  1738. firebrick: 0xb22222,
  1739. floralwhite: 0xfffaf0,
  1740. forestgreen: 0x228b22,
  1741. fuchsia: 0xff00ff,
  1742. gainsboro: 0xdcdcdc,
  1743. ghostwhite: 0xf8f8ff,
  1744. gold: 0xffd700,
  1745. goldenrod: 0xdaa520,
  1746. gray: 0x808080,
  1747. green: 0x008000,
  1748. greenyellow: 0xadff2f,
  1749. grey: 0x808080,
  1750. honeydew: 0xf0fff0,
  1751. hotpink: 0xff69b4,
  1752. indianred: 0xcd5c5c,
  1753. indigo: 0x4b0082,
  1754. ivory: 0xfffff0,
  1755. khaki: 0xf0e68c,
  1756. lavender: 0xe6e6fa,
  1757. lavenderblush: 0xfff0f5,
  1758. lawngreen: 0x7cfc00,
  1759. lemonchiffon: 0xfffacd,
  1760. lightblue: 0xadd8e6,
  1761. lightcoral: 0xf08080,
  1762. lightcyan: 0xe0ffff,
  1763. lightgoldenrodyellow: 0xfafad2,
  1764. lightgray: 0xd3d3d3,
  1765. lightgreen: 0x90ee90,
  1766. lightgrey: 0xd3d3d3,
  1767. lightpink: 0xffb6c1,
  1768. lightsalmon: 0xffa07a,
  1769. lightseagreen: 0x20b2aa,
  1770. lightskyblue: 0x87cefa,
  1771. lightslategray: 0x778899,
  1772. lightslategrey: 0x778899,
  1773. lightsteelblue: 0xb0c4de,
  1774. lightyellow: 0xffffe0,
  1775. lime: 0x00ff00,
  1776. limegreen: 0x32cd32,
  1777. linen: 0xfaf0e6,
  1778. magenta: 0xff00ff,
  1779. maroon: 0x800000,
  1780. mediumaquamarine: 0x66cdaa,
  1781. mediumblue: 0x0000cd,
  1782. mediumorchid: 0xba55d3,
  1783. mediumpurple: 0x9370db,
  1784. mediumseagreen: 0x3cb371,
  1785. mediumslateblue: 0x7b68ee,
  1786. mediumspringgreen: 0x00fa9a,
  1787. mediumturquoise: 0x48d1cc,
  1788. mediumvioletred: 0xc71585,
  1789. midnightblue: 0x191970,
  1790. mintcream: 0xf5fffa,
  1791. mistyrose: 0xffe4e1,
  1792. moccasin: 0xffe4b5,
  1793. navajowhite: 0xffdead,
  1794. navy: 0x000080,
  1795. oldlace: 0xfdf5e6,
  1796. olive: 0x808000,
  1797. olivedrab: 0x6b8e23,
  1798. orange: 0xffa500,
  1799. orangered: 0xff4500,
  1800. orchid: 0xda70d6,
  1801. palegoldenrod: 0xeee8aa,
  1802. palegreen: 0x98fb98,
  1803. paleturquoise: 0xafeeee,
  1804. palevioletred: 0xdb7093,
  1805. papayawhip: 0xffefd5,
  1806. peachpuff: 0xffdab9,
  1807. peru: 0xcd853f,
  1808. pink: 0xffc0cb,
  1809. plum: 0xdda0dd,
  1810. powderblue: 0xb0e0e6,
  1811. purple: 0x800080,
  1812. rebeccapurple: 0x663399,
  1813. red: 0xff0000,
  1814. rosybrown: 0xbc8f8f,
  1815. royalblue: 0x4169e1,
  1816. saddlebrown: 0x8b4513,
  1817. salmon: 0xfa8072,
  1818. sandybrown: 0xf4a460,
  1819. seagreen: 0x2e8b57,
  1820. seashell: 0xfff5ee,
  1821. sienna: 0xa0522d,
  1822. silver: 0xc0c0c0,
  1823. skyblue: 0x87ceeb,
  1824. slateblue: 0x6a5acd,
  1825. slategray: 0x708090,
  1826. slategrey: 0x708090,
  1827. snow: 0xfffafa,
  1828. springgreen: 0x00ff7f,
  1829. steelblue: 0x4682b4,
  1830. tan: 0xd2b48c,
  1831. teal: 0x008080,
  1832. thistle: 0xd8bfd8,
  1833. tomato: 0xff6347,
  1834. turquoise: 0x40e0d0,
  1835. violet: 0xee82ee,
  1836. wheat: 0xf5deb3,
  1837. white: 0xffffff,
  1838. whitesmoke: 0xf5f5f5,
  1839. yellow: 0xffff00,
  1840. yellowgreen: 0x9acd32
  1841. };
  1842. define(Color, color, {
  1843. copy: function(channels) {
  1844. return Object.assign(new this.constructor, this, channels);
  1845. },
  1846. displayable: function() {
  1847. return this.rgb().displayable();
  1848. },
  1849. hex: color_formatHex, // Deprecated! Use color.formatHex.
  1850. formatHex: color_formatHex,
  1851. formatHsl: color_formatHsl,
  1852. formatRgb: color_formatRgb,
  1853. toString: color_formatRgb
  1854. });
  1855. function color_formatHex() {
  1856. return this.rgb().formatHex();
  1857. }
  1858. function color_formatHsl() {
  1859. return hslConvert(this).formatHsl();
  1860. }
  1861. function color_formatRgb() {
  1862. return this.rgb().formatRgb();
  1863. }
  1864. function color(format) {
  1865. var m;
  1866. format = (format + "").trim().toLowerCase();
  1867. 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
  1868. : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
  1869. : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  1870. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  1871. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  1872. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  1873. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  1874. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  1875. : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
  1876. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
  1877. : null;
  1878. }
  1879. function rgbn(n) {
  1880. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  1881. }
  1882. function rgba(r, g, b, a) {
  1883. if (a <= 0) r = g = b = NaN;
  1884. return new Rgb(r, g, b, a);
  1885. }
  1886. function rgbConvert(o) {
  1887. if (!(o instanceof Color)) o = color(o);
  1888. if (!o) return new Rgb;
  1889. o = o.rgb();
  1890. return new Rgb(o.r, o.g, o.b, o.opacity);
  1891. }
  1892. function rgb(r, g, b, opacity) {
  1893. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  1894. }
  1895. function Rgb(r, g, b, opacity) {
  1896. this.r = +r;
  1897. this.g = +g;
  1898. this.b = +b;
  1899. this.opacity = +opacity;
  1900. }
  1901. define(Rgb, rgb, extend(Color, {
  1902. brighter: function(k) {
  1903. k = k == null ? brighter : Math.pow(brighter, k);
  1904. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1905. },
  1906. darker: function(k) {
  1907. k = k == null ? darker : Math.pow(darker, k);
  1908. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  1909. },
  1910. rgb: function() {
  1911. return this;
  1912. },
  1913. displayable: function() {
  1914. return (-0.5 <= this.r && this.r < 255.5)
  1915. && (-0.5 <= this.g && this.g < 255.5)
  1916. && (-0.5 <= this.b && this.b < 255.5)
  1917. && (0 <= this.opacity && this.opacity <= 1);
  1918. },
  1919. hex: rgb_formatHex, // Deprecated! Use color.formatHex.
  1920. formatHex: rgb_formatHex,
  1921. formatRgb: rgb_formatRgb,
  1922. toString: rgb_formatRgb
  1923. }));
  1924. function rgb_formatHex() {
  1925. return "#" + hex(this.r) + hex(this.g) + hex(this.b);
  1926. }
  1927. function rgb_formatRgb() {
  1928. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  1929. return (a === 1 ? "rgb(" : "rgba(")
  1930. + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
  1931. + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
  1932. + Math.max(0, Math.min(255, Math.round(this.b) || 0))
  1933. + (a === 1 ? ")" : ", " + a + ")");
  1934. }
  1935. function hex(value) {
  1936. value = Math.max(0, Math.min(255, Math.round(value) || 0));
  1937. return (value < 16 ? "0" : "") + value.toString(16);
  1938. }
  1939. function hsla(h, s, l, a) {
  1940. if (a <= 0) h = s = l = NaN;
  1941. else if (l <= 0 || l >= 1) h = s = NaN;
  1942. else if (s <= 0) h = NaN;
  1943. return new Hsl(h, s, l, a);
  1944. }
  1945. function hslConvert(o) {
  1946. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  1947. if (!(o instanceof Color)) o = color(o);
  1948. if (!o) return new Hsl;
  1949. if (o instanceof Hsl) return o;
  1950. o = o.rgb();
  1951. var r = o.r / 255,
  1952. g = o.g / 255,
  1953. b = o.b / 255,
  1954. min = Math.min(r, g, b),
  1955. max = Math.max(r, g, b),
  1956. h = NaN,
  1957. s = max - min,
  1958. l = (max + min) / 2;
  1959. if (s) {
  1960. if (r === max) h = (g - b) / s + (g < b) * 6;
  1961. else if (g === max) h = (b - r) / s + 2;
  1962. else h = (r - g) / s + 4;
  1963. s /= l < 0.5 ? max + min : 2 - max - min;
  1964. h *= 60;
  1965. } else {
  1966. s = l > 0 && l < 1 ? 0 : h;
  1967. }
  1968. return new Hsl(h, s, l, o.opacity);
  1969. }
  1970. function hsl(h, s, l, opacity) {
  1971. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  1972. }
  1973. function Hsl(h, s, l, opacity) {
  1974. this.h = +h;
  1975. this.s = +s;
  1976. this.l = +l;
  1977. this.opacity = +opacity;
  1978. }
  1979. define(Hsl, hsl, extend(Color, {
  1980. brighter: function(k) {
  1981. k = k == null ? brighter : Math.pow(brighter, k);
  1982. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1983. },
  1984. darker: function(k) {
  1985. k = k == null ? darker : Math.pow(darker, k);
  1986. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  1987. },
  1988. rgb: function() {
  1989. var h = this.h % 360 + (this.h < 0) * 360,
  1990. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  1991. l = this.l,
  1992. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  1993. m1 = 2 * l - m2;
  1994. return new Rgb(
  1995. hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
  1996. hsl2rgb(h, m1, m2),
  1997. hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
  1998. this.opacity
  1999. );
  2000. },
  2001. displayable: function() {
  2002. return (0 <= this.s && this.s <= 1 || isNaN(this.s))
  2003. && (0 <= this.l && this.l <= 1)
  2004. && (0 <= this.opacity && this.opacity <= 1);
  2005. },
  2006. formatHsl: function() {
  2007. var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  2008. return (a === 1 ? "hsl(" : "hsla(")
  2009. + (this.h || 0) + ", "
  2010. + (this.s || 0) * 100 + "%, "
  2011. + (this.l || 0) * 100 + "%"
  2012. + (a === 1 ? ")" : ", " + a + ")");
  2013. }
  2014. }));
  2015. /* From FvD 13.37, CSS Color Module Level 3 */
  2016. function hsl2rgb(h, m1, m2) {
  2017. return (h < 60 ? m1 + (m2 - m1) * h / 60
  2018. : h < 180 ? m2
  2019. : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
  2020. : m1) * 255;
  2021. }
  2022. var deg2rad = Math.PI / 180;
  2023. var rad2deg = 180 / Math.PI;
  2024. // https://observablehq.com/@mbostock/lab-and-rgb
  2025. var K = 18,
  2026. Xn = 0.96422,
  2027. Yn = 1,
  2028. Zn = 0.82521,
  2029. t0 = 4 / 29,
  2030. t1 = 6 / 29,
  2031. t2 = 3 * t1 * t1,
  2032. t3 = t1 * t1 * t1;
  2033. function labConvert(o) {
  2034. if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
  2035. if (o instanceof Hcl) return hcl2lab(o);
  2036. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2037. var r = rgb2lrgb(o.r),
  2038. g = rgb2lrgb(o.g),
  2039. b = rgb2lrgb(o.b),
  2040. y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
  2041. if (r === g && g === b) x = z = y; else {
  2042. x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
  2043. z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
  2044. }
  2045. return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
  2046. }
  2047. function gray(l, opacity) {
  2048. return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
  2049. }
  2050. function lab(l, a, b, opacity) {
  2051. return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
  2052. }
  2053. function Lab(l, a, b, opacity) {
  2054. this.l = +l;
  2055. this.a = +a;
  2056. this.b = +b;
  2057. this.opacity = +opacity;
  2058. }
  2059. define(Lab, lab, extend(Color, {
  2060. brighter: function(k) {
  2061. return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2062. },
  2063. darker: function(k) {
  2064. return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
  2065. },
  2066. rgb: function() {
  2067. var y = (this.l + 16) / 116,
  2068. x = isNaN(this.a) ? y : y + this.a / 500,
  2069. z = isNaN(this.b) ? y : y - this.b / 200;
  2070. x = Xn * lab2xyz(x);
  2071. y = Yn * lab2xyz(y);
  2072. z = Zn * lab2xyz(z);
  2073. return new Rgb(
  2074. lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
  2075. lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
  2076. lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
  2077. this.opacity
  2078. );
  2079. }
  2080. }));
  2081. function xyz2lab(t) {
  2082. return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
  2083. }
  2084. function lab2xyz(t) {
  2085. return t > t1 ? t * t * t : t2 * (t - t0);
  2086. }
  2087. function lrgb2rgb(x) {
  2088. return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
  2089. }
  2090. function rgb2lrgb(x) {
  2091. return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
  2092. }
  2093. function hclConvert(o) {
  2094. if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
  2095. if (!(o instanceof Lab)) o = labConvert(o);
  2096. if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
  2097. var h = Math.atan2(o.b, o.a) * rad2deg;
  2098. return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
  2099. }
  2100. function lch(l, c, h, opacity) {
  2101. return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2102. }
  2103. function hcl(h, c, l, opacity) {
  2104. return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
  2105. }
  2106. function Hcl(h, c, l, opacity) {
  2107. this.h = +h;
  2108. this.c = +c;
  2109. this.l = +l;
  2110. this.opacity = +opacity;
  2111. }
  2112. function hcl2lab(o) {
  2113. if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
  2114. var h = o.h * deg2rad;
  2115. return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
  2116. }
  2117. define(Hcl, hcl, extend(Color, {
  2118. brighter: function(k) {
  2119. return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
  2120. },
  2121. darker: function(k) {
  2122. return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
  2123. },
  2124. rgb: function() {
  2125. return hcl2lab(this).rgb();
  2126. }
  2127. }));
  2128. var A = -0.14861,
  2129. B = +1.78277,
  2130. C = -0.29227,
  2131. D = -0.90649,
  2132. E = +1.97294,
  2133. ED = E * D,
  2134. EB = E * B,
  2135. BC_DA = B * C - D * A;
  2136. function cubehelixConvert(o) {
  2137. if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
  2138. if (!(o instanceof Rgb)) o = rgbConvert(o);
  2139. var r = o.r / 255,
  2140. g = o.g / 255,
  2141. b = o.b / 255,
  2142. l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
  2143. bl = b - l,
  2144. k = (E * (g - l) - C * bl) / D,
  2145. s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
  2146. h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
  2147. return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
  2148. }
  2149. function cubehelix(h, s, l, opacity) {
  2150. return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
  2151. }
  2152. function Cubehelix(h, s, l, opacity) {
  2153. this.h = +h;
  2154. this.s = +s;
  2155. this.l = +l;
  2156. this.opacity = +opacity;
  2157. }
  2158. define(Cubehelix, cubehelix, extend(Color, {
  2159. brighter: function(k) {
  2160. k = k == null ? brighter : Math.pow(brighter, k);
  2161. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2162. },
  2163. darker: function(k) {
  2164. k = k == null ? darker : Math.pow(darker, k);
  2165. return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
  2166. },
  2167. rgb: function() {
  2168. var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
  2169. l = +this.l,
  2170. a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
  2171. cosh = Math.cos(h),
  2172. sinh = Math.sin(h);
  2173. return new Rgb(
  2174. 255 * (l + a * (A * cosh + B * sinh)),
  2175. 255 * (l + a * (C * cosh + D * sinh)),
  2176. 255 * (l + a * (E * cosh)),
  2177. this.opacity
  2178. );
  2179. }
  2180. }));
  2181. function basis(t1, v0, v1, v2, v3) {
  2182. var t2 = t1 * t1, t3 = t2 * t1;
  2183. return ((1 - 3 * t1 + 3 * t2 - t3) * v0
  2184. + (4 - 6 * t2 + 3 * t3) * v1
  2185. + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
  2186. + t3 * v3) / 6;
  2187. }
  2188. function basis$1(values) {
  2189. var n = values.length - 1;
  2190. return function(t) {
  2191. var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
  2192. v1 = values[i],
  2193. v2 = values[i + 1],
  2194. v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
  2195. v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
  2196. return basis((t - i / n) * n, v0, v1, v2, v3);
  2197. };
  2198. }
  2199. function basisClosed(values) {
  2200. var n = values.length;
  2201. return function(t) {
  2202. var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
  2203. v0 = values[(i + n - 1) % n],
  2204. v1 = values[i % n],
  2205. v2 = values[(i + 1) % n],
  2206. v3 = values[(i + 2) % n];
  2207. return basis((t - i / n) * n, v0, v1, v2, v3);
  2208. };
  2209. }
  2210. function constant$3(x) {
  2211. return function() {
  2212. return x;
  2213. };
  2214. }
  2215. function linear(a, d) {
  2216. return function(t) {
  2217. return a + t * d;
  2218. };
  2219. }
  2220. function exponential(a, b, y) {
  2221. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
  2222. return Math.pow(a + t * b, y);
  2223. };
  2224. }
  2225. function hue(a, b) {
  2226. var d = b - a;
  2227. return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
  2228. }
  2229. function gamma(y) {
  2230. return (y = +y) === 1 ? nogamma : function(a, b) {
  2231. return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
  2232. };
  2233. }
  2234. function nogamma(a, b) {
  2235. var d = b - a;
  2236. return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
  2237. }
  2238. var interpolateRgb = (function rgbGamma(y) {
  2239. var color = gamma(y);
  2240. function rgb$1(start, end) {
  2241. var r = color((start = rgb(start)).r, (end = rgb(end)).r),
  2242. g = color(start.g, end.g),
  2243. b = color(start.b, end.b),
  2244. opacity = nogamma(start.opacity, end.opacity);
  2245. return function(t) {
  2246. start.r = r(t);
  2247. start.g = g(t);
  2248. start.b = b(t);
  2249. start.opacity = opacity(t);
  2250. return start + "";
  2251. };
  2252. }
  2253. rgb$1.gamma = rgbGamma;
  2254. return rgb$1;
  2255. })(1);
  2256. function rgbSpline(spline) {
  2257. return function(colors) {
  2258. var n = colors.length,
  2259. r = new Array(n),
  2260. g = new Array(n),
  2261. b = new Array(n),
  2262. i, color;
  2263. for (i = 0; i < n; ++i) {
  2264. color = rgb(colors[i]);
  2265. r[i] = color.r || 0;
  2266. g[i] = color.g || 0;
  2267. b[i] = color.b || 0;
  2268. }
  2269. r = spline(r);
  2270. g = spline(g);
  2271. b = spline(b);
  2272. color.opacity = 1;
  2273. return function(t) {
  2274. color.r = r(t);
  2275. color.g = g(t);
  2276. color.b = b(t);
  2277. return color + "";
  2278. };
  2279. };
  2280. }
  2281. var rgbBasis = rgbSpline(basis$1);
  2282. var rgbBasisClosed = rgbSpline(basisClosed);
  2283. function array$1(a, b) {
  2284. var nb = b ? b.length : 0,
  2285. na = a ? Math.min(nb, a.length) : 0,
  2286. x = new Array(na),
  2287. c = new Array(nb),
  2288. i;
  2289. for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
  2290. for (; i < nb; ++i) c[i] = b[i];
  2291. return function(t) {
  2292. for (i = 0; i < na; ++i) c[i] = x[i](t);
  2293. return c;
  2294. };
  2295. }
  2296. function date(a, b) {
  2297. var d = new Date;
  2298. return a = +a, b -= a, function(t) {
  2299. return d.setTime(a + b * t), d;
  2300. };
  2301. }
  2302. function interpolateNumber(a, b) {
  2303. return a = +a, b -= a, function(t) {
  2304. return a + b * t;
  2305. };
  2306. }
  2307. function object(a, b) {
  2308. var i = {},
  2309. c = {},
  2310. k;
  2311. if (a === null || typeof a !== "object") a = {};
  2312. if (b === null || typeof b !== "object") b = {};
  2313. for (k in b) {
  2314. if (k in a) {
  2315. i[k] = interpolateValue(a[k], b[k]);
  2316. } else {
  2317. c[k] = b[k];
  2318. }
  2319. }
  2320. return function(t) {
  2321. for (k in i) c[k] = i[k](t);
  2322. return c;
  2323. };
  2324. }
  2325. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  2326. reB = new RegExp(reA.source, "g");
  2327. function zero(b) {
  2328. return function() {
  2329. return b;
  2330. };
  2331. }
  2332. function one(b) {
  2333. return function(t) {
  2334. return b(t) + "";
  2335. };
  2336. }
  2337. function interpolateString(a, b) {
  2338. var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
  2339. am, // current match in a
  2340. bm, // current match in b
  2341. bs, // string preceding current number in b, if any
  2342. i = -1, // index in s
  2343. s = [], // string constants and placeholders
  2344. q = []; // number interpolators
  2345. // Coerce inputs to strings.
  2346. a = a + "", b = b + "";
  2347. // Interpolate pairs of numbers in a & b.
  2348. while ((am = reA.exec(a))
  2349. && (bm = reB.exec(b))) {
  2350. if ((bs = bm.index) > bi) { // a string precedes the next number in b
  2351. bs = b.slice(bi, bs);
  2352. if (s[i]) s[i] += bs; // coalesce with previous string
  2353. else s[++i] = bs;
  2354. }
  2355. if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
  2356. if (s[i]) s[i] += bm; // coalesce with previous string
  2357. else s[++i] = bm;
  2358. } else { // interpolate non-matching numbers
  2359. s[++i] = null;
  2360. q.push({i: i, x: interpolateNumber(am, bm)});
  2361. }
  2362. bi = reB.lastIndex;
  2363. }
  2364. // Add remains of b.
  2365. if (bi < b.length) {
  2366. bs = b.slice(bi);
  2367. if (s[i]) s[i] += bs; // coalesce with previous string
  2368. else s[++i] = bs;
  2369. }
  2370. // Special optimization for only a single match.
  2371. // Otherwise, interpolate each of the numbers and rejoin the string.
  2372. return s.length < 2 ? (q[0]
  2373. ? one(q[0].x)
  2374. : zero(b))
  2375. : (b = q.length, function(t) {
  2376. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  2377. return s.join("");
  2378. });
  2379. }
  2380. function interpolateValue(a, b) {
  2381. var t = typeof b, c;
  2382. return b == null || t === "boolean" ? constant$3(b)
  2383. : (t === "number" ? interpolateNumber
  2384. : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
  2385. : b instanceof color ? interpolateRgb
  2386. : b instanceof Date ? date
  2387. : Array.isArray(b) ? array$1
  2388. : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
  2389. : interpolateNumber)(a, b);
  2390. }
  2391. function discrete(range) {
  2392. var n = range.length;
  2393. return function(t) {
  2394. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  2395. };
  2396. }
  2397. function hue$1(a, b) {
  2398. var i = hue(+a, +b);
  2399. return function(t) {
  2400. var x = i(t);
  2401. return x - 360 * Math.floor(x / 360);
  2402. };
  2403. }
  2404. function interpolateRound(a, b) {
  2405. return a = +a, b -= a, function(t) {
  2406. return Math.round(a + b * t);
  2407. };
  2408. }
  2409. var degrees = 180 / Math.PI;
  2410. var identity$2 = {
  2411. translateX: 0,
  2412. translateY: 0,
  2413. rotate: 0,
  2414. skewX: 0,
  2415. scaleX: 1,
  2416. scaleY: 1
  2417. };
  2418. function decompose(a, b, c, d, e, f) {
  2419. var scaleX, scaleY, skewX;
  2420. if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
  2421. if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
  2422. if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
  2423. if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
  2424. return {
  2425. translateX: e,
  2426. translateY: f,
  2427. rotate: Math.atan2(b, a) * degrees,
  2428. skewX: Math.atan(skewX) * degrees,
  2429. scaleX: scaleX,
  2430. scaleY: scaleY
  2431. };
  2432. }
  2433. var cssNode,
  2434. cssRoot,
  2435. cssView,
  2436. svgNode;
  2437. function parseCss(value) {
  2438. if (value === "none") return identity$2;
  2439. if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
  2440. cssNode.style.transform = value;
  2441. value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
  2442. cssRoot.removeChild(cssNode);
  2443. value = value.slice(7, -1).split(",");
  2444. return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
  2445. }
  2446. function parseSvg(value) {
  2447. if (value == null) return identity$2;
  2448. if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
  2449. svgNode.setAttribute("transform", value);
  2450. if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
  2451. value = value.matrix;
  2452. return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
  2453. }
  2454. function interpolateTransform(parse, pxComma, pxParen, degParen) {
  2455. function pop(s) {
  2456. return s.length ? s.pop() + " " : "";
  2457. }
  2458. function translate(xa, ya, xb, yb, s, q) {
  2459. if (xa !== xb || ya !== yb) {
  2460. var i = s.push("translate(", null, pxComma, null, pxParen);
  2461. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2462. } else if (xb || yb) {
  2463. s.push("translate(" + xb + pxComma + yb + pxParen);
  2464. }
  2465. }
  2466. function rotate(a, b, s, q) {
  2467. if (a !== b) {
  2468. if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
  2469. q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2470. } else if (b) {
  2471. s.push(pop(s) + "rotate(" + b + degParen);
  2472. }
  2473. }
  2474. function skewX(a, b, s, q) {
  2475. if (a !== b) {
  2476. q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
  2477. } else if (b) {
  2478. s.push(pop(s) + "skewX(" + b + degParen);
  2479. }
  2480. }
  2481. function scale(xa, ya, xb, yb, s, q) {
  2482. if (xa !== xb || ya !== yb) {
  2483. var i = s.push(pop(s) + "scale(", null, ",", null, ")");
  2484. q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
  2485. } else if (xb !== 1 || yb !== 1) {
  2486. s.push(pop(s) + "scale(" + xb + "," + yb + ")");
  2487. }
  2488. }
  2489. return function(a, b) {
  2490. var s = [], // string constants and placeholders
  2491. q = []; // number interpolators
  2492. a = parse(a), b = parse(b);
  2493. translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
  2494. rotate(a.rotate, b.rotate, s, q);
  2495. skewX(a.skewX, b.skewX, s, q);
  2496. scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
  2497. a = b = null; // gc
  2498. return function(t) {
  2499. var i = -1, n = q.length, o;
  2500. while (++i < n) s[(o = q[i]).i] = o.x(t);
  2501. return s.join("");
  2502. };
  2503. };
  2504. }
  2505. var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
  2506. var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
  2507. var rho = Math.SQRT2,
  2508. rho2 = 2,
  2509. rho4 = 4,
  2510. epsilon2 = 1e-12;
  2511. function cosh(x) {
  2512. return ((x = Math.exp(x)) + 1 / x) / 2;
  2513. }
  2514. function sinh(x) {
  2515. return ((x = Math.exp(x)) - 1 / x) / 2;
  2516. }
  2517. function tanh(x) {
  2518. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2519. }
  2520. // p0 = [ux0, uy0, w0]
  2521. // p1 = [ux1, uy1, w1]
  2522. function interpolateZoom(p0, p1) {
  2523. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
  2524. ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
  2525. dx = ux1 - ux0,
  2526. dy = uy1 - uy0,
  2527. d2 = dx * dx + dy * dy,
  2528. i,
  2529. S;
  2530. // Special case for u0 ≅ u1.
  2531. if (d2 < epsilon2) {
  2532. S = Math.log(w1 / w0) / rho;
  2533. i = function(t) {
  2534. return [
  2535. ux0 + t * dx,
  2536. uy0 + t * dy,
  2537. w0 * Math.exp(rho * t * S)
  2538. ];
  2539. };
  2540. }
  2541. // General case.
  2542. else {
  2543. var d1 = Math.sqrt(d2),
  2544. b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
  2545. b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
  2546. r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
  2547. r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2548. S = (r1 - r0) / rho;
  2549. i = function(t) {
  2550. var s = t * S,
  2551. coshr0 = cosh(r0),
  2552. u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
  2553. return [
  2554. ux0 + u * dx,
  2555. uy0 + u * dy,
  2556. w0 * coshr0 / cosh(rho * s + r0)
  2557. ];
  2558. };
  2559. }
  2560. i.duration = S * 1000;
  2561. return i;
  2562. }
  2563. function hsl$1(hue) {
  2564. return function(start, end) {
  2565. var h = hue((start = hsl(start)).h, (end = hsl(end)).h),
  2566. s = nogamma(start.s, end.s),
  2567. l = nogamma(start.l, end.l),
  2568. opacity = nogamma(start.opacity, end.opacity);
  2569. return function(t) {
  2570. start.h = h(t);
  2571. start.s = s(t);
  2572. start.l = l(t);
  2573. start.opacity = opacity(t);
  2574. return start + "";
  2575. };
  2576. }
  2577. }
  2578. var hsl$2 = hsl$1(hue);
  2579. var hslLong = hsl$1(nogamma);
  2580. function lab$1(start, end) {
  2581. var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
  2582. a = nogamma(start.a, end.a),
  2583. b = nogamma(start.b, end.b),
  2584. opacity = nogamma(start.opacity, end.opacity);
  2585. return function(t) {
  2586. start.l = l(t);
  2587. start.a = a(t);
  2588. start.b = b(t);
  2589. start.opacity = opacity(t);
  2590. return start + "";
  2591. };
  2592. }
  2593. function hcl$1(hue) {
  2594. return function(start, end) {
  2595. var h = hue((start = hcl(start)).h, (end = hcl(end)).h),
  2596. c = nogamma(start.c, end.c),
  2597. l = nogamma(start.l, end.l),
  2598. opacity = nogamma(start.opacity, end.opacity);
  2599. return function(t) {
  2600. start.h = h(t);
  2601. start.c = c(t);
  2602. start.l = l(t);
  2603. start.opacity = opacity(t);
  2604. return start + "";
  2605. };
  2606. }
  2607. }
  2608. var hcl$2 = hcl$1(hue);
  2609. var hclLong = hcl$1(nogamma);
  2610. function cubehelix$1(hue) {
  2611. return (function cubehelixGamma(y) {
  2612. y = +y;
  2613. function cubehelix$1(start, end) {
  2614. var h = hue((start = cubehelix(start)).h, (end = cubehelix(end)).h),
  2615. s = nogamma(start.s, end.s),
  2616. l = nogamma(start.l, end.l),
  2617. opacity = nogamma(start.opacity, end.opacity);
  2618. return function(t) {
  2619. start.h = h(t);
  2620. start.s = s(t);
  2621. start.l = l(Math.pow(t, y));
  2622. start.opacity = opacity(t);
  2623. return start + "";
  2624. };
  2625. }
  2626. cubehelix$1.gamma = cubehelixGamma;
  2627. return cubehelix$1;
  2628. })(1);
  2629. }
  2630. var cubehelix$2 = cubehelix$1(hue);
  2631. var cubehelixLong = cubehelix$1(nogamma);
  2632. function piecewise(interpolate, values) {
  2633. var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
  2634. while (i < n) I[i] = interpolate(v, v = values[++i]);
  2635. return function(t) {
  2636. var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
  2637. return I[i](t - i);
  2638. };
  2639. }
  2640. function quantize(interpolator, n) {
  2641. var samples = new Array(n);
  2642. for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
  2643. return samples;
  2644. }
  2645. var frame = 0, // is an animation frame pending?
  2646. timeout = 0, // is a timeout pending?
  2647. interval = 0, // are any timers active?
  2648. pokeDelay = 1000, // how frequently we check for clock skew
  2649. taskHead,
  2650. taskTail,
  2651. clockLast = 0,
  2652. clockNow = 0,
  2653. clockSkew = 0,
  2654. clock = typeof performance === "object" && performance.now ? performance : Date,
  2655. setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
  2656. function now() {
  2657. return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
  2658. }
  2659. function clearNow() {
  2660. clockNow = 0;
  2661. }
  2662. function Timer() {
  2663. this._call =
  2664. this._time =
  2665. this._next = null;
  2666. }
  2667. Timer.prototype = timer.prototype = {
  2668. constructor: Timer,
  2669. restart: function(callback, delay, time) {
  2670. if (typeof callback !== "function") throw new TypeError("callback is not a function");
  2671. time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
  2672. if (!this._next && taskTail !== this) {
  2673. if (taskTail) taskTail._next = this;
  2674. else taskHead = this;
  2675. taskTail = this;
  2676. }
  2677. this._call = callback;
  2678. this._time = time;
  2679. sleep();
  2680. },
  2681. stop: function() {
  2682. if (this._call) {
  2683. this._call = null;
  2684. this._time = Infinity;
  2685. sleep();
  2686. }
  2687. }
  2688. };
  2689. function timer(callback, delay, time) {
  2690. var t = new Timer;
  2691. t.restart(callback, delay, time);
  2692. return t;
  2693. }
  2694. function timerFlush() {
  2695. now(); // Get the current time, if not already set.
  2696. ++frame; // Pretend we’ve set an alarm, if we haven’t already.
  2697. var t = taskHead, e;
  2698. while (t) {
  2699. if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
  2700. t = t._next;
  2701. }
  2702. --frame;
  2703. }
  2704. function wake() {
  2705. clockNow = (clockLast = clock.now()) + clockSkew;
  2706. frame = timeout = 0;
  2707. try {
  2708. timerFlush();
  2709. } finally {
  2710. frame = 0;
  2711. nap();
  2712. clockNow = 0;
  2713. }
  2714. }
  2715. function poke() {
  2716. var now = clock.now(), delay = now - clockLast;
  2717. if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
  2718. }
  2719. function nap() {
  2720. var t0, t1 = taskHead, t2, time = Infinity;
  2721. while (t1) {
  2722. if (t1._call) {
  2723. if (time > t1._time) time = t1._time;
  2724. t0 = t1, t1 = t1._next;
  2725. } else {
  2726. t2 = t1._next, t1._next = null;
  2727. t1 = t0 ? t0._next = t2 : taskHead = t2;
  2728. }
  2729. }
  2730. taskTail = t0;
  2731. sleep(time);
  2732. }
  2733. function sleep(time) {
  2734. if (frame) return; // Soonest alarm already set, or will be.
  2735. if (timeout) timeout = clearTimeout(timeout);
  2736. var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
  2737. if (delay > 24) {
  2738. if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
  2739. if (interval) interval = clearInterval(interval);
  2740. } else {
  2741. if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
  2742. frame = 1, setFrame(wake);
  2743. }
  2744. }
  2745. function timeout$1(callback, delay, time) {
  2746. var t = new Timer;
  2747. delay = delay == null ? 0 : +delay;
  2748. t.restart(function(elapsed) {
  2749. t.stop();
  2750. callback(elapsed + delay);
  2751. }, delay, time);
  2752. return t;
  2753. }
  2754. function interval$1(callback, delay, time) {
  2755. var t = new Timer, total = delay;
  2756. if (delay == null) return t.restart(callback, delay, time), t;
  2757. delay = +delay, time = time == null ? now() : +time;
  2758. t.restart(function tick(elapsed) {
  2759. elapsed += total;
  2760. t.restart(tick, total += delay, time);
  2761. callback(elapsed);
  2762. }, delay, time);
  2763. return t;
  2764. }
  2765. var emptyOn = dispatch("start", "end", "cancel", "interrupt");
  2766. var emptyTween = [];
  2767. var CREATED = 0;
  2768. var SCHEDULED = 1;
  2769. var STARTING = 2;
  2770. var STARTED = 3;
  2771. var RUNNING = 4;
  2772. var ENDING = 5;
  2773. var ENDED = 6;
  2774. function schedule(node, name, id, index, group, timing) {
  2775. var schedules = node.__transition;
  2776. if (!schedules) node.__transition = {};
  2777. else if (id in schedules) return;
  2778. create$1(node, id, {
  2779. name: name,
  2780. index: index, // For context during callback.
  2781. group: group, // For context during callback.
  2782. on: emptyOn,
  2783. tween: emptyTween,
  2784. time: timing.time,
  2785. delay: timing.delay,
  2786. duration: timing.duration,
  2787. ease: timing.ease,
  2788. timer: null,
  2789. state: CREATED
  2790. });
  2791. }
  2792. function init(node, id) {
  2793. var schedule = get$1(node, id);
  2794. if (schedule.state > CREATED) throw new Error("too late; already scheduled");
  2795. return schedule;
  2796. }
  2797. function set$1(node, id) {
  2798. var schedule = get$1(node, id);
  2799. if (schedule.state > STARTED) throw new Error("too late; already running");
  2800. return schedule;
  2801. }
  2802. function get$1(node, id) {
  2803. var schedule = node.__transition;
  2804. if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
  2805. return schedule;
  2806. }
  2807. function create$1(node, id, self) {
  2808. var schedules = node.__transition,
  2809. tween;
  2810. // Initialize the self timer when the transition is created.
  2811. // Note the actual delay is not known until the first callback!
  2812. schedules[id] = self;
  2813. self.timer = timer(schedule, 0, self.time);
  2814. function schedule(elapsed) {
  2815. self.state = SCHEDULED;
  2816. self.timer.restart(start, self.delay, self.time);
  2817. // If the elapsed delay is less than our first sleep, start immediately.
  2818. if (self.delay <= elapsed) start(elapsed - self.delay);
  2819. }
  2820. function start(elapsed) {
  2821. var i, j, n, o;
  2822. // If the state is not SCHEDULED, then we previously errored on start.
  2823. if (self.state !== SCHEDULED) return stop();
  2824. for (i in schedules) {
  2825. o = schedules[i];
  2826. if (o.name !== self.name) continue;
  2827. // While this element already has a starting transition during this frame,
  2828. // defer starting an interrupting transition until that transition has a
  2829. // chance to tick (and possibly end); see d3/d3-transition#54!
  2830. if (o.state === STARTED) return timeout$1(start);
  2831. // Interrupt the active transition, if any.
  2832. if (o.state === RUNNING) {
  2833. o.state = ENDED;
  2834. o.timer.stop();
  2835. o.on.call("interrupt", node, node.__data__, o.index, o.group);
  2836. delete schedules[i];
  2837. }
  2838. // Cancel any pre-empted transitions.
  2839. else if (+i < id) {
  2840. o.state = ENDED;
  2841. o.timer.stop();
  2842. o.on.call("cancel", node, node.__data__, o.index, o.group);
  2843. delete schedules[i];
  2844. }
  2845. }
  2846. // Defer the first tick to end of the current frame; see d3/d3#1576.
  2847. // Note the transition may be canceled after start and before the first tick!
  2848. // Note this must be scheduled before the start event; see d3/d3-transition#16!
  2849. // Assuming this is successful, subsequent callbacks go straight to tick.
  2850. timeout$1(function() {
  2851. if (self.state === STARTED) {
  2852. self.state = RUNNING;
  2853. self.timer.restart(tick, self.delay, self.time);
  2854. tick(elapsed);
  2855. }
  2856. });
  2857. // Dispatch the start event.
  2858. // Note this must be done before the tween are initialized.
  2859. self.state = STARTING;
  2860. self.on.call("start", node, node.__data__, self.index, self.group);
  2861. if (self.state !== STARTING) return; // interrupted
  2862. self.state = STARTED;
  2863. // Initialize the tween, deleting null tween.
  2864. tween = new Array(n = self.tween.length);
  2865. for (i = 0, j = -1; i < n; ++i) {
  2866. if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
  2867. tween[++j] = o;
  2868. }
  2869. }
  2870. tween.length = j + 1;
  2871. }
  2872. function tick(elapsed) {
  2873. var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
  2874. i = -1,
  2875. n = tween.length;
  2876. while (++i < n) {
  2877. tween[i].call(node, t);
  2878. }
  2879. // Dispatch the end event.
  2880. if (self.state === ENDING) {
  2881. self.on.call("end", node, node.__data__, self.index, self.group);
  2882. stop();
  2883. }
  2884. }
  2885. function stop() {
  2886. self.state = ENDED;
  2887. self.timer.stop();
  2888. delete schedules[id];
  2889. for (var i in schedules) return; // eslint-disable-line no-unused-vars
  2890. delete node.__transition;
  2891. }
  2892. }
  2893. function interrupt(node, name) {
  2894. var schedules = node.__transition,
  2895. schedule,
  2896. active,
  2897. empty = true,
  2898. i;
  2899. if (!schedules) return;
  2900. name = name == null ? null : name + "";
  2901. for (i in schedules) {
  2902. if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
  2903. active = schedule.state > STARTING && schedule.state < ENDING;
  2904. schedule.state = ENDED;
  2905. schedule.timer.stop();
  2906. schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
  2907. delete schedules[i];
  2908. }
  2909. if (empty) delete node.__transition;
  2910. }
  2911. function selection_interrupt(name) {
  2912. return this.each(function() {
  2913. interrupt(this, name);
  2914. });
  2915. }
  2916. function tweenRemove(id, name) {
  2917. var tween0, tween1;
  2918. return function() {
  2919. var schedule = set$1(this, id),
  2920. tween = schedule.tween;
  2921. // If this node shared tween with the previous node,
  2922. // just assign the updated shared tween and we’re done!
  2923. // Otherwise, copy-on-write.
  2924. if (tween !== tween0) {
  2925. tween1 = tween0 = tween;
  2926. for (var i = 0, n = tween1.length; i < n; ++i) {
  2927. if (tween1[i].name === name) {
  2928. tween1 = tween1.slice();
  2929. tween1.splice(i, 1);
  2930. break;
  2931. }
  2932. }
  2933. }
  2934. schedule.tween = tween1;
  2935. };
  2936. }
  2937. function tweenFunction(id, name, value) {
  2938. var tween0, tween1;
  2939. if (typeof value !== "function") throw new Error;
  2940. return function() {
  2941. var schedule = set$1(this, id),
  2942. tween = schedule.tween;
  2943. // If this node shared tween with the previous node,
  2944. // just assign the updated shared tween and we’re done!
  2945. // Otherwise, copy-on-write.
  2946. if (tween !== tween0) {
  2947. tween1 = (tween0 = tween).slice();
  2948. for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
  2949. if (tween1[i].name === name) {
  2950. tween1[i] = t;
  2951. break;
  2952. }
  2953. }
  2954. if (i === n) tween1.push(t);
  2955. }
  2956. schedule.tween = tween1;
  2957. };
  2958. }
  2959. function transition_tween(name, value) {
  2960. var id = this._id;
  2961. name += "";
  2962. if (arguments.length < 2) {
  2963. var tween = get$1(this.node(), id).tween;
  2964. for (var i = 0, n = tween.length, t; i < n; ++i) {
  2965. if ((t = tween[i]).name === name) {
  2966. return t.value;
  2967. }
  2968. }
  2969. return null;
  2970. }
  2971. return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
  2972. }
  2973. function tweenValue(transition, name, value) {
  2974. var id = transition._id;
  2975. transition.each(function() {
  2976. var schedule = set$1(this, id);
  2977. (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
  2978. });
  2979. return function(node) {
  2980. return get$1(node, id).value[name];
  2981. };
  2982. }
  2983. function interpolate(a, b) {
  2984. var c;
  2985. return (typeof b === "number" ? interpolateNumber
  2986. : b instanceof color ? interpolateRgb
  2987. : (c = color(b)) ? (b = c, interpolateRgb)
  2988. : interpolateString)(a, b);
  2989. }
  2990. function attrRemove$1(name) {
  2991. return function() {
  2992. this.removeAttribute(name);
  2993. };
  2994. }
  2995. function attrRemoveNS$1(fullname) {
  2996. return function() {
  2997. this.removeAttributeNS(fullname.space, fullname.local);
  2998. };
  2999. }
  3000. function attrConstant$1(name, interpolate, value1) {
  3001. var string00,
  3002. string1 = value1 + "",
  3003. interpolate0;
  3004. return function() {
  3005. var string0 = this.getAttribute(name);
  3006. return string0 === string1 ? null
  3007. : string0 === string00 ? interpolate0
  3008. : interpolate0 = interpolate(string00 = string0, value1);
  3009. };
  3010. }
  3011. function attrConstantNS$1(fullname, interpolate, value1) {
  3012. var string00,
  3013. string1 = value1 + "",
  3014. interpolate0;
  3015. return function() {
  3016. var string0 = this.getAttributeNS(fullname.space, fullname.local);
  3017. return string0 === string1 ? null
  3018. : string0 === string00 ? interpolate0
  3019. : interpolate0 = interpolate(string00 = string0, value1);
  3020. };
  3021. }
  3022. function attrFunction$1(name, interpolate, value) {
  3023. var string00,
  3024. string10,
  3025. interpolate0;
  3026. return function() {
  3027. var string0, value1 = value(this), string1;
  3028. if (value1 == null) return void this.removeAttribute(name);
  3029. string0 = this.getAttribute(name);
  3030. string1 = value1 + "";
  3031. return string0 === string1 ? null
  3032. : string0 === string00 && string1 === string10 ? interpolate0
  3033. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3034. };
  3035. }
  3036. function attrFunctionNS$1(fullname, interpolate, value) {
  3037. var string00,
  3038. string10,
  3039. interpolate0;
  3040. return function() {
  3041. var string0, value1 = value(this), string1;
  3042. if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
  3043. string0 = this.getAttributeNS(fullname.space, fullname.local);
  3044. string1 = value1 + "";
  3045. return string0 === string1 ? null
  3046. : string0 === string00 && string1 === string10 ? interpolate0
  3047. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3048. };
  3049. }
  3050. function transition_attr(name, value) {
  3051. var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
  3052. return this.attrTween(name, typeof value === "function"
  3053. ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
  3054. : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
  3055. : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
  3056. }
  3057. function attrInterpolate(name, i) {
  3058. return function(t) {
  3059. this.setAttribute(name, i(t));
  3060. };
  3061. }
  3062. function attrInterpolateNS(fullname, i) {
  3063. return function(t) {
  3064. this.setAttributeNS(fullname.space, fullname.local, i(t));
  3065. };
  3066. }
  3067. function attrTweenNS(fullname, value) {
  3068. var t0, i0;
  3069. function tween() {
  3070. var i = value.apply(this, arguments);
  3071. if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
  3072. return t0;
  3073. }
  3074. tween._value = value;
  3075. return tween;
  3076. }
  3077. function attrTween(name, value) {
  3078. var t0, i0;
  3079. function tween() {
  3080. var i = value.apply(this, arguments);
  3081. if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
  3082. return t0;
  3083. }
  3084. tween._value = value;
  3085. return tween;
  3086. }
  3087. function transition_attrTween(name, value) {
  3088. var key = "attr." + name;
  3089. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3090. if (value == null) return this.tween(key, null);
  3091. if (typeof value !== "function") throw new Error;
  3092. var fullname = namespace(name);
  3093. return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
  3094. }
  3095. function delayFunction(id, value) {
  3096. return function() {
  3097. init(this, id).delay = +value.apply(this, arguments);
  3098. };
  3099. }
  3100. function delayConstant(id, value) {
  3101. return value = +value, function() {
  3102. init(this, id).delay = value;
  3103. };
  3104. }
  3105. function transition_delay(value) {
  3106. var id = this._id;
  3107. return arguments.length
  3108. ? this.each((typeof value === "function"
  3109. ? delayFunction
  3110. : delayConstant)(id, value))
  3111. : get$1(this.node(), id).delay;
  3112. }
  3113. function durationFunction(id, value) {
  3114. return function() {
  3115. set$1(this, id).duration = +value.apply(this, arguments);
  3116. };
  3117. }
  3118. function durationConstant(id, value) {
  3119. return value = +value, function() {
  3120. set$1(this, id).duration = value;
  3121. };
  3122. }
  3123. function transition_duration(value) {
  3124. var id = this._id;
  3125. return arguments.length
  3126. ? this.each((typeof value === "function"
  3127. ? durationFunction
  3128. : durationConstant)(id, value))
  3129. : get$1(this.node(), id).duration;
  3130. }
  3131. function easeConstant(id, value) {
  3132. if (typeof value !== "function") throw new Error;
  3133. return function() {
  3134. set$1(this, id).ease = value;
  3135. };
  3136. }
  3137. function transition_ease(value) {
  3138. var id = this._id;
  3139. return arguments.length
  3140. ? this.each(easeConstant(id, value))
  3141. : get$1(this.node(), id).ease;
  3142. }
  3143. function transition_filter(match) {
  3144. if (typeof match !== "function") match = matcher(match);
  3145. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3146. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
  3147. if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
  3148. subgroup.push(node);
  3149. }
  3150. }
  3151. }
  3152. return new Transition(subgroups, this._parents, this._name, this._id);
  3153. }
  3154. function transition_merge(transition) {
  3155. if (transition._id !== this._id) throw new Error;
  3156. 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) {
  3157. for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
  3158. if (node = group0[i] || group1[i]) {
  3159. merge[i] = node;
  3160. }
  3161. }
  3162. }
  3163. for (; j < m0; ++j) {
  3164. merges[j] = groups0[j];
  3165. }
  3166. return new Transition(merges, this._parents, this._name, this._id);
  3167. }
  3168. function start(name) {
  3169. return (name + "").trim().split(/^|\s+/).every(function(t) {
  3170. var i = t.indexOf(".");
  3171. if (i >= 0) t = t.slice(0, i);
  3172. return !t || t === "start";
  3173. });
  3174. }
  3175. function onFunction(id, name, listener) {
  3176. var on0, on1, sit = start(name) ? init : set$1;
  3177. return function() {
  3178. var schedule = sit(this, id),
  3179. on = schedule.on;
  3180. // If this node shared a dispatch with the previous node,
  3181. // just assign the updated shared dispatch and we’re done!
  3182. // Otherwise, copy-on-write.
  3183. if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
  3184. schedule.on = on1;
  3185. };
  3186. }
  3187. function transition_on(name, listener) {
  3188. var id = this._id;
  3189. return arguments.length < 2
  3190. ? get$1(this.node(), id).on.on(name)
  3191. : this.each(onFunction(id, name, listener));
  3192. }
  3193. function removeFunction(id) {
  3194. return function() {
  3195. var parent = this.parentNode;
  3196. for (var i in this.__transition) if (+i !== id) return;
  3197. if (parent) parent.removeChild(this);
  3198. };
  3199. }
  3200. function transition_remove() {
  3201. return this.on("end.remove", removeFunction(this._id));
  3202. }
  3203. function transition_select(select) {
  3204. var name = this._name,
  3205. id = this._id;
  3206. if (typeof select !== "function") select = selector(select);
  3207. for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
  3208. for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
  3209. if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
  3210. if ("__data__" in node) subnode.__data__ = node.__data__;
  3211. subgroup[i] = subnode;
  3212. schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
  3213. }
  3214. }
  3215. }
  3216. return new Transition(subgroups, this._parents, name, id);
  3217. }
  3218. function transition_selectAll(select) {
  3219. var name = this._name,
  3220. id = this._id;
  3221. if (typeof select !== "function") select = selectorAll(select);
  3222. for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
  3223. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3224. if (node = group[i]) {
  3225. for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
  3226. if (child = children[k]) {
  3227. schedule(child, name, id, k, children, inherit);
  3228. }
  3229. }
  3230. subgroups.push(children);
  3231. parents.push(node);
  3232. }
  3233. }
  3234. }
  3235. return new Transition(subgroups, parents, name, id);
  3236. }
  3237. var Selection$1 = selection.prototype.constructor;
  3238. function transition_selection() {
  3239. return new Selection$1(this._groups, this._parents);
  3240. }
  3241. function styleNull(name, interpolate) {
  3242. var string00,
  3243. string10,
  3244. interpolate0;
  3245. return function() {
  3246. var string0 = styleValue(this, name),
  3247. string1 = (this.style.removeProperty(name), styleValue(this, name));
  3248. return string0 === string1 ? null
  3249. : string0 === string00 && string1 === string10 ? interpolate0
  3250. : interpolate0 = interpolate(string00 = string0, string10 = string1);
  3251. };
  3252. }
  3253. function styleRemove$1(name) {
  3254. return function() {
  3255. this.style.removeProperty(name);
  3256. };
  3257. }
  3258. function styleConstant$1(name, interpolate, value1) {
  3259. var string00,
  3260. string1 = value1 + "",
  3261. interpolate0;
  3262. return function() {
  3263. var string0 = styleValue(this, name);
  3264. return string0 === string1 ? null
  3265. : string0 === string00 ? interpolate0
  3266. : interpolate0 = interpolate(string00 = string0, value1);
  3267. };
  3268. }
  3269. function styleFunction$1(name, interpolate, value) {
  3270. var string00,
  3271. string10,
  3272. interpolate0;
  3273. return function() {
  3274. var string0 = styleValue(this, name),
  3275. value1 = value(this),
  3276. string1 = value1 + "";
  3277. if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
  3278. return string0 === string1 ? null
  3279. : string0 === string00 && string1 === string10 ? interpolate0
  3280. : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
  3281. };
  3282. }
  3283. function styleMaybeRemove(id, name) {
  3284. var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
  3285. return function() {
  3286. var schedule = set$1(this, id),
  3287. on = schedule.on,
  3288. listener = schedule.value[key] == null ? remove || (remove = styleRemove$1(name)) : undefined;
  3289. // If this node shared a dispatch with the previous node,
  3290. // just assign the updated shared dispatch and we’re done!
  3291. // Otherwise, copy-on-write.
  3292. if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
  3293. schedule.on = on1;
  3294. };
  3295. }
  3296. function transition_style(name, value, priority) {
  3297. var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
  3298. return value == null ? this
  3299. .styleTween(name, styleNull(name, i))
  3300. .on("end.style." + name, styleRemove$1(name))
  3301. : typeof value === "function" ? this
  3302. .styleTween(name, styleFunction$1(name, i, tweenValue(this, "style." + name, value)))
  3303. .each(styleMaybeRemove(this._id, name))
  3304. : this
  3305. .styleTween(name, styleConstant$1(name, i, value), priority)
  3306. .on("end.style." + name, null);
  3307. }
  3308. function styleInterpolate(name, i, priority) {
  3309. return function(t) {
  3310. this.style.setProperty(name, i(t), priority);
  3311. };
  3312. }
  3313. function styleTween(name, value, priority) {
  3314. var t, i0;
  3315. function tween() {
  3316. var i = value.apply(this, arguments);
  3317. if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
  3318. return t;
  3319. }
  3320. tween._value = value;
  3321. return tween;
  3322. }
  3323. function transition_styleTween(name, value, priority) {
  3324. var key = "style." + (name += "");
  3325. if (arguments.length < 2) return (key = this.tween(key)) && key._value;
  3326. if (value == null) return this.tween(key, null);
  3327. if (typeof value !== "function") throw new Error;
  3328. return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
  3329. }
  3330. function textConstant$1(value) {
  3331. return function() {
  3332. this.textContent = value;
  3333. };
  3334. }
  3335. function textFunction$1(value) {
  3336. return function() {
  3337. var value1 = value(this);
  3338. this.textContent = value1 == null ? "" : value1;
  3339. };
  3340. }
  3341. function transition_text(value) {
  3342. return this.tween("text", typeof value === "function"
  3343. ? textFunction$1(tweenValue(this, "text", value))
  3344. : textConstant$1(value == null ? "" : value + ""));
  3345. }
  3346. function transition_transition() {
  3347. var name = this._name,
  3348. id0 = this._id,
  3349. id1 = newId();
  3350. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3351. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3352. if (node = group[i]) {
  3353. var inherit = get$1(node, id0);
  3354. schedule(node, name, id1, i, group, {
  3355. time: inherit.time + inherit.delay + inherit.duration,
  3356. delay: 0,
  3357. duration: inherit.duration,
  3358. ease: inherit.ease
  3359. });
  3360. }
  3361. }
  3362. }
  3363. return new Transition(groups, this._parents, name, id1);
  3364. }
  3365. function transition_end() {
  3366. var on0, on1, that = this, id = that._id, size = that.size();
  3367. return new Promise(function(resolve, reject) {
  3368. var cancel = {value: reject},
  3369. end = {value: function() { if (--size === 0) resolve(); }};
  3370. that.each(function() {
  3371. var schedule = set$1(this, id),
  3372. on = schedule.on;
  3373. // If this node shared a dispatch with the previous node,
  3374. // just assign the updated shared dispatch and we’re done!
  3375. // Otherwise, copy-on-write.
  3376. if (on !== on0) {
  3377. on1 = (on0 = on).copy();
  3378. on1._.cancel.push(cancel);
  3379. on1._.interrupt.push(cancel);
  3380. on1._.end.push(end);
  3381. }
  3382. schedule.on = on1;
  3383. });
  3384. });
  3385. }
  3386. var id = 0;
  3387. function Transition(groups, parents, name, id) {
  3388. this._groups = groups;
  3389. this._parents = parents;
  3390. this._name = name;
  3391. this._id = id;
  3392. }
  3393. function transition(name) {
  3394. return selection().transition(name);
  3395. }
  3396. function newId() {
  3397. return ++id;
  3398. }
  3399. var selection_prototype = selection.prototype;
  3400. Transition.prototype = transition.prototype = {
  3401. constructor: Transition,
  3402. select: transition_select,
  3403. selectAll: transition_selectAll,
  3404. filter: transition_filter,
  3405. merge: transition_merge,
  3406. selection: transition_selection,
  3407. transition: transition_transition,
  3408. call: selection_prototype.call,
  3409. nodes: selection_prototype.nodes,
  3410. node: selection_prototype.node,
  3411. size: selection_prototype.size,
  3412. empty: selection_prototype.empty,
  3413. each: selection_prototype.each,
  3414. on: transition_on,
  3415. attr: transition_attr,
  3416. attrTween: transition_attrTween,
  3417. style: transition_style,
  3418. styleTween: transition_styleTween,
  3419. text: transition_text,
  3420. remove: transition_remove,
  3421. tween: transition_tween,
  3422. delay: transition_delay,
  3423. duration: transition_duration,
  3424. ease: transition_ease,
  3425. end: transition_end
  3426. };
  3427. function linear$1(t) {
  3428. return +t;
  3429. }
  3430. function quadIn(t) {
  3431. return t * t;
  3432. }
  3433. function quadOut(t) {
  3434. return t * (2 - t);
  3435. }
  3436. function quadInOut(t) {
  3437. return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
  3438. }
  3439. function cubicIn(t) {
  3440. return t * t * t;
  3441. }
  3442. function cubicOut(t) {
  3443. return --t * t * t + 1;
  3444. }
  3445. function cubicInOut(t) {
  3446. return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
  3447. }
  3448. var exponent = 3;
  3449. var polyIn = (function custom(e) {
  3450. e = +e;
  3451. function polyIn(t) {
  3452. return Math.pow(t, e);
  3453. }
  3454. polyIn.exponent = custom;
  3455. return polyIn;
  3456. })(exponent);
  3457. var polyOut = (function custom(e) {
  3458. e = +e;
  3459. function polyOut(t) {
  3460. return 1 - Math.pow(1 - t, e);
  3461. }
  3462. polyOut.exponent = custom;
  3463. return polyOut;
  3464. })(exponent);
  3465. var polyInOut = (function custom(e) {
  3466. e = +e;
  3467. function polyInOut(t) {
  3468. return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
  3469. }
  3470. polyInOut.exponent = custom;
  3471. return polyInOut;
  3472. })(exponent);
  3473. var pi = Math.PI,
  3474. halfPi = pi / 2;
  3475. function sinIn(t) {
  3476. return 1 - Math.cos(t * halfPi);
  3477. }
  3478. function sinOut(t) {
  3479. return Math.sin(t * halfPi);
  3480. }
  3481. function sinInOut(t) {
  3482. return (1 - Math.cos(pi * t)) / 2;
  3483. }
  3484. function expIn(t) {
  3485. return Math.pow(2, 10 * t - 10);
  3486. }
  3487. function expOut(t) {
  3488. return 1 - Math.pow(2, -10 * t);
  3489. }
  3490. function expInOut(t) {
  3491. return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
  3492. }
  3493. function circleIn(t) {
  3494. return 1 - Math.sqrt(1 - t * t);
  3495. }
  3496. function circleOut(t) {
  3497. return Math.sqrt(1 - --t * t);
  3498. }
  3499. function circleInOut(t) {
  3500. return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
  3501. }
  3502. var b1 = 4 / 11,
  3503. b2 = 6 / 11,
  3504. b3 = 8 / 11,
  3505. b4 = 3 / 4,
  3506. b5 = 9 / 11,
  3507. b6 = 10 / 11,
  3508. b7 = 15 / 16,
  3509. b8 = 21 / 22,
  3510. b9 = 63 / 64,
  3511. b0 = 1 / b1 / b1;
  3512. function bounceIn(t) {
  3513. return 1 - bounceOut(1 - t);
  3514. }
  3515. function bounceOut(t) {
  3516. 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;
  3517. }
  3518. function bounceInOut(t) {
  3519. return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
  3520. }
  3521. var overshoot = 1.70158;
  3522. var backIn = (function custom(s) {
  3523. s = +s;
  3524. function backIn(t) {
  3525. return t * t * ((s + 1) * t - s);
  3526. }
  3527. backIn.overshoot = custom;
  3528. return backIn;
  3529. })(overshoot);
  3530. var backOut = (function custom(s) {
  3531. s = +s;
  3532. function backOut(t) {
  3533. return --t * t * ((s + 1) * t + s) + 1;
  3534. }
  3535. backOut.overshoot = custom;
  3536. return backOut;
  3537. })(overshoot);
  3538. var backInOut = (function custom(s) {
  3539. s = +s;
  3540. function backInOut(t) {
  3541. return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
  3542. }
  3543. backInOut.overshoot = custom;
  3544. return backInOut;
  3545. })(overshoot);
  3546. var tau = 2 * Math.PI,
  3547. amplitude = 1,
  3548. period = 0.3;
  3549. var elasticIn = (function custom(a, p) {
  3550. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3551. function elasticIn(t) {
  3552. return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
  3553. }
  3554. elasticIn.amplitude = function(a) { return custom(a, p * tau); };
  3555. elasticIn.period = function(p) { return custom(a, p); };
  3556. return elasticIn;
  3557. })(amplitude, period);
  3558. var elasticOut = (function custom(a, p) {
  3559. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3560. function elasticOut(t) {
  3561. return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
  3562. }
  3563. elasticOut.amplitude = function(a) { return custom(a, p * tau); };
  3564. elasticOut.period = function(p) { return custom(a, p); };
  3565. return elasticOut;
  3566. })(amplitude, period);
  3567. var elasticInOut = (function custom(a, p) {
  3568. var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
  3569. function elasticInOut(t) {
  3570. return ((t = t * 2 - 1) < 0
  3571. ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
  3572. : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
  3573. }
  3574. elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
  3575. elasticInOut.period = function(p) { return custom(a, p); };
  3576. return elasticInOut;
  3577. })(amplitude, period);
  3578. var defaultTiming = {
  3579. time: null, // Set on use.
  3580. delay: 0,
  3581. duration: 250,
  3582. ease: cubicInOut
  3583. };
  3584. function inherit(node, id) {
  3585. var timing;
  3586. while (!(timing = node.__transition) || !(timing = timing[id])) {
  3587. if (!(node = node.parentNode)) {
  3588. return defaultTiming.time = now(), defaultTiming;
  3589. }
  3590. }
  3591. return timing;
  3592. }
  3593. function selection_transition(name) {
  3594. var id,
  3595. timing;
  3596. if (name instanceof Transition) {
  3597. id = name._id, name = name._name;
  3598. } else {
  3599. id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
  3600. }
  3601. for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
  3602. for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
  3603. if (node = group[i]) {
  3604. schedule(node, name, id, i, group, timing || inherit(node, id));
  3605. }
  3606. }
  3607. }
  3608. return new Transition(groups, this._parents, name, id);
  3609. }
  3610. selection.prototype.interrupt = selection_interrupt;
  3611. selection.prototype.transition = selection_transition;
  3612. var root$1 = [null];
  3613. function active(node, name) {
  3614. var schedules = node.__transition,
  3615. schedule,
  3616. i;
  3617. if (schedules) {
  3618. name = name == null ? null : name + "";
  3619. for (i in schedules) {
  3620. if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
  3621. return new Transition([[node]], root$1, name, +i);
  3622. }
  3623. }
  3624. }
  3625. return null;
  3626. }
  3627. function constant$4(x) {
  3628. return function() {
  3629. return x;
  3630. };
  3631. }
  3632. function BrushEvent(target, type, selection) {
  3633. this.target = target;
  3634. this.type = type;
  3635. this.selection = selection;
  3636. }
  3637. function nopropagation$1() {
  3638. exports.event.stopImmediatePropagation();
  3639. }
  3640. function noevent$1() {
  3641. exports.event.preventDefault();
  3642. exports.event.stopImmediatePropagation();
  3643. }
  3644. var MODE_DRAG = {name: "drag"},
  3645. MODE_SPACE = {name: "space"},
  3646. MODE_HANDLE = {name: "handle"},
  3647. MODE_CENTER = {name: "center"};
  3648. function number1(e) {
  3649. return [+e[0], +e[1]];
  3650. }
  3651. function number2(e) {
  3652. return [number1(e[0]), number1(e[1])];
  3653. }
  3654. function toucher(identifier) {
  3655. return function(target) {
  3656. return touch(target, exports.event.touches, identifier);
  3657. };
  3658. }
  3659. var X = {
  3660. name: "x",
  3661. handles: ["w", "e"].map(type),
  3662. input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
  3663. output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
  3664. };
  3665. var Y = {
  3666. name: "y",
  3667. handles: ["n", "s"].map(type),
  3668. input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
  3669. output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
  3670. };
  3671. var XY = {
  3672. name: "xy",
  3673. handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
  3674. input: function(xy) { return xy == null ? null : number2(xy); },
  3675. output: function(xy) { return xy; }
  3676. };
  3677. var cursors = {
  3678. overlay: "crosshair",
  3679. selection: "move",
  3680. n: "ns-resize",
  3681. e: "ew-resize",
  3682. s: "ns-resize",
  3683. w: "ew-resize",
  3684. nw: "nwse-resize",
  3685. ne: "nesw-resize",
  3686. se: "nwse-resize",
  3687. sw: "nesw-resize"
  3688. };
  3689. var flipX = {
  3690. e: "w",
  3691. w: "e",
  3692. nw: "ne",
  3693. ne: "nw",
  3694. se: "sw",
  3695. sw: "se"
  3696. };
  3697. var flipY = {
  3698. n: "s",
  3699. s: "n",
  3700. nw: "sw",
  3701. ne: "se",
  3702. se: "ne",
  3703. sw: "nw"
  3704. };
  3705. var signsX = {
  3706. overlay: +1,
  3707. selection: +1,
  3708. n: null,
  3709. e: +1,
  3710. s: null,
  3711. w: -1,
  3712. nw: -1,
  3713. ne: +1,
  3714. se: +1,
  3715. sw: -1
  3716. };
  3717. var signsY = {
  3718. overlay: +1,
  3719. selection: +1,
  3720. n: -1,
  3721. e: null,
  3722. s: +1,
  3723. w: null,
  3724. nw: -1,
  3725. ne: -1,
  3726. se: +1,
  3727. sw: +1
  3728. };
  3729. function type(t) {
  3730. return {type: t};
  3731. }
  3732. // Ignore right-click, since that should open the context menu.
  3733. function defaultFilter$1() {
  3734. return !exports.event.ctrlKey && !exports.event.button;
  3735. }
  3736. function defaultExtent() {
  3737. var svg = this.ownerSVGElement || this;
  3738. if (svg.hasAttribute("viewBox")) {
  3739. svg = svg.viewBox.baseVal;
  3740. return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
  3741. }
  3742. return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
  3743. }
  3744. function defaultTouchable$1() {
  3745. return navigator.maxTouchPoints || ("ontouchstart" in this);
  3746. }
  3747. // Like d3.local, but with the name “__brush” rather than auto-generated.
  3748. function local$1(node) {
  3749. while (!node.__brush) if (!(node = node.parentNode)) return;
  3750. return node.__brush;
  3751. }
  3752. function empty$1(extent) {
  3753. return extent[0][0] === extent[1][0]
  3754. || extent[0][1] === extent[1][1];
  3755. }
  3756. function brushSelection(node) {
  3757. var state = node.__brush;
  3758. return state ? state.dim.output(state.selection) : null;
  3759. }
  3760. function brushX() {
  3761. return brush$1(X);
  3762. }
  3763. function brushY() {
  3764. return brush$1(Y);
  3765. }
  3766. function brush() {
  3767. return brush$1(XY);
  3768. }
  3769. function brush$1(dim) {
  3770. var extent = defaultExtent,
  3771. filter = defaultFilter$1,
  3772. touchable = defaultTouchable$1,
  3773. keys = true,
  3774. listeners = dispatch(brush, "start", "brush", "end"),
  3775. handleSize = 6,
  3776. touchending;
  3777. function brush(group) {
  3778. var overlay = group
  3779. .property("__brush", initialize)
  3780. .selectAll(".overlay")
  3781. .data([type("overlay")]);
  3782. overlay.enter().append("rect")
  3783. .attr("class", "overlay")
  3784. .attr("pointer-events", "all")
  3785. .attr("cursor", cursors.overlay)
  3786. .merge(overlay)
  3787. .each(function() {
  3788. var extent = local$1(this).extent;
  3789. select(this)
  3790. .attr("x", extent[0][0])
  3791. .attr("y", extent[0][1])
  3792. .attr("width", extent[1][0] - extent[0][0])
  3793. .attr("height", extent[1][1] - extent[0][1]);
  3794. });
  3795. group.selectAll(".selection")
  3796. .data([type("selection")])
  3797. .enter().append("rect")
  3798. .attr("class", "selection")
  3799. .attr("cursor", cursors.selection)
  3800. .attr("fill", "#777")
  3801. .attr("fill-opacity", 0.3)
  3802. .attr("stroke", "#fff")
  3803. .attr("shape-rendering", "crispEdges");
  3804. var handle = group.selectAll(".handle")
  3805. .data(dim.handles, function(d) { return d.type; });
  3806. handle.exit().remove();
  3807. handle.enter().append("rect")
  3808. .attr("class", function(d) { return "handle handle--" + d.type; })
  3809. .attr("cursor", function(d) { return cursors[d.type]; });
  3810. group
  3811. .each(redraw)
  3812. .attr("fill", "none")
  3813. .attr("pointer-events", "all")
  3814. .on("mousedown.brush", started)
  3815. .filter(touchable)
  3816. .on("touchstart.brush", started)
  3817. .on("touchmove.brush", touchmoved)
  3818. .on("touchend.brush touchcancel.brush", touchended)
  3819. .style("touch-action", "none")
  3820. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  3821. }
  3822. brush.move = function(group, selection) {
  3823. if (group.selection) {
  3824. group
  3825. .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
  3826. .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
  3827. .tween("brush", function() {
  3828. var that = this,
  3829. state = that.__brush,
  3830. emit = emitter(that, arguments),
  3831. selection0 = state.selection,
  3832. selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
  3833. i = interpolateValue(selection0, selection1);
  3834. function tween(t) {
  3835. state.selection = t === 1 && selection1 === null ? null : i(t);
  3836. redraw.call(that);
  3837. emit.brush();
  3838. }
  3839. return selection0 !== null && selection1 !== null ? tween : tween(1);
  3840. });
  3841. } else {
  3842. group
  3843. .each(function() {
  3844. var that = this,
  3845. args = arguments,
  3846. state = that.__brush,
  3847. selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
  3848. emit = emitter(that, args).beforestart();
  3849. interrupt(that);
  3850. state.selection = selection1 === null ? null : selection1;
  3851. redraw.call(that);
  3852. emit.start().brush().end();
  3853. });
  3854. }
  3855. };
  3856. brush.clear = function(group) {
  3857. brush.move(group, null);
  3858. };
  3859. function redraw() {
  3860. var group = select(this),
  3861. selection = local$1(this).selection;
  3862. if (selection) {
  3863. group.selectAll(".selection")
  3864. .style("display", null)
  3865. .attr("x", selection[0][0])
  3866. .attr("y", selection[0][1])
  3867. .attr("width", selection[1][0] - selection[0][0])
  3868. .attr("height", selection[1][1] - selection[0][1]);
  3869. group.selectAll(".handle")
  3870. .style("display", null)
  3871. .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
  3872. .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
  3873. .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
  3874. .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
  3875. }
  3876. else {
  3877. group.selectAll(".selection,.handle")
  3878. .style("display", "none")
  3879. .attr("x", null)
  3880. .attr("y", null)
  3881. .attr("width", null)
  3882. .attr("height", null);
  3883. }
  3884. }
  3885. function emitter(that, args, clean) {
  3886. return (!clean && that.__brush.emitter) || new Emitter(that, args);
  3887. }
  3888. function Emitter(that, args) {
  3889. this.that = that;
  3890. this.args = args;
  3891. this.state = that.__brush;
  3892. this.active = 0;
  3893. }
  3894. Emitter.prototype = {
  3895. beforestart: function() {
  3896. if (++this.active === 1) this.state.emitter = this, this.starting = true;
  3897. return this;
  3898. },
  3899. start: function() {
  3900. if (this.starting) this.starting = false, this.emit("start");
  3901. else this.emit("brush");
  3902. return this;
  3903. },
  3904. brush: function() {
  3905. this.emit("brush");
  3906. return this;
  3907. },
  3908. end: function() {
  3909. if (--this.active === 0) delete this.state.emitter, this.emit("end");
  3910. return this;
  3911. },
  3912. emit: function(type) {
  3913. customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
  3914. }
  3915. };
  3916. function started() {
  3917. if (touchending && !exports.event.touches) return;
  3918. if (!filter.apply(this, arguments)) return;
  3919. var that = this,
  3920. type = exports.event.target.__data__.type,
  3921. mode = (keys && exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
  3922. signX = dim === Y ? null : signsX[type],
  3923. signY = dim === X ? null : signsY[type],
  3924. state = local$1(that),
  3925. extent = state.extent,
  3926. selection = state.selection,
  3927. W = extent[0][0], w0, w1,
  3928. N = extent[0][1], n0, n1,
  3929. E = extent[1][0], e0, e1,
  3930. S = extent[1][1], s0, s1,
  3931. dx = 0,
  3932. dy = 0,
  3933. moving,
  3934. shifting = signX && signY && keys && exports.event.shiftKey,
  3935. lockX,
  3936. lockY,
  3937. pointer = exports.event.touches ? toucher(exports.event.changedTouches[0].identifier) : mouse,
  3938. point0 = pointer(that),
  3939. point = point0,
  3940. emit = emitter(that, arguments, true).beforestart();
  3941. if (type === "overlay") {
  3942. if (selection) moving = true;
  3943. state.selection = selection = [
  3944. [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
  3945. [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
  3946. ];
  3947. } else {
  3948. w0 = selection[0][0];
  3949. n0 = selection[0][1];
  3950. e0 = selection[1][0];
  3951. s0 = selection[1][1];
  3952. }
  3953. w1 = w0;
  3954. n1 = n0;
  3955. e1 = e0;
  3956. s1 = s0;
  3957. var group = select(that)
  3958. .attr("pointer-events", "none");
  3959. var overlay = group.selectAll(".overlay")
  3960. .attr("cursor", cursors[type]);
  3961. if (exports.event.touches) {
  3962. emit.moved = moved;
  3963. emit.ended = ended;
  3964. } else {
  3965. var view = select(exports.event.view)
  3966. .on("mousemove.brush", moved, true)
  3967. .on("mouseup.brush", ended, true);
  3968. if (keys) view
  3969. .on("keydown.brush", keydowned, true)
  3970. .on("keyup.brush", keyupped, true);
  3971. dragDisable(exports.event.view);
  3972. }
  3973. nopropagation$1();
  3974. interrupt(that);
  3975. redraw.call(that);
  3976. emit.start();
  3977. function moved() {
  3978. var point1 = pointer(that);
  3979. if (shifting && !lockX && !lockY) {
  3980. if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
  3981. else lockX = true;
  3982. }
  3983. point = point1;
  3984. moving = true;
  3985. noevent$1();
  3986. move();
  3987. }
  3988. function move() {
  3989. var t;
  3990. dx = point[0] - point0[0];
  3991. dy = point[1] - point0[1];
  3992. switch (mode) {
  3993. case MODE_SPACE:
  3994. case MODE_DRAG: {
  3995. if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
  3996. if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
  3997. break;
  3998. }
  3999. case MODE_HANDLE: {
  4000. if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
  4001. else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
  4002. if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
  4003. else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
  4004. break;
  4005. }
  4006. case MODE_CENTER: {
  4007. if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
  4008. if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
  4009. break;
  4010. }
  4011. }
  4012. if (e1 < w1) {
  4013. signX *= -1;
  4014. t = w0, w0 = e0, e0 = t;
  4015. t = w1, w1 = e1, e1 = t;
  4016. if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
  4017. }
  4018. if (s1 < n1) {
  4019. signY *= -1;
  4020. t = n0, n0 = s0, s0 = t;
  4021. t = n1, n1 = s1, s1 = t;
  4022. if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
  4023. }
  4024. if (state.selection) selection = state.selection; // May be set by brush.move!
  4025. if (lockX) w1 = selection[0][0], e1 = selection[1][0];
  4026. if (lockY) n1 = selection[0][1], s1 = selection[1][1];
  4027. if (selection[0][0] !== w1
  4028. || selection[0][1] !== n1
  4029. || selection[1][0] !== e1
  4030. || selection[1][1] !== s1) {
  4031. state.selection = [[w1, n1], [e1, s1]];
  4032. redraw.call(that);
  4033. emit.brush();
  4034. }
  4035. }
  4036. function ended() {
  4037. nopropagation$1();
  4038. if (exports.event.touches) {
  4039. if (exports.event.touches.length) return;
  4040. if (touchending) clearTimeout(touchending);
  4041. touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
  4042. } else {
  4043. yesdrag(exports.event.view, moving);
  4044. view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
  4045. }
  4046. group.attr("pointer-events", "all");
  4047. overlay.attr("cursor", cursors.overlay);
  4048. if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
  4049. if (empty$1(selection)) state.selection = null, redraw.call(that);
  4050. emit.end();
  4051. }
  4052. function keydowned() {
  4053. switch (exports.event.keyCode) {
  4054. case 16: { // SHIFT
  4055. shifting = signX && signY;
  4056. break;
  4057. }
  4058. case 18: { // ALT
  4059. if (mode === MODE_HANDLE) {
  4060. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4061. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4062. mode = MODE_CENTER;
  4063. move();
  4064. }
  4065. break;
  4066. }
  4067. case 32: { // SPACE; takes priority over ALT
  4068. if (mode === MODE_HANDLE || mode === MODE_CENTER) {
  4069. if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
  4070. if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
  4071. mode = MODE_SPACE;
  4072. overlay.attr("cursor", cursors.selection);
  4073. move();
  4074. }
  4075. break;
  4076. }
  4077. default: return;
  4078. }
  4079. noevent$1();
  4080. }
  4081. function keyupped() {
  4082. switch (exports.event.keyCode) {
  4083. case 16: { // SHIFT
  4084. if (shifting) {
  4085. lockX = lockY = shifting = false;
  4086. move();
  4087. }
  4088. break;
  4089. }
  4090. case 18: { // ALT
  4091. if (mode === MODE_CENTER) {
  4092. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4093. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4094. mode = MODE_HANDLE;
  4095. move();
  4096. }
  4097. break;
  4098. }
  4099. case 32: { // SPACE
  4100. if (mode === MODE_SPACE) {
  4101. if (exports.event.altKey) {
  4102. if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
  4103. if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
  4104. mode = MODE_CENTER;
  4105. } else {
  4106. if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
  4107. if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
  4108. mode = MODE_HANDLE;
  4109. }
  4110. overlay.attr("cursor", cursors[type]);
  4111. move();
  4112. }
  4113. break;
  4114. }
  4115. default: return;
  4116. }
  4117. noevent$1();
  4118. }
  4119. }
  4120. function touchmoved() {
  4121. emitter(this, arguments).moved();
  4122. }
  4123. function touchended() {
  4124. emitter(this, arguments).ended();
  4125. }
  4126. function initialize() {
  4127. var state = this.__brush || {selection: null};
  4128. state.extent = number2(extent.apply(this, arguments));
  4129. state.dim = dim;
  4130. return state;
  4131. }
  4132. brush.extent = function(_) {
  4133. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4(number2(_)), brush) : extent;
  4134. };
  4135. brush.filter = function(_) {
  4136. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
  4137. };
  4138. brush.handleSize = function(_) {
  4139. return arguments.length ? (handleSize = +_, brush) : handleSize;
  4140. };
  4141. brush.keyModifiers = function(_) {
  4142. return arguments.length ? (keys = !!_, brush) : keys;
  4143. };
  4144. brush.on = function() {
  4145. var value = listeners.on.apply(listeners, arguments);
  4146. return value === listeners ? brush : value;
  4147. };
  4148. return brush;
  4149. }
  4150. var cos = Math.cos;
  4151. var sin = Math.sin;
  4152. var pi$1 = Math.PI;
  4153. var halfPi$1 = pi$1 / 2;
  4154. var tau$1 = pi$1 * 2;
  4155. var max$1 = Math.max;
  4156. function compareValue(compare) {
  4157. return function(a, b) {
  4158. return compare(
  4159. a.source.value + a.target.value,
  4160. b.source.value + b.target.value
  4161. );
  4162. };
  4163. }
  4164. function chord() {
  4165. var padAngle = 0,
  4166. sortGroups = null,
  4167. sortSubgroups = null,
  4168. sortChords = null;
  4169. function chord(matrix) {
  4170. var n = matrix.length,
  4171. groupSums = [],
  4172. groupIndex = sequence(n),
  4173. subgroupIndex = [],
  4174. chords = [],
  4175. groups = chords.groups = new Array(n),
  4176. subgroups = new Array(n * n),
  4177. k,
  4178. x,
  4179. x0,
  4180. dx,
  4181. i,
  4182. j;
  4183. // Compute the sum.
  4184. k = 0, i = -1; while (++i < n) {
  4185. x = 0, j = -1; while (++j < n) {
  4186. x += matrix[i][j];
  4187. }
  4188. groupSums.push(x);
  4189. subgroupIndex.push(sequence(n));
  4190. k += x;
  4191. }
  4192. // Sort groups…
  4193. if (sortGroups) groupIndex.sort(function(a, b) {
  4194. return sortGroups(groupSums[a], groupSums[b]);
  4195. });
  4196. // Sort subgroups…
  4197. if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
  4198. d.sort(function(a, b) {
  4199. return sortSubgroups(matrix[i][a], matrix[i][b]);
  4200. });
  4201. });
  4202. // Convert the sum to scaling factor for [0, 2pi].
  4203. // TODO Allow start and end angle to be specified?
  4204. // TODO Allow padding to be specified as percentage?
  4205. k = max$1(0, tau$1 - padAngle * n) / k;
  4206. dx = k ? padAngle : tau$1 / n;
  4207. // Compute the start and end angle for each group and subgroup.
  4208. // Note: Opera has a bug reordering object literal properties!
  4209. x = 0, i = -1; while (++i < n) {
  4210. x0 = x, j = -1; while (++j < n) {
  4211. var di = groupIndex[i],
  4212. dj = subgroupIndex[di][j],
  4213. v = matrix[di][dj],
  4214. a0 = x,
  4215. a1 = x += v * k;
  4216. subgroups[dj * n + di] = {
  4217. index: di,
  4218. subindex: dj,
  4219. startAngle: a0,
  4220. endAngle: a1,
  4221. value: v
  4222. };
  4223. }
  4224. groups[di] = {
  4225. index: di,
  4226. startAngle: x0,
  4227. endAngle: x,
  4228. value: groupSums[di]
  4229. };
  4230. x += dx;
  4231. }
  4232. // Generate chords for each (non-empty) subgroup-subgroup link.
  4233. i = -1; while (++i < n) {
  4234. j = i - 1; while (++j < n) {
  4235. var source = subgroups[j * n + i],
  4236. target = subgroups[i * n + j];
  4237. if (source.value || target.value) {
  4238. chords.push(source.value < target.value
  4239. ? {source: target, target: source}
  4240. : {source: source, target: target});
  4241. }
  4242. }
  4243. }
  4244. return sortChords ? chords.sort(sortChords) : chords;
  4245. }
  4246. chord.padAngle = function(_) {
  4247. return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
  4248. };
  4249. chord.sortGroups = function(_) {
  4250. return arguments.length ? (sortGroups = _, chord) : sortGroups;
  4251. };
  4252. chord.sortSubgroups = function(_) {
  4253. return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
  4254. };
  4255. chord.sortChords = function(_) {
  4256. return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
  4257. };
  4258. return chord;
  4259. }
  4260. var slice$2 = Array.prototype.slice;
  4261. function constant$5(x) {
  4262. return function() {
  4263. return x;
  4264. };
  4265. }
  4266. var pi$2 = Math.PI,
  4267. tau$2 = 2 * pi$2,
  4268. epsilon$1 = 1e-6,
  4269. tauEpsilon = tau$2 - epsilon$1;
  4270. function Path() {
  4271. this._x0 = this._y0 = // start of current subpath
  4272. this._x1 = this._y1 = null; // end of current subpath
  4273. this._ = "";
  4274. }
  4275. function path() {
  4276. return new Path;
  4277. }
  4278. Path.prototype = path.prototype = {
  4279. constructor: Path,
  4280. moveTo: function(x, y) {
  4281. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
  4282. },
  4283. closePath: function() {
  4284. if (this._x1 !== null) {
  4285. this._x1 = this._x0, this._y1 = this._y0;
  4286. this._ += "Z";
  4287. }
  4288. },
  4289. lineTo: function(x, y) {
  4290. this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
  4291. },
  4292. quadraticCurveTo: function(x1, y1, x, y) {
  4293. this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4294. },
  4295. bezierCurveTo: function(x1, y1, x2, y2, x, y) {
  4296. this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
  4297. },
  4298. arcTo: function(x1, y1, x2, y2, r) {
  4299. x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
  4300. var x0 = this._x1,
  4301. y0 = this._y1,
  4302. x21 = x2 - x1,
  4303. y21 = y2 - y1,
  4304. x01 = x0 - x1,
  4305. y01 = y0 - y1,
  4306. l01_2 = x01 * x01 + y01 * y01;
  4307. // Is the radius negative? Error.
  4308. if (r < 0) throw new Error("negative radius: " + r);
  4309. // Is this path empty? Move to (x1,y1).
  4310. if (this._x1 === null) {
  4311. this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
  4312. }
  4313. // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
  4314. else if (!(l01_2 > epsilon$1));
  4315. // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
  4316. // Equivalently, is (x1,y1) coincident with (x2,y2)?
  4317. // Or, is the radius zero? Line to (x1,y1).
  4318. else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
  4319. this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
  4320. }
  4321. // Otherwise, draw an arc!
  4322. else {
  4323. var x20 = x2 - x0,
  4324. y20 = y2 - y0,
  4325. l21_2 = x21 * x21 + y21 * y21,
  4326. l20_2 = x20 * x20 + y20 * y20,
  4327. l21 = Math.sqrt(l21_2),
  4328. l01 = Math.sqrt(l01_2),
  4329. l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
  4330. t01 = l / l01,
  4331. t21 = l / l21;
  4332. // If the start tangent is not coincident with (x0,y0), line to.
  4333. if (Math.abs(t01 - 1) > epsilon$1) {
  4334. this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
  4335. }
  4336. this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
  4337. }
  4338. },
  4339. arc: function(x, y, r, a0, a1, ccw) {
  4340. x = +x, y = +y, r = +r, ccw = !!ccw;
  4341. var dx = r * Math.cos(a0),
  4342. dy = r * Math.sin(a0),
  4343. x0 = x + dx,
  4344. y0 = y + dy,
  4345. cw = 1 ^ ccw,
  4346. da = ccw ? a0 - a1 : a1 - a0;
  4347. // Is the radius negative? Error.
  4348. if (r < 0) throw new Error("negative radius: " + r);
  4349. // Is this path empty? Move to (x0,y0).
  4350. if (this._x1 === null) {
  4351. this._ += "M" + x0 + "," + y0;
  4352. }
  4353. // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
  4354. else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
  4355. this._ += "L" + x0 + "," + y0;
  4356. }
  4357. // Is this arc empty? We’re done.
  4358. if (!r) return;
  4359. // Does the angle go the wrong way? Flip the direction.
  4360. if (da < 0) da = da % tau$2 + tau$2;
  4361. // Is this a complete circle? Draw two arcs to complete the circle.
  4362. if (da > tauEpsilon) {
  4363. this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
  4364. }
  4365. // Is this arc non-empty? Draw an arc!
  4366. else if (da > epsilon$1) {
  4367. this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
  4368. }
  4369. },
  4370. rect: function(x, y, w, h) {
  4371. this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
  4372. },
  4373. toString: function() {
  4374. return this._;
  4375. }
  4376. };
  4377. function defaultSource(d) {
  4378. return d.source;
  4379. }
  4380. function defaultTarget(d) {
  4381. return d.target;
  4382. }
  4383. function defaultRadius(d) {
  4384. return d.radius;
  4385. }
  4386. function defaultStartAngle(d) {
  4387. return d.startAngle;
  4388. }
  4389. function defaultEndAngle(d) {
  4390. return d.endAngle;
  4391. }
  4392. function ribbon() {
  4393. var source = defaultSource,
  4394. target = defaultTarget,
  4395. radius = defaultRadius,
  4396. startAngle = defaultStartAngle,
  4397. endAngle = defaultEndAngle,
  4398. context = null;
  4399. function ribbon() {
  4400. var buffer,
  4401. argv = slice$2.call(arguments),
  4402. s = source.apply(this, argv),
  4403. t = target.apply(this, argv),
  4404. sr = +radius.apply(this, (argv[0] = s, argv)),
  4405. sa0 = startAngle.apply(this, argv) - halfPi$1,
  4406. sa1 = endAngle.apply(this, argv) - halfPi$1,
  4407. sx0 = sr * cos(sa0),
  4408. sy0 = sr * sin(sa0),
  4409. tr = +radius.apply(this, (argv[0] = t, argv)),
  4410. ta0 = startAngle.apply(this, argv) - halfPi$1,
  4411. ta1 = endAngle.apply(this, argv) - halfPi$1;
  4412. if (!context) context = buffer = path();
  4413. context.moveTo(sx0, sy0);
  4414. context.arc(0, 0, sr, sa0, sa1);
  4415. if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
  4416. context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
  4417. context.arc(0, 0, tr, ta0, ta1);
  4418. }
  4419. context.quadraticCurveTo(0, 0, sx0, sy0);
  4420. context.closePath();
  4421. if (buffer) return context = null, buffer + "" || null;
  4422. }
  4423. ribbon.radius = function(_) {
  4424. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
  4425. };
  4426. ribbon.startAngle = function(_) {
  4427. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
  4428. };
  4429. ribbon.endAngle = function(_) {
  4430. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
  4431. };
  4432. ribbon.source = function(_) {
  4433. return arguments.length ? (source = _, ribbon) : source;
  4434. };
  4435. ribbon.target = function(_) {
  4436. return arguments.length ? (target = _, ribbon) : target;
  4437. };
  4438. ribbon.context = function(_) {
  4439. return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
  4440. };
  4441. return ribbon;
  4442. }
  4443. var prefix = "$";
  4444. function Map() {}
  4445. Map.prototype = map$1.prototype = {
  4446. constructor: Map,
  4447. has: function(key) {
  4448. return (prefix + key) in this;
  4449. },
  4450. get: function(key) {
  4451. return this[prefix + key];
  4452. },
  4453. set: function(key, value) {
  4454. this[prefix + key] = value;
  4455. return this;
  4456. },
  4457. remove: function(key) {
  4458. var property = prefix + key;
  4459. return property in this && delete this[property];
  4460. },
  4461. clear: function() {
  4462. for (var property in this) if (property[0] === prefix) delete this[property];
  4463. },
  4464. keys: function() {
  4465. var keys = [];
  4466. for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
  4467. return keys;
  4468. },
  4469. values: function() {
  4470. var values = [];
  4471. for (var property in this) if (property[0] === prefix) values.push(this[property]);
  4472. return values;
  4473. },
  4474. entries: function() {
  4475. var entries = [];
  4476. for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
  4477. return entries;
  4478. },
  4479. size: function() {
  4480. var size = 0;
  4481. for (var property in this) if (property[0] === prefix) ++size;
  4482. return size;
  4483. },
  4484. empty: function() {
  4485. for (var property in this) if (property[0] === prefix) return false;
  4486. return true;
  4487. },
  4488. each: function(f) {
  4489. for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
  4490. }
  4491. };
  4492. function map$1(object, f) {
  4493. var map = new Map;
  4494. // Copy constructor.
  4495. if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
  4496. // Index array by numeric index or specified key function.
  4497. else if (Array.isArray(object)) {
  4498. var i = -1,
  4499. n = object.length,
  4500. o;
  4501. if (f == null) while (++i < n) map.set(i, object[i]);
  4502. else while (++i < n) map.set(f(o = object[i], i, object), o);
  4503. }
  4504. // Convert object to map.
  4505. else if (object) for (var key in object) map.set(key, object[key]);
  4506. return map;
  4507. }
  4508. function nest() {
  4509. var keys = [],
  4510. sortKeys = [],
  4511. sortValues,
  4512. rollup,
  4513. nest;
  4514. function apply(array, depth, createResult, setResult) {
  4515. if (depth >= keys.length) {
  4516. if (sortValues != null) array.sort(sortValues);
  4517. return rollup != null ? rollup(array) : array;
  4518. }
  4519. var i = -1,
  4520. n = array.length,
  4521. key = keys[depth++],
  4522. keyValue,
  4523. value,
  4524. valuesByKey = map$1(),
  4525. values,
  4526. result = createResult();
  4527. while (++i < n) {
  4528. if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
  4529. values.push(value);
  4530. } else {
  4531. valuesByKey.set(keyValue, [value]);
  4532. }
  4533. }
  4534. valuesByKey.each(function(values, key) {
  4535. setResult(result, key, apply(values, depth, createResult, setResult));
  4536. });
  4537. return result;
  4538. }
  4539. function entries(map, depth) {
  4540. if (++depth > keys.length) return map;
  4541. var array, sortKey = sortKeys[depth - 1];
  4542. if (rollup != null && depth >= keys.length) array = map.entries();
  4543. else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
  4544. return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
  4545. }
  4546. return nest = {
  4547. object: function(array) { return apply(array, 0, createObject, setObject); },
  4548. map: function(array) { return apply(array, 0, createMap, setMap); },
  4549. entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
  4550. key: function(d) { keys.push(d); return nest; },
  4551. sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
  4552. sortValues: function(order) { sortValues = order; return nest; },
  4553. rollup: function(f) { rollup = f; return nest; }
  4554. };
  4555. }
  4556. function createObject() {
  4557. return {};
  4558. }
  4559. function setObject(object, key, value) {
  4560. object[key] = value;
  4561. }
  4562. function createMap() {
  4563. return map$1();
  4564. }
  4565. function setMap(map, key, value) {
  4566. map.set(key, value);
  4567. }
  4568. function Set() {}
  4569. var proto = map$1.prototype;
  4570. Set.prototype = set$2.prototype = {
  4571. constructor: Set,
  4572. has: proto.has,
  4573. add: function(value) {
  4574. value += "";
  4575. this[prefix + value] = value;
  4576. return this;
  4577. },
  4578. remove: proto.remove,
  4579. clear: proto.clear,
  4580. values: proto.keys,
  4581. size: proto.size,
  4582. empty: proto.empty,
  4583. each: proto.each
  4584. };
  4585. function set$2(object, f) {
  4586. var set = new Set;
  4587. // Copy constructor.
  4588. if (object instanceof Set) object.each(function(value) { set.add(value); });
  4589. // Otherwise, assume it’s an array.
  4590. else if (object) {
  4591. var i = -1, n = object.length;
  4592. if (f == null) while (++i < n) set.add(object[i]);
  4593. else while (++i < n) set.add(f(object[i], i, object));
  4594. }
  4595. return set;
  4596. }
  4597. function keys(map) {
  4598. var keys = [];
  4599. for (var key in map) keys.push(key);
  4600. return keys;
  4601. }
  4602. function values(map) {
  4603. var values = [];
  4604. for (var key in map) values.push(map[key]);
  4605. return values;
  4606. }
  4607. function entries(map) {
  4608. var entries = [];
  4609. for (var key in map) entries.push({key: key, value: map[key]});
  4610. return entries;
  4611. }
  4612. var array$2 = Array.prototype;
  4613. var slice$3 = array$2.slice;
  4614. function ascending$2(a, b) {
  4615. return a - b;
  4616. }
  4617. function area(ring) {
  4618. var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
  4619. while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
  4620. return area;
  4621. }
  4622. function constant$6(x) {
  4623. return function() {
  4624. return x;
  4625. };
  4626. }
  4627. function contains(ring, hole) {
  4628. var i = -1, n = hole.length, c;
  4629. while (++i < n) if (c = ringContains(ring, hole[i])) return c;
  4630. return 0;
  4631. }
  4632. function ringContains(ring, point) {
  4633. var x = point[0], y = point[1], contains = -1;
  4634. for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
  4635. var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
  4636. if (segmentContains(pi, pj, point)) return 0;
  4637. if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
  4638. }
  4639. return contains;
  4640. }
  4641. function segmentContains(a, b, c) {
  4642. var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
  4643. }
  4644. function collinear(a, b, c) {
  4645. return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
  4646. }
  4647. function within(p, q, r) {
  4648. return p <= q && q <= r || r <= q && q <= p;
  4649. }
  4650. function noop$1() {}
  4651. var cases = [
  4652. [],
  4653. [[[1.0, 1.5], [0.5, 1.0]]],
  4654. [[[1.5, 1.0], [1.0, 1.5]]],
  4655. [[[1.5, 1.0], [0.5, 1.0]]],
  4656. [[[1.0, 0.5], [1.5, 1.0]]],
  4657. [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
  4658. [[[1.0, 0.5], [1.0, 1.5]]],
  4659. [[[1.0, 0.5], [0.5, 1.0]]],
  4660. [[[0.5, 1.0], [1.0, 0.5]]],
  4661. [[[1.0, 1.5], [1.0, 0.5]]],
  4662. [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
  4663. [[[1.5, 1.0], [1.0, 0.5]]],
  4664. [[[0.5, 1.0], [1.5, 1.0]]],
  4665. [[[1.0, 1.5], [1.5, 1.0]]],
  4666. [[[0.5, 1.0], [1.0, 1.5]]],
  4667. []
  4668. ];
  4669. function contours() {
  4670. var dx = 1,
  4671. dy = 1,
  4672. threshold = thresholdSturges,
  4673. smooth = smoothLinear;
  4674. function contours(values) {
  4675. var tz = threshold(values);
  4676. // Convert number of thresholds into uniform thresholds.
  4677. if (!Array.isArray(tz)) {
  4678. var domain = extent(values), start = domain[0], stop = domain[1];
  4679. tz = tickStep(start, stop, tz);
  4680. tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
  4681. } else {
  4682. tz = tz.slice().sort(ascending$2);
  4683. }
  4684. return tz.map(function(value) {
  4685. return contour(values, value);
  4686. });
  4687. }
  4688. // Accumulate, smooth contour rings, assign holes to exterior rings.
  4689. // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
  4690. function contour(values, value) {
  4691. var polygons = [],
  4692. holes = [];
  4693. isorings(values, value, function(ring) {
  4694. smooth(ring, values, value);
  4695. if (area(ring) > 0) polygons.push([ring]);
  4696. else holes.push(ring);
  4697. });
  4698. holes.forEach(function(hole) {
  4699. for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
  4700. if (contains((polygon = polygons[i])[0], hole) !== -1) {
  4701. polygon.push(hole);
  4702. return;
  4703. }
  4704. }
  4705. });
  4706. return {
  4707. type: "MultiPolygon",
  4708. value: value,
  4709. coordinates: polygons
  4710. };
  4711. }
  4712. // Marching squares with isolines stitched into rings.
  4713. // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
  4714. function isorings(values, value, callback) {
  4715. var fragmentByStart = new Array,
  4716. fragmentByEnd = new Array,
  4717. x, y, t0, t1, t2, t3;
  4718. // Special case for the first row (y = -1, t2 = t3 = 0).
  4719. x = y = -1;
  4720. t1 = values[0] >= value;
  4721. cases[t1 << 1].forEach(stitch);
  4722. while (++x < dx - 1) {
  4723. t0 = t1, t1 = values[x + 1] >= value;
  4724. cases[t0 | t1 << 1].forEach(stitch);
  4725. }
  4726. cases[t1 << 0].forEach(stitch);
  4727. // General case for the intermediate rows.
  4728. while (++y < dy - 1) {
  4729. x = -1;
  4730. t1 = values[y * dx + dx] >= value;
  4731. t2 = values[y * dx] >= value;
  4732. cases[t1 << 1 | t2 << 2].forEach(stitch);
  4733. while (++x < dx - 1) {
  4734. t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
  4735. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4736. cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
  4737. }
  4738. cases[t1 | t2 << 3].forEach(stitch);
  4739. }
  4740. // Special case for the last row (y = dy - 1, t0 = t1 = 0).
  4741. x = -1;
  4742. t2 = values[y * dx] >= value;
  4743. cases[t2 << 2].forEach(stitch);
  4744. while (++x < dx - 1) {
  4745. t3 = t2, t2 = values[y * dx + x + 1] >= value;
  4746. cases[t2 << 2 | t3 << 3].forEach(stitch);
  4747. }
  4748. cases[t2 << 3].forEach(stitch);
  4749. function stitch(line) {
  4750. var start = [line[0][0] + x, line[0][1] + y],
  4751. end = [line[1][0] + x, line[1][1] + y],
  4752. startIndex = index(start),
  4753. endIndex = index(end),
  4754. f, g;
  4755. if (f = fragmentByEnd[startIndex]) {
  4756. if (g = fragmentByStart[endIndex]) {
  4757. delete fragmentByEnd[f.end];
  4758. delete fragmentByStart[g.start];
  4759. if (f === g) {
  4760. f.ring.push(end);
  4761. callback(f.ring);
  4762. } else {
  4763. fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
  4764. }
  4765. } else {
  4766. delete fragmentByEnd[f.end];
  4767. f.ring.push(end);
  4768. fragmentByEnd[f.end = endIndex] = f;
  4769. }
  4770. } else if (f = fragmentByStart[endIndex]) {
  4771. if (g = fragmentByEnd[startIndex]) {
  4772. delete fragmentByStart[f.start];
  4773. delete fragmentByEnd[g.end];
  4774. if (f === g) {
  4775. f.ring.push(end);
  4776. callback(f.ring);
  4777. } else {
  4778. fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
  4779. }
  4780. } else {
  4781. delete fragmentByStart[f.start];
  4782. f.ring.unshift(start);
  4783. fragmentByStart[f.start = startIndex] = f;
  4784. }
  4785. } else {
  4786. fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
  4787. }
  4788. }
  4789. }
  4790. function index(point) {
  4791. return point[0] * 2 + point[1] * (dx + 1) * 4;
  4792. }
  4793. function smoothLinear(ring, values, value) {
  4794. ring.forEach(function(point) {
  4795. var x = point[0],
  4796. y = point[1],
  4797. xt = x | 0,
  4798. yt = y | 0,
  4799. v0,
  4800. v1 = values[yt * dx + xt];
  4801. if (x > 0 && x < dx && xt === x) {
  4802. v0 = values[yt * dx + xt - 1];
  4803. point[0] = x + (value - v0) / (v1 - v0) - 0.5;
  4804. }
  4805. if (y > 0 && y < dy && yt === y) {
  4806. v0 = values[(yt - 1) * dx + xt];
  4807. point[1] = y + (value - v0) / (v1 - v0) - 0.5;
  4808. }
  4809. });
  4810. }
  4811. contours.contour = contour;
  4812. contours.size = function(_) {
  4813. if (!arguments.length) return [dx, dy];
  4814. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4815. if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
  4816. return dx = _0, dy = _1, contours;
  4817. };
  4818. contours.thresholds = function(_) {
  4819. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold;
  4820. };
  4821. contours.smooth = function(_) {
  4822. return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
  4823. };
  4824. return contours;
  4825. }
  4826. // TODO Optimize edge cases.
  4827. // TODO Optimize index calculation.
  4828. // TODO Optimize arguments.
  4829. function blurX(source, target, r) {
  4830. var n = source.width,
  4831. m = source.height,
  4832. w = (r << 1) + 1;
  4833. for (var j = 0; j < m; ++j) {
  4834. for (var i = 0, sr = 0; i < n + r; ++i) {
  4835. if (i < n) {
  4836. sr += source.data[i + j * n];
  4837. }
  4838. if (i >= r) {
  4839. if (i >= w) {
  4840. sr -= source.data[i - w + j * n];
  4841. }
  4842. target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
  4843. }
  4844. }
  4845. }
  4846. }
  4847. // TODO Optimize edge cases.
  4848. // TODO Optimize index calculation.
  4849. // TODO Optimize arguments.
  4850. function blurY(source, target, r) {
  4851. var n = source.width,
  4852. m = source.height,
  4853. w = (r << 1) + 1;
  4854. for (var i = 0; i < n; ++i) {
  4855. for (var j = 0, sr = 0; j < m + r; ++j) {
  4856. if (j < m) {
  4857. sr += source.data[i + j * n];
  4858. }
  4859. if (j >= r) {
  4860. if (j >= w) {
  4861. sr -= source.data[i + (j - w) * n];
  4862. }
  4863. target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
  4864. }
  4865. }
  4866. }
  4867. }
  4868. function defaultX(d) {
  4869. return d[0];
  4870. }
  4871. function defaultY(d) {
  4872. return d[1];
  4873. }
  4874. function defaultWeight() {
  4875. return 1;
  4876. }
  4877. function density() {
  4878. var x = defaultX,
  4879. y = defaultY,
  4880. weight = defaultWeight,
  4881. dx = 960,
  4882. dy = 500,
  4883. r = 20, // blur radius
  4884. k = 2, // log2(grid cell size)
  4885. o = r * 3, // grid offset, to pad for blur
  4886. n = (dx + o * 2) >> k, // grid width
  4887. m = (dy + o * 2) >> k, // grid height
  4888. threshold = constant$6(20);
  4889. function density(data) {
  4890. var values0 = new Float32Array(n * m),
  4891. values1 = new Float32Array(n * m);
  4892. data.forEach(function(d, i, data) {
  4893. var xi = (+x(d, i, data) + o) >> k,
  4894. yi = (+y(d, i, data) + o) >> k,
  4895. wi = +weight(d, i, data);
  4896. if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
  4897. values0[xi + yi * n] += wi;
  4898. }
  4899. });
  4900. // TODO Optimize.
  4901. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4902. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4903. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4904. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4905. blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
  4906. blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
  4907. var tz = threshold(values0);
  4908. // Convert number of thresholds into uniform thresholds.
  4909. if (!Array.isArray(tz)) {
  4910. var stop = max(values0);
  4911. tz = tickStep(0, stop, tz);
  4912. tz = sequence(0, Math.floor(stop / tz) * tz, tz);
  4913. tz.shift();
  4914. }
  4915. return contours()
  4916. .thresholds(tz)
  4917. .size([n, m])
  4918. (values0)
  4919. .map(transform);
  4920. }
  4921. function transform(geometry) {
  4922. geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
  4923. geometry.coordinates.forEach(transformPolygon);
  4924. return geometry;
  4925. }
  4926. function transformPolygon(coordinates) {
  4927. coordinates.forEach(transformRing);
  4928. }
  4929. function transformRing(coordinates) {
  4930. coordinates.forEach(transformPoint);
  4931. }
  4932. // TODO Optimize.
  4933. function transformPoint(coordinates) {
  4934. coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
  4935. coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
  4936. }
  4937. function resize() {
  4938. o = r * 3;
  4939. n = (dx + o * 2) >> k;
  4940. m = (dy + o * 2) >> k;
  4941. return density;
  4942. }
  4943. density.x = function(_) {
  4944. return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
  4945. };
  4946. density.y = function(_) {
  4947. return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
  4948. };
  4949. density.weight = function(_) {
  4950. return arguments.length ? (weight = typeof _ === "function" ? _ : constant$6(+_), density) : weight;
  4951. };
  4952. density.size = function(_) {
  4953. if (!arguments.length) return [dx, dy];
  4954. var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
  4955. if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
  4956. return dx = _0, dy = _1, resize();
  4957. };
  4958. density.cellSize = function(_) {
  4959. if (!arguments.length) return 1 << k;
  4960. if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
  4961. return k = Math.floor(Math.log(_) / Math.LN2), resize();
  4962. };
  4963. density.thresholds = function(_) {
  4964. return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold;
  4965. };
  4966. density.bandwidth = function(_) {
  4967. if (!arguments.length) return Math.sqrt(r * (r + 1));
  4968. if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
  4969. return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
  4970. };
  4971. return density;
  4972. }
  4973. var EOL = {},
  4974. EOF = {},
  4975. QUOTE = 34,
  4976. NEWLINE = 10,
  4977. RETURN = 13;
  4978. function objectConverter(columns) {
  4979. return new Function("d", "return {" + columns.map(function(name, i) {
  4980. return JSON.stringify(name) + ": d[" + i + "]";
  4981. }).join(",") + "}");
  4982. }
  4983. function customConverter(columns, f) {
  4984. var object = objectConverter(columns);
  4985. return function(row, i) {
  4986. return f(object(row), i, columns);
  4987. };
  4988. }
  4989. // Compute unique columns in order of discovery.
  4990. function inferColumns(rows) {
  4991. var columnSet = Object.create(null),
  4992. columns = [];
  4993. rows.forEach(function(row) {
  4994. for (var column in row) {
  4995. if (!(column in columnSet)) {
  4996. columns.push(columnSet[column] = column);
  4997. }
  4998. }
  4999. });
  5000. return columns;
  5001. }
  5002. function pad(value, width) {
  5003. var s = value + "", length = s.length;
  5004. return length < width ? new Array(width - length + 1).join(0) + s : s;
  5005. }
  5006. function formatYear(year) {
  5007. return year < 0 ? "-" + pad(-year, 6)
  5008. : year > 9999 ? "+" + pad(year, 6)
  5009. : pad(year, 4);
  5010. }
  5011. function formatDate(date) {
  5012. var hours = date.getUTCHours(),
  5013. minutes = date.getUTCMinutes(),
  5014. seconds = date.getUTCSeconds(),
  5015. milliseconds = date.getUTCMilliseconds();
  5016. return isNaN(date) ? "Invalid Date"
  5017. : formatYear(date.getUTCFullYear()) + "-" + pad(date.getUTCMonth() + 1, 2) + "-" + pad(date.getUTCDate(), 2)
  5018. + (milliseconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "." + pad(milliseconds, 3) + "Z"
  5019. : seconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "Z"
  5020. : minutes || hours ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + "Z"
  5021. : "");
  5022. }
  5023. function dsvFormat(delimiter) {
  5024. var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
  5025. DELIMITER = delimiter.charCodeAt(0);
  5026. function parse(text, f) {
  5027. var convert, columns, rows = parseRows(text, function(row, i) {
  5028. if (convert) return convert(row, i - 1);
  5029. columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
  5030. });
  5031. rows.columns = columns || [];
  5032. return rows;
  5033. }
  5034. function parseRows(text, f) {
  5035. var rows = [], // output rows
  5036. N = text.length,
  5037. I = 0, // current character index
  5038. n = 0, // current line number
  5039. t, // current token
  5040. eof = N <= 0, // current token followed by EOF?
  5041. eol = false; // current token followed by EOL?
  5042. // Strip the trailing newline.
  5043. if (text.charCodeAt(N - 1) === NEWLINE) --N;
  5044. if (text.charCodeAt(N - 1) === RETURN) --N;
  5045. function token() {
  5046. if (eof) return EOF;
  5047. if (eol) return eol = false, EOL;
  5048. // Unescape quotes.
  5049. var i, j = I, c;
  5050. if (text.charCodeAt(j) === QUOTE) {
  5051. while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
  5052. if ((i = I) >= N) eof = true;
  5053. else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
  5054. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  5055. return text.slice(j + 1, i - 1).replace(/""/g, "\"");
  5056. }
  5057. // Find next delimiter or newline.
  5058. while (I < N) {
  5059. if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
  5060. else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
  5061. else if (c !== DELIMITER) continue;
  5062. return text.slice(j, i);
  5063. }
  5064. // Return last token before EOF.
  5065. return eof = true, text.slice(j, N);
  5066. }
  5067. while ((t = token()) !== EOF) {
  5068. var row = [];
  5069. while (t !== EOL && t !== EOF) row.push(t), t = token();
  5070. if (f && (row = f(row, n++)) == null) continue;
  5071. rows.push(row);
  5072. }
  5073. return rows;
  5074. }
  5075. function preformatBody(rows, columns) {
  5076. return rows.map(function(row) {
  5077. return columns.map(function(column) {
  5078. return formatValue(row[column]);
  5079. }).join(delimiter);
  5080. });
  5081. }
  5082. function format(rows, columns) {
  5083. if (columns == null) columns = inferColumns(rows);
  5084. return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
  5085. }
  5086. function formatBody(rows, columns) {
  5087. if (columns == null) columns = inferColumns(rows);
  5088. return preformatBody(rows, columns).join("\n");
  5089. }
  5090. function formatRows(rows) {
  5091. return rows.map(formatRow).join("\n");
  5092. }
  5093. function formatRow(row) {
  5094. return row.map(formatValue).join(delimiter);
  5095. }
  5096. function formatValue(value) {
  5097. return value == null ? ""
  5098. : value instanceof Date ? formatDate(value)
  5099. : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
  5100. : value;
  5101. }
  5102. return {
  5103. parse: parse,
  5104. parseRows: parseRows,
  5105. format: format,
  5106. formatBody: formatBody,
  5107. formatRows: formatRows
  5108. };
  5109. }
  5110. var csv = dsvFormat(",");
  5111. var csvParse = csv.parse;
  5112. var csvParseRows = csv.parseRows;
  5113. var csvFormat = csv.format;
  5114. var csvFormatBody = csv.formatBody;
  5115. var csvFormatRows = csv.formatRows;
  5116. var tsv = dsvFormat("\t");
  5117. var tsvParse = tsv.parse;
  5118. var tsvParseRows = tsv.parseRows;
  5119. var tsvFormat = tsv.format;
  5120. var tsvFormatBody = tsv.formatBody;
  5121. var tsvFormatRows = tsv.formatRows;
  5122. function autoType(object) {
  5123. for (var key in object) {
  5124. var value = object[key].trim(), number;
  5125. if (!value) value = null;
  5126. else if (value === "true") value = true;
  5127. else if (value === "false") value = false;
  5128. else if (value === "NaN") value = NaN;
  5129. else if (!isNaN(number = +value)) value = number;
  5130. else if (/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/.test(value)) value = new Date(value);
  5131. else continue;
  5132. object[key] = value;
  5133. }
  5134. return object;
  5135. }
  5136. function responseBlob(response) {
  5137. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5138. return response.blob();
  5139. }
  5140. function blob(input, init) {
  5141. return fetch(input, init).then(responseBlob);
  5142. }
  5143. function responseArrayBuffer(response) {
  5144. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5145. return response.arrayBuffer();
  5146. }
  5147. function buffer(input, init) {
  5148. return fetch(input, init).then(responseArrayBuffer);
  5149. }
  5150. function responseText(response) {
  5151. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5152. return response.text();
  5153. }
  5154. function text(input, init) {
  5155. return fetch(input, init).then(responseText);
  5156. }
  5157. function dsvParse(parse) {
  5158. return function(input, init, row) {
  5159. if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
  5160. return text(input, init).then(function(response) {
  5161. return parse(response, row);
  5162. });
  5163. };
  5164. }
  5165. function dsv(delimiter, input, init, row) {
  5166. if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
  5167. var format = dsvFormat(delimiter);
  5168. return text(input, init).then(function(response) {
  5169. return format.parse(response, row);
  5170. });
  5171. }
  5172. var csv$1 = dsvParse(csvParse);
  5173. var tsv$1 = dsvParse(tsvParse);
  5174. function image(input, init) {
  5175. return new Promise(function(resolve, reject) {
  5176. var image = new Image;
  5177. for (var key in init) image[key] = init[key];
  5178. image.onerror = reject;
  5179. image.onload = function() { resolve(image); };
  5180. image.src = input;
  5181. });
  5182. }
  5183. function responseJson(response) {
  5184. if (!response.ok) throw new Error(response.status + " " + response.statusText);
  5185. return response.json();
  5186. }
  5187. function json(input, init) {
  5188. return fetch(input, init).then(responseJson);
  5189. }
  5190. function parser(type) {
  5191. return function(input, init) {
  5192. return text(input, init).then(function(text) {
  5193. return (new DOMParser).parseFromString(text, type);
  5194. });
  5195. };
  5196. }
  5197. var xml = parser("application/xml");
  5198. var html = parser("text/html");
  5199. var svg = parser("image/svg+xml");
  5200. function center$1(x, y) {
  5201. var nodes;
  5202. if (x == null) x = 0;
  5203. if (y == null) y = 0;
  5204. function force() {
  5205. var i,
  5206. n = nodes.length,
  5207. node,
  5208. sx = 0,
  5209. sy = 0;
  5210. for (i = 0; i < n; ++i) {
  5211. node = nodes[i], sx += node.x, sy += node.y;
  5212. }
  5213. for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
  5214. node = nodes[i], node.x -= sx, node.y -= sy;
  5215. }
  5216. }
  5217. force.initialize = function(_) {
  5218. nodes = _;
  5219. };
  5220. force.x = function(_) {
  5221. return arguments.length ? (x = +_, force) : x;
  5222. };
  5223. force.y = function(_) {
  5224. return arguments.length ? (y = +_, force) : y;
  5225. };
  5226. return force;
  5227. }
  5228. function constant$7(x) {
  5229. return function() {
  5230. return x;
  5231. };
  5232. }
  5233. function jiggle() {
  5234. return (Math.random() - 0.5) * 1e-6;
  5235. }
  5236. function tree_add(d) {
  5237. var x = +this._x.call(null, d),
  5238. y = +this._y.call(null, d);
  5239. return add(this.cover(x, y), x, y, d);
  5240. }
  5241. function add(tree, x, y, d) {
  5242. if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
  5243. var parent,
  5244. node = tree._root,
  5245. leaf = {data: d},
  5246. x0 = tree._x0,
  5247. y0 = tree._y0,
  5248. x1 = tree._x1,
  5249. y1 = tree._y1,
  5250. xm,
  5251. ym,
  5252. xp,
  5253. yp,
  5254. right,
  5255. bottom,
  5256. i,
  5257. j;
  5258. // If the tree is empty, initialize the root as a leaf.
  5259. if (!node) return tree._root = leaf, tree;
  5260. // Find the existing leaf for the new point, or add it.
  5261. while (node.length) {
  5262. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5263. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5264. if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
  5265. }
  5266. // Is the new point is exactly coincident with the existing point?
  5267. xp = +tree._x.call(null, node.data);
  5268. yp = +tree._y.call(null, node.data);
  5269. if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
  5270. // Otherwise, split the leaf node until the old and new point are separated.
  5271. do {
  5272. parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
  5273. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5274. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5275. } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
  5276. return parent[j] = node, parent[i] = leaf, tree;
  5277. }
  5278. function addAll(data) {
  5279. var d, i, n = data.length,
  5280. x,
  5281. y,
  5282. xz = new Array(n),
  5283. yz = new Array(n),
  5284. x0 = Infinity,
  5285. y0 = Infinity,
  5286. x1 = -Infinity,
  5287. y1 = -Infinity;
  5288. // Compute the points and their extent.
  5289. for (i = 0; i < n; ++i) {
  5290. if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
  5291. xz[i] = x;
  5292. yz[i] = y;
  5293. if (x < x0) x0 = x;
  5294. if (x > x1) x1 = x;
  5295. if (y < y0) y0 = y;
  5296. if (y > y1) y1 = y;
  5297. }
  5298. // If there were no (valid) points, abort.
  5299. if (x0 > x1 || y0 > y1) return this;
  5300. // Expand the tree to cover the new points.
  5301. this.cover(x0, y0).cover(x1, y1);
  5302. // Add the new points.
  5303. for (i = 0; i < n; ++i) {
  5304. add(this, xz[i], yz[i], data[i]);
  5305. }
  5306. return this;
  5307. }
  5308. function tree_cover(x, y) {
  5309. if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
  5310. var x0 = this._x0,
  5311. y0 = this._y0,
  5312. x1 = this._x1,
  5313. y1 = this._y1;
  5314. // If the quadtree has no extent, initialize them.
  5315. // Integer extent are necessary so that if we later double the extent,
  5316. // the existing quadrant boundaries don’t change due to floating point error!
  5317. if (isNaN(x0)) {
  5318. x1 = (x0 = Math.floor(x)) + 1;
  5319. y1 = (y0 = Math.floor(y)) + 1;
  5320. }
  5321. // Otherwise, double repeatedly to cover.
  5322. else {
  5323. var z = x1 - x0,
  5324. node = this._root,
  5325. parent,
  5326. i;
  5327. while (x0 > x || x >= x1 || y0 > y || y >= y1) {
  5328. i = (y < y0) << 1 | (x < x0);
  5329. parent = new Array(4), parent[i] = node, node = parent, z *= 2;
  5330. switch (i) {
  5331. case 0: x1 = x0 + z, y1 = y0 + z; break;
  5332. case 1: x0 = x1 - z, y1 = y0 + z; break;
  5333. case 2: x1 = x0 + z, y0 = y1 - z; break;
  5334. case 3: x0 = x1 - z, y0 = y1 - z; break;
  5335. }
  5336. }
  5337. if (this._root && this._root.length) this._root = node;
  5338. }
  5339. this._x0 = x0;
  5340. this._y0 = y0;
  5341. this._x1 = x1;
  5342. this._y1 = y1;
  5343. return this;
  5344. }
  5345. function tree_data() {
  5346. var data = [];
  5347. this.visit(function(node) {
  5348. if (!node.length) do data.push(node.data); while (node = node.next)
  5349. });
  5350. return data;
  5351. }
  5352. function tree_extent(_) {
  5353. return arguments.length
  5354. ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
  5355. : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
  5356. }
  5357. function Quad(node, x0, y0, x1, y1) {
  5358. this.node = node;
  5359. this.x0 = x0;
  5360. this.y0 = y0;
  5361. this.x1 = x1;
  5362. this.y1 = y1;
  5363. }
  5364. function tree_find(x, y, radius) {
  5365. var data,
  5366. x0 = this._x0,
  5367. y0 = this._y0,
  5368. x1,
  5369. y1,
  5370. x2,
  5371. y2,
  5372. x3 = this._x1,
  5373. y3 = this._y1,
  5374. quads = [],
  5375. node = this._root,
  5376. q,
  5377. i;
  5378. if (node) quads.push(new Quad(node, x0, y0, x3, y3));
  5379. if (radius == null) radius = Infinity;
  5380. else {
  5381. x0 = x - radius, y0 = y - radius;
  5382. x3 = x + radius, y3 = y + radius;
  5383. radius *= radius;
  5384. }
  5385. while (q = quads.pop()) {
  5386. // Stop searching if this quadrant can’t contain a closer node.
  5387. if (!(node = q.node)
  5388. || (x1 = q.x0) > x3
  5389. || (y1 = q.y0) > y3
  5390. || (x2 = q.x1) < x0
  5391. || (y2 = q.y1) < y0) continue;
  5392. // Bisect the current quadrant.
  5393. if (node.length) {
  5394. var xm = (x1 + x2) / 2,
  5395. ym = (y1 + y2) / 2;
  5396. quads.push(
  5397. new Quad(node[3], xm, ym, x2, y2),
  5398. new Quad(node[2], x1, ym, xm, y2),
  5399. new Quad(node[1], xm, y1, x2, ym),
  5400. new Quad(node[0], x1, y1, xm, ym)
  5401. );
  5402. // Visit the closest quadrant first.
  5403. if (i = (y >= ym) << 1 | (x >= xm)) {
  5404. q = quads[quads.length - 1];
  5405. quads[quads.length - 1] = quads[quads.length - 1 - i];
  5406. quads[quads.length - 1 - i] = q;
  5407. }
  5408. }
  5409. // Visit this point. (Visiting coincident points isn’t necessary!)
  5410. else {
  5411. var dx = x - +this._x.call(null, node.data),
  5412. dy = y - +this._y.call(null, node.data),
  5413. d2 = dx * dx + dy * dy;
  5414. if (d2 < radius) {
  5415. var d = Math.sqrt(radius = d2);
  5416. x0 = x - d, y0 = y - d;
  5417. x3 = x + d, y3 = y + d;
  5418. data = node.data;
  5419. }
  5420. }
  5421. }
  5422. return data;
  5423. }
  5424. function tree_remove(d) {
  5425. if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
  5426. var parent,
  5427. node = this._root,
  5428. retainer,
  5429. previous,
  5430. next,
  5431. x0 = this._x0,
  5432. y0 = this._y0,
  5433. x1 = this._x1,
  5434. y1 = this._y1,
  5435. x,
  5436. y,
  5437. xm,
  5438. ym,
  5439. right,
  5440. bottom,
  5441. i,
  5442. j;
  5443. // If the tree is empty, initialize the root as a leaf.
  5444. if (!node) return this;
  5445. // Find the leaf node for the point.
  5446. // While descending, also retain the deepest parent with a non-removed sibling.
  5447. if (node.length) while (true) {
  5448. if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
  5449. if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
  5450. if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
  5451. if (!node.length) break;
  5452. if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
  5453. }
  5454. // Find the point to remove.
  5455. while (node.data !== d) if (!(previous = node, node = node.next)) return this;
  5456. if (next = node.next) delete node.next;
  5457. // If there are multiple coincident points, remove just the point.
  5458. if (previous) return (next ? previous.next = next : delete previous.next), this;
  5459. // If this is the root point, remove it.
  5460. if (!parent) return this._root = next, this;
  5461. // Remove this leaf.
  5462. next ? parent[i] = next : delete parent[i];
  5463. // If the parent now contains exactly one leaf, collapse superfluous parents.
  5464. if ((node = parent[0] || parent[1] || parent[2] || parent[3])
  5465. && node === (parent[3] || parent[2] || parent[1] || parent[0])
  5466. && !node.length) {
  5467. if (retainer) retainer[j] = node;
  5468. else this._root = node;
  5469. }
  5470. return this;
  5471. }
  5472. function removeAll(data) {
  5473. for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
  5474. return this;
  5475. }
  5476. function tree_root() {
  5477. return this._root;
  5478. }
  5479. function tree_size() {
  5480. var size = 0;
  5481. this.visit(function(node) {
  5482. if (!node.length) do ++size; while (node = node.next)
  5483. });
  5484. return size;
  5485. }
  5486. function tree_visit(callback) {
  5487. var quads = [], q, node = this._root, child, x0, y0, x1, y1;
  5488. if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
  5489. while (q = quads.pop()) {
  5490. if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
  5491. var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5492. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5493. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5494. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5495. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5496. }
  5497. }
  5498. return this;
  5499. }
  5500. function tree_visitAfter(callback) {
  5501. var quads = [], next = [], q;
  5502. if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
  5503. while (q = quads.pop()) {
  5504. var node = q.node;
  5505. if (node.length) {
  5506. var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
  5507. if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
  5508. if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
  5509. if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
  5510. if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
  5511. }
  5512. next.push(q);
  5513. }
  5514. while (q = next.pop()) {
  5515. callback(q.node, q.x0, q.y0, q.x1, q.y1);
  5516. }
  5517. return this;
  5518. }
  5519. function defaultX$1(d) {
  5520. return d[0];
  5521. }
  5522. function tree_x(_) {
  5523. return arguments.length ? (this._x = _, this) : this._x;
  5524. }
  5525. function defaultY$1(d) {
  5526. return d[1];
  5527. }
  5528. function tree_y(_) {
  5529. return arguments.length ? (this._y = _, this) : this._y;
  5530. }
  5531. function quadtree(nodes, x, y) {
  5532. var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
  5533. return nodes == null ? tree : tree.addAll(nodes);
  5534. }
  5535. function Quadtree(x, y, x0, y0, x1, y1) {
  5536. this._x = x;
  5537. this._y = y;
  5538. this._x0 = x0;
  5539. this._y0 = y0;
  5540. this._x1 = x1;
  5541. this._y1 = y1;
  5542. this._root = undefined;
  5543. }
  5544. function leaf_copy(leaf) {
  5545. var copy = {data: leaf.data}, next = copy;
  5546. while (leaf = leaf.next) next = next.next = {data: leaf.data};
  5547. return copy;
  5548. }
  5549. var treeProto = quadtree.prototype = Quadtree.prototype;
  5550. treeProto.copy = function() {
  5551. var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
  5552. node = this._root,
  5553. nodes,
  5554. child;
  5555. if (!node) return copy;
  5556. if (!node.length) return copy._root = leaf_copy(node), copy;
  5557. nodes = [{source: node, target: copy._root = new Array(4)}];
  5558. while (node = nodes.pop()) {
  5559. for (var i = 0; i < 4; ++i) {
  5560. if (child = node.source[i]) {
  5561. if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
  5562. else node.target[i] = leaf_copy(child);
  5563. }
  5564. }
  5565. }
  5566. return copy;
  5567. };
  5568. treeProto.add = tree_add;
  5569. treeProto.addAll = addAll;
  5570. treeProto.cover = tree_cover;
  5571. treeProto.data = tree_data;
  5572. treeProto.extent = tree_extent;
  5573. treeProto.find = tree_find;
  5574. treeProto.remove = tree_remove;
  5575. treeProto.removeAll = removeAll;
  5576. treeProto.root = tree_root;
  5577. treeProto.size = tree_size;
  5578. treeProto.visit = tree_visit;
  5579. treeProto.visitAfter = tree_visitAfter;
  5580. treeProto.x = tree_x;
  5581. treeProto.y = tree_y;
  5582. function x(d) {
  5583. return d.x + d.vx;
  5584. }
  5585. function y(d) {
  5586. return d.y + d.vy;
  5587. }
  5588. function collide(radius) {
  5589. var nodes,
  5590. radii,
  5591. strength = 1,
  5592. iterations = 1;
  5593. if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
  5594. function force() {
  5595. var i, n = nodes.length,
  5596. tree,
  5597. node,
  5598. xi,
  5599. yi,
  5600. ri,
  5601. ri2;
  5602. for (var k = 0; k < iterations; ++k) {
  5603. tree = quadtree(nodes, x, y).visitAfter(prepare);
  5604. for (i = 0; i < n; ++i) {
  5605. node = nodes[i];
  5606. ri = radii[node.index], ri2 = ri * ri;
  5607. xi = node.x + node.vx;
  5608. yi = node.y + node.vy;
  5609. tree.visit(apply);
  5610. }
  5611. }
  5612. function apply(quad, x0, y0, x1, y1) {
  5613. var data = quad.data, rj = quad.r, r = ri + rj;
  5614. if (data) {
  5615. if (data.index > node.index) {
  5616. var x = xi - data.x - data.vx,
  5617. y = yi - data.y - data.vy,
  5618. l = x * x + y * y;
  5619. if (l < r * r) {
  5620. if (x === 0) x = jiggle(), l += x * x;
  5621. if (y === 0) y = jiggle(), l += y * y;
  5622. l = (r - (l = Math.sqrt(l))) / l * strength;
  5623. node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
  5624. node.vy += (y *= l) * r;
  5625. data.vx -= x * (r = 1 - r);
  5626. data.vy -= y * r;
  5627. }
  5628. }
  5629. return;
  5630. }
  5631. return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
  5632. }
  5633. }
  5634. function prepare(quad) {
  5635. if (quad.data) return quad.r = radii[quad.data.index];
  5636. for (var i = quad.r = 0; i < 4; ++i) {
  5637. if (quad[i] && quad[i].r > quad.r) {
  5638. quad.r = quad[i].r;
  5639. }
  5640. }
  5641. }
  5642. function initialize() {
  5643. if (!nodes) return;
  5644. var i, n = nodes.length, node;
  5645. radii = new Array(n);
  5646. for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
  5647. }
  5648. force.initialize = function(_) {
  5649. nodes = _;
  5650. initialize();
  5651. };
  5652. force.iterations = function(_) {
  5653. return arguments.length ? (iterations = +_, force) : iterations;
  5654. };
  5655. force.strength = function(_) {
  5656. return arguments.length ? (strength = +_, force) : strength;
  5657. };
  5658. force.radius = function(_) {
  5659. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  5660. };
  5661. return force;
  5662. }
  5663. function index(d) {
  5664. return d.index;
  5665. }
  5666. function find(nodeById, nodeId) {
  5667. var node = nodeById.get(nodeId);
  5668. if (!node) throw new Error("missing: " + nodeId);
  5669. return node;
  5670. }
  5671. function link(links) {
  5672. var id = index,
  5673. strength = defaultStrength,
  5674. strengths,
  5675. distance = constant$7(30),
  5676. distances,
  5677. nodes,
  5678. count,
  5679. bias,
  5680. iterations = 1;
  5681. if (links == null) links = [];
  5682. function defaultStrength(link) {
  5683. return 1 / Math.min(count[link.source.index], count[link.target.index]);
  5684. }
  5685. function force(alpha) {
  5686. for (var k = 0, n = links.length; k < iterations; ++k) {
  5687. for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
  5688. link = links[i], source = link.source, target = link.target;
  5689. x = target.x + target.vx - source.x - source.vx || jiggle();
  5690. y = target.y + target.vy - source.y - source.vy || jiggle();
  5691. l = Math.sqrt(x * x + y * y);
  5692. l = (l - distances[i]) / l * alpha * strengths[i];
  5693. x *= l, y *= l;
  5694. target.vx -= x * (b = bias[i]);
  5695. target.vy -= y * b;
  5696. source.vx += x * (b = 1 - b);
  5697. source.vy += y * b;
  5698. }
  5699. }
  5700. }
  5701. function initialize() {
  5702. if (!nodes) return;
  5703. var i,
  5704. n = nodes.length,
  5705. m = links.length,
  5706. nodeById = map$1(nodes, id),
  5707. link;
  5708. for (i = 0, count = new Array(n); i < m; ++i) {
  5709. link = links[i], link.index = i;
  5710. if (typeof link.source !== "object") link.source = find(nodeById, link.source);
  5711. if (typeof link.target !== "object") link.target = find(nodeById, link.target);
  5712. count[link.source.index] = (count[link.source.index] || 0) + 1;
  5713. count[link.target.index] = (count[link.target.index] || 0) + 1;
  5714. }
  5715. for (i = 0, bias = new Array(m); i < m; ++i) {
  5716. link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
  5717. }
  5718. strengths = new Array(m), initializeStrength();
  5719. distances = new Array(m), initializeDistance();
  5720. }
  5721. function initializeStrength() {
  5722. if (!nodes) return;
  5723. for (var i = 0, n = links.length; i < n; ++i) {
  5724. strengths[i] = +strength(links[i], i, links);
  5725. }
  5726. }
  5727. function initializeDistance() {
  5728. if (!nodes) return;
  5729. for (var i = 0, n = links.length; i < n; ++i) {
  5730. distances[i] = +distance(links[i], i, links);
  5731. }
  5732. }
  5733. force.initialize = function(_) {
  5734. nodes = _;
  5735. initialize();
  5736. };
  5737. force.links = function(_) {
  5738. return arguments.length ? (links = _, initialize(), force) : links;
  5739. };
  5740. force.id = function(_) {
  5741. return arguments.length ? (id = _, force) : id;
  5742. };
  5743. force.iterations = function(_) {
  5744. return arguments.length ? (iterations = +_, force) : iterations;
  5745. };
  5746. force.strength = function(_) {
  5747. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
  5748. };
  5749. force.distance = function(_) {
  5750. return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
  5751. };
  5752. return force;
  5753. }
  5754. function x$1(d) {
  5755. return d.x;
  5756. }
  5757. function y$1(d) {
  5758. return d.y;
  5759. }
  5760. var initialRadius = 10,
  5761. initialAngle = Math.PI * (3 - Math.sqrt(5));
  5762. function simulation(nodes) {
  5763. var simulation,
  5764. alpha = 1,
  5765. alphaMin = 0.001,
  5766. alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
  5767. alphaTarget = 0,
  5768. velocityDecay = 0.6,
  5769. forces = map$1(),
  5770. stepper = timer(step),
  5771. event = dispatch("tick", "end");
  5772. if (nodes == null) nodes = [];
  5773. function step() {
  5774. tick();
  5775. event.call("tick", simulation);
  5776. if (alpha < alphaMin) {
  5777. stepper.stop();
  5778. event.call("end", simulation);
  5779. }
  5780. }
  5781. function tick(iterations) {
  5782. var i, n = nodes.length, node;
  5783. if (iterations === undefined) iterations = 1;
  5784. for (var k = 0; k < iterations; ++k) {
  5785. alpha += (alphaTarget - alpha) * alphaDecay;
  5786. forces.each(function (force) {
  5787. force(alpha);
  5788. });
  5789. for (i = 0; i < n; ++i) {
  5790. node = nodes[i];
  5791. if (node.fx == null) node.x += node.vx *= velocityDecay;
  5792. else node.x = node.fx, node.vx = 0;
  5793. if (node.fy == null) node.y += node.vy *= velocityDecay;
  5794. else node.y = node.fy, node.vy = 0;
  5795. }
  5796. }
  5797. return simulation;
  5798. }
  5799. function initializeNodes() {
  5800. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  5801. node = nodes[i], node.index = i;
  5802. if (node.fx != null) node.x = node.fx;
  5803. if (node.fy != null) node.y = node.fy;
  5804. if (isNaN(node.x) || isNaN(node.y)) {
  5805. var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
  5806. node.x = radius * Math.cos(angle);
  5807. node.y = radius * Math.sin(angle);
  5808. }
  5809. if (isNaN(node.vx) || isNaN(node.vy)) {
  5810. node.vx = node.vy = 0;
  5811. }
  5812. }
  5813. }
  5814. function initializeForce(force) {
  5815. if (force.initialize) force.initialize(nodes);
  5816. return force;
  5817. }
  5818. initializeNodes();
  5819. return simulation = {
  5820. tick: tick,
  5821. restart: function() {
  5822. return stepper.restart(step), simulation;
  5823. },
  5824. stop: function() {
  5825. return stepper.stop(), simulation;
  5826. },
  5827. nodes: function(_) {
  5828. return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
  5829. },
  5830. alpha: function(_) {
  5831. return arguments.length ? (alpha = +_, simulation) : alpha;
  5832. },
  5833. alphaMin: function(_) {
  5834. return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
  5835. },
  5836. alphaDecay: function(_) {
  5837. return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
  5838. },
  5839. alphaTarget: function(_) {
  5840. return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
  5841. },
  5842. velocityDecay: function(_) {
  5843. return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
  5844. },
  5845. force: function(name, _) {
  5846. return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
  5847. },
  5848. find: function(x, y, radius) {
  5849. var i = 0,
  5850. n = nodes.length,
  5851. dx,
  5852. dy,
  5853. d2,
  5854. node,
  5855. closest;
  5856. if (radius == null) radius = Infinity;
  5857. else radius *= radius;
  5858. for (i = 0; i < n; ++i) {
  5859. node = nodes[i];
  5860. dx = x - node.x;
  5861. dy = y - node.y;
  5862. d2 = dx * dx + dy * dy;
  5863. if (d2 < radius) closest = node, radius = d2;
  5864. }
  5865. return closest;
  5866. },
  5867. on: function(name, _) {
  5868. return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
  5869. }
  5870. };
  5871. }
  5872. function manyBody() {
  5873. var nodes,
  5874. node,
  5875. alpha,
  5876. strength = constant$7(-30),
  5877. strengths,
  5878. distanceMin2 = 1,
  5879. distanceMax2 = Infinity,
  5880. theta2 = 0.81;
  5881. function force(_) {
  5882. var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
  5883. for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
  5884. }
  5885. function initialize() {
  5886. if (!nodes) return;
  5887. var i, n = nodes.length, node;
  5888. strengths = new Array(n);
  5889. for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
  5890. }
  5891. function accumulate(quad) {
  5892. var strength = 0, q, c, weight = 0, x, y, i;
  5893. // For internal nodes, accumulate forces from child quadrants.
  5894. if (quad.length) {
  5895. for (x = y = i = 0; i < 4; ++i) {
  5896. if ((q = quad[i]) && (c = Math.abs(q.value))) {
  5897. strength += q.value, weight += c, x += c * q.x, y += c * q.y;
  5898. }
  5899. }
  5900. quad.x = x / weight;
  5901. quad.y = y / weight;
  5902. }
  5903. // For leaf nodes, accumulate forces from coincident quadrants.
  5904. else {
  5905. q = quad;
  5906. q.x = q.data.x;
  5907. q.y = q.data.y;
  5908. do strength += strengths[q.data.index];
  5909. while (q = q.next);
  5910. }
  5911. quad.value = strength;
  5912. }
  5913. function apply(quad, x1, _, x2) {
  5914. if (!quad.value) return true;
  5915. var x = quad.x - node.x,
  5916. y = quad.y - node.y,
  5917. w = x2 - x1,
  5918. l = x * x + y * y;
  5919. // Apply the Barnes-Hut approximation if possible.
  5920. // Limit forces for very close nodes; randomize direction if coincident.
  5921. if (w * w / theta2 < l) {
  5922. if (l < distanceMax2) {
  5923. if (x === 0) x = jiggle(), l += x * x;
  5924. if (y === 0) y = jiggle(), l += y * y;
  5925. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5926. node.vx += x * quad.value * alpha / l;
  5927. node.vy += y * quad.value * alpha / l;
  5928. }
  5929. return true;
  5930. }
  5931. // Otherwise, process points directly.
  5932. else if (quad.length || l >= distanceMax2) return;
  5933. // Limit forces for very close nodes; randomize direction if coincident.
  5934. if (quad.data !== node || quad.next) {
  5935. if (x === 0) x = jiggle(), l += x * x;
  5936. if (y === 0) y = jiggle(), l += y * y;
  5937. if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
  5938. }
  5939. do if (quad.data !== node) {
  5940. w = strengths[quad.data.index] * alpha / l;
  5941. node.vx += x * w;
  5942. node.vy += y * w;
  5943. } while (quad = quad.next);
  5944. }
  5945. force.initialize = function(_) {
  5946. nodes = _;
  5947. initialize();
  5948. };
  5949. force.strength = function(_) {
  5950. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5951. };
  5952. force.distanceMin = function(_) {
  5953. return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
  5954. };
  5955. force.distanceMax = function(_) {
  5956. return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
  5957. };
  5958. force.theta = function(_) {
  5959. return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
  5960. };
  5961. return force;
  5962. }
  5963. function radial(radius, x, y) {
  5964. var nodes,
  5965. strength = constant$7(0.1),
  5966. strengths,
  5967. radiuses;
  5968. if (typeof radius !== "function") radius = constant$7(+radius);
  5969. if (x == null) x = 0;
  5970. if (y == null) y = 0;
  5971. function force(alpha) {
  5972. for (var i = 0, n = nodes.length; i < n; ++i) {
  5973. var node = nodes[i],
  5974. dx = node.x - x || 1e-6,
  5975. dy = node.y - y || 1e-6,
  5976. r = Math.sqrt(dx * dx + dy * dy),
  5977. k = (radiuses[i] - r) * strengths[i] * alpha / r;
  5978. node.vx += dx * k;
  5979. node.vy += dy * k;
  5980. }
  5981. }
  5982. function initialize() {
  5983. if (!nodes) return;
  5984. var i, n = nodes.length;
  5985. strengths = new Array(n);
  5986. radiuses = new Array(n);
  5987. for (i = 0; i < n; ++i) {
  5988. radiuses[i] = +radius(nodes[i], i, nodes);
  5989. strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
  5990. }
  5991. }
  5992. force.initialize = function(_) {
  5993. nodes = _, initialize();
  5994. };
  5995. force.strength = function(_) {
  5996. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  5997. };
  5998. force.radius = function(_) {
  5999. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
  6000. };
  6001. force.x = function(_) {
  6002. return arguments.length ? (x = +_, force) : x;
  6003. };
  6004. force.y = function(_) {
  6005. return arguments.length ? (y = +_, force) : y;
  6006. };
  6007. return force;
  6008. }
  6009. function x$2(x) {
  6010. var strength = constant$7(0.1),
  6011. nodes,
  6012. strengths,
  6013. xz;
  6014. if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
  6015. function force(alpha) {
  6016. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  6017. node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
  6018. }
  6019. }
  6020. function initialize() {
  6021. if (!nodes) return;
  6022. var i, n = nodes.length;
  6023. strengths = new Array(n);
  6024. xz = new Array(n);
  6025. for (i = 0; i < n; ++i) {
  6026. strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  6027. }
  6028. }
  6029. force.initialize = function(_) {
  6030. nodes = _;
  6031. initialize();
  6032. };
  6033. force.strength = function(_) {
  6034. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6035. };
  6036. force.x = function(_) {
  6037. return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
  6038. };
  6039. return force;
  6040. }
  6041. function y$2(y) {
  6042. var strength = constant$7(0.1),
  6043. nodes,
  6044. strengths,
  6045. yz;
  6046. if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
  6047. function force(alpha) {
  6048. for (var i = 0, n = nodes.length, node; i < n; ++i) {
  6049. node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
  6050. }
  6051. }
  6052. function initialize() {
  6053. if (!nodes) return;
  6054. var i, n = nodes.length;
  6055. strengths = new Array(n);
  6056. yz = new Array(n);
  6057. for (i = 0; i < n; ++i) {
  6058. strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
  6059. }
  6060. }
  6061. force.initialize = function(_) {
  6062. nodes = _;
  6063. initialize();
  6064. };
  6065. force.strength = function(_) {
  6066. return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
  6067. };
  6068. force.y = function(_) {
  6069. return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
  6070. };
  6071. return force;
  6072. }
  6073. // Computes the decimal coefficient and exponent of the specified number x with
  6074. // significant digits p, where x is positive and p is in [1, 21] or undefined.
  6075. // For example, formatDecimal(1.23) returns ["123", 0].
  6076. function formatDecimal(x, p) {
  6077. if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
  6078. var i, coefficient = x.slice(0, i);
  6079. // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
  6080. // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
  6081. return [
  6082. coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
  6083. +x.slice(i + 1)
  6084. ];
  6085. }
  6086. function exponent$1(x) {
  6087. return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
  6088. }
  6089. function formatGroup(grouping, thousands) {
  6090. return function(value, width) {
  6091. var i = value.length,
  6092. t = [],
  6093. j = 0,
  6094. g = grouping[0],
  6095. length = 0;
  6096. while (i > 0 && g > 0) {
  6097. if (length + g + 1 > width) g = Math.max(1, width - length);
  6098. t.push(value.substring(i -= g, i + g));
  6099. if ((length += g + 1) > width) break;
  6100. g = grouping[j = (j + 1) % grouping.length];
  6101. }
  6102. return t.reverse().join(thousands);
  6103. };
  6104. }
  6105. function formatNumerals(numerals) {
  6106. return function(value) {
  6107. return value.replace(/[0-9]/g, function(i) {
  6108. return numerals[+i];
  6109. });
  6110. };
  6111. }
  6112. // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
  6113. var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
  6114. function formatSpecifier(specifier) {
  6115. if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
  6116. var match;
  6117. return new FormatSpecifier({
  6118. fill: match[1],
  6119. align: match[2],
  6120. sign: match[3],
  6121. symbol: match[4],
  6122. zero: match[5],
  6123. width: match[6],
  6124. comma: match[7],
  6125. precision: match[8] && match[8].slice(1),
  6126. trim: match[9],
  6127. type: match[10]
  6128. });
  6129. }
  6130. formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
  6131. function FormatSpecifier(specifier) {
  6132. this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
  6133. this.align = specifier.align === undefined ? ">" : specifier.align + "";
  6134. this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
  6135. this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
  6136. this.zero = !!specifier.zero;
  6137. this.width = specifier.width === undefined ? undefined : +specifier.width;
  6138. this.comma = !!specifier.comma;
  6139. this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
  6140. this.trim = !!specifier.trim;
  6141. this.type = specifier.type === undefined ? "" : specifier.type + "";
  6142. }
  6143. FormatSpecifier.prototype.toString = function() {
  6144. return this.fill
  6145. + this.align
  6146. + this.sign
  6147. + this.symbol
  6148. + (this.zero ? "0" : "")
  6149. + (this.width === undefined ? "" : Math.max(1, this.width | 0))
  6150. + (this.comma ? "," : "")
  6151. + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
  6152. + (this.trim ? "~" : "")
  6153. + this.type;
  6154. };
  6155. // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
  6156. function formatTrim(s) {
  6157. out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
  6158. switch (s[i]) {
  6159. case ".": i0 = i1 = i; break;
  6160. case "0": if (i0 === 0) i0 = i; i1 = i; break;
  6161. default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
  6162. }
  6163. }
  6164. return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
  6165. }
  6166. var prefixExponent;
  6167. function formatPrefixAuto(x, p) {
  6168. var d = formatDecimal(x, p);
  6169. if (!d) return x + "";
  6170. var coefficient = d[0],
  6171. exponent = d[1],
  6172. i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
  6173. n = coefficient.length;
  6174. return i === n ? coefficient
  6175. : i > n ? coefficient + new Array(i - n + 1).join("0")
  6176. : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
  6177. : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
  6178. }
  6179. function formatRounded(x, p) {
  6180. var d = formatDecimal(x, p);
  6181. if (!d) return x + "";
  6182. var coefficient = d[0],
  6183. exponent = d[1];
  6184. return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
  6185. : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
  6186. : coefficient + new Array(exponent - coefficient.length + 2).join("0");
  6187. }
  6188. var formatTypes = {
  6189. "%": function(x, p) { return (x * 100).toFixed(p); },
  6190. "b": function(x) { return Math.round(x).toString(2); },
  6191. "c": function(x) { return x + ""; },
  6192. "d": function(x) { return Math.round(x).toString(10); },
  6193. "e": function(x, p) { return x.toExponential(p); },
  6194. "f": function(x, p) { return x.toFixed(p); },
  6195. "g": function(x, p) { return x.toPrecision(p); },
  6196. "o": function(x) { return Math.round(x).toString(8); },
  6197. "p": function(x, p) { return formatRounded(x * 100, p); },
  6198. "r": formatRounded,
  6199. "s": formatPrefixAuto,
  6200. "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
  6201. "x": function(x) { return Math.round(x).toString(16); }
  6202. };
  6203. function identity$3(x) {
  6204. return x;
  6205. }
  6206. var map$2 = Array.prototype.map,
  6207. prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
  6208. function formatLocale(locale) {
  6209. var group = locale.grouping === undefined || locale.thousands === undefined ? identity$3 : formatGroup(map$2.call(locale.grouping, Number), locale.thousands + ""),
  6210. currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
  6211. currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
  6212. decimal = locale.decimal === undefined ? "." : locale.decimal + "",
  6213. numerals = locale.numerals === undefined ? identity$3 : formatNumerals(map$2.call(locale.numerals, String)),
  6214. percent = locale.percent === undefined ? "%" : locale.percent + "",
  6215. minus = locale.minus === undefined ? "-" : locale.minus + "",
  6216. nan = locale.nan === undefined ? "NaN" : locale.nan + "";
  6217. function newFormat(specifier) {
  6218. specifier = formatSpecifier(specifier);
  6219. var fill = specifier.fill,
  6220. align = specifier.align,
  6221. sign = specifier.sign,
  6222. symbol = specifier.symbol,
  6223. zero = specifier.zero,
  6224. width = specifier.width,
  6225. comma = specifier.comma,
  6226. precision = specifier.precision,
  6227. trim = specifier.trim,
  6228. type = specifier.type;
  6229. // The "n" type is an alias for ",g".
  6230. if (type === "n") comma = true, type = "g";
  6231. // The "" type, and any invalid type, is an alias for ".12~g".
  6232. else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
  6233. // If zero fill is specified, padding goes after sign and before digits.
  6234. if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
  6235. // Compute the prefix and suffix.
  6236. // For SI-prefix, the suffix is lazily computed.
  6237. var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
  6238. suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
  6239. // What format function should we use?
  6240. // Is this an integer type?
  6241. // Can this type generate exponential notation?
  6242. var formatType = formatTypes[type],
  6243. maybeSuffix = /[defgprs%]/.test(type);
  6244. // Set the default precision if not specified,
  6245. // or clamp the specified precision to the supported range.
  6246. // For significant precision, it must be in [1, 21].
  6247. // For fixed precision, it must be in [0, 20].
  6248. precision = precision === undefined ? 6
  6249. : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
  6250. : Math.max(0, Math.min(20, precision));
  6251. function format(value) {
  6252. var valuePrefix = prefix,
  6253. valueSuffix = suffix,
  6254. i, n, c;
  6255. if (type === "c") {
  6256. valueSuffix = formatType(value) + valueSuffix;
  6257. value = "";
  6258. } else {
  6259. value = +value;
  6260. // Perform the initial formatting.
  6261. var valueNegative = value < 0;
  6262. value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
  6263. // Trim insignificant zeros.
  6264. if (trim) value = formatTrim(value);
  6265. // If a negative value rounds to zero during formatting, treat as positive.
  6266. if (valueNegative && +value === 0) valueNegative = false;
  6267. // Compute the prefix and suffix.
  6268. valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
  6269. valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
  6270. // Break the formatted value into the integer “value” part that can be
  6271. // grouped, and fractional or exponential “suffix” part that is not.
  6272. if (maybeSuffix) {
  6273. i = -1, n = value.length;
  6274. while (++i < n) {
  6275. if (c = value.charCodeAt(i), 48 > c || c > 57) {
  6276. valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
  6277. value = value.slice(0, i);
  6278. break;
  6279. }
  6280. }
  6281. }
  6282. }
  6283. // If the fill character is not "0", grouping is applied before padding.
  6284. if (comma && !zero) value = group(value, Infinity);
  6285. // Compute the padding.
  6286. var length = valuePrefix.length + value.length + valueSuffix.length,
  6287. padding = length < width ? new Array(width - length + 1).join(fill) : "";
  6288. // If the fill character is "0", grouping is applied after padding.
  6289. if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
  6290. // Reconstruct the final output based on the desired alignment.
  6291. switch (align) {
  6292. case "<": value = valuePrefix + value + valueSuffix + padding; break;
  6293. case "=": value = valuePrefix + padding + value + valueSuffix; break;
  6294. case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
  6295. default: value = padding + valuePrefix + value + valueSuffix; break;
  6296. }
  6297. return numerals(value);
  6298. }
  6299. format.toString = function() {
  6300. return specifier + "";
  6301. };
  6302. return format;
  6303. }
  6304. function formatPrefix(specifier, value) {
  6305. var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
  6306. e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
  6307. k = Math.pow(10, -e),
  6308. prefix = prefixes[8 + e / 3];
  6309. return function(value) {
  6310. return f(k * value) + prefix;
  6311. };
  6312. }
  6313. return {
  6314. format: newFormat,
  6315. formatPrefix: formatPrefix
  6316. };
  6317. }
  6318. var locale;
  6319. defaultLocale({
  6320. decimal: ".",
  6321. thousands: ",",
  6322. grouping: [3],
  6323. currency: ["$", ""],
  6324. minus: "-"
  6325. });
  6326. function defaultLocale(definition) {
  6327. locale = formatLocale(definition);
  6328. exports.format = locale.format;
  6329. exports.formatPrefix = locale.formatPrefix;
  6330. return locale;
  6331. }
  6332. function precisionFixed(step) {
  6333. return Math.max(0, -exponent$1(Math.abs(step)));
  6334. }
  6335. function precisionPrefix(step, value) {
  6336. return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
  6337. }
  6338. function precisionRound(step, max) {
  6339. step = Math.abs(step), max = Math.abs(max) - step;
  6340. return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
  6341. }
  6342. // Adds floating point numbers with twice the normal precision.
  6343. // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
  6344. // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
  6345. // 305–363 (1997).
  6346. // Code adapted from GeographicLib by Charles F. F. Karney,
  6347. // http://geographiclib.sourceforge.net/
  6348. function adder() {
  6349. return new Adder;
  6350. }
  6351. function Adder() {
  6352. this.reset();
  6353. }
  6354. Adder.prototype = {
  6355. constructor: Adder,
  6356. reset: function() {
  6357. this.s = // rounded value
  6358. this.t = 0; // exact error
  6359. },
  6360. add: function(y) {
  6361. add$1(temp, y, this.t);
  6362. add$1(this, temp.s, this.s);
  6363. if (this.s) this.t += temp.t;
  6364. else this.s = temp.t;
  6365. },
  6366. valueOf: function() {
  6367. return this.s;
  6368. }
  6369. };
  6370. var temp = new Adder;
  6371. function add$1(adder, a, b) {
  6372. var x = adder.s = a + b,
  6373. bv = x - a,
  6374. av = x - bv;
  6375. adder.t = (a - av) + (b - bv);
  6376. }
  6377. var epsilon$2 = 1e-6;
  6378. var epsilon2$1 = 1e-12;
  6379. var pi$3 = Math.PI;
  6380. var halfPi$2 = pi$3 / 2;
  6381. var quarterPi = pi$3 / 4;
  6382. var tau$3 = pi$3 * 2;
  6383. var degrees$1 = 180 / pi$3;
  6384. var radians = pi$3 / 180;
  6385. var abs = Math.abs;
  6386. var atan = Math.atan;
  6387. var atan2 = Math.atan2;
  6388. var cos$1 = Math.cos;
  6389. var ceil = Math.ceil;
  6390. var exp = Math.exp;
  6391. var log = Math.log;
  6392. var pow = Math.pow;
  6393. var sin$1 = Math.sin;
  6394. var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
  6395. var sqrt = Math.sqrt;
  6396. var tan = Math.tan;
  6397. function acos(x) {
  6398. return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
  6399. }
  6400. function asin(x) {
  6401. return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
  6402. }
  6403. function haversin(x) {
  6404. return (x = sin$1(x / 2)) * x;
  6405. }
  6406. function noop$2() {}
  6407. function streamGeometry(geometry, stream) {
  6408. if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
  6409. streamGeometryType[geometry.type](geometry, stream);
  6410. }
  6411. }
  6412. var streamObjectType = {
  6413. Feature: function(object, stream) {
  6414. streamGeometry(object.geometry, stream);
  6415. },
  6416. FeatureCollection: function(object, stream) {
  6417. var features = object.features, i = -1, n = features.length;
  6418. while (++i < n) streamGeometry(features[i].geometry, stream);
  6419. }
  6420. };
  6421. var streamGeometryType = {
  6422. Sphere: function(object, stream) {
  6423. stream.sphere();
  6424. },
  6425. Point: function(object, stream) {
  6426. object = object.coordinates;
  6427. stream.point(object[0], object[1], object[2]);
  6428. },
  6429. MultiPoint: function(object, stream) {
  6430. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6431. while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
  6432. },
  6433. LineString: function(object, stream) {
  6434. streamLine(object.coordinates, stream, 0);
  6435. },
  6436. MultiLineString: function(object, stream) {
  6437. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6438. while (++i < n) streamLine(coordinates[i], stream, 0);
  6439. },
  6440. Polygon: function(object, stream) {
  6441. streamPolygon(object.coordinates, stream);
  6442. },
  6443. MultiPolygon: function(object, stream) {
  6444. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  6445. while (++i < n) streamPolygon(coordinates[i], stream);
  6446. },
  6447. GeometryCollection: function(object, stream) {
  6448. var geometries = object.geometries, i = -1, n = geometries.length;
  6449. while (++i < n) streamGeometry(geometries[i], stream);
  6450. }
  6451. };
  6452. function streamLine(coordinates, stream, closed) {
  6453. var i = -1, n = coordinates.length - closed, coordinate;
  6454. stream.lineStart();
  6455. while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
  6456. stream.lineEnd();
  6457. }
  6458. function streamPolygon(coordinates, stream) {
  6459. var i = -1, n = coordinates.length;
  6460. stream.polygonStart();
  6461. while (++i < n) streamLine(coordinates[i], stream, 1);
  6462. stream.polygonEnd();
  6463. }
  6464. function geoStream(object, stream) {
  6465. if (object && streamObjectType.hasOwnProperty(object.type)) {
  6466. streamObjectType[object.type](object, stream);
  6467. } else {
  6468. streamGeometry(object, stream);
  6469. }
  6470. }
  6471. var areaRingSum = adder();
  6472. var areaSum = adder(),
  6473. lambda00,
  6474. phi00,
  6475. lambda0,
  6476. cosPhi0,
  6477. sinPhi0;
  6478. var areaStream = {
  6479. point: noop$2,
  6480. lineStart: noop$2,
  6481. lineEnd: noop$2,
  6482. polygonStart: function() {
  6483. areaRingSum.reset();
  6484. areaStream.lineStart = areaRingStart;
  6485. areaStream.lineEnd = areaRingEnd;
  6486. },
  6487. polygonEnd: function() {
  6488. var areaRing = +areaRingSum;
  6489. areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
  6490. this.lineStart = this.lineEnd = this.point = noop$2;
  6491. },
  6492. sphere: function() {
  6493. areaSum.add(tau$3);
  6494. }
  6495. };
  6496. function areaRingStart() {
  6497. areaStream.point = areaPointFirst;
  6498. }
  6499. function areaRingEnd() {
  6500. areaPoint(lambda00, phi00);
  6501. }
  6502. function areaPointFirst(lambda, phi) {
  6503. areaStream.point = areaPoint;
  6504. lambda00 = lambda, phi00 = phi;
  6505. lambda *= radians, phi *= radians;
  6506. lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
  6507. }
  6508. function areaPoint(lambda, phi) {
  6509. lambda *= radians, phi *= radians;
  6510. phi = phi / 2 + quarterPi; // half the angular distance from south pole
  6511. // Spherical excess E for a spherical triangle with vertices: south pole,
  6512. // previous point, current point. Uses a formula derived from Cagnoli’s
  6513. // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
  6514. var dLambda = lambda - lambda0,
  6515. sdLambda = dLambda >= 0 ? 1 : -1,
  6516. adLambda = sdLambda * dLambda,
  6517. cosPhi = cos$1(phi),
  6518. sinPhi = sin$1(phi),
  6519. k = sinPhi0 * sinPhi,
  6520. u = cosPhi0 * cosPhi + k * cos$1(adLambda),
  6521. v = k * sdLambda * sin$1(adLambda);
  6522. areaRingSum.add(atan2(v, u));
  6523. // Advance the previous points.
  6524. lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
  6525. }
  6526. function area$1(object) {
  6527. areaSum.reset();
  6528. geoStream(object, areaStream);
  6529. return areaSum * 2;
  6530. }
  6531. function spherical(cartesian) {
  6532. return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
  6533. }
  6534. function cartesian(spherical) {
  6535. var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
  6536. return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
  6537. }
  6538. function cartesianDot(a, b) {
  6539. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6540. }
  6541. function cartesianCross(a, b) {
  6542. 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]];
  6543. }
  6544. // TODO return a
  6545. function cartesianAddInPlace(a, b) {
  6546. a[0] += b[0], a[1] += b[1], a[2] += b[2];
  6547. }
  6548. function cartesianScale(vector, k) {
  6549. return [vector[0] * k, vector[1] * k, vector[2] * k];
  6550. }
  6551. // TODO return d
  6552. function cartesianNormalizeInPlace(d) {
  6553. var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  6554. d[0] /= l, d[1] /= l, d[2] /= l;
  6555. }
  6556. var lambda0$1, phi0, lambda1, phi1, // bounds
  6557. lambda2, // previous lambda-coordinate
  6558. lambda00$1, phi00$1, // first point
  6559. p0, // previous 3D point
  6560. deltaSum = adder(),
  6561. ranges,
  6562. range;
  6563. var boundsStream = {
  6564. point: boundsPoint,
  6565. lineStart: boundsLineStart,
  6566. lineEnd: boundsLineEnd,
  6567. polygonStart: function() {
  6568. boundsStream.point = boundsRingPoint;
  6569. boundsStream.lineStart = boundsRingStart;
  6570. boundsStream.lineEnd = boundsRingEnd;
  6571. deltaSum.reset();
  6572. areaStream.polygonStart();
  6573. },
  6574. polygonEnd: function() {
  6575. areaStream.polygonEnd();
  6576. boundsStream.point = boundsPoint;
  6577. boundsStream.lineStart = boundsLineStart;
  6578. boundsStream.lineEnd = boundsLineEnd;
  6579. if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6580. else if (deltaSum > epsilon$2) phi1 = 90;
  6581. else if (deltaSum < -epsilon$2) phi0 = -90;
  6582. range[0] = lambda0$1, range[1] = lambda1;
  6583. },
  6584. sphere: function() {
  6585. lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
  6586. }
  6587. };
  6588. function boundsPoint(lambda, phi) {
  6589. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6590. if (phi < phi0) phi0 = phi;
  6591. if (phi > phi1) phi1 = phi;
  6592. }
  6593. function linePoint(lambda, phi) {
  6594. var p = cartesian([lambda * radians, phi * radians]);
  6595. if (p0) {
  6596. var normal = cartesianCross(p0, p),
  6597. equatorial = [normal[1], -normal[0], 0],
  6598. inflection = cartesianCross(equatorial, normal);
  6599. cartesianNormalizeInPlace(inflection);
  6600. inflection = spherical(inflection);
  6601. var delta = lambda - lambda2,
  6602. sign = delta > 0 ? 1 : -1,
  6603. lambdai = inflection[0] * degrees$1 * sign,
  6604. phii,
  6605. antimeridian = abs(delta) > 180;
  6606. if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  6607. phii = inflection[1] * degrees$1;
  6608. if (phii > phi1) phi1 = phii;
  6609. } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
  6610. phii = -inflection[1] * degrees$1;
  6611. if (phii < phi0) phi0 = phii;
  6612. } else {
  6613. if (phi < phi0) phi0 = phi;
  6614. if (phi > phi1) phi1 = phi;
  6615. }
  6616. if (antimeridian) {
  6617. if (lambda < lambda2) {
  6618. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6619. } else {
  6620. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6621. }
  6622. } else {
  6623. if (lambda1 >= lambda0$1) {
  6624. if (lambda < lambda0$1) lambda0$1 = lambda;
  6625. if (lambda > lambda1) lambda1 = lambda;
  6626. } else {
  6627. if (lambda > lambda2) {
  6628. if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
  6629. } else {
  6630. if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
  6631. }
  6632. }
  6633. }
  6634. } else {
  6635. ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
  6636. }
  6637. if (phi < phi0) phi0 = phi;
  6638. if (phi > phi1) phi1 = phi;
  6639. p0 = p, lambda2 = lambda;
  6640. }
  6641. function boundsLineStart() {
  6642. boundsStream.point = linePoint;
  6643. }
  6644. function boundsLineEnd() {
  6645. range[0] = lambda0$1, range[1] = lambda1;
  6646. boundsStream.point = boundsPoint;
  6647. p0 = null;
  6648. }
  6649. function boundsRingPoint(lambda, phi) {
  6650. if (p0) {
  6651. var delta = lambda - lambda2;
  6652. deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
  6653. } else {
  6654. lambda00$1 = lambda, phi00$1 = phi;
  6655. }
  6656. areaStream.point(lambda, phi);
  6657. linePoint(lambda, phi);
  6658. }
  6659. function boundsRingStart() {
  6660. areaStream.lineStart();
  6661. }
  6662. function boundsRingEnd() {
  6663. boundsRingPoint(lambda00$1, phi00$1);
  6664. areaStream.lineEnd();
  6665. if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
  6666. range[0] = lambda0$1, range[1] = lambda1;
  6667. p0 = null;
  6668. }
  6669. // Finds the left-right distance between two longitudes.
  6670. // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
  6671. // the distance between ±180° to be 360°.
  6672. function angle(lambda0, lambda1) {
  6673. return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
  6674. }
  6675. function rangeCompare(a, b) {
  6676. return a[0] - b[0];
  6677. }
  6678. function rangeContains(range, x) {
  6679. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  6680. }
  6681. function bounds(feature) {
  6682. var i, n, a, b, merged, deltaMax, delta;
  6683. phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
  6684. ranges = [];
  6685. geoStream(feature, boundsStream);
  6686. // First, sort ranges by their minimum longitudes.
  6687. if (n = ranges.length) {
  6688. ranges.sort(rangeCompare);
  6689. // Then, merge any ranges that overlap.
  6690. for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
  6691. b = ranges[i];
  6692. if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
  6693. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  6694. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  6695. } else {
  6696. merged.push(a = b);
  6697. }
  6698. }
  6699. // Finally, find the largest gap between the merged ranges.
  6700. // The final bounding box will be the inverse of this gap.
  6701. for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
  6702. b = merged[i];
  6703. if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
  6704. }
  6705. }
  6706. ranges = range = null;
  6707. return lambda0$1 === Infinity || phi0 === Infinity
  6708. ? [[NaN, NaN], [NaN, NaN]]
  6709. : [[lambda0$1, phi0], [lambda1, phi1]];
  6710. }
  6711. var W0, W1,
  6712. X0, Y0, Z0,
  6713. X1, Y1, Z1,
  6714. X2, Y2, Z2,
  6715. lambda00$2, phi00$2, // first point
  6716. x0, y0, z0; // previous point
  6717. var centroidStream = {
  6718. sphere: noop$2,
  6719. point: centroidPoint,
  6720. lineStart: centroidLineStart,
  6721. lineEnd: centroidLineEnd,
  6722. polygonStart: function() {
  6723. centroidStream.lineStart = centroidRingStart;
  6724. centroidStream.lineEnd = centroidRingEnd;
  6725. },
  6726. polygonEnd: function() {
  6727. centroidStream.lineStart = centroidLineStart;
  6728. centroidStream.lineEnd = centroidLineEnd;
  6729. }
  6730. };
  6731. // Arithmetic mean of Cartesian vectors.
  6732. function centroidPoint(lambda, phi) {
  6733. lambda *= radians, phi *= radians;
  6734. var cosPhi = cos$1(phi);
  6735. centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
  6736. }
  6737. function centroidPointCartesian(x, y, z) {
  6738. ++W0;
  6739. X0 += (x - X0) / W0;
  6740. Y0 += (y - Y0) / W0;
  6741. Z0 += (z - Z0) / W0;
  6742. }
  6743. function centroidLineStart() {
  6744. centroidStream.point = centroidLinePointFirst;
  6745. }
  6746. function centroidLinePointFirst(lambda, phi) {
  6747. lambda *= radians, phi *= radians;
  6748. var cosPhi = cos$1(phi);
  6749. x0 = cosPhi * cos$1(lambda);
  6750. y0 = cosPhi * sin$1(lambda);
  6751. z0 = sin$1(phi);
  6752. centroidStream.point = centroidLinePoint;
  6753. centroidPointCartesian(x0, y0, z0);
  6754. }
  6755. function centroidLinePoint(lambda, phi) {
  6756. lambda *= radians, phi *= radians;
  6757. var cosPhi = cos$1(phi),
  6758. x = cosPhi * cos$1(lambda),
  6759. y = cosPhi * sin$1(lambda),
  6760. z = sin$1(phi),
  6761. w = atan2(sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
  6762. W1 += w;
  6763. X1 += w * (x0 + (x0 = x));
  6764. Y1 += w * (y0 + (y0 = y));
  6765. Z1 += w * (z0 + (z0 = z));
  6766. centroidPointCartesian(x0, y0, z0);
  6767. }
  6768. function centroidLineEnd() {
  6769. centroidStream.point = centroidPoint;
  6770. }
  6771. // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
  6772. // J. Applied Mechanics 42, 239 (1975).
  6773. function centroidRingStart() {
  6774. centroidStream.point = centroidRingPointFirst;
  6775. }
  6776. function centroidRingEnd() {
  6777. centroidRingPoint(lambda00$2, phi00$2);
  6778. centroidStream.point = centroidPoint;
  6779. }
  6780. function centroidRingPointFirst(lambda, phi) {
  6781. lambda00$2 = lambda, phi00$2 = phi;
  6782. lambda *= radians, phi *= radians;
  6783. centroidStream.point = centroidRingPoint;
  6784. var cosPhi = cos$1(phi);
  6785. x0 = cosPhi * cos$1(lambda);
  6786. y0 = cosPhi * sin$1(lambda);
  6787. z0 = sin$1(phi);
  6788. centroidPointCartesian(x0, y0, z0);
  6789. }
  6790. function centroidRingPoint(lambda, phi) {
  6791. lambda *= radians, phi *= radians;
  6792. var cosPhi = cos$1(phi),
  6793. x = cosPhi * cos$1(lambda),
  6794. y = cosPhi * sin$1(lambda),
  6795. z = sin$1(phi),
  6796. cx = y0 * z - z0 * y,
  6797. cy = z0 * x - x0 * z,
  6798. cz = x0 * y - y0 * x,
  6799. m = sqrt(cx * cx + cy * cy + cz * cz),
  6800. w = asin(m), // line weight = angle
  6801. v = m && -w / m; // area weight multiplier
  6802. X2 += v * cx;
  6803. Y2 += v * cy;
  6804. Z2 += v * cz;
  6805. W1 += w;
  6806. X1 += w * (x0 + (x0 = x));
  6807. Y1 += w * (y0 + (y0 = y));
  6808. Z1 += w * (z0 + (z0 = z));
  6809. centroidPointCartesian(x0, y0, z0);
  6810. }
  6811. function centroid(object) {
  6812. W0 = W1 =
  6813. X0 = Y0 = Z0 =
  6814. X1 = Y1 = Z1 =
  6815. X2 = Y2 = Z2 = 0;
  6816. geoStream(object, centroidStream);
  6817. var x = X2,
  6818. y = Y2,
  6819. z = Z2,
  6820. m = x * x + y * y + z * z;
  6821. // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
  6822. if (m < epsilon2$1) {
  6823. x = X1, y = Y1, z = Z1;
  6824. // If the feature has zero length, fall back to arithmetic mean of point vectors.
  6825. if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
  6826. m = x * x + y * y + z * z;
  6827. // If the feature still has an undefined ccentroid, then return.
  6828. if (m < epsilon2$1) return [NaN, NaN];
  6829. }
  6830. return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
  6831. }
  6832. function constant$8(x) {
  6833. return function() {
  6834. return x;
  6835. };
  6836. }
  6837. function compose(a, b) {
  6838. function compose(x, y) {
  6839. return x = a(x, y), b(x[0], x[1]);
  6840. }
  6841. if (a.invert && b.invert) compose.invert = function(x, y) {
  6842. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  6843. };
  6844. return compose;
  6845. }
  6846. function rotationIdentity(lambda, phi) {
  6847. return [abs(lambda) > pi$3 ? lambda + Math.round(-lambda / tau$3) * tau$3 : lambda, phi];
  6848. }
  6849. rotationIdentity.invert = rotationIdentity;
  6850. function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
  6851. return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
  6852. : rotationLambda(deltaLambda))
  6853. : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
  6854. : rotationIdentity);
  6855. }
  6856. function forwardRotationLambda(deltaLambda) {
  6857. return function(lambda, phi) {
  6858. return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
  6859. };
  6860. }
  6861. function rotationLambda(deltaLambda) {
  6862. var rotation = forwardRotationLambda(deltaLambda);
  6863. rotation.invert = forwardRotationLambda(-deltaLambda);
  6864. return rotation;
  6865. }
  6866. function rotationPhiGamma(deltaPhi, deltaGamma) {
  6867. var cosDeltaPhi = cos$1(deltaPhi),
  6868. sinDeltaPhi = sin$1(deltaPhi),
  6869. cosDeltaGamma = cos$1(deltaGamma),
  6870. sinDeltaGamma = sin$1(deltaGamma);
  6871. function rotation(lambda, phi) {
  6872. var cosPhi = cos$1(phi),
  6873. x = cos$1(lambda) * cosPhi,
  6874. y = sin$1(lambda) * cosPhi,
  6875. z = sin$1(phi),
  6876. k = z * cosDeltaPhi + x * sinDeltaPhi;
  6877. return [
  6878. atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
  6879. asin(k * cosDeltaGamma + y * sinDeltaGamma)
  6880. ];
  6881. }
  6882. rotation.invert = function(lambda, phi) {
  6883. var cosPhi = cos$1(phi),
  6884. x = cos$1(lambda) * cosPhi,
  6885. y = sin$1(lambda) * cosPhi,
  6886. z = sin$1(phi),
  6887. k = z * cosDeltaGamma - y * sinDeltaGamma;
  6888. return [
  6889. atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
  6890. asin(k * cosDeltaPhi - x * sinDeltaPhi)
  6891. ];
  6892. };
  6893. return rotation;
  6894. }
  6895. function rotation(rotate) {
  6896. rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
  6897. function forward(coordinates) {
  6898. coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
  6899. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6900. }
  6901. forward.invert = function(coordinates) {
  6902. coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
  6903. return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
  6904. };
  6905. return forward;
  6906. }
  6907. // Generates a circle centered at [0°, 0°], with a given radius and precision.
  6908. function circleStream(stream, radius, delta, direction, t0, t1) {
  6909. if (!delta) return;
  6910. var cosRadius = cos$1(radius),
  6911. sinRadius = sin$1(radius),
  6912. step = direction * delta;
  6913. if (t0 == null) {
  6914. t0 = radius + direction * tau$3;
  6915. t1 = radius - step / 2;
  6916. } else {
  6917. t0 = circleRadius(cosRadius, t0);
  6918. t1 = circleRadius(cosRadius, t1);
  6919. if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
  6920. }
  6921. for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
  6922. point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
  6923. stream.point(point[0], point[1]);
  6924. }
  6925. }
  6926. // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
  6927. function circleRadius(cosRadius, point) {
  6928. point = cartesian(point), point[0] -= cosRadius;
  6929. cartesianNormalizeInPlace(point);
  6930. var radius = acos(-point[1]);
  6931. return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
  6932. }
  6933. function circle() {
  6934. var center = constant$8([0, 0]),
  6935. radius = constant$8(90),
  6936. precision = constant$8(6),
  6937. ring,
  6938. rotate,
  6939. stream = {point: point};
  6940. function point(x, y) {
  6941. ring.push(x = rotate(x, y));
  6942. x[0] *= degrees$1, x[1] *= degrees$1;
  6943. }
  6944. function circle() {
  6945. var c = center.apply(this, arguments),
  6946. r = radius.apply(this, arguments) * radians,
  6947. p = precision.apply(this, arguments) * radians;
  6948. ring = [];
  6949. rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
  6950. circleStream(stream, r, p, 1);
  6951. c = {type: "Polygon", coordinates: [ring]};
  6952. ring = rotate = null;
  6953. return c;
  6954. }
  6955. circle.center = function(_) {
  6956. return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
  6957. };
  6958. circle.radius = function(_) {
  6959. return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
  6960. };
  6961. circle.precision = function(_) {
  6962. return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
  6963. };
  6964. return circle;
  6965. }
  6966. function clipBuffer() {
  6967. var lines = [],
  6968. line;
  6969. return {
  6970. point: function(x, y) {
  6971. line.push([x, y]);
  6972. },
  6973. lineStart: function() {
  6974. lines.push(line = []);
  6975. },
  6976. lineEnd: noop$2,
  6977. rejoin: function() {
  6978. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  6979. },
  6980. result: function() {
  6981. var result = lines;
  6982. lines = [];
  6983. line = null;
  6984. return result;
  6985. }
  6986. };
  6987. }
  6988. function pointEqual(a, b) {
  6989. return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
  6990. }
  6991. function Intersection(point, points, other, entry) {
  6992. this.x = point;
  6993. this.z = points;
  6994. this.o = other; // another intersection
  6995. this.e = entry; // is an entry?
  6996. this.v = false; // visited
  6997. this.n = this.p = null; // next & previous
  6998. }
  6999. // A generalized polygon clipping algorithm: given a polygon that has been cut
  7000. // into its visible line segments, and rejoins the segments by interpolating
  7001. // along the clip edge.
  7002. function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
  7003. var subject = [],
  7004. clip = [],
  7005. i,
  7006. n;
  7007. segments.forEach(function(segment) {
  7008. if ((n = segment.length - 1) <= 0) return;
  7009. var n, p0 = segment[0], p1 = segment[n], x;
  7010. // If the first and last points of a segment are coincident, then treat as a
  7011. // closed ring. TODO if all rings are closed, then the winding order of the
  7012. // exterior ring should be checked.
  7013. if (pointEqual(p0, p1)) {
  7014. stream.lineStart();
  7015. for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
  7016. stream.lineEnd();
  7017. return;
  7018. }
  7019. subject.push(x = new Intersection(p0, segment, null, true));
  7020. clip.push(x.o = new Intersection(p0, null, x, false));
  7021. subject.push(x = new Intersection(p1, segment, null, false));
  7022. clip.push(x.o = new Intersection(p1, null, x, true));
  7023. });
  7024. if (!subject.length) return;
  7025. clip.sort(compareIntersection);
  7026. link$1(subject);
  7027. link$1(clip);
  7028. for (i = 0, n = clip.length; i < n; ++i) {
  7029. clip[i].e = startInside = !startInside;
  7030. }
  7031. var start = subject[0],
  7032. points,
  7033. point;
  7034. while (1) {
  7035. // Find first unvisited intersection.
  7036. var current = start,
  7037. isSubject = true;
  7038. while (current.v) if ((current = current.n) === start) return;
  7039. points = current.z;
  7040. stream.lineStart();
  7041. do {
  7042. current.v = current.o.v = true;
  7043. if (current.e) {
  7044. if (isSubject) {
  7045. for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
  7046. } else {
  7047. interpolate(current.x, current.n.x, 1, stream);
  7048. }
  7049. current = current.n;
  7050. } else {
  7051. if (isSubject) {
  7052. points = current.p.z;
  7053. for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
  7054. } else {
  7055. interpolate(current.x, current.p.x, -1, stream);
  7056. }
  7057. current = current.p;
  7058. }
  7059. current = current.o;
  7060. points = current.z;
  7061. isSubject = !isSubject;
  7062. } while (!current.v);
  7063. stream.lineEnd();
  7064. }
  7065. }
  7066. function link$1(array) {
  7067. if (!(n = array.length)) return;
  7068. var n,
  7069. i = 0,
  7070. a = array[0],
  7071. b;
  7072. while (++i < n) {
  7073. a.n = b = array[i];
  7074. b.p = a;
  7075. a = b;
  7076. }
  7077. a.n = b = array[0];
  7078. b.p = a;
  7079. }
  7080. var sum$1 = adder();
  7081. function longitude(point) {
  7082. if (abs(point[0]) <= pi$3)
  7083. return point[0];
  7084. else
  7085. return sign(point[0]) * ((abs(point[0]) + pi$3) % tau$3 - pi$3);
  7086. }
  7087. function polygonContains(polygon, point) {
  7088. var lambda = longitude(point),
  7089. phi = point[1],
  7090. sinPhi = sin$1(phi),
  7091. normal = [sin$1(lambda), -cos$1(lambda), 0],
  7092. angle = 0,
  7093. winding = 0;
  7094. sum$1.reset();
  7095. if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
  7096. else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
  7097. for (var i = 0, n = polygon.length; i < n; ++i) {
  7098. if (!(m = (ring = polygon[i]).length)) continue;
  7099. var ring,
  7100. m,
  7101. point0 = ring[m - 1],
  7102. lambda0 = longitude(point0),
  7103. phi0 = point0[1] / 2 + quarterPi,
  7104. sinPhi0 = sin$1(phi0),
  7105. cosPhi0 = cos$1(phi0);
  7106. for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
  7107. var point1 = ring[j],
  7108. lambda1 = longitude(point1),
  7109. phi1 = point1[1] / 2 + quarterPi,
  7110. sinPhi1 = sin$1(phi1),
  7111. cosPhi1 = cos$1(phi1),
  7112. delta = lambda1 - lambda0,
  7113. sign = delta >= 0 ? 1 : -1,
  7114. absDelta = sign * delta,
  7115. antimeridian = absDelta > pi$3,
  7116. k = sinPhi0 * sinPhi1;
  7117. sum$1.add(atan2(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
  7118. angle += antimeridian ? delta + sign * tau$3 : delta;
  7119. // Are the longitudes either side of the point’s meridian (lambda),
  7120. // and are the latitudes smaller than the parallel (phi)?
  7121. if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
  7122. var arc = cartesianCross(cartesian(point0), cartesian(point1));
  7123. cartesianNormalizeInPlace(arc);
  7124. var intersection = cartesianCross(normal, arc);
  7125. cartesianNormalizeInPlace(intersection);
  7126. var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
  7127. if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
  7128. winding += antimeridian ^ delta >= 0 ? 1 : -1;
  7129. }
  7130. }
  7131. }
  7132. }
  7133. // First, determine whether the South pole is inside or outside:
  7134. //
  7135. // It is inside if:
  7136. // * the polygon winds around it in a clockwise direction.
  7137. // * the polygon does not (cumulatively) wind around it, but has a negative
  7138. // (counter-clockwise) area.
  7139. //
  7140. // Second, count the (signed) number of times a segment crosses a lambda
  7141. // from the point to the South pole. If it is zero, then the point is the
  7142. // same side as the South pole.
  7143. return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
  7144. }
  7145. function clip(pointVisible, clipLine, interpolate, start) {
  7146. return function(sink) {
  7147. var line = clipLine(sink),
  7148. ringBuffer = clipBuffer(),
  7149. ringSink = clipLine(ringBuffer),
  7150. polygonStarted = false,
  7151. polygon,
  7152. segments,
  7153. ring;
  7154. var clip = {
  7155. point: point,
  7156. lineStart: lineStart,
  7157. lineEnd: lineEnd,
  7158. polygonStart: function() {
  7159. clip.point = pointRing;
  7160. clip.lineStart = ringStart;
  7161. clip.lineEnd = ringEnd;
  7162. segments = [];
  7163. polygon = [];
  7164. },
  7165. polygonEnd: function() {
  7166. clip.point = point;
  7167. clip.lineStart = lineStart;
  7168. clip.lineEnd = lineEnd;
  7169. segments = merge(segments);
  7170. var startInside = polygonContains(polygon, start);
  7171. if (segments.length) {
  7172. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7173. clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
  7174. } else if (startInside) {
  7175. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7176. sink.lineStart();
  7177. interpolate(null, null, 1, sink);
  7178. sink.lineEnd();
  7179. }
  7180. if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
  7181. segments = polygon = null;
  7182. },
  7183. sphere: function() {
  7184. sink.polygonStart();
  7185. sink.lineStart();
  7186. interpolate(null, null, 1, sink);
  7187. sink.lineEnd();
  7188. sink.polygonEnd();
  7189. }
  7190. };
  7191. function point(lambda, phi) {
  7192. if (pointVisible(lambda, phi)) sink.point(lambda, phi);
  7193. }
  7194. function pointLine(lambda, phi) {
  7195. line.point(lambda, phi);
  7196. }
  7197. function lineStart() {
  7198. clip.point = pointLine;
  7199. line.lineStart();
  7200. }
  7201. function lineEnd() {
  7202. clip.point = point;
  7203. line.lineEnd();
  7204. }
  7205. function pointRing(lambda, phi) {
  7206. ring.push([lambda, phi]);
  7207. ringSink.point(lambda, phi);
  7208. }
  7209. function ringStart() {
  7210. ringSink.lineStart();
  7211. ring = [];
  7212. }
  7213. function ringEnd() {
  7214. pointRing(ring[0][0], ring[0][1]);
  7215. ringSink.lineEnd();
  7216. var clean = ringSink.clean(),
  7217. ringSegments = ringBuffer.result(),
  7218. i, n = ringSegments.length, m,
  7219. segment,
  7220. point;
  7221. ring.pop();
  7222. polygon.push(ring);
  7223. ring = null;
  7224. if (!n) return;
  7225. // No intersections.
  7226. if (clean & 1) {
  7227. segment = ringSegments[0];
  7228. if ((m = segment.length - 1) > 0) {
  7229. if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
  7230. sink.lineStart();
  7231. for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
  7232. sink.lineEnd();
  7233. }
  7234. return;
  7235. }
  7236. // Rejoin connected segments.
  7237. // TODO reuse ringBuffer.rejoin()?
  7238. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  7239. segments.push(ringSegments.filter(validSegment));
  7240. }
  7241. return clip;
  7242. };
  7243. }
  7244. function validSegment(segment) {
  7245. return segment.length > 1;
  7246. }
  7247. // Intersections are sorted along the clip edge. For both antimeridian cutting
  7248. // and circle clipping, the same comparison is used.
  7249. function compareIntersection(a, b) {
  7250. return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
  7251. - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
  7252. }
  7253. var clipAntimeridian = clip(
  7254. function() { return true; },
  7255. clipAntimeridianLine,
  7256. clipAntimeridianInterpolate,
  7257. [-pi$3, -halfPi$2]
  7258. );
  7259. // Takes a line and cuts into visible segments. Return values: 0 - there were
  7260. // intersections or the line was empty; 1 - no intersections; 2 - there were
  7261. // intersections, and the first and last segments should be rejoined.
  7262. function clipAntimeridianLine(stream) {
  7263. var lambda0 = NaN,
  7264. phi0 = NaN,
  7265. sign0 = NaN,
  7266. clean; // no intersections
  7267. return {
  7268. lineStart: function() {
  7269. stream.lineStart();
  7270. clean = 1;
  7271. },
  7272. point: function(lambda1, phi1) {
  7273. var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
  7274. delta = abs(lambda1 - lambda0);
  7275. if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
  7276. stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
  7277. stream.point(sign0, phi0);
  7278. stream.lineEnd();
  7279. stream.lineStart();
  7280. stream.point(sign1, phi0);
  7281. stream.point(lambda1, phi0);
  7282. clean = 0;
  7283. } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
  7284. if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
  7285. if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
  7286. phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
  7287. stream.point(sign0, phi0);
  7288. stream.lineEnd();
  7289. stream.lineStart();
  7290. stream.point(sign1, phi0);
  7291. clean = 0;
  7292. }
  7293. stream.point(lambda0 = lambda1, phi0 = phi1);
  7294. sign0 = sign1;
  7295. },
  7296. lineEnd: function() {
  7297. stream.lineEnd();
  7298. lambda0 = phi0 = NaN;
  7299. },
  7300. clean: function() {
  7301. return 2 - clean; // if intersections, rejoin first and last segments
  7302. }
  7303. };
  7304. }
  7305. function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
  7306. var cosPhi0,
  7307. cosPhi1,
  7308. sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
  7309. return abs(sinLambda0Lambda1) > epsilon$2
  7310. ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
  7311. - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
  7312. / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
  7313. : (phi0 + phi1) / 2;
  7314. }
  7315. function clipAntimeridianInterpolate(from, to, direction, stream) {
  7316. var phi;
  7317. if (from == null) {
  7318. phi = direction * halfPi$2;
  7319. stream.point(-pi$3, phi);
  7320. stream.point(0, phi);
  7321. stream.point(pi$3, phi);
  7322. stream.point(pi$3, 0);
  7323. stream.point(pi$3, -phi);
  7324. stream.point(0, -phi);
  7325. stream.point(-pi$3, -phi);
  7326. stream.point(-pi$3, 0);
  7327. stream.point(-pi$3, phi);
  7328. } else if (abs(from[0] - to[0]) > epsilon$2) {
  7329. var lambda = from[0] < to[0] ? pi$3 : -pi$3;
  7330. phi = direction * lambda / 2;
  7331. stream.point(-lambda, phi);
  7332. stream.point(0, phi);
  7333. stream.point(lambda, phi);
  7334. } else {
  7335. stream.point(to[0], to[1]);
  7336. }
  7337. }
  7338. function clipCircle(radius) {
  7339. var cr = cos$1(radius),
  7340. delta = 6 * radians,
  7341. smallRadius = cr > 0,
  7342. notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
  7343. function interpolate(from, to, direction, stream) {
  7344. circleStream(stream, radius, delta, direction, from, to);
  7345. }
  7346. function visible(lambda, phi) {
  7347. return cos$1(lambda) * cos$1(phi) > cr;
  7348. }
  7349. // Takes a line and cuts into visible segments. Return values used for polygon
  7350. // clipping: 0 - there were intersections or the line was empty; 1 - no
  7351. // intersections 2 - there were intersections, and the first and last segments
  7352. // should be rejoined.
  7353. function clipLine(stream) {
  7354. var point0, // previous point
  7355. c0, // code for previous point
  7356. v0, // visibility of previous point
  7357. v00, // visibility of first point
  7358. clean; // no intersections
  7359. return {
  7360. lineStart: function() {
  7361. v00 = v0 = false;
  7362. clean = 1;
  7363. },
  7364. point: function(lambda, phi) {
  7365. var point1 = [lambda, phi],
  7366. point2,
  7367. v = visible(lambda, phi),
  7368. c = smallRadius
  7369. ? v ? 0 : code(lambda, phi)
  7370. : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
  7371. if (!point0 && (v00 = v0 = v)) stream.lineStart();
  7372. // Handle degeneracies.
  7373. // TODO ignore if not clipping polygons.
  7374. if (v !== v0) {
  7375. point2 = intersect(point0, point1);
  7376. if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
  7377. point1[0] += epsilon$2;
  7378. point1[1] += epsilon$2;
  7379. v = visible(point1[0], point1[1]);
  7380. }
  7381. }
  7382. if (v !== v0) {
  7383. clean = 0;
  7384. if (v) {
  7385. // outside going in
  7386. stream.lineStart();
  7387. point2 = intersect(point1, point0);
  7388. stream.point(point2[0], point2[1]);
  7389. } else {
  7390. // inside going out
  7391. point2 = intersect(point0, point1);
  7392. stream.point(point2[0], point2[1]);
  7393. stream.lineEnd();
  7394. }
  7395. point0 = point2;
  7396. } else if (notHemisphere && point0 && smallRadius ^ v) {
  7397. var t;
  7398. // If the codes for two points are different, or are both zero,
  7399. // and there this segment intersects with the small circle.
  7400. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  7401. clean = 0;
  7402. if (smallRadius) {
  7403. stream.lineStart();
  7404. stream.point(t[0][0], t[0][1]);
  7405. stream.point(t[1][0], t[1][1]);
  7406. stream.lineEnd();
  7407. } else {
  7408. stream.point(t[1][0], t[1][1]);
  7409. stream.lineEnd();
  7410. stream.lineStart();
  7411. stream.point(t[0][0], t[0][1]);
  7412. }
  7413. }
  7414. }
  7415. if (v && (!point0 || !pointEqual(point0, point1))) {
  7416. stream.point(point1[0], point1[1]);
  7417. }
  7418. point0 = point1, v0 = v, c0 = c;
  7419. },
  7420. lineEnd: function() {
  7421. if (v0) stream.lineEnd();
  7422. point0 = null;
  7423. },
  7424. // Rejoin first and last segments if there were intersections and the first
  7425. // and last points were visible.
  7426. clean: function() {
  7427. return clean | ((v00 && v0) << 1);
  7428. }
  7429. };
  7430. }
  7431. // Intersects the great circle between a and b with the clip circle.
  7432. function intersect(a, b, two) {
  7433. var pa = cartesian(a),
  7434. pb = cartesian(b);
  7435. // We have two planes, n1.p = d1 and n2.p = d2.
  7436. // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
  7437. var n1 = [1, 0, 0], // normal
  7438. n2 = cartesianCross(pa, pb),
  7439. n2n2 = cartesianDot(n2, n2),
  7440. n1n2 = n2[0], // cartesianDot(n1, n2),
  7441. determinant = n2n2 - n1n2 * n1n2;
  7442. // Two polar points.
  7443. if (!determinant) return !two && a;
  7444. var c1 = cr * n2n2 / determinant,
  7445. c2 = -cr * n1n2 / determinant,
  7446. n1xn2 = cartesianCross(n1, n2),
  7447. A = cartesianScale(n1, c1),
  7448. B = cartesianScale(n2, c2);
  7449. cartesianAddInPlace(A, B);
  7450. // Solve |p(t)|^2 = 1.
  7451. var u = n1xn2,
  7452. w = cartesianDot(A, u),
  7453. uu = cartesianDot(u, u),
  7454. t2 = w * w - uu * (cartesianDot(A, A) - 1);
  7455. if (t2 < 0) return;
  7456. var t = sqrt(t2),
  7457. q = cartesianScale(u, (-w - t) / uu);
  7458. cartesianAddInPlace(q, A);
  7459. q = spherical(q);
  7460. if (!two) return q;
  7461. // Two intersection points.
  7462. var lambda0 = a[0],
  7463. lambda1 = b[0],
  7464. phi0 = a[1],
  7465. phi1 = b[1],
  7466. z;
  7467. if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
  7468. var delta = lambda1 - lambda0,
  7469. polar = abs(delta - pi$3) < epsilon$2,
  7470. meridian = polar || delta < epsilon$2;
  7471. if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
  7472. // Check that the first point is between a and b.
  7473. if (meridian
  7474. ? polar
  7475. ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
  7476. : phi0 <= q[1] && q[1] <= phi1
  7477. : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
  7478. var q1 = cartesianScale(u, (-w + t) / uu);
  7479. cartesianAddInPlace(q1, A);
  7480. return [q, spherical(q1)];
  7481. }
  7482. }
  7483. // Generates a 4-bit vector representing the location of a point relative to
  7484. // the small circle's bounding box.
  7485. function code(lambda, phi) {
  7486. var r = smallRadius ? radius : pi$3 - radius,
  7487. code = 0;
  7488. if (lambda < -r) code |= 1; // left
  7489. else if (lambda > r) code |= 2; // right
  7490. if (phi < -r) code |= 4; // below
  7491. else if (phi > r) code |= 8; // above
  7492. return code;
  7493. }
  7494. return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
  7495. }
  7496. function clipLine(a, b, x0, y0, x1, y1) {
  7497. var ax = a[0],
  7498. ay = a[1],
  7499. bx = b[0],
  7500. by = b[1],
  7501. t0 = 0,
  7502. t1 = 1,
  7503. dx = bx - ax,
  7504. dy = by - ay,
  7505. r;
  7506. r = x0 - ax;
  7507. if (!dx && r > 0) return;
  7508. r /= dx;
  7509. if (dx < 0) {
  7510. if (r < t0) return;
  7511. if (r < t1) t1 = r;
  7512. } else if (dx > 0) {
  7513. if (r > t1) return;
  7514. if (r > t0) t0 = r;
  7515. }
  7516. r = x1 - ax;
  7517. if (!dx && r < 0) return;
  7518. r /= dx;
  7519. if (dx < 0) {
  7520. if (r > t1) return;
  7521. if (r > t0) t0 = r;
  7522. } else if (dx > 0) {
  7523. if (r < t0) return;
  7524. if (r < t1) t1 = r;
  7525. }
  7526. r = y0 - ay;
  7527. if (!dy && r > 0) return;
  7528. r /= dy;
  7529. if (dy < 0) {
  7530. if (r < t0) return;
  7531. if (r < t1) t1 = r;
  7532. } else if (dy > 0) {
  7533. if (r > t1) return;
  7534. if (r > t0) t0 = r;
  7535. }
  7536. r = y1 - ay;
  7537. if (!dy && r < 0) return;
  7538. r /= dy;
  7539. if (dy < 0) {
  7540. if (r > t1) return;
  7541. if (r > t0) t0 = r;
  7542. } else if (dy > 0) {
  7543. if (r < t0) return;
  7544. if (r < t1) t1 = r;
  7545. }
  7546. if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
  7547. if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
  7548. return true;
  7549. }
  7550. var clipMax = 1e9, clipMin = -clipMax;
  7551. // TODO Use d3-polygon’s polygonContains here for the ring check?
  7552. // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
  7553. function clipRectangle(x0, y0, x1, y1) {
  7554. function visible(x, y) {
  7555. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  7556. }
  7557. function interpolate(from, to, direction, stream) {
  7558. var a = 0, a1 = 0;
  7559. if (from == null
  7560. || (a = corner(from, direction)) !== (a1 = corner(to, direction))
  7561. || comparePoint(from, to) < 0 ^ direction > 0) {
  7562. do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  7563. while ((a = (a + direction + 4) % 4) !== a1);
  7564. } else {
  7565. stream.point(to[0], to[1]);
  7566. }
  7567. }
  7568. function corner(p, direction) {
  7569. return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
  7570. : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
  7571. : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
  7572. : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
  7573. }
  7574. function compareIntersection(a, b) {
  7575. return comparePoint(a.x, b.x);
  7576. }
  7577. function comparePoint(a, b) {
  7578. var ca = corner(a, 1),
  7579. cb = corner(b, 1);
  7580. return ca !== cb ? ca - cb
  7581. : ca === 0 ? b[1] - a[1]
  7582. : ca === 1 ? a[0] - b[0]
  7583. : ca === 2 ? a[1] - b[1]
  7584. : b[0] - a[0];
  7585. }
  7586. return function(stream) {
  7587. var activeStream = stream,
  7588. bufferStream = clipBuffer(),
  7589. segments,
  7590. polygon,
  7591. ring,
  7592. x__, y__, v__, // first point
  7593. x_, y_, v_, // previous point
  7594. first,
  7595. clean;
  7596. var clipStream = {
  7597. point: point,
  7598. lineStart: lineStart,
  7599. lineEnd: lineEnd,
  7600. polygonStart: polygonStart,
  7601. polygonEnd: polygonEnd
  7602. };
  7603. function point(x, y) {
  7604. if (visible(x, y)) activeStream.point(x, y);
  7605. }
  7606. function polygonInside() {
  7607. var winding = 0;
  7608. for (var i = 0, n = polygon.length; i < n; ++i) {
  7609. for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
  7610. a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
  7611. if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
  7612. else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
  7613. }
  7614. }
  7615. return winding;
  7616. }
  7617. // Buffer geometry within a polygon and then clip it en masse.
  7618. function polygonStart() {
  7619. activeStream = bufferStream, segments = [], polygon = [], clean = true;
  7620. }
  7621. function polygonEnd() {
  7622. var startInside = polygonInside(),
  7623. cleanInside = clean && startInside,
  7624. visible = (segments = merge(segments)).length;
  7625. if (cleanInside || visible) {
  7626. stream.polygonStart();
  7627. if (cleanInside) {
  7628. stream.lineStart();
  7629. interpolate(null, null, 1, stream);
  7630. stream.lineEnd();
  7631. }
  7632. if (visible) {
  7633. clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
  7634. }
  7635. stream.polygonEnd();
  7636. }
  7637. activeStream = stream, segments = polygon = ring = null;
  7638. }
  7639. function lineStart() {
  7640. clipStream.point = linePoint;
  7641. if (polygon) polygon.push(ring = []);
  7642. first = true;
  7643. v_ = false;
  7644. x_ = y_ = NaN;
  7645. }
  7646. // TODO rather than special-case polygons, simply handle them separately.
  7647. // Ideally, coincident intersection points should be jittered to avoid
  7648. // clipping issues.
  7649. function lineEnd() {
  7650. if (segments) {
  7651. linePoint(x__, y__);
  7652. if (v__ && v_) bufferStream.rejoin();
  7653. segments.push(bufferStream.result());
  7654. }
  7655. clipStream.point = point;
  7656. if (v_) activeStream.lineEnd();
  7657. }
  7658. function linePoint(x, y) {
  7659. var v = visible(x, y);
  7660. if (polygon) ring.push([x, y]);
  7661. if (first) {
  7662. x__ = x, y__ = y, v__ = v;
  7663. first = false;
  7664. if (v) {
  7665. activeStream.lineStart();
  7666. activeStream.point(x, y);
  7667. }
  7668. } else {
  7669. if (v && v_) activeStream.point(x, y);
  7670. else {
  7671. var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
  7672. b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
  7673. if (clipLine(a, b, x0, y0, x1, y1)) {
  7674. if (!v_) {
  7675. activeStream.lineStart();
  7676. activeStream.point(a[0], a[1]);
  7677. }
  7678. activeStream.point(b[0], b[1]);
  7679. if (!v) activeStream.lineEnd();
  7680. clean = false;
  7681. } else if (v) {
  7682. activeStream.lineStart();
  7683. activeStream.point(x, y);
  7684. clean = false;
  7685. }
  7686. }
  7687. }
  7688. x_ = x, y_ = y, v_ = v;
  7689. }
  7690. return clipStream;
  7691. };
  7692. }
  7693. function extent$1() {
  7694. var x0 = 0,
  7695. y0 = 0,
  7696. x1 = 960,
  7697. y1 = 500,
  7698. cache,
  7699. cacheStream,
  7700. clip;
  7701. return clip = {
  7702. stream: function(stream) {
  7703. return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
  7704. },
  7705. extent: function(_) {
  7706. return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
  7707. }
  7708. };
  7709. }
  7710. var lengthSum = adder(),
  7711. lambda0$2,
  7712. sinPhi0$1,
  7713. cosPhi0$1;
  7714. var lengthStream = {
  7715. sphere: noop$2,
  7716. point: noop$2,
  7717. lineStart: lengthLineStart,
  7718. lineEnd: noop$2,
  7719. polygonStart: noop$2,
  7720. polygonEnd: noop$2
  7721. };
  7722. function lengthLineStart() {
  7723. lengthStream.point = lengthPointFirst;
  7724. lengthStream.lineEnd = lengthLineEnd;
  7725. }
  7726. function lengthLineEnd() {
  7727. lengthStream.point = lengthStream.lineEnd = noop$2;
  7728. }
  7729. function lengthPointFirst(lambda, phi) {
  7730. lambda *= radians, phi *= radians;
  7731. lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
  7732. lengthStream.point = lengthPoint;
  7733. }
  7734. function lengthPoint(lambda, phi) {
  7735. lambda *= radians, phi *= radians;
  7736. var sinPhi = sin$1(phi),
  7737. cosPhi = cos$1(phi),
  7738. delta = abs(lambda - lambda0$2),
  7739. cosDelta = cos$1(delta),
  7740. sinDelta = sin$1(delta),
  7741. x = cosPhi * sinDelta,
  7742. y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
  7743. z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
  7744. lengthSum.add(atan2(sqrt(x * x + y * y), z));
  7745. lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
  7746. }
  7747. function length$1(object) {
  7748. lengthSum.reset();
  7749. geoStream(object, lengthStream);
  7750. return +lengthSum;
  7751. }
  7752. var coordinates = [null, null],
  7753. object$1 = {type: "LineString", coordinates: coordinates};
  7754. function distance(a, b) {
  7755. coordinates[0] = a;
  7756. coordinates[1] = b;
  7757. return length$1(object$1);
  7758. }
  7759. var containsObjectType = {
  7760. Feature: function(object, point) {
  7761. return containsGeometry(object.geometry, point);
  7762. },
  7763. FeatureCollection: function(object, point) {
  7764. var features = object.features, i = -1, n = features.length;
  7765. while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
  7766. return false;
  7767. }
  7768. };
  7769. var containsGeometryType = {
  7770. Sphere: function() {
  7771. return true;
  7772. },
  7773. Point: function(object, point) {
  7774. return containsPoint(object.coordinates, point);
  7775. },
  7776. MultiPoint: function(object, point) {
  7777. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7778. while (++i < n) if (containsPoint(coordinates[i], point)) return true;
  7779. return false;
  7780. },
  7781. LineString: function(object, point) {
  7782. return containsLine(object.coordinates, point);
  7783. },
  7784. MultiLineString: function(object, point) {
  7785. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7786. while (++i < n) if (containsLine(coordinates[i], point)) return true;
  7787. return false;
  7788. },
  7789. Polygon: function(object, point) {
  7790. return containsPolygon(object.coordinates, point);
  7791. },
  7792. MultiPolygon: function(object, point) {
  7793. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  7794. while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
  7795. return false;
  7796. },
  7797. GeometryCollection: function(object, point) {
  7798. var geometries = object.geometries, i = -1, n = geometries.length;
  7799. while (++i < n) if (containsGeometry(geometries[i], point)) return true;
  7800. return false;
  7801. }
  7802. };
  7803. function containsGeometry(geometry, point) {
  7804. return geometry && containsGeometryType.hasOwnProperty(geometry.type)
  7805. ? containsGeometryType[geometry.type](geometry, point)
  7806. : false;
  7807. }
  7808. function containsPoint(coordinates, point) {
  7809. return distance(coordinates, point) === 0;
  7810. }
  7811. function containsLine(coordinates, point) {
  7812. var ao, bo, ab;
  7813. for (var i = 0, n = coordinates.length; i < n; i++) {
  7814. bo = distance(coordinates[i], point);
  7815. if (bo === 0) return true;
  7816. if (i > 0) {
  7817. ab = distance(coordinates[i], coordinates[i - 1]);
  7818. if (
  7819. ab > 0 &&
  7820. ao <= ab &&
  7821. bo <= ab &&
  7822. (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2$1 * ab
  7823. )
  7824. return true;
  7825. }
  7826. ao = bo;
  7827. }
  7828. return false;
  7829. }
  7830. function containsPolygon(coordinates, point) {
  7831. return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
  7832. }
  7833. function ringRadians(ring) {
  7834. return ring = ring.map(pointRadians), ring.pop(), ring;
  7835. }
  7836. function pointRadians(point) {
  7837. return [point[0] * radians, point[1] * radians];
  7838. }
  7839. function contains$1(object, point) {
  7840. return (object && containsObjectType.hasOwnProperty(object.type)
  7841. ? containsObjectType[object.type]
  7842. : containsGeometry)(object, point);
  7843. }
  7844. function graticuleX(y0, y1, dy) {
  7845. var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
  7846. return function(x) { return y.map(function(y) { return [x, y]; }); };
  7847. }
  7848. function graticuleY(x0, x1, dx) {
  7849. var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
  7850. return function(y) { return x.map(function(x) { return [x, y]; }); };
  7851. }
  7852. function graticule() {
  7853. var x1, x0, X1, X0,
  7854. y1, y0, Y1, Y0,
  7855. dx = 10, dy = dx, DX = 90, DY = 360,
  7856. x, y, X, Y,
  7857. precision = 2.5;
  7858. function graticule() {
  7859. return {type: "MultiLineString", coordinates: lines()};
  7860. }
  7861. function lines() {
  7862. return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
  7863. .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
  7864. .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
  7865. .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
  7866. }
  7867. graticule.lines = function() {
  7868. return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
  7869. };
  7870. graticule.outline = function() {
  7871. return {
  7872. type: "Polygon",
  7873. coordinates: [
  7874. X(X0).concat(
  7875. Y(Y1).slice(1),
  7876. X(X1).reverse().slice(1),
  7877. Y(Y0).reverse().slice(1))
  7878. ]
  7879. };
  7880. };
  7881. graticule.extent = function(_) {
  7882. if (!arguments.length) return graticule.extentMinor();
  7883. return graticule.extentMajor(_).extentMinor(_);
  7884. };
  7885. graticule.extentMajor = function(_) {
  7886. if (!arguments.length) return [[X0, Y0], [X1, Y1]];
  7887. X0 = +_[0][0], X1 = +_[1][0];
  7888. Y0 = +_[0][1], Y1 = +_[1][1];
  7889. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  7890. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  7891. return graticule.precision(precision);
  7892. };
  7893. graticule.extentMinor = function(_) {
  7894. if (!arguments.length) return [[x0, y0], [x1, y1]];
  7895. x0 = +_[0][0], x1 = +_[1][0];
  7896. y0 = +_[0][1], y1 = +_[1][1];
  7897. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  7898. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  7899. return graticule.precision(precision);
  7900. };
  7901. graticule.step = function(_) {
  7902. if (!arguments.length) return graticule.stepMinor();
  7903. return graticule.stepMajor(_).stepMinor(_);
  7904. };
  7905. graticule.stepMajor = function(_) {
  7906. if (!arguments.length) return [DX, DY];
  7907. DX = +_[0], DY = +_[1];
  7908. return graticule;
  7909. };
  7910. graticule.stepMinor = function(_) {
  7911. if (!arguments.length) return [dx, dy];
  7912. dx = +_[0], dy = +_[1];
  7913. return graticule;
  7914. };
  7915. graticule.precision = function(_) {
  7916. if (!arguments.length) return precision;
  7917. precision = +_;
  7918. x = graticuleX(y0, y1, 90);
  7919. y = graticuleY(x0, x1, precision);
  7920. X = graticuleX(Y0, Y1, 90);
  7921. Y = graticuleY(X0, X1, precision);
  7922. return graticule;
  7923. };
  7924. return graticule
  7925. .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
  7926. .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
  7927. }
  7928. function graticule10() {
  7929. return graticule()();
  7930. }
  7931. function interpolate$1(a, b) {
  7932. var x0 = a[0] * radians,
  7933. y0 = a[1] * radians,
  7934. x1 = b[0] * radians,
  7935. y1 = b[1] * radians,
  7936. cy0 = cos$1(y0),
  7937. sy0 = sin$1(y0),
  7938. cy1 = cos$1(y1),
  7939. sy1 = sin$1(y1),
  7940. kx0 = cy0 * cos$1(x0),
  7941. ky0 = cy0 * sin$1(x0),
  7942. kx1 = cy1 * cos$1(x1),
  7943. ky1 = cy1 * sin$1(x1),
  7944. d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
  7945. k = sin$1(d);
  7946. var interpolate = d ? function(t) {
  7947. var B = sin$1(t *= d) / k,
  7948. A = sin$1(d - t) / k,
  7949. x = A * kx0 + B * kx1,
  7950. y = A * ky0 + B * ky1,
  7951. z = A * sy0 + B * sy1;
  7952. return [
  7953. atan2(y, x) * degrees$1,
  7954. atan2(z, sqrt(x * x + y * y)) * degrees$1
  7955. ];
  7956. } : function() {
  7957. return [x0 * degrees$1, y0 * degrees$1];
  7958. };
  7959. interpolate.distance = d;
  7960. return interpolate;
  7961. }
  7962. function identity$4(x) {
  7963. return x;
  7964. }
  7965. var areaSum$1 = adder(),
  7966. areaRingSum$1 = adder(),
  7967. x00,
  7968. y00,
  7969. x0$1,
  7970. y0$1;
  7971. var areaStream$1 = {
  7972. point: noop$2,
  7973. lineStart: noop$2,
  7974. lineEnd: noop$2,
  7975. polygonStart: function() {
  7976. areaStream$1.lineStart = areaRingStart$1;
  7977. areaStream$1.lineEnd = areaRingEnd$1;
  7978. },
  7979. polygonEnd: function() {
  7980. areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
  7981. areaSum$1.add(abs(areaRingSum$1));
  7982. areaRingSum$1.reset();
  7983. },
  7984. result: function() {
  7985. var area = areaSum$1 / 2;
  7986. areaSum$1.reset();
  7987. return area;
  7988. }
  7989. };
  7990. function areaRingStart$1() {
  7991. areaStream$1.point = areaPointFirst$1;
  7992. }
  7993. function areaPointFirst$1(x, y) {
  7994. areaStream$1.point = areaPoint$1;
  7995. x00 = x0$1 = x, y00 = y0$1 = y;
  7996. }
  7997. function areaPoint$1(x, y) {
  7998. areaRingSum$1.add(y0$1 * x - x0$1 * y);
  7999. x0$1 = x, y0$1 = y;
  8000. }
  8001. function areaRingEnd$1() {
  8002. areaPoint$1(x00, y00);
  8003. }
  8004. var x0$2 = Infinity,
  8005. y0$2 = x0$2,
  8006. x1 = -x0$2,
  8007. y1 = x1;
  8008. var boundsStream$1 = {
  8009. point: boundsPoint$1,
  8010. lineStart: noop$2,
  8011. lineEnd: noop$2,
  8012. polygonStart: noop$2,
  8013. polygonEnd: noop$2,
  8014. result: function() {
  8015. var bounds = [[x0$2, y0$2], [x1, y1]];
  8016. x1 = y1 = -(y0$2 = x0$2 = Infinity);
  8017. return bounds;
  8018. }
  8019. };
  8020. function boundsPoint$1(x, y) {
  8021. if (x < x0$2) x0$2 = x;
  8022. if (x > x1) x1 = x;
  8023. if (y < y0$2) y0$2 = y;
  8024. if (y > y1) y1 = y;
  8025. }
  8026. // TODO Enforce positive area for exterior, negative area for interior?
  8027. var X0$1 = 0,
  8028. Y0$1 = 0,
  8029. Z0$1 = 0,
  8030. X1$1 = 0,
  8031. Y1$1 = 0,
  8032. Z1$1 = 0,
  8033. X2$1 = 0,
  8034. Y2$1 = 0,
  8035. Z2$1 = 0,
  8036. x00$1,
  8037. y00$1,
  8038. x0$3,
  8039. y0$3;
  8040. var centroidStream$1 = {
  8041. point: centroidPoint$1,
  8042. lineStart: centroidLineStart$1,
  8043. lineEnd: centroidLineEnd$1,
  8044. polygonStart: function() {
  8045. centroidStream$1.lineStart = centroidRingStart$1;
  8046. centroidStream$1.lineEnd = centroidRingEnd$1;
  8047. },
  8048. polygonEnd: function() {
  8049. centroidStream$1.point = centroidPoint$1;
  8050. centroidStream$1.lineStart = centroidLineStart$1;
  8051. centroidStream$1.lineEnd = centroidLineEnd$1;
  8052. },
  8053. result: function() {
  8054. var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
  8055. : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
  8056. : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
  8057. : [NaN, NaN];
  8058. X0$1 = Y0$1 = Z0$1 =
  8059. X1$1 = Y1$1 = Z1$1 =
  8060. X2$1 = Y2$1 = Z2$1 = 0;
  8061. return centroid;
  8062. }
  8063. };
  8064. function centroidPoint$1(x, y) {
  8065. X0$1 += x;
  8066. Y0$1 += y;
  8067. ++Z0$1;
  8068. }
  8069. function centroidLineStart$1() {
  8070. centroidStream$1.point = centroidPointFirstLine;
  8071. }
  8072. function centroidPointFirstLine(x, y) {
  8073. centroidStream$1.point = centroidPointLine;
  8074. centroidPoint$1(x0$3 = x, y0$3 = y);
  8075. }
  8076. function centroidPointLine(x, y) {
  8077. var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
  8078. X1$1 += z * (x0$3 + x) / 2;
  8079. Y1$1 += z * (y0$3 + y) / 2;
  8080. Z1$1 += z;
  8081. centroidPoint$1(x0$3 = x, y0$3 = y);
  8082. }
  8083. function centroidLineEnd$1() {
  8084. centroidStream$1.point = centroidPoint$1;
  8085. }
  8086. function centroidRingStart$1() {
  8087. centroidStream$1.point = centroidPointFirstRing;
  8088. }
  8089. function centroidRingEnd$1() {
  8090. centroidPointRing(x00$1, y00$1);
  8091. }
  8092. function centroidPointFirstRing(x, y) {
  8093. centroidStream$1.point = centroidPointRing;
  8094. centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
  8095. }
  8096. function centroidPointRing(x, y) {
  8097. var dx = x - x0$3,
  8098. dy = y - y0$3,
  8099. z = sqrt(dx * dx + dy * dy);
  8100. X1$1 += z * (x0$3 + x) / 2;
  8101. Y1$1 += z * (y0$3 + y) / 2;
  8102. Z1$1 += z;
  8103. z = y0$3 * x - x0$3 * y;
  8104. X2$1 += z * (x0$3 + x);
  8105. Y2$1 += z * (y0$3 + y);
  8106. Z2$1 += z * 3;
  8107. centroidPoint$1(x0$3 = x, y0$3 = y);
  8108. }
  8109. function PathContext(context) {
  8110. this._context = context;
  8111. }
  8112. PathContext.prototype = {
  8113. _radius: 4.5,
  8114. pointRadius: function(_) {
  8115. return this._radius = _, this;
  8116. },
  8117. polygonStart: function() {
  8118. this._line = 0;
  8119. },
  8120. polygonEnd: function() {
  8121. this._line = NaN;
  8122. },
  8123. lineStart: function() {
  8124. this._point = 0;
  8125. },
  8126. lineEnd: function() {
  8127. if (this._line === 0) this._context.closePath();
  8128. this._point = NaN;
  8129. },
  8130. point: function(x, y) {
  8131. switch (this._point) {
  8132. case 0: {
  8133. this._context.moveTo(x, y);
  8134. this._point = 1;
  8135. break;
  8136. }
  8137. case 1: {
  8138. this._context.lineTo(x, y);
  8139. break;
  8140. }
  8141. default: {
  8142. this._context.moveTo(x + this._radius, y);
  8143. this._context.arc(x, y, this._radius, 0, tau$3);
  8144. break;
  8145. }
  8146. }
  8147. },
  8148. result: noop$2
  8149. };
  8150. var lengthSum$1 = adder(),
  8151. lengthRing,
  8152. x00$2,
  8153. y00$2,
  8154. x0$4,
  8155. y0$4;
  8156. var lengthStream$1 = {
  8157. point: noop$2,
  8158. lineStart: function() {
  8159. lengthStream$1.point = lengthPointFirst$1;
  8160. },
  8161. lineEnd: function() {
  8162. if (lengthRing) lengthPoint$1(x00$2, y00$2);
  8163. lengthStream$1.point = noop$2;
  8164. },
  8165. polygonStart: function() {
  8166. lengthRing = true;
  8167. },
  8168. polygonEnd: function() {
  8169. lengthRing = null;
  8170. },
  8171. result: function() {
  8172. var length = +lengthSum$1;
  8173. lengthSum$1.reset();
  8174. return length;
  8175. }
  8176. };
  8177. function lengthPointFirst$1(x, y) {
  8178. lengthStream$1.point = lengthPoint$1;
  8179. x00$2 = x0$4 = x, y00$2 = y0$4 = y;
  8180. }
  8181. function lengthPoint$1(x, y) {
  8182. x0$4 -= x, y0$4 -= y;
  8183. lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
  8184. x0$4 = x, y0$4 = y;
  8185. }
  8186. function PathString() {
  8187. this._string = [];
  8188. }
  8189. PathString.prototype = {
  8190. _radius: 4.5,
  8191. _circle: circle$1(4.5),
  8192. pointRadius: function(_) {
  8193. if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
  8194. return this;
  8195. },
  8196. polygonStart: function() {
  8197. this._line = 0;
  8198. },
  8199. polygonEnd: function() {
  8200. this._line = NaN;
  8201. },
  8202. lineStart: function() {
  8203. this._point = 0;
  8204. },
  8205. lineEnd: function() {
  8206. if (this._line === 0) this._string.push("Z");
  8207. this._point = NaN;
  8208. },
  8209. point: function(x, y) {
  8210. switch (this._point) {
  8211. case 0: {
  8212. this._string.push("M", x, ",", y);
  8213. this._point = 1;
  8214. break;
  8215. }
  8216. case 1: {
  8217. this._string.push("L", x, ",", y);
  8218. break;
  8219. }
  8220. default: {
  8221. if (this._circle == null) this._circle = circle$1(this._radius);
  8222. this._string.push("M", x, ",", y, this._circle);
  8223. break;
  8224. }
  8225. }
  8226. },
  8227. result: function() {
  8228. if (this._string.length) {
  8229. var result = this._string.join("");
  8230. this._string = [];
  8231. return result;
  8232. } else {
  8233. return null;
  8234. }
  8235. }
  8236. };
  8237. function circle$1(radius) {
  8238. return "m0," + radius
  8239. + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
  8240. + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
  8241. + "z";
  8242. }
  8243. function index$1(projection, context) {
  8244. var pointRadius = 4.5,
  8245. projectionStream,
  8246. contextStream;
  8247. function path(object) {
  8248. if (object) {
  8249. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  8250. geoStream(object, projectionStream(contextStream));
  8251. }
  8252. return contextStream.result();
  8253. }
  8254. path.area = function(object) {
  8255. geoStream(object, projectionStream(areaStream$1));
  8256. return areaStream$1.result();
  8257. };
  8258. path.measure = function(object) {
  8259. geoStream(object, projectionStream(lengthStream$1));
  8260. return lengthStream$1.result();
  8261. };
  8262. path.bounds = function(object) {
  8263. geoStream(object, projectionStream(boundsStream$1));
  8264. return boundsStream$1.result();
  8265. };
  8266. path.centroid = function(object) {
  8267. geoStream(object, projectionStream(centroidStream$1));
  8268. return centroidStream$1.result();
  8269. };
  8270. path.projection = function(_) {
  8271. return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
  8272. };
  8273. path.context = function(_) {
  8274. if (!arguments.length) return context;
  8275. contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
  8276. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  8277. return path;
  8278. };
  8279. path.pointRadius = function(_) {
  8280. if (!arguments.length) return pointRadius;
  8281. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  8282. return path;
  8283. };
  8284. return path.projection(projection).context(context);
  8285. }
  8286. function transform(methods) {
  8287. return {
  8288. stream: transformer(methods)
  8289. };
  8290. }
  8291. function transformer(methods) {
  8292. return function(stream) {
  8293. var s = new TransformStream;
  8294. for (var key in methods) s[key] = methods[key];
  8295. s.stream = stream;
  8296. return s;
  8297. };
  8298. }
  8299. function TransformStream() {}
  8300. TransformStream.prototype = {
  8301. constructor: TransformStream,
  8302. point: function(x, y) { this.stream.point(x, y); },
  8303. sphere: function() { this.stream.sphere(); },
  8304. lineStart: function() { this.stream.lineStart(); },
  8305. lineEnd: function() { this.stream.lineEnd(); },
  8306. polygonStart: function() { this.stream.polygonStart(); },
  8307. polygonEnd: function() { this.stream.polygonEnd(); }
  8308. };
  8309. function fit(projection, fitBounds, object) {
  8310. var clip = projection.clipExtent && projection.clipExtent();
  8311. projection.scale(150).translate([0, 0]);
  8312. if (clip != null) projection.clipExtent(null);
  8313. geoStream(object, projection.stream(boundsStream$1));
  8314. fitBounds(boundsStream$1.result());
  8315. if (clip != null) projection.clipExtent(clip);
  8316. return projection;
  8317. }
  8318. function fitExtent(projection, extent, object) {
  8319. return fit(projection, function(b) {
  8320. var w = extent[1][0] - extent[0][0],
  8321. h = extent[1][1] - extent[0][1],
  8322. k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
  8323. x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
  8324. y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
  8325. projection.scale(150 * k).translate([x, y]);
  8326. }, object);
  8327. }
  8328. function fitSize(projection, size, object) {
  8329. return fitExtent(projection, [[0, 0], size], object);
  8330. }
  8331. function fitWidth(projection, width, object) {
  8332. return fit(projection, function(b) {
  8333. var w = +width,
  8334. k = w / (b[1][0] - b[0][0]),
  8335. x = (w - k * (b[1][0] + b[0][0])) / 2,
  8336. y = -k * b[0][1];
  8337. projection.scale(150 * k).translate([x, y]);
  8338. }, object);
  8339. }
  8340. function fitHeight(projection, height, object) {
  8341. return fit(projection, function(b) {
  8342. var h = +height,
  8343. k = h / (b[1][1] - b[0][1]),
  8344. x = -k * b[0][0],
  8345. y = (h - k * (b[1][1] + b[0][1])) / 2;
  8346. projection.scale(150 * k).translate([x, y]);
  8347. }, object);
  8348. }
  8349. var maxDepth = 16, // maximum depth of subdivision
  8350. cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
  8351. function resample(project, delta2) {
  8352. return +delta2 ? resample$1(project, delta2) : resampleNone(project);
  8353. }
  8354. function resampleNone(project) {
  8355. return transformer({
  8356. point: function(x, y) {
  8357. x = project(x, y);
  8358. this.stream.point(x[0], x[1]);
  8359. }
  8360. });
  8361. }
  8362. function resample$1(project, delta2) {
  8363. function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
  8364. var dx = x1 - x0,
  8365. dy = y1 - y0,
  8366. d2 = dx * dx + dy * dy;
  8367. if (d2 > 4 * delta2 && depth--) {
  8368. var a = a0 + a1,
  8369. b = b0 + b1,
  8370. c = c0 + c1,
  8371. m = sqrt(a * a + b * b + c * c),
  8372. phi2 = asin(c /= m),
  8373. lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
  8374. p = project(lambda2, phi2),
  8375. x2 = p[0],
  8376. y2 = p[1],
  8377. dx2 = x2 - x0,
  8378. dy2 = y2 - y0,
  8379. dz = dy * dx2 - dx * dy2;
  8380. if (dz * dz / d2 > delta2 // perpendicular projected distance
  8381. || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
  8382. || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
  8383. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
  8384. stream.point(x2, y2);
  8385. resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
  8386. }
  8387. }
  8388. }
  8389. return function(stream) {
  8390. var lambda00, x00, y00, a00, b00, c00, // first point
  8391. lambda0, x0, y0, a0, b0, c0; // previous point
  8392. var resampleStream = {
  8393. point: point,
  8394. lineStart: lineStart,
  8395. lineEnd: lineEnd,
  8396. polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
  8397. polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
  8398. };
  8399. function point(x, y) {
  8400. x = project(x, y);
  8401. stream.point(x[0], x[1]);
  8402. }
  8403. function lineStart() {
  8404. x0 = NaN;
  8405. resampleStream.point = linePoint;
  8406. stream.lineStart();
  8407. }
  8408. function linePoint(lambda, phi) {
  8409. var c = cartesian([lambda, phi]), p = project(lambda, phi);
  8410. 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);
  8411. stream.point(x0, y0);
  8412. }
  8413. function lineEnd() {
  8414. resampleStream.point = point;
  8415. stream.lineEnd();
  8416. }
  8417. function ringStart() {
  8418. lineStart();
  8419. resampleStream.point = ringPoint;
  8420. resampleStream.lineEnd = ringEnd;
  8421. }
  8422. function ringPoint(lambda, phi) {
  8423. linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  8424. resampleStream.point = linePoint;
  8425. }
  8426. function ringEnd() {
  8427. resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
  8428. resampleStream.lineEnd = lineEnd;
  8429. lineEnd();
  8430. }
  8431. return resampleStream;
  8432. };
  8433. }
  8434. var transformRadians = transformer({
  8435. point: function(x, y) {
  8436. this.stream.point(x * radians, y * radians);
  8437. }
  8438. });
  8439. function transformRotate(rotate) {
  8440. return transformer({
  8441. point: function(x, y) {
  8442. var r = rotate(x, y);
  8443. return this.stream.point(r[0], r[1]);
  8444. }
  8445. });
  8446. }
  8447. function scaleTranslate(k, dx, dy) {
  8448. function transform(x, y) {
  8449. return [dx + k * x, dy - k * y];
  8450. }
  8451. transform.invert = function(x, y) {
  8452. return [(x - dx) / k, (dy - y) / k];
  8453. };
  8454. return transform;
  8455. }
  8456. function scaleTranslateRotate(k, dx, dy, alpha) {
  8457. var cosAlpha = cos$1(alpha),
  8458. sinAlpha = sin$1(alpha),
  8459. a = cosAlpha * k,
  8460. b = sinAlpha * k,
  8461. ai = cosAlpha / k,
  8462. bi = sinAlpha / k,
  8463. ci = (sinAlpha * dy - cosAlpha * dx) / k,
  8464. fi = (sinAlpha * dx + cosAlpha * dy) / k;
  8465. function transform(x, y) {
  8466. return [a * x - b * y + dx, dy - b * x - a * y];
  8467. }
  8468. transform.invert = function(x, y) {
  8469. return [ai * x - bi * y + ci, fi - bi * x - ai * y];
  8470. };
  8471. return transform;
  8472. }
  8473. function projection(project) {
  8474. return projectionMutator(function() { return project; })();
  8475. }
  8476. function projectionMutator(projectAt) {
  8477. var project,
  8478. k = 150, // scale
  8479. x = 480, y = 250, // translate
  8480. lambda = 0, phi = 0, // center
  8481. deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
  8482. alpha = 0, // post-rotate
  8483. theta = null, preclip = clipAntimeridian, // pre-clip angle
  8484. x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
  8485. delta2 = 0.5, // precision
  8486. projectResample,
  8487. projectTransform,
  8488. projectRotateTransform,
  8489. cache,
  8490. cacheStream;
  8491. function projection(point) {
  8492. return projectRotateTransform(point[0] * radians, point[1] * radians);
  8493. }
  8494. function invert(point) {
  8495. point = projectRotateTransform.invert(point[0], point[1]);
  8496. return point && [point[0] * degrees$1, point[1] * degrees$1];
  8497. }
  8498. projection.stream = function(stream) {
  8499. return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
  8500. };
  8501. projection.preclip = function(_) {
  8502. return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
  8503. };
  8504. projection.postclip = function(_) {
  8505. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8506. };
  8507. projection.clipAngle = function(_) {
  8508. return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
  8509. };
  8510. projection.clipExtent = function(_) {
  8511. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  8512. };
  8513. projection.scale = function(_) {
  8514. return arguments.length ? (k = +_, recenter()) : k;
  8515. };
  8516. projection.translate = function(_) {
  8517. return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
  8518. };
  8519. projection.center = function(_) {
  8520. return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
  8521. };
  8522. projection.rotate = function(_) {
  8523. 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];
  8524. };
  8525. projection.angle = function(_) {
  8526. return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
  8527. };
  8528. projection.precision = function(_) {
  8529. return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
  8530. };
  8531. projection.fitExtent = function(extent, object) {
  8532. return fitExtent(projection, extent, object);
  8533. };
  8534. projection.fitSize = function(size, object) {
  8535. return fitSize(projection, size, object);
  8536. };
  8537. projection.fitWidth = function(width, object) {
  8538. return fitWidth(projection, width, object);
  8539. };
  8540. projection.fitHeight = function(height, object) {
  8541. return fitHeight(projection, height, object);
  8542. };
  8543. function recenter() {
  8544. var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
  8545. transform = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
  8546. rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
  8547. projectTransform = compose(project, transform);
  8548. projectRotateTransform = compose(rotate, projectTransform);
  8549. projectResample = resample(projectTransform, delta2);
  8550. return reset();
  8551. }
  8552. function reset() {
  8553. cache = cacheStream = null;
  8554. return projection;
  8555. }
  8556. return function() {
  8557. project = projectAt.apply(this, arguments);
  8558. projection.invert = project.invert && invert;
  8559. return recenter();
  8560. };
  8561. }
  8562. function conicProjection(projectAt) {
  8563. var phi0 = 0,
  8564. phi1 = pi$3 / 3,
  8565. m = projectionMutator(projectAt),
  8566. p = m(phi0, phi1);
  8567. p.parallels = function(_) {
  8568. return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
  8569. };
  8570. return p;
  8571. }
  8572. function cylindricalEqualAreaRaw(phi0) {
  8573. var cosPhi0 = cos$1(phi0);
  8574. function forward(lambda, phi) {
  8575. return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
  8576. }
  8577. forward.invert = function(x, y) {
  8578. return [x / cosPhi0, asin(y * cosPhi0)];
  8579. };
  8580. return forward;
  8581. }
  8582. function conicEqualAreaRaw(y0, y1) {
  8583. var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
  8584. // Are the parallels symmetrical around the Equator?
  8585. if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
  8586. var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
  8587. function project(x, y) {
  8588. var r = sqrt(c - 2 * n * sin$1(y)) / n;
  8589. return [r * sin$1(x *= n), r0 - r * cos$1(x)];
  8590. }
  8591. project.invert = function(x, y) {
  8592. var r0y = r0 - y;
  8593. return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
  8594. };
  8595. return project;
  8596. }
  8597. function conicEqualArea() {
  8598. return conicProjection(conicEqualAreaRaw)
  8599. .scale(155.424)
  8600. .center([0, 33.6442]);
  8601. }
  8602. function albers() {
  8603. return conicEqualArea()
  8604. .parallels([29.5, 45.5])
  8605. .scale(1070)
  8606. .translate([480, 250])
  8607. .rotate([96, 0])
  8608. .center([-0.6, 38.7]);
  8609. }
  8610. // The projections must have mutually exclusive clip regions on the sphere,
  8611. // as this will avoid emitting interleaving lines and polygons.
  8612. function multiplex(streams) {
  8613. var n = streams.length;
  8614. return {
  8615. point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
  8616. sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
  8617. lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
  8618. lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
  8619. polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
  8620. polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
  8621. };
  8622. }
  8623. // A composite projection for the United States, configured by default for
  8624. // 960×500. The projection also works quite well at 960×600 if you change the
  8625. // scale to 1285 and adjust the translate accordingly. The set of standard
  8626. // parallels for each region comes from USGS, which is published here:
  8627. // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
  8628. function albersUsa() {
  8629. var cache,
  8630. cacheStream,
  8631. lower48 = albers(), lower48Point,
  8632. alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
  8633. hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
  8634. point, pointStream = {point: function(x, y) { point = [x, y]; }};
  8635. function albersUsa(coordinates) {
  8636. var x = coordinates[0], y = coordinates[1];
  8637. return point = null,
  8638. (lower48Point.point(x, y), point)
  8639. || (alaskaPoint.point(x, y), point)
  8640. || (hawaiiPoint.point(x, y), point);
  8641. }
  8642. albersUsa.invert = function(coordinates) {
  8643. var k = lower48.scale(),
  8644. t = lower48.translate(),
  8645. x = (coordinates[0] - t[0]) / k,
  8646. y = (coordinates[1] - t[1]) / k;
  8647. return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
  8648. : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
  8649. : lower48).invert(coordinates);
  8650. };
  8651. albersUsa.stream = function(stream) {
  8652. return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
  8653. };
  8654. albersUsa.precision = function(_) {
  8655. if (!arguments.length) return lower48.precision();
  8656. lower48.precision(_), alaska.precision(_), hawaii.precision(_);
  8657. return reset();
  8658. };
  8659. albersUsa.scale = function(_) {
  8660. if (!arguments.length) return lower48.scale();
  8661. lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
  8662. return albersUsa.translate(lower48.translate());
  8663. };
  8664. albersUsa.translate = function(_) {
  8665. if (!arguments.length) return lower48.translate();
  8666. var k = lower48.scale(), x = +_[0], y = +_[1];
  8667. lower48Point = lower48
  8668. .translate(_)
  8669. .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
  8670. .stream(pointStream);
  8671. alaskaPoint = alaska
  8672. .translate([x - 0.307 * k, y + 0.201 * k])
  8673. .clipExtent([[x - 0.425 * k + epsilon$2, y + 0.120 * k + epsilon$2], [x - 0.214 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
  8674. .stream(pointStream);
  8675. hawaiiPoint = hawaii
  8676. .translate([x - 0.205 * k, y + 0.212 * k])
  8677. .clipExtent([[x - 0.214 * k + epsilon$2, y + 0.166 * k + epsilon$2], [x - 0.115 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
  8678. .stream(pointStream);
  8679. return reset();
  8680. };
  8681. albersUsa.fitExtent = function(extent, object) {
  8682. return fitExtent(albersUsa, extent, object);
  8683. };
  8684. albersUsa.fitSize = function(size, object) {
  8685. return fitSize(albersUsa, size, object);
  8686. };
  8687. albersUsa.fitWidth = function(width, object) {
  8688. return fitWidth(albersUsa, width, object);
  8689. };
  8690. albersUsa.fitHeight = function(height, object) {
  8691. return fitHeight(albersUsa, height, object);
  8692. };
  8693. function reset() {
  8694. cache = cacheStream = null;
  8695. return albersUsa;
  8696. }
  8697. return albersUsa.scale(1070);
  8698. }
  8699. function azimuthalRaw(scale) {
  8700. return function(x, y) {
  8701. var cx = cos$1(x),
  8702. cy = cos$1(y),
  8703. k = scale(cx * cy);
  8704. return [
  8705. k * cy * sin$1(x),
  8706. k * sin$1(y)
  8707. ];
  8708. }
  8709. }
  8710. function azimuthalInvert(angle) {
  8711. return function(x, y) {
  8712. var z = sqrt(x * x + y * y),
  8713. c = angle(z),
  8714. sc = sin$1(c),
  8715. cc = cos$1(c);
  8716. return [
  8717. atan2(x * sc, z * cc),
  8718. asin(z && y * sc / z)
  8719. ];
  8720. }
  8721. }
  8722. var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
  8723. return sqrt(2 / (1 + cxcy));
  8724. });
  8725. azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
  8726. return 2 * asin(z / 2);
  8727. });
  8728. function azimuthalEqualArea() {
  8729. return projection(azimuthalEqualAreaRaw)
  8730. .scale(124.75)
  8731. .clipAngle(180 - 1e-3);
  8732. }
  8733. var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
  8734. return (c = acos(c)) && c / sin$1(c);
  8735. });
  8736. azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
  8737. return z;
  8738. });
  8739. function azimuthalEquidistant() {
  8740. return projection(azimuthalEquidistantRaw)
  8741. .scale(79.4188)
  8742. .clipAngle(180 - 1e-3);
  8743. }
  8744. function mercatorRaw(lambda, phi) {
  8745. return [lambda, log(tan((halfPi$2 + phi) / 2))];
  8746. }
  8747. mercatorRaw.invert = function(x, y) {
  8748. return [x, 2 * atan(exp(y)) - halfPi$2];
  8749. };
  8750. function mercator() {
  8751. return mercatorProjection(mercatorRaw)
  8752. .scale(961 / tau$3);
  8753. }
  8754. function mercatorProjection(project) {
  8755. var m = projection(project),
  8756. center = m.center,
  8757. scale = m.scale,
  8758. translate = m.translate,
  8759. clipExtent = m.clipExtent,
  8760. x0 = null, y0, x1, y1; // clip extent
  8761. m.scale = function(_) {
  8762. return arguments.length ? (scale(_), reclip()) : scale();
  8763. };
  8764. m.translate = function(_) {
  8765. return arguments.length ? (translate(_), reclip()) : translate();
  8766. };
  8767. m.center = function(_) {
  8768. return arguments.length ? (center(_), reclip()) : center();
  8769. };
  8770. m.clipExtent = function(_) {
  8771. return arguments.length ? ((_ == null ? x0 = y0 = x1 = y1 = null : (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1])), reclip()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  8772. };
  8773. function reclip() {
  8774. var k = pi$3 * scale(),
  8775. t = m(rotation(m.rotate()).invert([0, 0]));
  8776. return clipExtent(x0 == null
  8777. ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
  8778. ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
  8779. : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
  8780. }
  8781. return reclip();
  8782. }
  8783. function tany(y) {
  8784. return tan((halfPi$2 + y) / 2);
  8785. }
  8786. function conicConformalRaw(y0, y1) {
  8787. var cy0 = cos$1(y0),
  8788. n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
  8789. f = cy0 * pow(tany(y0), n) / n;
  8790. if (!n) return mercatorRaw;
  8791. function project(x, y) {
  8792. if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
  8793. else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
  8794. var r = f / pow(tany(y), n);
  8795. return [r * sin$1(n * x), f - r * cos$1(n * x)];
  8796. }
  8797. project.invert = function(x, y) {
  8798. var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
  8799. return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
  8800. };
  8801. return project;
  8802. }
  8803. function conicConformal() {
  8804. return conicProjection(conicConformalRaw)
  8805. .scale(109.5)
  8806. .parallels([30, 30]);
  8807. }
  8808. function equirectangularRaw(lambda, phi) {
  8809. return [lambda, phi];
  8810. }
  8811. equirectangularRaw.invert = equirectangularRaw;
  8812. function equirectangular() {
  8813. return projection(equirectangularRaw)
  8814. .scale(152.63);
  8815. }
  8816. function conicEquidistantRaw(y0, y1) {
  8817. var cy0 = cos$1(y0),
  8818. n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
  8819. g = cy0 / n + y0;
  8820. if (abs(n) < epsilon$2) return equirectangularRaw;
  8821. function project(x, y) {
  8822. var gy = g - y, nx = n * x;
  8823. return [gy * sin$1(nx), g - gy * cos$1(nx)];
  8824. }
  8825. project.invert = function(x, y) {
  8826. var gy = g - y;
  8827. return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
  8828. };
  8829. return project;
  8830. }
  8831. function conicEquidistant() {
  8832. return conicProjection(conicEquidistantRaw)
  8833. .scale(131.154)
  8834. .center([0, 13.9389]);
  8835. }
  8836. var A1 = 1.340264,
  8837. A2 = -0.081106,
  8838. A3 = 0.000893,
  8839. A4 = 0.003796,
  8840. M = sqrt(3) / 2,
  8841. iterations = 12;
  8842. function equalEarthRaw(lambda, phi) {
  8843. var l = asin(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
  8844. return [
  8845. lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
  8846. l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
  8847. ];
  8848. }
  8849. equalEarthRaw.invert = function(x, y) {
  8850. var l = y, l2 = l * l, l6 = l2 * l2 * l2;
  8851. for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
  8852. fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
  8853. fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
  8854. l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
  8855. if (abs(delta) < epsilon2$1) break;
  8856. }
  8857. return [
  8858. M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
  8859. asin(sin$1(l) / M)
  8860. ];
  8861. };
  8862. function equalEarth() {
  8863. return projection(equalEarthRaw)
  8864. .scale(177.158);
  8865. }
  8866. function gnomonicRaw(x, y) {
  8867. var cy = cos$1(y), k = cos$1(x) * cy;
  8868. return [cy * sin$1(x) / k, sin$1(y) / k];
  8869. }
  8870. gnomonicRaw.invert = azimuthalInvert(atan);
  8871. function gnomonic() {
  8872. return projection(gnomonicRaw)
  8873. .scale(144.049)
  8874. .clipAngle(60);
  8875. }
  8876. function scaleTranslate$1(kx, ky, tx, ty) {
  8877. return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
  8878. point: function(x, y) {
  8879. this.stream.point(x * kx + tx, y * ky + ty);
  8880. }
  8881. });
  8882. }
  8883. function identity$5() {
  8884. var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform = identity$4, // scale, translate and reflect
  8885. x0 = null, y0, x1, y1, // clip extent
  8886. postclip = identity$4,
  8887. cache,
  8888. cacheStream,
  8889. projection;
  8890. function reset() {
  8891. cache = cacheStream = null;
  8892. return projection;
  8893. }
  8894. return projection = {
  8895. stream: function(stream) {
  8896. return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
  8897. },
  8898. postclip: function(_) {
  8899. return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
  8900. },
  8901. clipExtent: function(_) {
  8902. return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
  8903. },
  8904. scale: function(_) {
  8905. return arguments.length ? (transform = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
  8906. },
  8907. translate: function(_) {
  8908. return arguments.length ? (transform = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
  8909. },
  8910. reflectX: function(_) {
  8911. return arguments.length ? (transform = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
  8912. },
  8913. reflectY: function(_) {
  8914. return arguments.length ? (transform = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
  8915. },
  8916. fitExtent: function(extent, object) {
  8917. return fitExtent(projection, extent, object);
  8918. },
  8919. fitSize: function(size, object) {
  8920. return fitSize(projection, size, object);
  8921. },
  8922. fitWidth: function(width, object) {
  8923. return fitWidth(projection, width, object);
  8924. },
  8925. fitHeight: function(height, object) {
  8926. return fitHeight(projection, height, object);
  8927. }
  8928. };
  8929. }
  8930. function naturalEarth1Raw(lambda, phi) {
  8931. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8932. return [
  8933. lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
  8934. phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
  8935. ];
  8936. }
  8937. naturalEarth1Raw.invert = function(x, y) {
  8938. var phi = y, i = 25, delta;
  8939. do {
  8940. var phi2 = phi * phi, phi4 = phi2 * phi2;
  8941. phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
  8942. (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
  8943. } while (abs(delta) > epsilon$2 && --i > 0);
  8944. return [
  8945. x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
  8946. phi
  8947. ];
  8948. };
  8949. function naturalEarth1() {
  8950. return projection(naturalEarth1Raw)
  8951. .scale(175.295);
  8952. }
  8953. function orthographicRaw(x, y) {
  8954. return [cos$1(y) * sin$1(x), sin$1(y)];
  8955. }
  8956. orthographicRaw.invert = azimuthalInvert(asin);
  8957. function orthographic() {
  8958. return projection(orthographicRaw)
  8959. .scale(249.5)
  8960. .clipAngle(90 + epsilon$2);
  8961. }
  8962. function stereographicRaw(x, y) {
  8963. var cy = cos$1(y), k = 1 + cos$1(x) * cy;
  8964. return [cy * sin$1(x) / k, sin$1(y) / k];
  8965. }
  8966. stereographicRaw.invert = azimuthalInvert(function(z) {
  8967. return 2 * atan(z);
  8968. });
  8969. function stereographic() {
  8970. return projection(stereographicRaw)
  8971. .scale(250)
  8972. .clipAngle(142);
  8973. }
  8974. function transverseMercatorRaw(lambda, phi) {
  8975. return [log(tan((halfPi$2 + phi) / 2)), -lambda];
  8976. }
  8977. transverseMercatorRaw.invert = function(x, y) {
  8978. return [-y, 2 * atan(exp(x)) - halfPi$2];
  8979. };
  8980. function transverseMercator() {
  8981. var m = mercatorProjection(transverseMercatorRaw),
  8982. center = m.center,
  8983. rotate = m.rotate;
  8984. m.center = function(_) {
  8985. return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
  8986. };
  8987. m.rotate = function(_) {
  8988. return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
  8989. };
  8990. return rotate([0, 0, 90])
  8991. .scale(159.155);
  8992. }
  8993. function defaultSeparation(a, b) {
  8994. return a.parent === b.parent ? 1 : 2;
  8995. }
  8996. function meanX(children) {
  8997. return children.reduce(meanXReduce, 0) / children.length;
  8998. }
  8999. function meanXReduce(x, c) {
  9000. return x + c.x;
  9001. }
  9002. function maxY(children) {
  9003. return 1 + children.reduce(maxYReduce, 0);
  9004. }
  9005. function maxYReduce(y, c) {
  9006. return Math.max(y, c.y);
  9007. }
  9008. function leafLeft(node) {
  9009. var children;
  9010. while (children = node.children) node = children[0];
  9011. return node;
  9012. }
  9013. function leafRight(node) {
  9014. var children;
  9015. while (children = node.children) node = children[children.length - 1];
  9016. return node;
  9017. }
  9018. function cluster() {
  9019. var separation = defaultSeparation,
  9020. dx = 1,
  9021. dy = 1,
  9022. nodeSize = false;
  9023. function cluster(root) {
  9024. var previousNode,
  9025. x = 0;
  9026. // First walk, computing the initial x & y values.
  9027. root.eachAfter(function(node) {
  9028. var children = node.children;
  9029. if (children) {
  9030. node.x = meanX(children);
  9031. node.y = maxY(children);
  9032. } else {
  9033. node.x = previousNode ? x += separation(node, previousNode) : 0;
  9034. node.y = 0;
  9035. previousNode = node;
  9036. }
  9037. });
  9038. var left = leafLeft(root),
  9039. right = leafRight(root),
  9040. x0 = left.x - separation(left, right) / 2,
  9041. x1 = right.x + separation(right, left) / 2;
  9042. // Second walk, normalizing x & y to the desired size.
  9043. return root.eachAfter(nodeSize ? function(node) {
  9044. node.x = (node.x - root.x) * dx;
  9045. node.y = (root.y - node.y) * dy;
  9046. } : function(node) {
  9047. node.x = (node.x - x0) / (x1 - x0) * dx;
  9048. node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
  9049. });
  9050. }
  9051. cluster.separation = function(x) {
  9052. return arguments.length ? (separation = x, cluster) : separation;
  9053. };
  9054. cluster.size = function(x) {
  9055. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
  9056. };
  9057. cluster.nodeSize = function(x) {
  9058. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
  9059. };
  9060. return cluster;
  9061. }
  9062. function count(node) {
  9063. var sum = 0,
  9064. children = node.children,
  9065. i = children && children.length;
  9066. if (!i) sum = 1;
  9067. else while (--i >= 0) sum += children[i].value;
  9068. node.value = sum;
  9069. }
  9070. function node_count() {
  9071. return this.eachAfter(count);
  9072. }
  9073. function node_each(callback) {
  9074. var node = this, current, next = [node], children, i, n;
  9075. do {
  9076. current = next.reverse(), next = [];
  9077. while (node = current.pop()) {
  9078. callback(node), children = node.children;
  9079. if (children) for (i = 0, n = children.length; i < n; ++i) {
  9080. next.push(children[i]);
  9081. }
  9082. }
  9083. } while (next.length);
  9084. return this;
  9085. }
  9086. function node_eachBefore(callback) {
  9087. var node = this, nodes = [node], children, i;
  9088. while (node = nodes.pop()) {
  9089. callback(node), children = node.children;
  9090. if (children) for (i = children.length - 1; i >= 0; --i) {
  9091. nodes.push(children[i]);
  9092. }
  9093. }
  9094. return this;
  9095. }
  9096. function node_eachAfter(callback) {
  9097. var node = this, nodes = [node], next = [], children, i, n;
  9098. while (node = nodes.pop()) {
  9099. next.push(node), children = node.children;
  9100. if (children) for (i = 0, n = children.length; i < n; ++i) {
  9101. nodes.push(children[i]);
  9102. }
  9103. }
  9104. while (node = next.pop()) {
  9105. callback(node);
  9106. }
  9107. return this;
  9108. }
  9109. function node_sum(value) {
  9110. return this.eachAfter(function(node) {
  9111. var sum = +value(node.data) || 0,
  9112. children = node.children,
  9113. i = children && children.length;
  9114. while (--i >= 0) sum += children[i].value;
  9115. node.value = sum;
  9116. });
  9117. }
  9118. function node_sort(compare) {
  9119. return this.eachBefore(function(node) {
  9120. if (node.children) {
  9121. node.children.sort(compare);
  9122. }
  9123. });
  9124. }
  9125. function node_path(end) {
  9126. var start = this,
  9127. ancestor = leastCommonAncestor(start, end),
  9128. nodes = [start];
  9129. while (start !== ancestor) {
  9130. start = start.parent;
  9131. nodes.push(start);
  9132. }
  9133. var k = nodes.length;
  9134. while (end !== ancestor) {
  9135. nodes.splice(k, 0, end);
  9136. end = end.parent;
  9137. }
  9138. return nodes;
  9139. }
  9140. function leastCommonAncestor(a, b) {
  9141. if (a === b) return a;
  9142. var aNodes = a.ancestors(),
  9143. bNodes = b.ancestors(),
  9144. c = null;
  9145. a = aNodes.pop();
  9146. b = bNodes.pop();
  9147. while (a === b) {
  9148. c = a;
  9149. a = aNodes.pop();
  9150. b = bNodes.pop();
  9151. }
  9152. return c;
  9153. }
  9154. function node_ancestors() {
  9155. var node = this, nodes = [node];
  9156. while (node = node.parent) {
  9157. nodes.push(node);
  9158. }
  9159. return nodes;
  9160. }
  9161. function node_descendants() {
  9162. var nodes = [];
  9163. this.each(function(node) {
  9164. nodes.push(node);
  9165. });
  9166. return nodes;
  9167. }
  9168. function node_leaves() {
  9169. var leaves = [];
  9170. this.eachBefore(function(node) {
  9171. if (!node.children) {
  9172. leaves.push(node);
  9173. }
  9174. });
  9175. return leaves;
  9176. }
  9177. function node_links() {
  9178. var root = this, links = [];
  9179. root.each(function(node) {
  9180. if (node !== root) { // Don’t include the root’s parent, if any.
  9181. links.push({source: node.parent, target: node});
  9182. }
  9183. });
  9184. return links;
  9185. }
  9186. function hierarchy(data, children) {
  9187. var root = new Node(data),
  9188. valued = +data.value && (root.value = data.value),
  9189. node,
  9190. nodes = [root],
  9191. child,
  9192. childs,
  9193. i,
  9194. n;
  9195. if (children == null) children = defaultChildren;
  9196. while (node = nodes.pop()) {
  9197. if (valued) node.value = +node.data.value;
  9198. if ((childs = children(node.data)) && (n = childs.length)) {
  9199. node.children = new Array(n);
  9200. for (i = n - 1; i >= 0; --i) {
  9201. nodes.push(child = node.children[i] = new Node(childs[i]));
  9202. child.parent = node;
  9203. child.depth = node.depth + 1;
  9204. }
  9205. }
  9206. }
  9207. return root.eachBefore(computeHeight);
  9208. }
  9209. function node_copy() {
  9210. return hierarchy(this).eachBefore(copyData);
  9211. }
  9212. function defaultChildren(d) {
  9213. return d.children;
  9214. }
  9215. function copyData(node) {
  9216. node.data = node.data.data;
  9217. }
  9218. function computeHeight(node) {
  9219. var height = 0;
  9220. do node.height = height;
  9221. while ((node = node.parent) && (node.height < ++height));
  9222. }
  9223. function Node(data) {
  9224. this.data = data;
  9225. this.depth =
  9226. this.height = 0;
  9227. this.parent = null;
  9228. }
  9229. Node.prototype = hierarchy.prototype = {
  9230. constructor: Node,
  9231. count: node_count,
  9232. each: node_each,
  9233. eachAfter: node_eachAfter,
  9234. eachBefore: node_eachBefore,
  9235. sum: node_sum,
  9236. sort: node_sort,
  9237. path: node_path,
  9238. ancestors: node_ancestors,
  9239. descendants: node_descendants,
  9240. leaves: node_leaves,
  9241. links: node_links,
  9242. copy: node_copy
  9243. };
  9244. var slice$4 = Array.prototype.slice;
  9245. function shuffle$1(array) {
  9246. var m = array.length,
  9247. t,
  9248. i;
  9249. while (m) {
  9250. i = Math.random() * m-- | 0;
  9251. t = array[m];
  9252. array[m] = array[i];
  9253. array[i] = t;
  9254. }
  9255. return array;
  9256. }
  9257. function enclose(circles) {
  9258. var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
  9259. while (i < n) {
  9260. p = circles[i];
  9261. if (e && enclosesWeak(e, p)) ++i;
  9262. else e = encloseBasis(B = extendBasis(B, p)), i = 0;
  9263. }
  9264. return e;
  9265. }
  9266. function extendBasis(B, p) {
  9267. var i, j;
  9268. if (enclosesWeakAll(p, B)) return [p];
  9269. // If we get here then B must have at least one element.
  9270. for (i = 0; i < B.length; ++i) {
  9271. if (enclosesNot(p, B[i])
  9272. && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
  9273. return [B[i], p];
  9274. }
  9275. }
  9276. // If we get here then B must have at least two elements.
  9277. for (i = 0; i < B.length - 1; ++i) {
  9278. for (j = i + 1; j < B.length; ++j) {
  9279. if (enclosesNot(encloseBasis2(B[i], B[j]), p)
  9280. && enclosesNot(encloseBasis2(B[i], p), B[j])
  9281. && enclosesNot(encloseBasis2(B[j], p), B[i])
  9282. && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
  9283. return [B[i], B[j], p];
  9284. }
  9285. }
  9286. }
  9287. // If we get here then something is very wrong.
  9288. throw new Error;
  9289. }
  9290. function enclosesNot(a, b) {
  9291. var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
  9292. return dr < 0 || dr * dr < dx * dx + dy * dy;
  9293. }
  9294. function enclosesWeak(a, b) {
  9295. var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9296. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9297. }
  9298. function enclosesWeakAll(a, B) {
  9299. for (var i = 0; i < B.length; ++i) {
  9300. if (!enclosesWeak(a, B[i])) {
  9301. return false;
  9302. }
  9303. }
  9304. return true;
  9305. }
  9306. function encloseBasis(B) {
  9307. switch (B.length) {
  9308. case 1: return encloseBasis1(B[0]);
  9309. case 2: return encloseBasis2(B[0], B[1]);
  9310. case 3: return encloseBasis3(B[0], B[1], B[2]);
  9311. }
  9312. }
  9313. function encloseBasis1(a) {
  9314. return {
  9315. x: a.x,
  9316. y: a.y,
  9317. r: a.r
  9318. };
  9319. }
  9320. function encloseBasis2(a, b) {
  9321. var x1 = a.x, y1 = a.y, r1 = a.r,
  9322. x2 = b.x, y2 = b.y, r2 = b.r,
  9323. x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
  9324. l = Math.sqrt(x21 * x21 + y21 * y21);
  9325. return {
  9326. x: (x1 + x2 + x21 / l * r21) / 2,
  9327. y: (y1 + y2 + y21 / l * r21) / 2,
  9328. r: (l + r1 + r2) / 2
  9329. };
  9330. }
  9331. function encloseBasis3(a, b, c) {
  9332. var x1 = a.x, y1 = a.y, r1 = a.r,
  9333. x2 = b.x, y2 = b.y, r2 = b.r,
  9334. x3 = c.x, y3 = c.y, r3 = c.r,
  9335. a2 = x1 - x2,
  9336. a3 = x1 - x3,
  9337. b2 = y1 - y2,
  9338. b3 = y1 - y3,
  9339. c2 = r2 - r1,
  9340. c3 = r3 - r1,
  9341. d1 = x1 * x1 + y1 * y1 - r1 * r1,
  9342. d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
  9343. d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
  9344. ab = a3 * b2 - a2 * b3,
  9345. xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
  9346. xb = (b3 * c2 - b2 * c3) / ab,
  9347. ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
  9348. yb = (a2 * c3 - a3 * c2) / ab,
  9349. A = xb * xb + yb * yb - 1,
  9350. B = 2 * (r1 + xa * xb + ya * yb),
  9351. C = xa * xa + ya * ya - r1 * r1,
  9352. r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
  9353. return {
  9354. x: x1 + xa + xb * r,
  9355. y: y1 + ya + yb * r,
  9356. r: r
  9357. };
  9358. }
  9359. function place(b, a, c) {
  9360. var dx = b.x - a.x, x, a2,
  9361. dy = b.y - a.y, y, b2,
  9362. d2 = dx * dx + dy * dy;
  9363. if (d2) {
  9364. a2 = a.r + c.r, a2 *= a2;
  9365. b2 = b.r + c.r, b2 *= b2;
  9366. if (a2 > b2) {
  9367. x = (d2 + b2 - a2) / (2 * d2);
  9368. y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
  9369. c.x = b.x - x * dx - y * dy;
  9370. c.y = b.y - x * dy + y * dx;
  9371. } else {
  9372. x = (d2 + a2 - b2) / (2 * d2);
  9373. y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
  9374. c.x = a.x + x * dx - y * dy;
  9375. c.y = a.y + x * dy + y * dx;
  9376. }
  9377. } else {
  9378. c.x = a.x + c.r;
  9379. c.y = a.y;
  9380. }
  9381. }
  9382. function intersects(a, b) {
  9383. var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
  9384. return dr > 0 && dr * dr > dx * dx + dy * dy;
  9385. }
  9386. function score(node) {
  9387. var a = node._,
  9388. b = node.next._,
  9389. ab = a.r + b.r,
  9390. dx = (a.x * b.r + b.x * a.r) / ab,
  9391. dy = (a.y * b.r + b.y * a.r) / ab;
  9392. return dx * dx + dy * dy;
  9393. }
  9394. function Node$1(circle) {
  9395. this._ = circle;
  9396. this.next = null;
  9397. this.previous = null;
  9398. }
  9399. function packEnclose(circles) {
  9400. if (!(n = circles.length)) return 0;
  9401. var a, b, c, n, aa, ca, i, j, k, sj, sk;
  9402. // Place the first circle.
  9403. a = circles[0], a.x = 0, a.y = 0;
  9404. if (!(n > 1)) return a.r;
  9405. // Place the second circle.
  9406. b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
  9407. if (!(n > 2)) return a.r + b.r;
  9408. // Place the third circle.
  9409. place(b, a, c = circles[2]);
  9410. // Initialize the front-chain using the first three circles a, b and c.
  9411. a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
  9412. a.next = c.previous = b;
  9413. b.next = a.previous = c;
  9414. c.next = b.previous = a;
  9415. // Attempt to place each remaining circle…
  9416. pack: for (i = 3; i < n; ++i) {
  9417. place(a._, b._, c = circles[i]), c = new Node$1(c);
  9418. // Find the closest intersecting circle on the front-chain, if any.
  9419. // “Closeness” is determined by linear distance along the front-chain.
  9420. // “Ahead” or “behind” is likewise determined by linear distance.
  9421. j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
  9422. do {
  9423. if (sj <= sk) {
  9424. if (intersects(j._, c._)) {
  9425. b = j, a.next = b, b.previous = a, --i;
  9426. continue pack;
  9427. }
  9428. sj += j._.r, j = j.next;
  9429. } else {
  9430. if (intersects(k._, c._)) {
  9431. a = k, a.next = b, b.previous = a, --i;
  9432. continue pack;
  9433. }
  9434. sk += k._.r, k = k.previous;
  9435. }
  9436. } while (j !== k.next);
  9437. // Success! Insert the new circle c between a and b.
  9438. c.previous = a, c.next = b, a.next = b.previous = b = c;
  9439. // Compute the new closest circle pair to the centroid.
  9440. aa = score(a);
  9441. while ((c = c.next) !== b) {
  9442. if ((ca = score(c)) < aa) {
  9443. a = c, aa = ca;
  9444. }
  9445. }
  9446. b = a.next;
  9447. }
  9448. // Compute the enclosing circle of the front chain.
  9449. a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
  9450. // Translate the circles to put the enclosing circle around the origin.
  9451. for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
  9452. return c.r;
  9453. }
  9454. function siblings(circles) {
  9455. packEnclose(circles);
  9456. return circles;
  9457. }
  9458. function optional(f) {
  9459. return f == null ? null : required(f);
  9460. }
  9461. function required(f) {
  9462. if (typeof f !== "function") throw new Error;
  9463. return f;
  9464. }
  9465. function constantZero() {
  9466. return 0;
  9467. }
  9468. function constant$9(x) {
  9469. return function() {
  9470. return x;
  9471. };
  9472. }
  9473. function defaultRadius$1(d) {
  9474. return Math.sqrt(d.value);
  9475. }
  9476. function index$2() {
  9477. var radius = null,
  9478. dx = 1,
  9479. dy = 1,
  9480. padding = constantZero;
  9481. function pack(root) {
  9482. root.x = dx / 2, root.y = dy / 2;
  9483. if (radius) {
  9484. root.eachBefore(radiusLeaf(radius))
  9485. .eachAfter(packChildren(padding, 0.5))
  9486. .eachBefore(translateChild(1));
  9487. } else {
  9488. root.eachBefore(radiusLeaf(defaultRadius$1))
  9489. .eachAfter(packChildren(constantZero, 1))
  9490. .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
  9491. .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
  9492. }
  9493. return root;
  9494. }
  9495. pack.radius = function(x) {
  9496. return arguments.length ? (radius = optional(x), pack) : radius;
  9497. };
  9498. pack.size = function(x) {
  9499. return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
  9500. };
  9501. pack.padding = function(x) {
  9502. return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
  9503. };
  9504. return pack;
  9505. }
  9506. function radiusLeaf(radius) {
  9507. return function(node) {
  9508. if (!node.children) {
  9509. node.r = Math.max(0, +radius(node) || 0);
  9510. }
  9511. };
  9512. }
  9513. function packChildren(padding, k) {
  9514. return function(node) {
  9515. if (children = node.children) {
  9516. var children,
  9517. i,
  9518. n = children.length,
  9519. r = padding(node) * k || 0,
  9520. e;
  9521. if (r) for (i = 0; i < n; ++i) children[i].r += r;
  9522. e = packEnclose(children);
  9523. if (r) for (i = 0; i < n; ++i) children[i].r -= r;
  9524. node.r = e + r;
  9525. }
  9526. };
  9527. }
  9528. function translateChild(k) {
  9529. return function(node) {
  9530. var parent = node.parent;
  9531. node.r *= k;
  9532. if (parent) {
  9533. node.x = parent.x + k * node.x;
  9534. node.y = parent.y + k * node.y;
  9535. }
  9536. };
  9537. }
  9538. function roundNode(node) {
  9539. node.x0 = Math.round(node.x0);
  9540. node.y0 = Math.round(node.y0);
  9541. node.x1 = Math.round(node.x1);
  9542. node.y1 = Math.round(node.y1);
  9543. }
  9544. function treemapDice(parent, x0, y0, x1, y1) {
  9545. var nodes = parent.children,
  9546. node,
  9547. i = -1,
  9548. n = nodes.length,
  9549. k = parent.value && (x1 - x0) / parent.value;
  9550. while (++i < n) {
  9551. node = nodes[i], node.y0 = y0, node.y1 = y1;
  9552. node.x0 = x0, node.x1 = x0 += node.value * k;
  9553. }
  9554. }
  9555. function partition() {
  9556. var dx = 1,
  9557. dy = 1,
  9558. padding = 0,
  9559. round = false;
  9560. function partition(root) {
  9561. var n = root.height + 1;
  9562. root.x0 =
  9563. root.y0 = padding;
  9564. root.x1 = dx;
  9565. root.y1 = dy / n;
  9566. root.eachBefore(positionNode(dy, n));
  9567. if (round) root.eachBefore(roundNode);
  9568. return root;
  9569. }
  9570. function positionNode(dy, n) {
  9571. return function(node) {
  9572. if (node.children) {
  9573. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  9574. }
  9575. var x0 = node.x0,
  9576. y0 = node.y0,
  9577. x1 = node.x1 - padding,
  9578. y1 = node.y1 - padding;
  9579. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9580. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9581. node.x0 = x0;
  9582. node.y0 = y0;
  9583. node.x1 = x1;
  9584. node.y1 = y1;
  9585. };
  9586. }
  9587. partition.round = function(x) {
  9588. return arguments.length ? (round = !!x, partition) : round;
  9589. };
  9590. partition.size = function(x) {
  9591. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  9592. };
  9593. partition.padding = function(x) {
  9594. return arguments.length ? (padding = +x, partition) : padding;
  9595. };
  9596. return partition;
  9597. }
  9598. var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
  9599. preroot = {depth: -1},
  9600. ambiguous = {};
  9601. function defaultId(d) {
  9602. return d.id;
  9603. }
  9604. function defaultParentId(d) {
  9605. return d.parentId;
  9606. }
  9607. function stratify() {
  9608. var id = defaultId,
  9609. parentId = defaultParentId;
  9610. function stratify(data) {
  9611. var d,
  9612. i,
  9613. n = data.length,
  9614. root,
  9615. parent,
  9616. node,
  9617. nodes = new Array(n),
  9618. nodeId,
  9619. nodeKey,
  9620. nodeByKey = {};
  9621. for (i = 0; i < n; ++i) {
  9622. d = data[i], node = nodes[i] = new Node(d);
  9623. if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
  9624. nodeKey = keyPrefix$1 + (node.id = nodeId);
  9625. nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
  9626. }
  9627. }
  9628. for (i = 0; i < n; ++i) {
  9629. node = nodes[i], nodeId = parentId(data[i], i, data);
  9630. if (nodeId == null || !(nodeId += "")) {
  9631. if (root) throw new Error("multiple roots");
  9632. root = node;
  9633. } else {
  9634. parent = nodeByKey[keyPrefix$1 + nodeId];
  9635. if (!parent) throw new Error("missing: " + nodeId);
  9636. if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
  9637. if (parent.children) parent.children.push(node);
  9638. else parent.children = [node];
  9639. node.parent = parent;
  9640. }
  9641. }
  9642. if (!root) throw new Error("no root");
  9643. root.parent = preroot;
  9644. root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
  9645. root.parent = null;
  9646. if (n > 0) throw new Error("cycle");
  9647. return root;
  9648. }
  9649. stratify.id = function(x) {
  9650. return arguments.length ? (id = required(x), stratify) : id;
  9651. };
  9652. stratify.parentId = function(x) {
  9653. return arguments.length ? (parentId = required(x), stratify) : parentId;
  9654. };
  9655. return stratify;
  9656. }
  9657. function defaultSeparation$1(a, b) {
  9658. return a.parent === b.parent ? 1 : 2;
  9659. }
  9660. // function radialSeparation(a, b) {
  9661. // return (a.parent === b.parent ? 1 : 2) / a.depth;
  9662. // }
  9663. // This function is used to traverse the left contour of a subtree (or
  9664. // subforest). It returns the successor of v on this contour. This successor is
  9665. // either given by the leftmost child of v or by the thread of v. The function
  9666. // returns null if and only if v is on the highest level of its subtree.
  9667. function nextLeft(v) {
  9668. var children = v.children;
  9669. return children ? children[0] : v.t;
  9670. }
  9671. // This function works analogously to nextLeft.
  9672. function nextRight(v) {
  9673. var children = v.children;
  9674. return children ? children[children.length - 1] : v.t;
  9675. }
  9676. // Shifts the current subtree rooted at w+. This is done by increasing
  9677. // prelim(w+) and mod(w+) by shift.
  9678. function moveSubtree(wm, wp, shift) {
  9679. var change = shift / (wp.i - wm.i);
  9680. wp.c -= change;
  9681. wp.s += shift;
  9682. wm.c += change;
  9683. wp.z += shift;
  9684. wp.m += shift;
  9685. }
  9686. // All other shifts, applied to the smaller subtrees between w- and w+, are
  9687. // performed by this function. To prepare the shifts, we have to adjust
  9688. // change(w+), shift(w+), and change(w-).
  9689. function executeShifts(v) {
  9690. var shift = 0,
  9691. change = 0,
  9692. children = v.children,
  9693. i = children.length,
  9694. w;
  9695. while (--i >= 0) {
  9696. w = children[i];
  9697. w.z += shift;
  9698. w.m += shift;
  9699. shift += w.s + (change += w.c);
  9700. }
  9701. }
  9702. // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
  9703. // returns the specified (default) ancestor.
  9704. function nextAncestor(vim, v, ancestor) {
  9705. return vim.a.parent === v.parent ? vim.a : ancestor;
  9706. }
  9707. function TreeNode(node, i) {
  9708. this._ = node;
  9709. this.parent = null;
  9710. this.children = null;
  9711. this.A = null; // default ancestor
  9712. this.a = this; // ancestor
  9713. this.z = 0; // prelim
  9714. this.m = 0; // mod
  9715. this.c = 0; // change
  9716. this.s = 0; // shift
  9717. this.t = null; // thread
  9718. this.i = i; // number
  9719. }
  9720. TreeNode.prototype = Object.create(Node.prototype);
  9721. function treeRoot(root) {
  9722. var tree = new TreeNode(root, 0),
  9723. node,
  9724. nodes = [tree],
  9725. child,
  9726. children,
  9727. i,
  9728. n;
  9729. while (node = nodes.pop()) {
  9730. if (children = node._.children) {
  9731. node.children = new Array(n = children.length);
  9732. for (i = n - 1; i >= 0; --i) {
  9733. nodes.push(child = node.children[i] = new TreeNode(children[i], i));
  9734. child.parent = node;
  9735. }
  9736. }
  9737. }
  9738. (tree.parent = new TreeNode(null, 0)).children = [tree];
  9739. return tree;
  9740. }
  9741. // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
  9742. function tree() {
  9743. var separation = defaultSeparation$1,
  9744. dx = 1,
  9745. dy = 1,
  9746. nodeSize = null;
  9747. function tree(root) {
  9748. var t = treeRoot(root);
  9749. // Compute the layout using Buchheim et al.’s algorithm.
  9750. t.eachAfter(firstWalk), t.parent.m = -t.z;
  9751. t.eachBefore(secondWalk);
  9752. // If a fixed node size is specified, scale x and y.
  9753. if (nodeSize) root.eachBefore(sizeNode);
  9754. // If a fixed tree size is specified, scale x and y based on the extent.
  9755. // Compute the left-most, right-most, and depth-most nodes for extents.
  9756. else {
  9757. var left = root,
  9758. right = root,
  9759. bottom = root;
  9760. root.eachBefore(function(node) {
  9761. if (node.x < left.x) left = node;
  9762. if (node.x > right.x) right = node;
  9763. if (node.depth > bottom.depth) bottom = node;
  9764. });
  9765. var s = left === right ? 1 : separation(left, right) / 2,
  9766. tx = s - left.x,
  9767. kx = dx / (right.x + s + tx),
  9768. ky = dy / (bottom.depth || 1);
  9769. root.eachBefore(function(node) {
  9770. node.x = (node.x + tx) * kx;
  9771. node.y = node.depth * ky;
  9772. });
  9773. }
  9774. return root;
  9775. }
  9776. // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
  9777. // applied recursively to the children of v, as well as the function
  9778. // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
  9779. // node v is placed to the midpoint of its outermost children.
  9780. function firstWalk(v) {
  9781. var children = v.children,
  9782. siblings = v.parent.children,
  9783. w = v.i ? siblings[v.i - 1] : null;
  9784. if (children) {
  9785. executeShifts(v);
  9786. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  9787. if (w) {
  9788. v.z = w.z + separation(v._, w._);
  9789. v.m = v.z - midpoint;
  9790. } else {
  9791. v.z = midpoint;
  9792. }
  9793. } else if (w) {
  9794. v.z = w.z + separation(v._, w._);
  9795. }
  9796. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  9797. }
  9798. // Computes all real x-coordinates by summing up the modifiers recursively.
  9799. function secondWalk(v) {
  9800. v._.x = v.z + v.parent.m;
  9801. v.m += v.parent.m;
  9802. }
  9803. // The core of the algorithm. Here, a new subtree is combined with the
  9804. // previous subtrees. Threads are used to traverse the inside and outside
  9805. // contours of the left and right subtree up to the highest common level. The
  9806. // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
  9807. // superscript o means outside and i means inside, the subscript - means left
  9808. // subtree and + means right subtree. For summing up the modifiers along the
  9809. // contour, we use respective variables si+, si-, so-, and so+. Whenever two
  9810. // nodes of the inside contours conflict, we compute the left one of the
  9811. // greatest uncommon ancestors using the function ANCESTOR and call MOVE
  9812. // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
  9813. // Finally, we add a new thread (if necessary).
  9814. function apportion(v, w, ancestor) {
  9815. if (w) {
  9816. var vip = v,
  9817. vop = v,
  9818. vim = w,
  9819. vom = vip.parent.children[0],
  9820. sip = vip.m,
  9821. sop = vop.m,
  9822. sim = vim.m,
  9823. som = vom.m,
  9824. shift;
  9825. while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
  9826. vom = nextLeft(vom);
  9827. vop = nextRight(vop);
  9828. vop.a = v;
  9829. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  9830. if (shift > 0) {
  9831. moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
  9832. sip += shift;
  9833. sop += shift;
  9834. }
  9835. sim += vim.m;
  9836. sip += vip.m;
  9837. som += vom.m;
  9838. sop += vop.m;
  9839. }
  9840. if (vim && !nextRight(vop)) {
  9841. vop.t = vim;
  9842. vop.m += sim - sop;
  9843. }
  9844. if (vip && !nextLeft(vom)) {
  9845. vom.t = vip;
  9846. vom.m += sip - som;
  9847. ancestor = v;
  9848. }
  9849. }
  9850. return ancestor;
  9851. }
  9852. function sizeNode(node) {
  9853. node.x *= dx;
  9854. node.y = node.depth * dy;
  9855. }
  9856. tree.separation = function(x) {
  9857. return arguments.length ? (separation = x, tree) : separation;
  9858. };
  9859. tree.size = function(x) {
  9860. return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
  9861. };
  9862. tree.nodeSize = function(x) {
  9863. return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
  9864. };
  9865. return tree;
  9866. }
  9867. function treemapSlice(parent, x0, y0, x1, y1) {
  9868. var nodes = parent.children,
  9869. node,
  9870. i = -1,
  9871. n = nodes.length,
  9872. k = parent.value && (y1 - y0) / parent.value;
  9873. while (++i < n) {
  9874. node = nodes[i], node.x0 = x0, node.x1 = x1;
  9875. node.y0 = y0, node.y1 = y0 += node.value * k;
  9876. }
  9877. }
  9878. var phi = (1 + Math.sqrt(5)) / 2;
  9879. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  9880. var rows = [],
  9881. nodes = parent.children,
  9882. row,
  9883. nodeValue,
  9884. i0 = 0,
  9885. i1 = 0,
  9886. n = nodes.length,
  9887. dx, dy,
  9888. value = parent.value,
  9889. sumValue,
  9890. minValue,
  9891. maxValue,
  9892. newRatio,
  9893. minRatio,
  9894. alpha,
  9895. beta;
  9896. while (i0 < n) {
  9897. dx = x1 - x0, dy = y1 - y0;
  9898. // Find the next non-empty node.
  9899. do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
  9900. minValue = maxValue = sumValue;
  9901. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  9902. beta = sumValue * sumValue * alpha;
  9903. minRatio = Math.max(maxValue / beta, beta / minValue);
  9904. // Keep adding nodes while the aspect ratio maintains or improves.
  9905. for (; i1 < n; ++i1) {
  9906. sumValue += nodeValue = nodes[i1].value;
  9907. if (nodeValue < minValue) minValue = nodeValue;
  9908. if (nodeValue > maxValue) maxValue = nodeValue;
  9909. beta = sumValue * sumValue * alpha;
  9910. newRatio = Math.max(maxValue / beta, beta / minValue);
  9911. if (newRatio > minRatio) { sumValue -= nodeValue; break; }
  9912. minRatio = newRatio;
  9913. }
  9914. // Position and record the row orientation.
  9915. rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
  9916. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
  9917. else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  9918. value -= sumValue, i0 = i1;
  9919. }
  9920. return rows;
  9921. }
  9922. var squarify = (function custom(ratio) {
  9923. function squarify(parent, x0, y0, x1, y1) {
  9924. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  9925. }
  9926. squarify.ratio = function(x) {
  9927. return custom((x = +x) > 1 ? x : 1);
  9928. };
  9929. return squarify;
  9930. })(phi);
  9931. function index$3() {
  9932. var tile = squarify,
  9933. round = false,
  9934. dx = 1,
  9935. dy = 1,
  9936. paddingStack = [0],
  9937. paddingInner = constantZero,
  9938. paddingTop = constantZero,
  9939. paddingRight = constantZero,
  9940. paddingBottom = constantZero,
  9941. paddingLeft = constantZero;
  9942. function treemap(root) {
  9943. root.x0 =
  9944. root.y0 = 0;
  9945. root.x1 = dx;
  9946. root.y1 = dy;
  9947. root.eachBefore(positionNode);
  9948. paddingStack = [0];
  9949. if (round) root.eachBefore(roundNode);
  9950. return root;
  9951. }
  9952. function positionNode(node) {
  9953. var p = paddingStack[node.depth],
  9954. x0 = node.x0 + p,
  9955. y0 = node.y0 + p,
  9956. x1 = node.x1 - p,
  9957. y1 = node.y1 - p;
  9958. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9959. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9960. node.x0 = x0;
  9961. node.y0 = y0;
  9962. node.x1 = x1;
  9963. node.y1 = y1;
  9964. if (node.children) {
  9965. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  9966. x0 += paddingLeft(node) - p;
  9967. y0 += paddingTop(node) - p;
  9968. x1 -= paddingRight(node) - p;
  9969. y1 -= paddingBottom(node) - p;
  9970. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  9971. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  9972. tile(node, x0, y0, x1, y1);
  9973. }
  9974. }
  9975. treemap.round = function(x) {
  9976. return arguments.length ? (round = !!x, treemap) : round;
  9977. };
  9978. treemap.size = function(x) {
  9979. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  9980. };
  9981. treemap.tile = function(x) {
  9982. return arguments.length ? (tile = required(x), treemap) : tile;
  9983. };
  9984. treemap.padding = function(x) {
  9985. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  9986. };
  9987. treemap.paddingInner = function(x) {
  9988. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
  9989. };
  9990. treemap.paddingOuter = function(x) {
  9991. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  9992. };
  9993. treemap.paddingTop = function(x) {
  9994. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
  9995. };
  9996. treemap.paddingRight = function(x) {
  9997. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
  9998. };
  9999. treemap.paddingBottom = function(x) {
  10000. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
  10001. };
  10002. treemap.paddingLeft = function(x) {
  10003. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
  10004. };
  10005. return treemap;
  10006. }
  10007. function binary(parent, x0, y0, x1, y1) {
  10008. var nodes = parent.children,
  10009. i, n = nodes.length,
  10010. sum, sums = new Array(n + 1);
  10011. for (sums[0] = sum = i = 0; i < n; ++i) {
  10012. sums[i + 1] = sum += nodes[i].value;
  10013. }
  10014. partition(0, n, parent.value, x0, y0, x1, y1);
  10015. function partition(i, j, value, x0, y0, x1, y1) {
  10016. if (i >= j - 1) {
  10017. var node = nodes[i];
  10018. node.x0 = x0, node.y0 = y0;
  10019. node.x1 = x1, node.y1 = y1;
  10020. return;
  10021. }
  10022. var valueOffset = sums[i],
  10023. valueTarget = (value / 2) + valueOffset,
  10024. k = i + 1,
  10025. hi = j - 1;
  10026. while (k < hi) {
  10027. var mid = k + hi >>> 1;
  10028. if (sums[mid] < valueTarget) k = mid + 1;
  10029. else hi = mid;
  10030. }
  10031. if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
  10032. var valueLeft = sums[k] - valueOffset,
  10033. valueRight = value - valueLeft;
  10034. if ((x1 - x0) > (y1 - y0)) {
  10035. var xk = (x0 * valueRight + x1 * valueLeft) / value;
  10036. partition(i, k, valueLeft, x0, y0, xk, y1);
  10037. partition(k, j, valueRight, xk, y0, x1, y1);
  10038. } else {
  10039. var yk = (y0 * valueRight + y1 * valueLeft) / value;
  10040. partition(i, k, valueLeft, x0, y0, x1, yk);
  10041. partition(k, j, valueRight, x0, yk, x1, y1);
  10042. }
  10043. }
  10044. }
  10045. function sliceDice(parent, x0, y0, x1, y1) {
  10046. (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
  10047. }
  10048. var resquarify = (function custom(ratio) {
  10049. function resquarify(parent, x0, y0, x1, y1) {
  10050. if ((rows = parent._squarify) && (rows.ratio === ratio)) {
  10051. var rows,
  10052. row,
  10053. nodes,
  10054. i,
  10055. j = -1,
  10056. n,
  10057. m = rows.length,
  10058. value = parent.value;
  10059. while (++j < m) {
  10060. row = rows[j], nodes = row.children;
  10061. for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
  10062. if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
  10063. else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
  10064. value -= row.value;
  10065. }
  10066. } else {
  10067. parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
  10068. rows.ratio = ratio;
  10069. }
  10070. }
  10071. resquarify.ratio = function(x) {
  10072. return custom((x = +x) > 1 ? x : 1);
  10073. };
  10074. return resquarify;
  10075. })(phi);
  10076. function area$2(polygon) {
  10077. var i = -1,
  10078. n = polygon.length,
  10079. a,
  10080. b = polygon[n - 1],
  10081. area = 0;
  10082. while (++i < n) {
  10083. a = b;
  10084. b = polygon[i];
  10085. area += a[1] * b[0] - a[0] * b[1];
  10086. }
  10087. return area / 2;
  10088. }
  10089. function centroid$1(polygon) {
  10090. var i = -1,
  10091. n = polygon.length,
  10092. x = 0,
  10093. y = 0,
  10094. a,
  10095. b = polygon[n - 1],
  10096. c,
  10097. k = 0;
  10098. while (++i < n) {
  10099. a = b;
  10100. b = polygon[i];
  10101. k += c = a[0] * b[1] - b[0] * a[1];
  10102. x += (a[0] + b[0]) * c;
  10103. y += (a[1] + b[1]) * c;
  10104. }
  10105. return k *= 3, [x / k, y / k];
  10106. }
  10107. // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
  10108. // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
  10109. // right, +y is up). Returns a positive value if ABC is counter-clockwise,
  10110. // negative if clockwise, and zero if the points are collinear.
  10111. function cross$1(a, b, c) {
  10112. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  10113. }
  10114. function lexicographicOrder(a, b) {
  10115. return a[0] - b[0] || a[1] - b[1];
  10116. }
  10117. // Computes the upper convex hull per the monotone chain algorithm.
  10118. // Assumes points.length >= 3, is sorted by x, unique in y.
  10119. // Returns an array of indices into points in left-to-right order.
  10120. function computeUpperHullIndexes(points) {
  10121. var n = points.length,
  10122. indexes = [0, 1],
  10123. size = 2;
  10124. for (var i = 2; i < n; ++i) {
  10125. while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
  10126. indexes[size++] = i;
  10127. }
  10128. return indexes.slice(0, size); // remove popped points
  10129. }
  10130. function hull(points) {
  10131. if ((n = points.length) < 3) return null;
  10132. var i,
  10133. n,
  10134. sortedPoints = new Array(n),
  10135. flippedPoints = new Array(n);
  10136. for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
  10137. sortedPoints.sort(lexicographicOrder);
  10138. for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
  10139. var upperIndexes = computeUpperHullIndexes(sortedPoints),
  10140. lowerIndexes = computeUpperHullIndexes(flippedPoints);
  10141. // Construct the hull polygon, removing possible duplicate endpoints.
  10142. var skipLeft = lowerIndexes[0] === upperIndexes[0],
  10143. skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
  10144. hull = [];
  10145. // Add upper hull in right-to-l order.
  10146. // Then add lower hull in left-to-right order.
  10147. for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
  10148. for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
  10149. return hull;
  10150. }
  10151. function contains$2(polygon, point) {
  10152. var n = polygon.length,
  10153. p = polygon[n - 1],
  10154. x = point[0], y = point[1],
  10155. x0 = p[0], y0 = p[1],
  10156. x1, y1,
  10157. inside = false;
  10158. for (var i = 0; i < n; ++i) {
  10159. p = polygon[i], x1 = p[0], y1 = p[1];
  10160. if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
  10161. x0 = x1, y0 = y1;
  10162. }
  10163. return inside;
  10164. }
  10165. function length$2(polygon) {
  10166. var i = -1,
  10167. n = polygon.length,
  10168. b = polygon[n - 1],
  10169. xa,
  10170. ya,
  10171. xb = b[0],
  10172. yb = b[1],
  10173. perimeter = 0;
  10174. while (++i < n) {
  10175. xa = xb;
  10176. ya = yb;
  10177. b = polygon[i];
  10178. xb = b[0];
  10179. yb = b[1];
  10180. xa -= xb;
  10181. ya -= yb;
  10182. perimeter += Math.sqrt(xa * xa + ya * ya);
  10183. }
  10184. return perimeter;
  10185. }
  10186. function defaultSource$1() {
  10187. return Math.random();
  10188. }
  10189. var uniform = (function sourceRandomUniform(source) {
  10190. function randomUniform(min, max) {
  10191. min = min == null ? 0 : +min;
  10192. max = max == null ? 1 : +max;
  10193. if (arguments.length === 1) max = min, min = 0;
  10194. else max -= min;
  10195. return function() {
  10196. return source() * max + min;
  10197. };
  10198. }
  10199. randomUniform.source = sourceRandomUniform;
  10200. return randomUniform;
  10201. })(defaultSource$1);
  10202. var normal = (function sourceRandomNormal(source) {
  10203. function randomNormal(mu, sigma) {
  10204. var x, r;
  10205. mu = mu == null ? 0 : +mu;
  10206. sigma = sigma == null ? 1 : +sigma;
  10207. return function() {
  10208. var y;
  10209. // If available, use the second previously-generated uniform random.
  10210. if (x != null) y = x, x = null;
  10211. // Otherwise, generate a new x and y.
  10212. else do {
  10213. x = source() * 2 - 1;
  10214. y = source() * 2 - 1;
  10215. r = x * x + y * y;
  10216. } while (!r || r > 1);
  10217. return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
  10218. };
  10219. }
  10220. randomNormal.source = sourceRandomNormal;
  10221. return randomNormal;
  10222. })(defaultSource$1);
  10223. var logNormal = (function sourceRandomLogNormal(source) {
  10224. function randomLogNormal() {
  10225. var randomNormal = normal.source(source).apply(this, arguments);
  10226. return function() {
  10227. return Math.exp(randomNormal());
  10228. };
  10229. }
  10230. randomLogNormal.source = sourceRandomLogNormal;
  10231. return randomLogNormal;
  10232. })(defaultSource$1);
  10233. var irwinHall = (function sourceRandomIrwinHall(source) {
  10234. function randomIrwinHall(n) {
  10235. return function() {
  10236. for (var sum = 0, i = 0; i < n; ++i) sum += source();
  10237. return sum;
  10238. };
  10239. }
  10240. randomIrwinHall.source = sourceRandomIrwinHall;
  10241. return randomIrwinHall;
  10242. })(defaultSource$1);
  10243. var bates = (function sourceRandomBates(source) {
  10244. function randomBates(n) {
  10245. var randomIrwinHall = irwinHall.source(source)(n);
  10246. return function() {
  10247. return randomIrwinHall() / n;
  10248. };
  10249. }
  10250. randomBates.source = sourceRandomBates;
  10251. return randomBates;
  10252. })(defaultSource$1);
  10253. var exponential$1 = (function sourceRandomExponential(source) {
  10254. function randomExponential(lambda) {
  10255. return function() {
  10256. return -Math.log(1 - source()) / lambda;
  10257. };
  10258. }
  10259. randomExponential.source = sourceRandomExponential;
  10260. return randomExponential;
  10261. })(defaultSource$1);
  10262. function initRange(domain, range) {
  10263. switch (arguments.length) {
  10264. case 0: break;
  10265. case 1: this.range(domain); break;
  10266. default: this.range(range).domain(domain); break;
  10267. }
  10268. return this;
  10269. }
  10270. function initInterpolator(domain, interpolator) {
  10271. switch (arguments.length) {
  10272. case 0: break;
  10273. case 1: this.interpolator(domain); break;
  10274. default: this.interpolator(interpolator).domain(domain); break;
  10275. }
  10276. return this;
  10277. }
  10278. var array$3 = Array.prototype;
  10279. var map$3 = array$3.map;
  10280. var slice$5 = array$3.slice;
  10281. var implicit = {name: "implicit"};
  10282. function ordinal() {
  10283. var index = map$1(),
  10284. domain = [],
  10285. range = [],
  10286. unknown = implicit;
  10287. function scale(d) {
  10288. var key = d + "", i = index.get(key);
  10289. if (!i) {
  10290. if (unknown !== implicit) return unknown;
  10291. index.set(key, i = domain.push(d));
  10292. }
  10293. return range[(i - 1) % range.length];
  10294. }
  10295. scale.domain = function(_) {
  10296. if (!arguments.length) return domain.slice();
  10297. domain = [], index = map$1();
  10298. var i = -1, n = _.length, d, key;
  10299. while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
  10300. return scale;
  10301. };
  10302. scale.range = function(_) {
  10303. return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
  10304. };
  10305. scale.unknown = function(_) {
  10306. return arguments.length ? (unknown = _, scale) : unknown;
  10307. };
  10308. scale.copy = function() {
  10309. return ordinal(domain, range).unknown(unknown);
  10310. };
  10311. initRange.apply(scale, arguments);
  10312. return scale;
  10313. }
  10314. function band() {
  10315. var scale = ordinal().unknown(undefined),
  10316. domain = scale.domain,
  10317. ordinalRange = scale.range,
  10318. range = [0, 1],
  10319. step,
  10320. bandwidth,
  10321. round = false,
  10322. paddingInner = 0,
  10323. paddingOuter = 0,
  10324. align = 0.5;
  10325. delete scale.unknown;
  10326. function rescale() {
  10327. var n = domain().length,
  10328. reverse = range[1] < range[0],
  10329. start = range[reverse - 0],
  10330. stop = range[1 - reverse];
  10331. step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
  10332. if (round) step = Math.floor(step);
  10333. start += (stop - start - step * (n - paddingInner)) * align;
  10334. bandwidth = step * (1 - paddingInner);
  10335. if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
  10336. var values = sequence(n).map(function(i) { return start + step * i; });
  10337. return ordinalRange(reverse ? values.reverse() : values);
  10338. }
  10339. scale.domain = function(_) {
  10340. return arguments.length ? (domain(_), rescale()) : domain();
  10341. };
  10342. scale.range = function(_) {
  10343. return arguments.length ? (range = [+_[0], +_[1]], rescale()) : range.slice();
  10344. };
  10345. scale.rangeRound = function(_) {
  10346. return range = [+_[0], +_[1]], round = true, rescale();
  10347. };
  10348. scale.bandwidth = function() {
  10349. return bandwidth;
  10350. };
  10351. scale.step = function() {
  10352. return step;
  10353. };
  10354. scale.round = function(_) {
  10355. return arguments.length ? (round = !!_, rescale()) : round;
  10356. };
  10357. scale.padding = function(_) {
  10358. return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
  10359. };
  10360. scale.paddingInner = function(_) {
  10361. return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
  10362. };
  10363. scale.paddingOuter = function(_) {
  10364. return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
  10365. };
  10366. scale.align = function(_) {
  10367. return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
  10368. };
  10369. scale.copy = function() {
  10370. return band(domain(), range)
  10371. .round(round)
  10372. .paddingInner(paddingInner)
  10373. .paddingOuter(paddingOuter)
  10374. .align(align);
  10375. };
  10376. return initRange.apply(rescale(), arguments);
  10377. }
  10378. function pointish(scale) {
  10379. var copy = scale.copy;
  10380. scale.padding = scale.paddingOuter;
  10381. delete scale.paddingInner;
  10382. delete scale.paddingOuter;
  10383. scale.copy = function() {
  10384. return pointish(copy());
  10385. };
  10386. return scale;
  10387. }
  10388. function point$1() {
  10389. return pointish(band.apply(null, arguments).paddingInner(1));
  10390. }
  10391. function constant$a(x) {
  10392. return function() {
  10393. return x;
  10394. };
  10395. }
  10396. function number$2(x) {
  10397. return +x;
  10398. }
  10399. var unit = [0, 1];
  10400. function identity$6(x) {
  10401. return x;
  10402. }
  10403. function normalize(a, b) {
  10404. return (b -= (a = +a))
  10405. ? function(x) { return (x - a) / b; }
  10406. : constant$a(isNaN(b) ? NaN : 0.5);
  10407. }
  10408. function clamper(domain) {
  10409. var a = domain[0], b = domain[domain.length - 1], t;
  10410. if (a > b) t = a, a = b, b = t;
  10411. return function(x) { return Math.max(a, Math.min(b, x)); };
  10412. }
  10413. // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
  10414. // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
  10415. function bimap(domain, range, interpolate) {
  10416. var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
  10417. if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
  10418. else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
  10419. return function(x) { return r0(d0(x)); };
  10420. }
  10421. function polymap(domain, range, interpolate) {
  10422. var j = Math.min(domain.length, range.length) - 1,
  10423. d = new Array(j),
  10424. r = new Array(j),
  10425. i = -1;
  10426. // Reverse descending domains.
  10427. if (domain[j] < domain[0]) {
  10428. domain = domain.slice().reverse();
  10429. range = range.slice().reverse();
  10430. }
  10431. while (++i < j) {
  10432. d[i] = normalize(domain[i], domain[i + 1]);
  10433. r[i] = interpolate(range[i], range[i + 1]);
  10434. }
  10435. return function(x) {
  10436. var i = bisectRight(domain, x, 1, j) - 1;
  10437. return r[i](d[i](x));
  10438. };
  10439. }
  10440. function copy(source, target) {
  10441. return target
  10442. .domain(source.domain())
  10443. .range(source.range())
  10444. .interpolate(source.interpolate())
  10445. .clamp(source.clamp())
  10446. .unknown(source.unknown());
  10447. }
  10448. function transformer$1() {
  10449. var domain = unit,
  10450. range = unit,
  10451. interpolate = interpolateValue,
  10452. transform,
  10453. untransform,
  10454. unknown,
  10455. clamp = identity$6,
  10456. piecewise,
  10457. output,
  10458. input;
  10459. function rescale() {
  10460. piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
  10461. output = input = null;
  10462. return scale;
  10463. }
  10464. function scale(x) {
  10465. return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
  10466. }
  10467. scale.invert = function(y) {
  10468. return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
  10469. };
  10470. scale.domain = function(_) {
  10471. return arguments.length ? (domain = map$3.call(_, number$2), clamp === identity$6 || (clamp = clamper(domain)), rescale()) : domain.slice();
  10472. };
  10473. scale.range = function(_) {
  10474. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10475. };
  10476. scale.rangeRound = function(_) {
  10477. return range = slice$5.call(_), interpolate = interpolateRound, rescale();
  10478. };
  10479. scale.clamp = function(_) {
  10480. return arguments.length ? (clamp = _ ? clamper(domain) : identity$6, scale) : clamp !== identity$6;
  10481. };
  10482. scale.interpolate = function(_) {
  10483. return arguments.length ? (interpolate = _, rescale()) : interpolate;
  10484. };
  10485. scale.unknown = function(_) {
  10486. return arguments.length ? (unknown = _, scale) : unknown;
  10487. };
  10488. return function(t, u) {
  10489. transform = t, untransform = u;
  10490. return rescale();
  10491. };
  10492. }
  10493. function continuous(transform, untransform) {
  10494. return transformer$1()(transform, untransform);
  10495. }
  10496. function tickFormat(start, stop, count, specifier) {
  10497. var step = tickStep(start, stop, count),
  10498. precision;
  10499. specifier = formatSpecifier(specifier == null ? ",f" : specifier);
  10500. switch (specifier.type) {
  10501. case "s": {
  10502. var value = Math.max(Math.abs(start), Math.abs(stop));
  10503. if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
  10504. return exports.formatPrefix(specifier, value);
  10505. }
  10506. case "":
  10507. case "e":
  10508. case "g":
  10509. case "p":
  10510. case "r": {
  10511. if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
  10512. break;
  10513. }
  10514. case "f":
  10515. case "%": {
  10516. if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
  10517. break;
  10518. }
  10519. }
  10520. return exports.format(specifier);
  10521. }
  10522. function linearish(scale) {
  10523. var domain = scale.domain;
  10524. scale.ticks = function(count) {
  10525. var d = domain();
  10526. return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
  10527. };
  10528. scale.tickFormat = function(count, specifier) {
  10529. var d = domain();
  10530. return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
  10531. };
  10532. scale.nice = function(count) {
  10533. if (count == null) count = 10;
  10534. var d = domain(),
  10535. i0 = 0,
  10536. i1 = d.length - 1,
  10537. start = d[i0],
  10538. stop = d[i1],
  10539. step;
  10540. if (stop < start) {
  10541. step = start, start = stop, stop = step;
  10542. step = i0, i0 = i1, i1 = step;
  10543. }
  10544. step = tickIncrement(start, stop, count);
  10545. if (step > 0) {
  10546. start = Math.floor(start / step) * step;
  10547. stop = Math.ceil(stop / step) * step;
  10548. step = tickIncrement(start, stop, count);
  10549. } else if (step < 0) {
  10550. start = Math.ceil(start * step) / step;
  10551. stop = Math.floor(stop * step) / step;
  10552. step = tickIncrement(start, stop, count);
  10553. }
  10554. if (step > 0) {
  10555. d[i0] = Math.floor(start / step) * step;
  10556. d[i1] = Math.ceil(stop / step) * step;
  10557. domain(d);
  10558. } else if (step < 0) {
  10559. d[i0] = Math.ceil(start * step) / step;
  10560. d[i1] = Math.floor(stop * step) / step;
  10561. domain(d);
  10562. }
  10563. return scale;
  10564. };
  10565. return scale;
  10566. }
  10567. function linear$2() {
  10568. var scale = continuous(identity$6, identity$6);
  10569. scale.copy = function() {
  10570. return copy(scale, linear$2());
  10571. };
  10572. initRange.apply(scale, arguments);
  10573. return linearish(scale);
  10574. }
  10575. function identity$7(domain) {
  10576. var unknown;
  10577. function scale(x) {
  10578. return isNaN(x = +x) ? unknown : x;
  10579. }
  10580. scale.invert = scale;
  10581. scale.domain = scale.range = function(_) {
  10582. return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
  10583. };
  10584. scale.unknown = function(_) {
  10585. return arguments.length ? (unknown = _, scale) : unknown;
  10586. };
  10587. scale.copy = function() {
  10588. return identity$7(domain).unknown(unknown);
  10589. };
  10590. domain = arguments.length ? map$3.call(domain, number$2) : [0, 1];
  10591. return linearish(scale);
  10592. }
  10593. function nice(domain, interval) {
  10594. domain = domain.slice();
  10595. var i0 = 0,
  10596. i1 = domain.length - 1,
  10597. x0 = domain[i0],
  10598. x1 = domain[i1],
  10599. t;
  10600. if (x1 < x0) {
  10601. t = i0, i0 = i1, i1 = t;
  10602. t = x0, x0 = x1, x1 = t;
  10603. }
  10604. domain[i0] = interval.floor(x0);
  10605. domain[i1] = interval.ceil(x1);
  10606. return domain;
  10607. }
  10608. function transformLog(x) {
  10609. return Math.log(x);
  10610. }
  10611. function transformExp(x) {
  10612. return Math.exp(x);
  10613. }
  10614. function transformLogn(x) {
  10615. return -Math.log(-x);
  10616. }
  10617. function transformExpn(x) {
  10618. return -Math.exp(-x);
  10619. }
  10620. function pow10(x) {
  10621. return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
  10622. }
  10623. function powp(base) {
  10624. return base === 10 ? pow10
  10625. : base === Math.E ? Math.exp
  10626. : function(x) { return Math.pow(base, x); };
  10627. }
  10628. function logp(base) {
  10629. return base === Math.E ? Math.log
  10630. : base === 10 && Math.log10
  10631. || base === 2 && Math.log2
  10632. || (base = Math.log(base), function(x) { return Math.log(x) / base; });
  10633. }
  10634. function reflect(f) {
  10635. return function(x) {
  10636. return -f(-x);
  10637. };
  10638. }
  10639. function loggish(transform) {
  10640. var scale = transform(transformLog, transformExp),
  10641. domain = scale.domain,
  10642. base = 10,
  10643. logs,
  10644. pows;
  10645. function rescale() {
  10646. logs = logp(base), pows = powp(base);
  10647. if (domain()[0] < 0) {
  10648. logs = reflect(logs), pows = reflect(pows);
  10649. transform(transformLogn, transformExpn);
  10650. } else {
  10651. transform(transformLog, transformExp);
  10652. }
  10653. return scale;
  10654. }
  10655. scale.base = function(_) {
  10656. return arguments.length ? (base = +_, rescale()) : base;
  10657. };
  10658. scale.domain = function(_) {
  10659. return arguments.length ? (domain(_), rescale()) : domain();
  10660. };
  10661. scale.ticks = function(count) {
  10662. var d = domain(),
  10663. u = d[0],
  10664. v = d[d.length - 1],
  10665. r;
  10666. if (r = v < u) i = u, u = v, v = i;
  10667. var i = logs(u),
  10668. j = logs(v),
  10669. p,
  10670. k,
  10671. t,
  10672. n = count == null ? 10 : +count,
  10673. z = [];
  10674. if (!(base % 1) && j - i < n) {
  10675. i = Math.round(i) - 1, j = Math.round(j) + 1;
  10676. if (u > 0) for (; i < j; ++i) {
  10677. for (k = 1, p = pows(i); k < base; ++k) {
  10678. t = p * k;
  10679. if (t < u) continue;
  10680. if (t > v) break;
  10681. z.push(t);
  10682. }
  10683. } else for (; i < j; ++i) {
  10684. for (k = base - 1, p = pows(i); k >= 1; --k) {
  10685. t = p * k;
  10686. if (t < u) continue;
  10687. if (t > v) break;
  10688. z.push(t);
  10689. }
  10690. }
  10691. } else {
  10692. z = ticks(i, j, Math.min(j - i, n)).map(pows);
  10693. }
  10694. return r ? z.reverse() : z;
  10695. };
  10696. scale.tickFormat = function(count, specifier) {
  10697. if (specifier == null) specifier = base === 10 ? ".0e" : ",";
  10698. if (typeof specifier !== "function") specifier = exports.format(specifier);
  10699. if (count === Infinity) return specifier;
  10700. if (count == null) count = 10;
  10701. var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
  10702. return function(d) {
  10703. var i = d / pows(Math.round(logs(d)));
  10704. if (i * base < base - 0.5) i *= base;
  10705. return i <= k ? specifier(d) : "";
  10706. };
  10707. };
  10708. scale.nice = function() {
  10709. return domain(nice(domain(), {
  10710. floor: function(x) { return pows(Math.floor(logs(x))); },
  10711. ceil: function(x) { return pows(Math.ceil(logs(x))); }
  10712. }));
  10713. };
  10714. return scale;
  10715. }
  10716. function log$1() {
  10717. var scale = loggish(transformer$1()).domain([1, 10]);
  10718. scale.copy = function() {
  10719. return copy(scale, log$1()).base(scale.base());
  10720. };
  10721. initRange.apply(scale, arguments);
  10722. return scale;
  10723. }
  10724. function transformSymlog(c) {
  10725. return function(x) {
  10726. return Math.sign(x) * Math.log1p(Math.abs(x / c));
  10727. };
  10728. }
  10729. function transformSymexp(c) {
  10730. return function(x) {
  10731. return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
  10732. };
  10733. }
  10734. function symlogish(transform) {
  10735. var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
  10736. scale.constant = function(_) {
  10737. return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
  10738. };
  10739. return linearish(scale);
  10740. }
  10741. function symlog() {
  10742. var scale = symlogish(transformer$1());
  10743. scale.copy = function() {
  10744. return copy(scale, symlog()).constant(scale.constant());
  10745. };
  10746. return initRange.apply(scale, arguments);
  10747. }
  10748. function transformPow(exponent) {
  10749. return function(x) {
  10750. return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
  10751. };
  10752. }
  10753. function transformSqrt(x) {
  10754. return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
  10755. }
  10756. function transformSquare(x) {
  10757. return x < 0 ? -x * x : x * x;
  10758. }
  10759. function powish(transform) {
  10760. var scale = transform(identity$6, identity$6),
  10761. exponent = 1;
  10762. function rescale() {
  10763. return exponent === 1 ? transform(identity$6, identity$6)
  10764. : exponent === 0.5 ? transform(transformSqrt, transformSquare)
  10765. : transform(transformPow(exponent), transformPow(1 / exponent));
  10766. }
  10767. scale.exponent = function(_) {
  10768. return arguments.length ? (exponent = +_, rescale()) : exponent;
  10769. };
  10770. return linearish(scale);
  10771. }
  10772. function pow$1() {
  10773. var scale = powish(transformer$1());
  10774. scale.copy = function() {
  10775. return copy(scale, pow$1()).exponent(scale.exponent());
  10776. };
  10777. initRange.apply(scale, arguments);
  10778. return scale;
  10779. }
  10780. function sqrt$1() {
  10781. return pow$1.apply(null, arguments).exponent(0.5);
  10782. }
  10783. function quantile() {
  10784. var domain = [],
  10785. range = [],
  10786. thresholds = [],
  10787. unknown;
  10788. function rescale() {
  10789. var i = 0, n = Math.max(1, range.length);
  10790. thresholds = new Array(n - 1);
  10791. while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
  10792. return scale;
  10793. }
  10794. function scale(x) {
  10795. return isNaN(x = +x) ? unknown : range[bisectRight(thresholds, x)];
  10796. }
  10797. scale.invertExtent = function(y) {
  10798. var i = range.indexOf(y);
  10799. return i < 0 ? [NaN, NaN] : [
  10800. i > 0 ? thresholds[i - 1] : domain[0],
  10801. i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
  10802. ];
  10803. };
  10804. scale.domain = function(_) {
  10805. if (!arguments.length) return domain.slice();
  10806. domain = [];
  10807. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  10808. domain.sort(ascending);
  10809. return rescale();
  10810. };
  10811. scale.range = function(_) {
  10812. return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
  10813. };
  10814. scale.unknown = function(_) {
  10815. return arguments.length ? (unknown = _, scale) : unknown;
  10816. };
  10817. scale.quantiles = function() {
  10818. return thresholds.slice();
  10819. };
  10820. scale.copy = function() {
  10821. return quantile()
  10822. .domain(domain)
  10823. .range(range)
  10824. .unknown(unknown);
  10825. };
  10826. return initRange.apply(scale, arguments);
  10827. }
  10828. function quantize$1() {
  10829. var x0 = 0,
  10830. x1 = 1,
  10831. n = 1,
  10832. domain = [0.5],
  10833. range = [0, 1],
  10834. unknown;
  10835. function scale(x) {
  10836. return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
  10837. }
  10838. function rescale() {
  10839. var i = -1;
  10840. domain = new Array(n);
  10841. while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
  10842. return scale;
  10843. }
  10844. scale.domain = function(_) {
  10845. return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
  10846. };
  10847. scale.range = function(_) {
  10848. return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
  10849. };
  10850. scale.invertExtent = function(y) {
  10851. var i = range.indexOf(y);
  10852. return i < 0 ? [NaN, NaN]
  10853. : i < 1 ? [x0, domain[0]]
  10854. : i >= n ? [domain[n - 1], x1]
  10855. : [domain[i - 1], domain[i]];
  10856. };
  10857. scale.unknown = function(_) {
  10858. return arguments.length ? (unknown = _, scale) : scale;
  10859. };
  10860. scale.thresholds = function() {
  10861. return domain.slice();
  10862. };
  10863. scale.copy = function() {
  10864. return quantize$1()
  10865. .domain([x0, x1])
  10866. .range(range)
  10867. .unknown(unknown);
  10868. };
  10869. return initRange.apply(linearish(scale), arguments);
  10870. }
  10871. function threshold$1() {
  10872. var domain = [0.5],
  10873. range = [0, 1],
  10874. unknown,
  10875. n = 1;
  10876. function scale(x) {
  10877. return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
  10878. }
  10879. scale.domain = function(_) {
  10880. return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
  10881. };
  10882. scale.range = function(_) {
  10883. return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
  10884. };
  10885. scale.invertExtent = function(y) {
  10886. var i = range.indexOf(y);
  10887. return [domain[i - 1], domain[i]];
  10888. };
  10889. scale.unknown = function(_) {
  10890. return arguments.length ? (unknown = _, scale) : unknown;
  10891. };
  10892. scale.copy = function() {
  10893. return threshold$1()
  10894. .domain(domain)
  10895. .range(range)
  10896. .unknown(unknown);
  10897. };
  10898. return initRange.apply(scale, arguments);
  10899. }
  10900. var t0$1 = new Date,
  10901. t1$1 = new Date;
  10902. function newInterval(floori, offseti, count, field) {
  10903. function interval(date) {
  10904. return floori(date = new Date(+date)), date;
  10905. }
  10906. interval.floor = interval;
  10907. interval.ceil = function(date) {
  10908. return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
  10909. };
  10910. interval.round = function(date) {
  10911. var d0 = interval(date),
  10912. d1 = interval.ceil(date);
  10913. return date - d0 < d1 - date ? d0 : d1;
  10914. };
  10915. interval.offset = function(date, step) {
  10916. return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
  10917. };
  10918. interval.range = function(start, stop, step) {
  10919. var range = [], previous;
  10920. start = interval.ceil(start);
  10921. step = step == null ? 1 : Math.floor(step);
  10922. if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
  10923. do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
  10924. while (previous < start && start < stop);
  10925. return range;
  10926. };
  10927. interval.filter = function(test) {
  10928. return newInterval(function(date) {
  10929. if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
  10930. }, function(date, step) {
  10931. if (date >= date) {
  10932. if (step < 0) while (++step <= 0) {
  10933. while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
  10934. } else while (--step >= 0) {
  10935. while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
  10936. }
  10937. }
  10938. });
  10939. };
  10940. if (count) {
  10941. interval.count = function(start, end) {
  10942. t0$1.setTime(+start), t1$1.setTime(+end);
  10943. floori(t0$1), floori(t1$1);
  10944. return Math.floor(count(t0$1, t1$1));
  10945. };
  10946. interval.every = function(step) {
  10947. step = Math.floor(step);
  10948. return !isFinite(step) || !(step > 0) ? null
  10949. : !(step > 1) ? interval
  10950. : interval.filter(field
  10951. ? function(d) { return field(d) % step === 0; }
  10952. : function(d) { return interval.count(0, d) % step === 0; });
  10953. };
  10954. }
  10955. return interval;
  10956. }
  10957. var millisecond = newInterval(function() {
  10958. // noop
  10959. }, function(date, step) {
  10960. date.setTime(+date + step);
  10961. }, function(start, end) {
  10962. return end - start;
  10963. });
  10964. // An optimized implementation for this simple case.
  10965. millisecond.every = function(k) {
  10966. k = Math.floor(k);
  10967. if (!isFinite(k) || !(k > 0)) return null;
  10968. if (!(k > 1)) return millisecond;
  10969. return newInterval(function(date) {
  10970. date.setTime(Math.floor(date / k) * k);
  10971. }, function(date, step) {
  10972. date.setTime(+date + step * k);
  10973. }, function(start, end) {
  10974. return (end - start) / k;
  10975. });
  10976. };
  10977. var milliseconds = millisecond.range;
  10978. var durationSecond = 1e3;
  10979. var durationMinute = 6e4;
  10980. var durationHour = 36e5;
  10981. var durationDay = 864e5;
  10982. var durationWeek = 6048e5;
  10983. var second = newInterval(function(date) {
  10984. date.setTime(date - date.getMilliseconds());
  10985. }, function(date, step) {
  10986. date.setTime(+date + step * durationSecond);
  10987. }, function(start, end) {
  10988. return (end - start) / durationSecond;
  10989. }, function(date) {
  10990. return date.getUTCSeconds();
  10991. });
  10992. var seconds = second.range;
  10993. var minute = newInterval(function(date) {
  10994. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
  10995. }, function(date, step) {
  10996. date.setTime(+date + step * durationMinute);
  10997. }, function(start, end) {
  10998. return (end - start) / durationMinute;
  10999. }, function(date) {
  11000. return date.getMinutes();
  11001. });
  11002. var minutes = minute.range;
  11003. var hour = newInterval(function(date) {
  11004. date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
  11005. }, function(date, step) {
  11006. date.setTime(+date + step * durationHour);
  11007. }, function(start, end) {
  11008. return (end - start) / durationHour;
  11009. }, function(date) {
  11010. return date.getHours();
  11011. });
  11012. var hours = hour.range;
  11013. var day = newInterval(function(date) {
  11014. date.setHours(0, 0, 0, 0);
  11015. }, function(date, step) {
  11016. date.setDate(date.getDate() + step);
  11017. }, function(start, end) {
  11018. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
  11019. }, function(date) {
  11020. return date.getDate() - 1;
  11021. });
  11022. var days = day.range;
  11023. function weekday(i) {
  11024. return newInterval(function(date) {
  11025. date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
  11026. date.setHours(0, 0, 0, 0);
  11027. }, function(date, step) {
  11028. date.setDate(date.getDate() + step * 7);
  11029. }, function(start, end) {
  11030. return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
  11031. });
  11032. }
  11033. var sunday = weekday(0);
  11034. var monday = weekday(1);
  11035. var tuesday = weekday(2);
  11036. var wednesday = weekday(3);
  11037. var thursday = weekday(4);
  11038. var friday = weekday(5);
  11039. var saturday = weekday(6);
  11040. var sundays = sunday.range;
  11041. var mondays = monday.range;
  11042. var tuesdays = tuesday.range;
  11043. var wednesdays = wednesday.range;
  11044. var thursdays = thursday.range;
  11045. var fridays = friday.range;
  11046. var saturdays = saturday.range;
  11047. var month = newInterval(function(date) {
  11048. date.setDate(1);
  11049. date.setHours(0, 0, 0, 0);
  11050. }, function(date, step) {
  11051. date.setMonth(date.getMonth() + step);
  11052. }, function(start, end) {
  11053. return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
  11054. }, function(date) {
  11055. return date.getMonth();
  11056. });
  11057. var months = month.range;
  11058. var year = newInterval(function(date) {
  11059. date.setMonth(0, 1);
  11060. date.setHours(0, 0, 0, 0);
  11061. }, function(date, step) {
  11062. date.setFullYear(date.getFullYear() + step);
  11063. }, function(start, end) {
  11064. return end.getFullYear() - start.getFullYear();
  11065. }, function(date) {
  11066. return date.getFullYear();
  11067. });
  11068. // An optimized implementation for this simple case.
  11069. year.every = function(k) {
  11070. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  11071. date.setFullYear(Math.floor(date.getFullYear() / k) * k);
  11072. date.setMonth(0, 1);
  11073. date.setHours(0, 0, 0, 0);
  11074. }, function(date, step) {
  11075. date.setFullYear(date.getFullYear() + step * k);
  11076. });
  11077. };
  11078. var years = year.range;
  11079. var utcMinute = newInterval(function(date) {
  11080. date.setUTCSeconds(0, 0);
  11081. }, function(date, step) {
  11082. date.setTime(+date + step * durationMinute);
  11083. }, function(start, end) {
  11084. return (end - start) / durationMinute;
  11085. }, function(date) {
  11086. return date.getUTCMinutes();
  11087. });
  11088. var utcMinutes = utcMinute.range;
  11089. var utcHour = newInterval(function(date) {
  11090. date.setUTCMinutes(0, 0, 0);
  11091. }, function(date, step) {
  11092. date.setTime(+date + step * durationHour);
  11093. }, function(start, end) {
  11094. return (end - start) / durationHour;
  11095. }, function(date) {
  11096. return date.getUTCHours();
  11097. });
  11098. var utcHours = utcHour.range;
  11099. var utcDay = newInterval(function(date) {
  11100. date.setUTCHours(0, 0, 0, 0);
  11101. }, function(date, step) {
  11102. date.setUTCDate(date.getUTCDate() + step);
  11103. }, function(start, end) {
  11104. return (end - start) / durationDay;
  11105. }, function(date) {
  11106. return date.getUTCDate() - 1;
  11107. });
  11108. var utcDays = utcDay.range;
  11109. function utcWeekday(i) {
  11110. return newInterval(function(date) {
  11111. date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
  11112. date.setUTCHours(0, 0, 0, 0);
  11113. }, function(date, step) {
  11114. date.setUTCDate(date.getUTCDate() + step * 7);
  11115. }, function(start, end) {
  11116. return (end - start) / durationWeek;
  11117. });
  11118. }
  11119. var utcSunday = utcWeekday(0);
  11120. var utcMonday = utcWeekday(1);
  11121. var utcTuesday = utcWeekday(2);
  11122. var utcWednesday = utcWeekday(3);
  11123. var utcThursday = utcWeekday(4);
  11124. var utcFriday = utcWeekday(5);
  11125. var utcSaturday = utcWeekday(6);
  11126. var utcSundays = utcSunday.range;
  11127. var utcMondays = utcMonday.range;
  11128. var utcTuesdays = utcTuesday.range;
  11129. var utcWednesdays = utcWednesday.range;
  11130. var utcThursdays = utcThursday.range;
  11131. var utcFridays = utcFriday.range;
  11132. var utcSaturdays = utcSaturday.range;
  11133. var utcMonth = newInterval(function(date) {
  11134. date.setUTCDate(1);
  11135. date.setUTCHours(0, 0, 0, 0);
  11136. }, function(date, step) {
  11137. date.setUTCMonth(date.getUTCMonth() + step);
  11138. }, function(start, end) {
  11139. return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
  11140. }, function(date) {
  11141. return date.getUTCMonth();
  11142. });
  11143. var utcMonths = utcMonth.range;
  11144. var utcYear = newInterval(function(date) {
  11145. date.setUTCMonth(0, 1);
  11146. date.setUTCHours(0, 0, 0, 0);
  11147. }, function(date, step) {
  11148. date.setUTCFullYear(date.getUTCFullYear() + step);
  11149. }, function(start, end) {
  11150. return end.getUTCFullYear() - start.getUTCFullYear();
  11151. }, function(date) {
  11152. return date.getUTCFullYear();
  11153. });
  11154. // An optimized implementation for this simple case.
  11155. utcYear.every = function(k) {
  11156. return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
  11157. date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
  11158. date.setUTCMonth(0, 1);
  11159. date.setUTCHours(0, 0, 0, 0);
  11160. }, function(date, step) {
  11161. date.setUTCFullYear(date.getUTCFullYear() + step * k);
  11162. });
  11163. };
  11164. var utcYears = utcYear.range;
  11165. function localDate(d) {
  11166. if (0 <= d.y && d.y < 100) {
  11167. var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
  11168. date.setFullYear(d.y);
  11169. return date;
  11170. }
  11171. return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
  11172. }
  11173. function utcDate(d) {
  11174. if (0 <= d.y && d.y < 100) {
  11175. var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
  11176. date.setUTCFullYear(d.y);
  11177. return date;
  11178. }
  11179. return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
  11180. }
  11181. function newYear(y) {
  11182. return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
  11183. }
  11184. function formatLocale$1(locale) {
  11185. var locale_dateTime = locale.dateTime,
  11186. locale_date = locale.date,
  11187. locale_time = locale.time,
  11188. locale_periods = locale.periods,
  11189. locale_weekdays = locale.days,
  11190. locale_shortWeekdays = locale.shortDays,
  11191. locale_months = locale.months,
  11192. locale_shortMonths = locale.shortMonths;
  11193. var periodRe = formatRe(locale_periods),
  11194. periodLookup = formatLookup(locale_periods),
  11195. weekdayRe = formatRe(locale_weekdays),
  11196. weekdayLookup = formatLookup(locale_weekdays),
  11197. shortWeekdayRe = formatRe(locale_shortWeekdays),
  11198. shortWeekdayLookup = formatLookup(locale_shortWeekdays),
  11199. monthRe = formatRe(locale_months),
  11200. monthLookup = formatLookup(locale_months),
  11201. shortMonthRe = formatRe(locale_shortMonths),
  11202. shortMonthLookup = formatLookup(locale_shortMonths);
  11203. var formats = {
  11204. "a": formatShortWeekday,
  11205. "A": formatWeekday,
  11206. "b": formatShortMonth,
  11207. "B": formatMonth,
  11208. "c": null,
  11209. "d": formatDayOfMonth,
  11210. "e": formatDayOfMonth,
  11211. "f": formatMicroseconds,
  11212. "H": formatHour24,
  11213. "I": formatHour12,
  11214. "j": formatDayOfYear,
  11215. "L": formatMilliseconds,
  11216. "m": formatMonthNumber,
  11217. "M": formatMinutes,
  11218. "p": formatPeriod,
  11219. "Q": formatUnixTimestamp,
  11220. "s": formatUnixTimestampSeconds,
  11221. "S": formatSeconds,
  11222. "u": formatWeekdayNumberMonday,
  11223. "U": formatWeekNumberSunday,
  11224. "V": formatWeekNumberISO,
  11225. "w": formatWeekdayNumberSunday,
  11226. "W": formatWeekNumberMonday,
  11227. "x": null,
  11228. "X": null,
  11229. "y": formatYear$1,
  11230. "Y": formatFullYear,
  11231. "Z": formatZone,
  11232. "%": formatLiteralPercent
  11233. };
  11234. var utcFormats = {
  11235. "a": formatUTCShortWeekday,
  11236. "A": formatUTCWeekday,
  11237. "b": formatUTCShortMonth,
  11238. "B": formatUTCMonth,
  11239. "c": null,
  11240. "d": formatUTCDayOfMonth,
  11241. "e": formatUTCDayOfMonth,
  11242. "f": formatUTCMicroseconds,
  11243. "H": formatUTCHour24,
  11244. "I": formatUTCHour12,
  11245. "j": formatUTCDayOfYear,
  11246. "L": formatUTCMilliseconds,
  11247. "m": formatUTCMonthNumber,
  11248. "M": formatUTCMinutes,
  11249. "p": formatUTCPeriod,
  11250. "Q": formatUnixTimestamp,
  11251. "s": formatUnixTimestampSeconds,
  11252. "S": formatUTCSeconds,
  11253. "u": formatUTCWeekdayNumberMonday,
  11254. "U": formatUTCWeekNumberSunday,
  11255. "V": formatUTCWeekNumberISO,
  11256. "w": formatUTCWeekdayNumberSunday,
  11257. "W": formatUTCWeekNumberMonday,
  11258. "x": null,
  11259. "X": null,
  11260. "y": formatUTCYear,
  11261. "Y": formatUTCFullYear,
  11262. "Z": formatUTCZone,
  11263. "%": formatLiteralPercent
  11264. };
  11265. var parses = {
  11266. "a": parseShortWeekday,
  11267. "A": parseWeekday,
  11268. "b": parseShortMonth,
  11269. "B": parseMonth,
  11270. "c": parseLocaleDateTime,
  11271. "d": parseDayOfMonth,
  11272. "e": parseDayOfMonth,
  11273. "f": parseMicroseconds,
  11274. "H": parseHour24,
  11275. "I": parseHour24,
  11276. "j": parseDayOfYear,
  11277. "L": parseMilliseconds,
  11278. "m": parseMonthNumber,
  11279. "M": parseMinutes,
  11280. "p": parsePeriod,
  11281. "Q": parseUnixTimestamp,
  11282. "s": parseUnixTimestampSeconds,
  11283. "S": parseSeconds,
  11284. "u": parseWeekdayNumberMonday,
  11285. "U": parseWeekNumberSunday,
  11286. "V": parseWeekNumberISO,
  11287. "w": parseWeekdayNumberSunday,
  11288. "W": parseWeekNumberMonday,
  11289. "x": parseLocaleDate,
  11290. "X": parseLocaleTime,
  11291. "y": parseYear,
  11292. "Y": parseFullYear,
  11293. "Z": parseZone,
  11294. "%": parseLiteralPercent
  11295. };
  11296. // These recursive directive definitions must be deferred.
  11297. formats.x = newFormat(locale_date, formats);
  11298. formats.X = newFormat(locale_time, formats);
  11299. formats.c = newFormat(locale_dateTime, formats);
  11300. utcFormats.x = newFormat(locale_date, utcFormats);
  11301. utcFormats.X = newFormat(locale_time, utcFormats);
  11302. utcFormats.c = newFormat(locale_dateTime, utcFormats);
  11303. function newFormat(specifier, formats) {
  11304. return function(date) {
  11305. var string = [],
  11306. i = -1,
  11307. j = 0,
  11308. n = specifier.length,
  11309. c,
  11310. pad,
  11311. format;
  11312. if (!(date instanceof Date)) date = new Date(+date);
  11313. while (++i < n) {
  11314. if (specifier.charCodeAt(i) === 37) {
  11315. string.push(specifier.slice(j, i));
  11316. if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
  11317. else pad = c === "e" ? " " : "0";
  11318. if (format = formats[c]) c = format(date, pad);
  11319. string.push(c);
  11320. j = i + 1;
  11321. }
  11322. }
  11323. string.push(specifier.slice(j, i));
  11324. return string.join("");
  11325. };
  11326. }
  11327. function newParse(specifier, newDate) {
  11328. return function(string) {
  11329. var d = newYear(1900),
  11330. i = parseSpecifier(d, specifier, string += "", 0),
  11331. week, day$1;
  11332. if (i != string.length) return null;
  11333. // If a UNIX timestamp is specified, return it.
  11334. if ("Q" in d) return new Date(d.Q);
  11335. // The am-pm flag is 0 for AM, and 1 for PM.
  11336. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  11337. // Convert day-of-week and week-of-year to day-of-year.
  11338. if ("V" in d) {
  11339. if (d.V < 1 || d.V > 53) return null;
  11340. if (!("w" in d)) d.w = 1;
  11341. if ("Z" in d) {
  11342. week = utcDate(newYear(d.y)), day$1 = week.getUTCDay();
  11343. week = day$1 > 4 || day$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
  11344. week = utcDay.offset(week, (d.V - 1) * 7);
  11345. d.y = week.getUTCFullYear();
  11346. d.m = week.getUTCMonth();
  11347. d.d = week.getUTCDate() + (d.w + 6) % 7;
  11348. } else {
  11349. week = newDate(newYear(d.y)), day$1 = week.getDay();
  11350. week = day$1 > 4 || day$1 === 0 ? monday.ceil(week) : monday(week);
  11351. week = day.offset(week, (d.V - 1) * 7);
  11352. d.y = week.getFullYear();
  11353. d.m = week.getMonth();
  11354. d.d = week.getDate() + (d.w + 6) % 7;
  11355. }
  11356. } else if ("W" in d || "U" in d) {
  11357. if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
  11358. day$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
  11359. d.m = 0;
  11360. 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;
  11361. }
  11362. // If a time zone is specified, all fields are interpreted as UTC and then
  11363. // offset according to the specified time zone.
  11364. if ("Z" in d) {
  11365. d.H += d.Z / 100 | 0;
  11366. d.M += d.Z % 100;
  11367. return utcDate(d);
  11368. }
  11369. // Otherwise, all fields are in local time.
  11370. return newDate(d);
  11371. };
  11372. }
  11373. function parseSpecifier(d, specifier, string, j) {
  11374. var i = 0,
  11375. n = specifier.length,
  11376. m = string.length,
  11377. c,
  11378. parse;
  11379. while (i < n) {
  11380. if (j >= m) return -1;
  11381. c = specifier.charCodeAt(i++);
  11382. if (c === 37) {
  11383. c = specifier.charAt(i++);
  11384. parse = parses[c in pads ? specifier.charAt(i++) : c];
  11385. if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
  11386. } else if (c != string.charCodeAt(j++)) {
  11387. return -1;
  11388. }
  11389. }
  11390. return j;
  11391. }
  11392. function parsePeriod(d, string, i) {
  11393. var n = periodRe.exec(string.slice(i));
  11394. return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11395. }
  11396. function parseShortWeekday(d, string, i) {
  11397. var n = shortWeekdayRe.exec(string.slice(i));
  11398. return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11399. }
  11400. function parseWeekday(d, string, i) {
  11401. var n = weekdayRe.exec(string.slice(i));
  11402. return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11403. }
  11404. function parseShortMonth(d, string, i) {
  11405. var n = shortMonthRe.exec(string.slice(i));
  11406. return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11407. }
  11408. function parseMonth(d, string, i) {
  11409. var n = monthRe.exec(string.slice(i));
  11410. return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
  11411. }
  11412. function parseLocaleDateTime(d, string, i) {
  11413. return parseSpecifier(d, locale_dateTime, string, i);
  11414. }
  11415. function parseLocaleDate(d, string, i) {
  11416. return parseSpecifier(d, locale_date, string, i);
  11417. }
  11418. function parseLocaleTime(d, string, i) {
  11419. return parseSpecifier(d, locale_time, string, i);
  11420. }
  11421. function formatShortWeekday(d) {
  11422. return locale_shortWeekdays[d.getDay()];
  11423. }
  11424. function formatWeekday(d) {
  11425. return locale_weekdays[d.getDay()];
  11426. }
  11427. function formatShortMonth(d) {
  11428. return locale_shortMonths[d.getMonth()];
  11429. }
  11430. function formatMonth(d) {
  11431. return locale_months[d.getMonth()];
  11432. }
  11433. function formatPeriod(d) {
  11434. return locale_periods[+(d.getHours() >= 12)];
  11435. }
  11436. function formatUTCShortWeekday(d) {
  11437. return locale_shortWeekdays[d.getUTCDay()];
  11438. }
  11439. function formatUTCWeekday(d) {
  11440. return locale_weekdays[d.getUTCDay()];
  11441. }
  11442. function formatUTCShortMonth(d) {
  11443. return locale_shortMonths[d.getUTCMonth()];
  11444. }
  11445. function formatUTCMonth(d) {
  11446. return locale_months[d.getUTCMonth()];
  11447. }
  11448. function formatUTCPeriod(d) {
  11449. return locale_periods[+(d.getUTCHours() >= 12)];
  11450. }
  11451. return {
  11452. format: function(specifier) {
  11453. var f = newFormat(specifier += "", formats);
  11454. f.toString = function() { return specifier; };
  11455. return f;
  11456. },
  11457. parse: function(specifier) {
  11458. var p = newParse(specifier += "", localDate);
  11459. p.toString = function() { return specifier; };
  11460. return p;
  11461. },
  11462. utcFormat: function(specifier) {
  11463. var f = newFormat(specifier += "", utcFormats);
  11464. f.toString = function() { return specifier; };
  11465. return f;
  11466. },
  11467. utcParse: function(specifier) {
  11468. var p = newParse(specifier, utcDate);
  11469. p.toString = function() { return specifier; };
  11470. return p;
  11471. }
  11472. };
  11473. }
  11474. var pads = {"-": "", "_": " ", "0": "0"},
  11475. numberRe = /^\s*\d+/, // note: ignores next directive
  11476. percentRe = /^%/,
  11477. requoteRe = /[\\^$*+?|[\]().{}]/g;
  11478. function pad$1(value, fill, width) {
  11479. var sign = value < 0 ? "-" : "",
  11480. string = (sign ? -value : value) + "",
  11481. length = string.length;
  11482. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  11483. }
  11484. function requote(s) {
  11485. return s.replace(requoteRe, "\\$&");
  11486. }
  11487. function formatRe(names) {
  11488. return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
  11489. }
  11490. function formatLookup(names) {
  11491. var map = {}, i = -1, n = names.length;
  11492. while (++i < n) map[names[i].toLowerCase()] = i;
  11493. return map;
  11494. }
  11495. function parseWeekdayNumberSunday(d, string, i) {
  11496. var n = numberRe.exec(string.slice(i, i + 1));
  11497. return n ? (d.w = +n[0], i + n[0].length) : -1;
  11498. }
  11499. function parseWeekdayNumberMonday(d, string, i) {
  11500. var n = numberRe.exec(string.slice(i, i + 1));
  11501. return n ? (d.u = +n[0], i + n[0].length) : -1;
  11502. }
  11503. function parseWeekNumberSunday(d, string, i) {
  11504. var n = numberRe.exec(string.slice(i, i + 2));
  11505. return n ? (d.U = +n[0], i + n[0].length) : -1;
  11506. }
  11507. function parseWeekNumberISO(d, string, i) {
  11508. var n = numberRe.exec(string.slice(i, i + 2));
  11509. return n ? (d.V = +n[0], i + n[0].length) : -1;
  11510. }
  11511. function parseWeekNumberMonday(d, string, i) {
  11512. var n = numberRe.exec(string.slice(i, i + 2));
  11513. return n ? (d.W = +n[0], i + n[0].length) : -1;
  11514. }
  11515. function parseFullYear(d, string, i) {
  11516. var n = numberRe.exec(string.slice(i, i + 4));
  11517. return n ? (d.y = +n[0], i + n[0].length) : -1;
  11518. }
  11519. function parseYear(d, string, i) {
  11520. var n = numberRe.exec(string.slice(i, i + 2));
  11521. return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
  11522. }
  11523. function parseZone(d, string, i) {
  11524. var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
  11525. return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
  11526. }
  11527. function parseMonthNumber(d, string, i) {
  11528. var n = numberRe.exec(string.slice(i, i + 2));
  11529. return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
  11530. }
  11531. function parseDayOfMonth(d, string, i) {
  11532. var n = numberRe.exec(string.slice(i, i + 2));
  11533. return n ? (d.d = +n[0], i + n[0].length) : -1;
  11534. }
  11535. function parseDayOfYear(d, string, i) {
  11536. var n = numberRe.exec(string.slice(i, i + 3));
  11537. return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
  11538. }
  11539. function parseHour24(d, string, i) {
  11540. var n = numberRe.exec(string.slice(i, i + 2));
  11541. return n ? (d.H = +n[0], i + n[0].length) : -1;
  11542. }
  11543. function parseMinutes(d, string, i) {
  11544. var n = numberRe.exec(string.slice(i, i + 2));
  11545. return n ? (d.M = +n[0], i + n[0].length) : -1;
  11546. }
  11547. function parseSeconds(d, string, i) {
  11548. var n = numberRe.exec(string.slice(i, i + 2));
  11549. return n ? (d.S = +n[0], i + n[0].length) : -1;
  11550. }
  11551. function parseMilliseconds(d, string, i) {
  11552. var n = numberRe.exec(string.slice(i, i + 3));
  11553. return n ? (d.L = +n[0], i + n[0].length) : -1;
  11554. }
  11555. function parseMicroseconds(d, string, i) {
  11556. var n = numberRe.exec(string.slice(i, i + 6));
  11557. return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
  11558. }
  11559. function parseLiteralPercent(d, string, i) {
  11560. var n = percentRe.exec(string.slice(i, i + 1));
  11561. return n ? i + n[0].length : -1;
  11562. }
  11563. function parseUnixTimestamp(d, string, i) {
  11564. var n = numberRe.exec(string.slice(i));
  11565. return n ? (d.Q = +n[0], i + n[0].length) : -1;
  11566. }
  11567. function parseUnixTimestampSeconds(d, string, i) {
  11568. var n = numberRe.exec(string.slice(i));
  11569. return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
  11570. }
  11571. function formatDayOfMonth(d, p) {
  11572. return pad$1(d.getDate(), p, 2);
  11573. }
  11574. function formatHour24(d, p) {
  11575. return pad$1(d.getHours(), p, 2);
  11576. }
  11577. function formatHour12(d, p) {
  11578. return pad$1(d.getHours() % 12 || 12, p, 2);
  11579. }
  11580. function formatDayOfYear(d, p) {
  11581. return pad$1(1 + day.count(year(d), d), p, 3);
  11582. }
  11583. function formatMilliseconds(d, p) {
  11584. return pad$1(d.getMilliseconds(), p, 3);
  11585. }
  11586. function formatMicroseconds(d, p) {
  11587. return formatMilliseconds(d, p) + "000";
  11588. }
  11589. function formatMonthNumber(d, p) {
  11590. return pad$1(d.getMonth() + 1, p, 2);
  11591. }
  11592. function formatMinutes(d, p) {
  11593. return pad$1(d.getMinutes(), p, 2);
  11594. }
  11595. function formatSeconds(d, p) {
  11596. return pad$1(d.getSeconds(), p, 2);
  11597. }
  11598. function formatWeekdayNumberMonday(d) {
  11599. var day = d.getDay();
  11600. return day === 0 ? 7 : day;
  11601. }
  11602. function formatWeekNumberSunday(d, p) {
  11603. return pad$1(sunday.count(year(d), d), p, 2);
  11604. }
  11605. function formatWeekNumberISO(d, p) {
  11606. var day = d.getDay();
  11607. d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
  11608. return pad$1(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
  11609. }
  11610. function formatWeekdayNumberSunday(d) {
  11611. return d.getDay();
  11612. }
  11613. function formatWeekNumberMonday(d, p) {
  11614. return pad$1(monday.count(year(d), d), p, 2);
  11615. }
  11616. function formatYear$1(d, p) {
  11617. return pad$1(d.getFullYear() % 100, p, 2);
  11618. }
  11619. function formatFullYear(d, p) {
  11620. return pad$1(d.getFullYear() % 10000, p, 4);
  11621. }
  11622. function formatZone(d) {
  11623. var z = d.getTimezoneOffset();
  11624. return (z > 0 ? "-" : (z *= -1, "+"))
  11625. + pad$1(z / 60 | 0, "0", 2)
  11626. + pad$1(z % 60, "0", 2);
  11627. }
  11628. function formatUTCDayOfMonth(d, p) {
  11629. return pad$1(d.getUTCDate(), p, 2);
  11630. }
  11631. function formatUTCHour24(d, p) {
  11632. return pad$1(d.getUTCHours(), p, 2);
  11633. }
  11634. function formatUTCHour12(d, p) {
  11635. return pad$1(d.getUTCHours() % 12 || 12, p, 2);
  11636. }
  11637. function formatUTCDayOfYear(d, p) {
  11638. return pad$1(1 + utcDay.count(utcYear(d), d), p, 3);
  11639. }
  11640. function formatUTCMilliseconds(d, p) {
  11641. return pad$1(d.getUTCMilliseconds(), p, 3);
  11642. }
  11643. function formatUTCMicroseconds(d, p) {
  11644. return formatUTCMilliseconds(d, p) + "000";
  11645. }
  11646. function formatUTCMonthNumber(d, p) {
  11647. return pad$1(d.getUTCMonth() + 1, p, 2);
  11648. }
  11649. function formatUTCMinutes(d, p) {
  11650. return pad$1(d.getUTCMinutes(), p, 2);
  11651. }
  11652. function formatUTCSeconds(d, p) {
  11653. return pad$1(d.getUTCSeconds(), p, 2);
  11654. }
  11655. function formatUTCWeekdayNumberMonday(d) {
  11656. var dow = d.getUTCDay();
  11657. return dow === 0 ? 7 : dow;
  11658. }
  11659. function formatUTCWeekNumberSunday(d, p) {
  11660. return pad$1(utcSunday.count(utcYear(d), d), p, 2);
  11661. }
  11662. function formatUTCWeekNumberISO(d, p) {
  11663. var day = d.getUTCDay();
  11664. d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
  11665. return pad$1(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
  11666. }
  11667. function formatUTCWeekdayNumberSunday(d) {
  11668. return d.getUTCDay();
  11669. }
  11670. function formatUTCWeekNumberMonday(d, p) {
  11671. return pad$1(utcMonday.count(utcYear(d), d), p, 2);
  11672. }
  11673. function formatUTCYear(d, p) {
  11674. return pad$1(d.getUTCFullYear() % 100, p, 2);
  11675. }
  11676. function formatUTCFullYear(d, p) {
  11677. return pad$1(d.getUTCFullYear() % 10000, p, 4);
  11678. }
  11679. function formatUTCZone() {
  11680. return "+0000";
  11681. }
  11682. function formatLiteralPercent() {
  11683. return "%";
  11684. }
  11685. function formatUnixTimestamp(d) {
  11686. return +d;
  11687. }
  11688. function formatUnixTimestampSeconds(d) {
  11689. return Math.floor(+d / 1000);
  11690. }
  11691. var locale$1;
  11692. defaultLocale$1({
  11693. dateTime: "%x, %X",
  11694. date: "%-m/%-d/%Y",
  11695. time: "%-I:%M:%S %p",
  11696. periods: ["AM", "PM"],
  11697. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  11698. shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  11699. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  11700. shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
  11701. });
  11702. function defaultLocale$1(definition) {
  11703. locale$1 = formatLocale$1(definition);
  11704. exports.timeFormat = locale$1.format;
  11705. exports.timeParse = locale$1.parse;
  11706. exports.utcFormat = locale$1.utcFormat;
  11707. exports.utcParse = locale$1.utcParse;
  11708. return locale$1;
  11709. }
  11710. var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
  11711. function formatIsoNative(date) {
  11712. return date.toISOString();
  11713. }
  11714. var formatIso = Date.prototype.toISOString
  11715. ? formatIsoNative
  11716. : exports.utcFormat(isoSpecifier);
  11717. function parseIsoNative(string) {
  11718. var date = new Date(string);
  11719. return isNaN(date) ? null : date;
  11720. }
  11721. var parseIso = +new Date("2000-01-01T00:00:00.000Z")
  11722. ? parseIsoNative
  11723. : exports.utcParse(isoSpecifier);
  11724. var durationSecond$1 = 1000,
  11725. durationMinute$1 = durationSecond$1 * 60,
  11726. durationHour$1 = durationMinute$1 * 60,
  11727. durationDay$1 = durationHour$1 * 24,
  11728. durationWeek$1 = durationDay$1 * 7,
  11729. durationMonth = durationDay$1 * 30,
  11730. durationYear = durationDay$1 * 365;
  11731. function date$1(t) {
  11732. return new Date(t);
  11733. }
  11734. function number$3(t) {
  11735. return t instanceof Date ? +t : +new Date(+t);
  11736. }
  11737. function calendar(year, month, week, day, hour, minute, second, millisecond, format) {
  11738. var scale = continuous(identity$6, identity$6),
  11739. invert = scale.invert,
  11740. domain = scale.domain;
  11741. var formatMillisecond = format(".%L"),
  11742. formatSecond = format(":%S"),
  11743. formatMinute = format("%I:%M"),
  11744. formatHour = format("%I %p"),
  11745. formatDay = format("%a %d"),
  11746. formatWeek = format("%b %d"),
  11747. formatMonth = format("%B"),
  11748. formatYear = format("%Y");
  11749. var tickIntervals = [
  11750. [second, 1, durationSecond$1],
  11751. [second, 5, 5 * durationSecond$1],
  11752. [second, 15, 15 * durationSecond$1],
  11753. [second, 30, 30 * durationSecond$1],
  11754. [minute, 1, durationMinute$1],
  11755. [minute, 5, 5 * durationMinute$1],
  11756. [minute, 15, 15 * durationMinute$1],
  11757. [minute, 30, 30 * durationMinute$1],
  11758. [ hour, 1, durationHour$1 ],
  11759. [ hour, 3, 3 * durationHour$1 ],
  11760. [ hour, 6, 6 * durationHour$1 ],
  11761. [ hour, 12, 12 * durationHour$1 ],
  11762. [ day, 1, durationDay$1 ],
  11763. [ day, 2, 2 * durationDay$1 ],
  11764. [ week, 1, durationWeek$1 ],
  11765. [ month, 1, durationMonth ],
  11766. [ month, 3, 3 * durationMonth ],
  11767. [ year, 1, durationYear ]
  11768. ];
  11769. function tickFormat(date) {
  11770. return (second(date) < date ? formatMillisecond
  11771. : minute(date) < date ? formatSecond
  11772. : hour(date) < date ? formatMinute
  11773. : day(date) < date ? formatHour
  11774. : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
  11775. : year(date) < date ? formatMonth
  11776. : formatYear)(date);
  11777. }
  11778. function tickInterval(interval, start, stop, step) {
  11779. if (interval == null) interval = 10;
  11780. // If a desired tick count is specified, pick a reasonable tick interval
  11781. // based on the extent of the domain and a rough estimate of tick size.
  11782. // Otherwise, assume interval is already a time interval and use it.
  11783. if (typeof interval === "number") {
  11784. var target = Math.abs(stop - start) / interval,
  11785. i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
  11786. if (i === tickIntervals.length) {
  11787. step = tickStep(start / durationYear, stop / durationYear, interval);
  11788. interval = year;
  11789. } else if (i) {
  11790. i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
  11791. step = i[1];
  11792. interval = i[0];
  11793. } else {
  11794. step = Math.max(tickStep(start, stop, interval), 1);
  11795. interval = millisecond;
  11796. }
  11797. }
  11798. return step == null ? interval : interval.every(step);
  11799. }
  11800. scale.invert = function(y) {
  11801. return new Date(invert(y));
  11802. };
  11803. scale.domain = function(_) {
  11804. return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
  11805. };
  11806. scale.ticks = function(interval, step) {
  11807. var d = domain(),
  11808. t0 = d[0],
  11809. t1 = d[d.length - 1],
  11810. r = t1 < t0,
  11811. t;
  11812. if (r) t = t0, t0 = t1, t1 = t;
  11813. t = tickInterval(interval, t0, t1, step);
  11814. t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
  11815. return r ? t.reverse() : t;
  11816. };
  11817. scale.tickFormat = function(count, specifier) {
  11818. return specifier == null ? tickFormat : format(specifier);
  11819. };
  11820. scale.nice = function(interval, step) {
  11821. var d = domain();
  11822. return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
  11823. ? domain(nice(d, interval))
  11824. : scale;
  11825. };
  11826. scale.copy = function() {
  11827. return copy(scale, calendar(year, month, week, day, hour, minute, second, millisecond, format));
  11828. };
  11829. return scale;
  11830. }
  11831. function time() {
  11832. return initRange.apply(calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
  11833. }
  11834. function utcTime() {
  11835. return initRange.apply(calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
  11836. }
  11837. function transformer$2() {
  11838. var x0 = 0,
  11839. x1 = 1,
  11840. t0,
  11841. t1,
  11842. k10,
  11843. transform,
  11844. interpolator = identity$6,
  11845. clamp = false,
  11846. unknown;
  11847. function scale(x) {
  11848. return isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
  11849. }
  11850. scale.domain = function(_) {
  11851. return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
  11852. };
  11853. scale.clamp = function(_) {
  11854. return arguments.length ? (clamp = !!_, scale) : clamp;
  11855. };
  11856. scale.interpolator = function(_) {
  11857. return arguments.length ? (interpolator = _, scale) : interpolator;
  11858. };
  11859. scale.unknown = function(_) {
  11860. return arguments.length ? (unknown = _, scale) : unknown;
  11861. };
  11862. return function(t) {
  11863. transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
  11864. return scale;
  11865. };
  11866. }
  11867. function copy$1(source, target) {
  11868. return target
  11869. .domain(source.domain())
  11870. .interpolator(source.interpolator())
  11871. .clamp(source.clamp())
  11872. .unknown(source.unknown());
  11873. }
  11874. function sequential() {
  11875. var scale = linearish(transformer$2()(identity$6));
  11876. scale.copy = function() {
  11877. return copy$1(scale, sequential());
  11878. };
  11879. return initInterpolator.apply(scale, arguments);
  11880. }
  11881. function sequentialLog() {
  11882. var scale = loggish(transformer$2()).domain([1, 10]);
  11883. scale.copy = function() {
  11884. return copy$1(scale, sequentialLog()).base(scale.base());
  11885. };
  11886. return initInterpolator.apply(scale, arguments);
  11887. }
  11888. function sequentialSymlog() {
  11889. var scale = symlogish(transformer$2());
  11890. scale.copy = function() {
  11891. return copy$1(scale, sequentialSymlog()).constant(scale.constant());
  11892. };
  11893. return initInterpolator.apply(scale, arguments);
  11894. }
  11895. function sequentialPow() {
  11896. var scale = powish(transformer$2());
  11897. scale.copy = function() {
  11898. return copy$1(scale, sequentialPow()).exponent(scale.exponent());
  11899. };
  11900. return initInterpolator.apply(scale, arguments);
  11901. }
  11902. function sequentialSqrt() {
  11903. return sequentialPow.apply(null, arguments).exponent(0.5);
  11904. }
  11905. function sequentialQuantile() {
  11906. var domain = [],
  11907. interpolator = identity$6;
  11908. function scale(x) {
  11909. if (!isNaN(x = +x)) return interpolator((bisectRight(domain, x) - 1) / (domain.length - 1));
  11910. }
  11911. scale.domain = function(_) {
  11912. if (!arguments.length) return domain.slice();
  11913. domain = [];
  11914. for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
  11915. domain.sort(ascending);
  11916. return scale;
  11917. };
  11918. scale.interpolator = function(_) {
  11919. return arguments.length ? (interpolator = _, scale) : interpolator;
  11920. };
  11921. scale.copy = function() {
  11922. return sequentialQuantile(interpolator).domain(domain);
  11923. };
  11924. return initInterpolator.apply(scale, arguments);
  11925. }
  11926. function transformer$3() {
  11927. var x0 = 0,
  11928. x1 = 0.5,
  11929. x2 = 1,
  11930. t0,
  11931. t1,
  11932. t2,
  11933. k10,
  11934. k21,
  11935. interpolator = identity$6,
  11936. transform,
  11937. clamp = false,
  11938. unknown;
  11939. function scale(x) {
  11940. return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (x < t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
  11941. }
  11942. scale.domain = function(_) {
  11943. return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), t2 = transform(x2 = +_[2]), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), scale) : [x0, x1, x2];
  11944. };
  11945. scale.clamp = function(_) {
  11946. return arguments.length ? (clamp = !!_, scale) : clamp;
  11947. };
  11948. scale.interpolator = function(_) {
  11949. return arguments.length ? (interpolator = _, scale) : interpolator;
  11950. };
  11951. scale.unknown = function(_) {
  11952. return arguments.length ? (unknown = _, scale) : unknown;
  11953. };
  11954. return function(t) {
  11955. transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1);
  11956. return scale;
  11957. };
  11958. }
  11959. function diverging() {
  11960. var scale = linearish(transformer$3()(identity$6));
  11961. scale.copy = function() {
  11962. return copy$1(scale, diverging());
  11963. };
  11964. return initInterpolator.apply(scale, arguments);
  11965. }
  11966. function divergingLog() {
  11967. var scale = loggish(transformer$3()).domain([0.1, 1, 10]);
  11968. scale.copy = function() {
  11969. return copy$1(scale, divergingLog()).base(scale.base());
  11970. };
  11971. return initInterpolator.apply(scale, arguments);
  11972. }
  11973. function divergingSymlog() {
  11974. var scale = symlogish(transformer$3());
  11975. scale.copy = function() {
  11976. return copy$1(scale, divergingSymlog()).constant(scale.constant());
  11977. };
  11978. return initInterpolator.apply(scale, arguments);
  11979. }
  11980. function divergingPow() {
  11981. var scale = powish(transformer$3());
  11982. scale.copy = function() {
  11983. return copy$1(scale, divergingPow()).exponent(scale.exponent());
  11984. };
  11985. return initInterpolator.apply(scale, arguments);
  11986. }
  11987. function divergingSqrt() {
  11988. return divergingPow.apply(null, arguments).exponent(0.5);
  11989. }
  11990. function colors(specifier) {
  11991. var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
  11992. while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
  11993. return colors;
  11994. }
  11995. var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
  11996. var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
  11997. var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
  11998. var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
  11999. var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
  12000. var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
  12001. var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
  12002. var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
  12003. var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
  12004. var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
  12005. function ramp(scheme) {
  12006. return rgbBasis(scheme[scheme.length - 1]);
  12007. }
  12008. var scheme = new Array(3).concat(
  12009. "d8b365f5f5f55ab4ac",
  12010. "a6611adfc27d80cdc1018571",
  12011. "a6611adfc27df5f5f580cdc1018571",
  12012. "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
  12013. "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
  12014. "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
  12015. "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
  12016. "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
  12017. "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
  12018. ).map(colors);
  12019. var BrBG = ramp(scheme);
  12020. var scheme$1 = new Array(3).concat(
  12021. "af8dc3f7f7f77fbf7b",
  12022. "7b3294c2a5cfa6dba0008837",
  12023. "7b3294c2a5cff7f7f7a6dba0008837",
  12024. "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
  12025. "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
  12026. "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
  12027. "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
  12028. "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
  12029. "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
  12030. ).map(colors);
  12031. var PRGn = ramp(scheme$1);
  12032. var scheme$2 = new Array(3).concat(
  12033. "e9a3c9f7f7f7a1d76a",
  12034. "d01c8bf1b6dab8e1864dac26",
  12035. "d01c8bf1b6daf7f7f7b8e1864dac26",
  12036. "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
  12037. "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
  12038. "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
  12039. "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
  12040. "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
  12041. "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
  12042. ).map(colors);
  12043. var PiYG = ramp(scheme$2);
  12044. var scheme$3 = new Array(3).concat(
  12045. "998ec3f7f7f7f1a340",
  12046. "5e3c99b2abd2fdb863e66101",
  12047. "5e3c99b2abd2f7f7f7fdb863e66101",
  12048. "542788998ec3d8daebfee0b6f1a340b35806",
  12049. "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
  12050. "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
  12051. "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
  12052. "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
  12053. "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
  12054. ).map(colors);
  12055. var PuOr = ramp(scheme$3);
  12056. var scheme$4 = new Array(3).concat(
  12057. "ef8a62f7f7f767a9cf",
  12058. "ca0020f4a58292c5de0571b0",
  12059. "ca0020f4a582f7f7f792c5de0571b0",
  12060. "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
  12061. "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
  12062. "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
  12063. "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
  12064. "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
  12065. "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
  12066. ).map(colors);
  12067. var RdBu = ramp(scheme$4);
  12068. var scheme$5 = new Array(3).concat(
  12069. "ef8a62ffffff999999",
  12070. "ca0020f4a582bababa404040",
  12071. "ca0020f4a582ffffffbababa404040",
  12072. "b2182bef8a62fddbc7e0e0e09999994d4d4d",
  12073. "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
  12074. "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
  12075. "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
  12076. "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
  12077. "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
  12078. ).map(colors);
  12079. var RdGy = ramp(scheme$5);
  12080. var scheme$6 = new Array(3).concat(
  12081. "fc8d59ffffbf91bfdb",
  12082. "d7191cfdae61abd9e92c7bb6",
  12083. "d7191cfdae61ffffbfabd9e92c7bb6",
  12084. "d73027fc8d59fee090e0f3f891bfdb4575b4",
  12085. "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
  12086. "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
  12087. "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
  12088. "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
  12089. "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
  12090. ).map(colors);
  12091. var RdYlBu = ramp(scheme$6);
  12092. var scheme$7 = new Array(3).concat(
  12093. "fc8d59ffffbf91cf60",
  12094. "d7191cfdae61a6d96a1a9641",
  12095. "d7191cfdae61ffffbfa6d96a1a9641",
  12096. "d73027fc8d59fee08bd9ef8b91cf601a9850",
  12097. "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
  12098. "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
  12099. "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
  12100. "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
  12101. "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
  12102. ).map(colors);
  12103. var RdYlGn = ramp(scheme$7);
  12104. var scheme$8 = new Array(3).concat(
  12105. "fc8d59ffffbf99d594",
  12106. "d7191cfdae61abdda42b83ba",
  12107. "d7191cfdae61ffffbfabdda42b83ba",
  12108. "d53e4ffc8d59fee08be6f59899d5943288bd",
  12109. "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
  12110. "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
  12111. "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
  12112. "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
  12113. "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
  12114. ).map(colors);
  12115. var Spectral = ramp(scheme$8);
  12116. var scheme$9 = new Array(3).concat(
  12117. "e5f5f999d8c92ca25f",
  12118. "edf8fbb2e2e266c2a4238b45",
  12119. "edf8fbb2e2e266c2a42ca25f006d2c",
  12120. "edf8fbccece699d8c966c2a42ca25f006d2c",
  12121. "edf8fbccece699d8c966c2a441ae76238b45005824",
  12122. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
  12123. "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
  12124. ).map(colors);
  12125. var BuGn = ramp(scheme$9);
  12126. var scheme$a = new Array(3).concat(
  12127. "e0ecf49ebcda8856a7",
  12128. "edf8fbb3cde38c96c688419d",
  12129. "edf8fbb3cde38c96c68856a7810f7c",
  12130. "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
  12131. "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
  12132. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
  12133. "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
  12134. ).map(colors);
  12135. var BuPu = ramp(scheme$a);
  12136. var scheme$b = new Array(3).concat(
  12137. "e0f3dba8ddb543a2ca",
  12138. "f0f9e8bae4bc7bccc42b8cbe",
  12139. "f0f9e8bae4bc7bccc443a2ca0868ac",
  12140. "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
  12141. "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  12142. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
  12143. "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
  12144. ).map(colors);
  12145. var GnBu = ramp(scheme$b);
  12146. var scheme$c = new Array(3).concat(
  12147. "fee8c8fdbb84e34a33",
  12148. "fef0d9fdcc8afc8d59d7301f",
  12149. "fef0d9fdcc8afc8d59e34a33b30000",
  12150. "fef0d9fdd49efdbb84fc8d59e34a33b30000",
  12151. "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
  12152. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
  12153. "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
  12154. ).map(colors);
  12155. var OrRd = ramp(scheme$c);
  12156. var scheme$d = new Array(3).concat(
  12157. "ece2f0a6bddb1c9099",
  12158. "f6eff7bdc9e167a9cf02818a",
  12159. "f6eff7bdc9e167a9cf1c9099016c59",
  12160. "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
  12161. "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
  12162. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
  12163. "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
  12164. ).map(colors);
  12165. var PuBuGn = ramp(scheme$d);
  12166. var scheme$e = new Array(3).concat(
  12167. "ece7f2a6bddb2b8cbe",
  12168. "f1eef6bdc9e174a9cf0570b0",
  12169. "f1eef6bdc9e174a9cf2b8cbe045a8d",
  12170. "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
  12171. "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  12172. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
  12173. "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
  12174. ).map(colors);
  12175. var PuBu = ramp(scheme$e);
  12176. var scheme$f = new Array(3).concat(
  12177. "e7e1efc994c7dd1c77",
  12178. "f1eef6d7b5d8df65b0ce1256",
  12179. "f1eef6d7b5d8df65b0dd1c77980043",
  12180. "f1eef6d4b9dac994c7df65b0dd1c77980043",
  12181. "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
  12182. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
  12183. "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
  12184. ).map(colors);
  12185. var PuRd = ramp(scheme$f);
  12186. var scheme$g = new Array(3).concat(
  12187. "fde0ddfa9fb5c51b8a",
  12188. "feebe2fbb4b9f768a1ae017e",
  12189. "feebe2fbb4b9f768a1c51b8a7a0177",
  12190. "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
  12191. "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  12192. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
  12193. "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
  12194. ).map(colors);
  12195. var RdPu = ramp(scheme$g);
  12196. var scheme$h = new Array(3).concat(
  12197. "edf8b17fcdbb2c7fb8",
  12198. "ffffcca1dab441b6c4225ea8",
  12199. "ffffcca1dab441b6c42c7fb8253494",
  12200. "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
  12201. "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  12202. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
  12203. "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
  12204. ).map(colors);
  12205. var YlGnBu = ramp(scheme$h);
  12206. var scheme$i = new Array(3).concat(
  12207. "f7fcb9addd8e31a354",
  12208. "ffffccc2e69978c679238443",
  12209. "ffffccc2e69978c67931a354006837",
  12210. "ffffccd9f0a3addd8e78c67931a354006837",
  12211. "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
  12212. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
  12213. "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
  12214. ).map(colors);
  12215. var YlGn = ramp(scheme$i);
  12216. var scheme$j = new Array(3).concat(
  12217. "fff7bcfec44fd95f0e",
  12218. "ffffd4fed98efe9929cc4c02",
  12219. "ffffd4fed98efe9929d95f0e993404",
  12220. "ffffd4fee391fec44ffe9929d95f0e993404",
  12221. "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
  12222. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
  12223. "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
  12224. ).map(colors);
  12225. var YlOrBr = ramp(scheme$j);
  12226. var scheme$k = new Array(3).concat(
  12227. "ffeda0feb24cf03b20",
  12228. "ffffb2fecc5cfd8d3ce31a1c",
  12229. "ffffb2fecc5cfd8d3cf03b20bd0026",
  12230. "ffffb2fed976feb24cfd8d3cf03b20bd0026",
  12231. "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  12232. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
  12233. "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
  12234. ).map(colors);
  12235. var YlOrRd = ramp(scheme$k);
  12236. var scheme$l = new Array(3).concat(
  12237. "deebf79ecae13182bd",
  12238. "eff3ffbdd7e76baed62171b5",
  12239. "eff3ffbdd7e76baed63182bd08519c",
  12240. "eff3ffc6dbef9ecae16baed63182bd08519c",
  12241. "eff3ffc6dbef9ecae16baed64292c62171b5084594",
  12242. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
  12243. "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
  12244. ).map(colors);
  12245. var Blues = ramp(scheme$l);
  12246. var scheme$m = new Array(3).concat(
  12247. "e5f5e0a1d99b31a354",
  12248. "edf8e9bae4b374c476238b45",
  12249. "edf8e9bae4b374c47631a354006d2c",
  12250. "edf8e9c7e9c0a1d99b74c47631a354006d2c",
  12251. "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
  12252. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
  12253. "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
  12254. ).map(colors);
  12255. var Greens = ramp(scheme$m);
  12256. var scheme$n = new Array(3).concat(
  12257. "f0f0f0bdbdbd636363",
  12258. "f7f7f7cccccc969696525252",
  12259. "f7f7f7cccccc969696636363252525",
  12260. "f7f7f7d9d9d9bdbdbd969696636363252525",
  12261. "f7f7f7d9d9d9bdbdbd969696737373525252252525",
  12262. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
  12263. "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
  12264. ).map(colors);
  12265. var Greys = ramp(scheme$n);
  12266. var scheme$o = new Array(3).concat(
  12267. "efedf5bcbddc756bb1",
  12268. "f2f0f7cbc9e29e9ac86a51a3",
  12269. "f2f0f7cbc9e29e9ac8756bb154278f",
  12270. "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
  12271. "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
  12272. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
  12273. "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
  12274. ).map(colors);
  12275. var Purples = ramp(scheme$o);
  12276. var scheme$p = new Array(3).concat(
  12277. "fee0d2fc9272de2d26",
  12278. "fee5d9fcae91fb6a4acb181d",
  12279. "fee5d9fcae91fb6a4ade2d26a50f15",
  12280. "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
  12281. "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  12282. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
  12283. "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
  12284. ).map(colors);
  12285. var Reds = ramp(scheme$p);
  12286. var scheme$q = new Array(3).concat(
  12287. "fee6cefdae6be6550d",
  12288. "feeddefdbe85fd8d3cd94701",
  12289. "feeddefdbe85fd8d3ce6550da63603",
  12290. "feeddefdd0a2fdae6bfd8d3ce6550da63603",
  12291. "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  12292. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
  12293. "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
  12294. ).map(colors);
  12295. var Oranges = ramp(scheme$q);
  12296. function cividis(t) {
  12297. t = Math.max(0, Math.min(1, t));
  12298. return "rgb("
  12299. + Math.max(0, Math.min(255, Math.round(-4.54 - t * (35.34 - t * (2381.73 - t * (6402.7 - t * (7024.72 - t * 2710.57))))))) + ", "
  12300. + Math.max(0, Math.min(255, Math.round(32.49 + t * (170.73 + t * (52.82 - t * (131.46 - t * (176.58 - t * 67.37))))))) + ", "
  12301. + Math.max(0, Math.min(255, Math.round(81.24 + t * (442.36 - t * (2482.43 - t * (6167.24 - t * (6614.94 - t * 2475.67)))))))
  12302. + ")";
  12303. }
  12304. var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
  12305. var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  12306. var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
  12307. var c = cubehelix();
  12308. function rainbow(t) {
  12309. if (t < 0 || t > 1) t -= Math.floor(t);
  12310. var ts = Math.abs(t - 0.5);
  12311. c.h = 360 * t - 100;
  12312. c.s = 1.5 - 1.5 * ts;
  12313. c.l = 0.8 - 0.9 * ts;
  12314. return c + "";
  12315. }
  12316. var c$1 = rgb(),
  12317. pi_1_3 = Math.PI / 3,
  12318. pi_2_3 = Math.PI * 2 / 3;
  12319. function sinebow(t) {
  12320. var x;
  12321. t = (0.5 - t) * Math.PI;
  12322. c$1.r = 255 * (x = Math.sin(t)) * x;
  12323. c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
  12324. c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
  12325. return c$1 + "";
  12326. }
  12327. function turbo(t) {
  12328. t = Math.max(0, Math.min(1, t));
  12329. return "rgb("
  12330. + Math.max(0, Math.min(255, Math.round(34.61 + t * (1172.33 - t * (10793.56 - t * (33300.12 - t * (38394.49 - t * 14825.05))))))) + ", "
  12331. + Math.max(0, Math.min(255, Math.round(23.31 + t * (557.33 + t * (1225.33 - t * (3574.96 - t * (1073.77 + t * 707.56))))))) + ", "
  12332. + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
  12333. + ")";
  12334. }
  12335. function ramp$1(range) {
  12336. var n = range.length;
  12337. return function(t) {
  12338. return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
  12339. };
  12340. }
  12341. var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
  12342. var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
  12343. var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
  12344. var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
  12345. function constant$b(x) {
  12346. return function constant() {
  12347. return x;
  12348. };
  12349. }
  12350. var abs$1 = Math.abs;
  12351. var atan2$1 = Math.atan2;
  12352. var cos$2 = Math.cos;
  12353. var max$2 = Math.max;
  12354. var min$1 = Math.min;
  12355. var sin$2 = Math.sin;
  12356. var sqrt$2 = Math.sqrt;
  12357. var epsilon$3 = 1e-12;
  12358. var pi$4 = Math.PI;
  12359. var halfPi$3 = pi$4 / 2;
  12360. var tau$4 = 2 * pi$4;
  12361. function acos$1(x) {
  12362. return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
  12363. }
  12364. function asin$1(x) {
  12365. return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
  12366. }
  12367. function arcInnerRadius(d) {
  12368. return d.innerRadius;
  12369. }
  12370. function arcOuterRadius(d) {
  12371. return d.outerRadius;
  12372. }
  12373. function arcStartAngle(d) {
  12374. return d.startAngle;
  12375. }
  12376. function arcEndAngle(d) {
  12377. return d.endAngle;
  12378. }
  12379. function arcPadAngle(d) {
  12380. return d && d.padAngle; // Note: optional!
  12381. }
  12382. function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
  12383. var x10 = x1 - x0, y10 = y1 - y0,
  12384. x32 = x3 - x2, y32 = y3 - y2,
  12385. t = y32 * x10 - x32 * y10;
  12386. if (t * t < epsilon$3) return;
  12387. t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
  12388. return [x0 + t * x10, y0 + t * y10];
  12389. }
  12390. // Compute perpendicular offset line of length rc.
  12391. // http://mathworld.wolfram.com/Circle-LineIntersection.html
  12392. function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
  12393. var x01 = x0 - x1,
  12394. y01 = y0 - y1,
  12395. lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
  12396. ox = lo * y01,
  12397. oy = -lo * x01,
  12398. x11 = x0 + ox,
  12399. y11 = y0 + oy,
  12400. x10 = x1 + ox,
  12401. y10 = y1 + oy,
  12402. x00 = (x11 + x10) / 2,
  12403. y00 = (y11 + y10) / 2,
  12404. dx = x10 - x11,
  12405. dy = y10 - y11,
  12406. d2 = dx * dx + dy * dy,
  12407. r = r1 - rc,
  12408. D = x11 * y10 - x10 * y11,
  12409. d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
  12410. cx0 = (D * dy - dx * d) / d2,
  12411. cy0 = (-D * dx - dy * d) / d2,
  12412. cx1 = (D * dy + dx * d) / d2,
  12413. cy1 = (-D * dx + dy * d) / d2,
  12414. dx0 = cx0 - x00,
  12415. dy0 = cy0 - y00,
  12416. dx1 = cx1 - x00,
  12417. dy1 = cy1 - y00;
  12418. // Pick the closer of the two intersection points.
  12419. // TODO Is there a faster way to determine which intersection to use?
  12420. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  12421. return {
  12422. cx: cx0,
  12423. cy: cy0,
  12424. x01: -ox,
  12425. y01: -oy,
  12426. x11: cx0 * (r1 / r - 1),
  12427. y11: cy0 * (r1 / r - 1)
  12428. };
  12429. }
  12430. function arc() {
  12431. var innerRadius = arcInnerRadius,
  12432. outerRadius = arcOuterRadius,
  12433. cornerRadius = constant$b(0),
  12434. padRadius = null,
  12435. startAngle = arcStartAngle,
  12436. endAngle = arcEndAngle,
  12437. padAngle = arcPadAngle,
  12438. context = null;
  12439. function arc() {
  12440. var buffer,
  12441. r,
  12442. r0 = +innerRadius.apply(this, arguments),
  12443. r1 = +outerRadius.apply(this, arguments),
  12444. a0 = startAngle.apply(this, arguments) - halfPi$3,
  12445. a1 = endAngle.apply(this, arguments) - halfPi$3,
  12446. da = abs$1(a1 - a0),
  12447. cw = a1 > a0;
  12448. if (!context) context = buffer = path();
  12449. // Ensure that the outer radius is always larger than the inner radius.
  12450. if (r1 < r0) r = r1, r1 = r0, r0 = r;
  12451. // Is it a point?
  12452. if (!(r1 > epsilon$3)) context.moveTo(0, 0);
  12453. // Or is it a circle or annulus?
  12454. else if (da > tau$4 - epsilon$3) {
  12455. context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
  12456. context.arc(0, 0, r1, a0, a1, !cw);
  12457. if (r0 > epsilon$3) {
  12458. context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
  12459. context.arc(0, 0, r0, a1, a0, cw);
  12460. }
  12461. }
  12462. // Or is it a circular or annular sector?
  12463. else {
  12464. var a01 = a0,
  12465. a11 = a1,
  12466. a00 = a0,
  12467. a10 = a1,
  12468. da0 = da,
  12469. da1 = da,
  12470. ap = padAngle.apply(this, arguments) / 2,
  12471. rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
  12472. rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
  12473. rc0 = rc,
  12474. rc1 = rc,
  12475. t0,
  12476. t1;
  12477. // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
  12478. if (rp > epsilon$3) {
  12479. var p0 = asin$1(rp / r0 * sin$2(ap)),
  12480. p1 = asin$1(rp / r1 * sin$2(ap));
  12481. if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
  12482. else da0 = 0, a00 = a10 = (a0 + a1) / 2;
  12483. if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
  12484. else da1 = 0, a01 = a11 = (a0 + a1) / 2;
  12485. }
  12486. var x01 = r1 * cos$2(a01),
  12487. y01 = r1 * sin$2(a01),
  12488. x10 = r0 * cos$2(a10),
  12489. y10 = r0 * sin$2(a10);
  12490. // Apply rounded corners?
  12491. if (rc > epsilon$3) {
  12492. var x11 = r1 * cos$2(a11),
  12493. y11 = r1 * sin$2(a11),
  12494. x00 = r0 * cos$2(a00),
  12495. y00 = r0 * sin$2(a00),
  12496. oc;
  12497. // Restrict the corner radius according to the sector angle.
  12498. if (da < pi$4 && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
  12499. var ax = x01 - oc[0],
  12500. ay = y01 - oc[1],
  12501. bx = x11 - oc[0],
  12502. by = y11 - oc[1],
  12503. kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
  12504. lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
  12505. rc0 = min$1(rc, (r0 - lc) / (kc - 1));
  12506. rc1 = min$1(rc, (r1 - lc) / (kc + 1));
  12507. }
  12508. }
  12509. // Is the sector collapsed to a line?
  12510. if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
  12511. // Does the sector’s outer ring have rounded corners?
  12512. else if (rc1 > epsilon$3) {
  12513. t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
  12514. t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
  12515. context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12516. // Have the corners merged?
  12517. if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12518. // Otherwise, draw the two corners and the ring.
  12519. else {
  12520. context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12521. context.arc(0, 0, r1, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
  12522. context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12523. }
  12524. }
  12525. // Or is the outer ring just a circular arc?
  12526. else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
  12527. // Is there no inner ring, and it’s a circular sector?
  12528. // Or perhaps it’s an annular sector collapsed due to padding?
  12529. if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
  12530. // Does the sector’s inner ring (or point) have rounded corners?
  12531. else if (rc0 > epsilon$3) {
  12532. t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
  12533. t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
  12534. context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
  12535. // Have the corners merged?
  12536. if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
  12537. // Otherwise, draw the two corners and the ring.
  12538. else {
  12539. context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
  12540. context.arc(0, 0, r0, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), cw);
  12541. context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
  12542. }
  12543. }
  12544. // Or is the inner ring just a circular arc?
  12545. else context.arc(0, 0, r0, a10, a00, cw);
  12546. }
  12547. context.closePath();
  12548. if (buffer) return context = null, buffer + "" || null;
  12549. }
  12550. arc.centroid = function() {
  12551. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
  12552. a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
  12553. return [cos$2(a) * r, sin$2(a) * r];
  12554. };
  12555. arc.innerRadius = function(_) {
  12556. return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : innerRadius;
  12557. };
  12558. arc.outerRadius = function(_) {
  12559. return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : outerRadius;
  12560. };
  12561. arc.cornerRadius = function(_) {
  12562. return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : cornerRadius;
  12563. };
  12564. arc.padRadius = function(_) {
  12565. return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), arc) : padRadius;
  12566. };
  12567. arc.startAngle = function(_) {
  12568. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : startAngle;
  12569. };
  12570. arc.endAngle = function(_) {
  12571. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : endAngle;
  12572. };
  12573. arc.padAngle = function(_) {
  12574. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : padAngle;
  12575. };
  12576. arc.context = function(_) {
  12577. return arguments.length ? ((context = _ == null ? null : _), arc) : context;
  12578. };
  12579. return arc;
  12580. }
  12581. function Linear(context) {
  12582. this._context = context;
  12583. }
  12584. Linear.prototype = {
  12585. areaStart: function() {
  12586. this._line = 0;
  12587. },
  12588. areaEnd: function() {
  12589. this._line = NaN;
  12590. },
  12591. lineStart: function() {
  12592. this._point = 0;
  12593. },
  12594. lineEnd: function() {
  12595. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  12596. this._line = 1 - this._line;
  12597. },
  12598. point: function(x, y) {
  12599. x = +x, y = +y;
  12600. switch (this._point) {
  12601. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  12602. case 1: this._point = 2; // proceed
  12603. default: this._context.lineTo(x, y); break;
  12604. }
  12605. }
  12606. };
  12607. function curveLinear(context) {
  12608. return new Linear(context);
  12609. }
  12610. function x$3(p) {
  12611. return p[0];
  12612. }
  12613. function y$3(p) {
  12614. return p[1];
  12615. }
  12616. function line() {
  12617. var x = x$3,
  12618. y = y$3,
  12619. defined = constant$b(true),
  12620. context = null,
  12621. curve = curveLinear,
  12622. output = null;
  12623. function line(data) {
  12624. var i,
  12625. n = data.length,
  12626. d,
  12627. defined0 = false,
  12628. buffer;
  12629. if (context == null) output = curve(buffer = path());
  12630. for (i = 0; i <= n; ++i) {
  12631. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12632. if (defined0 = !defined0) output.lineStart();
  12633. else output.lineEnd();
  12634. }
  12635. if (defined0) output.point(+x(d, i, data), +y(d, i, data));
  12636. }
  12637. if (buffer) return output = null, buffer + "" || null;
  12638. }
  12639. line.x = function(_) {
  12640. return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), line) : x;
  12641. };
  12642. line.y = function(_) {
  12643. return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), line) : y;
  12644. };
  12645. line.defined = function(_) {
  12646. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), line) : defined;
  12647. };
  12648. line.curve = function(_) {
  12649. return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
  12650. };
  12651. line.context = function(_) {
  12652. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
  12653. };
  12654. return line;
  12655. }
  12656. function area$3() {
  12657. var x0 = x$3,
  12658. x1 = null,
  12659. y0 = constant$b(0),
  12660. y1 = y$3,
  12661. defined = constant$b(true),
  12662. context = null,
  12663. curve = curveLinear,
  12664. output = null;
  12665. function area(data) {
  12666. var i,
  12667. j,
  12668. k,
  12669. n = data.length,
  12670. d,
  12671. defined0 = false,
  12672. buffer,
  12673. x0z = new Array(n),
  12674. y0z = new Array(n);
  12675. if (context == null) output = curve(buffer = path());
  12676. for (i = 0; i <= n; ++i) {
  12677. if (!(i < n && defined(d = data[i], i, data)) === defined0) {
  12678. if (defined0 = !defined0) {
  12679. j = i;
  12680. output.areaStart();
  12681. output.lineStart();
  12682. } else {
  12683. output.lineEnd();
  12684. output.lineStart();
  12685. for (k = i - 1; k >= j; --k) {
  12686. output.point(x0z[k], y0z[k]);
  12687. }
  12688. output.lineEnd();
  12689. output.areaEnd();
  12690. }
  12691. }
  12692. if (defined0) {
  12693. x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
  12694. output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
  12695. }
  12696. }
  12697. if (buffer) return output = null, buffer + "" || null;
  12698. }
  12699. function arealine() {
  12700. return line().defined(defined).curve(curve).context(context);
  12701. }
  12702. area.x = function(_) {
  12703. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), x1 = null, area) : x0;
  12704. };
  12705. area.x0 = function(_) {
  12706. return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), area) : x0;
  12707. };
  12708. area.x1 = function(_) {
  12709. return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : x1;
  12710. };
  12711. area.y = function(_) {
  12712. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), y1 = null, area) : y0;
  12713. };
  12714. area.y0 = function(_) {
  12715. return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), area) : y0;
  12716. };
  12717. area.y1 = function(_) {
  12718. return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : y1;
  12719. };
  12720. area.lineX0 =
  12721. area.lineY0 = function() {
  12722. return arealine().x(x0).y(y0);
  12723. };
  12724. area.lineY1 = function() {
  12725. return arealine().x(x0).y(y1);
  12726. };
  12727. area.lineX1 = function() {
  12728. return arealine().x(x1).y(y0);
  12729. };
  12730. area.defined = function(_) {
  12731. return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), area) : defined;
  12732. };
  12733. area.curve = function(_) {
  12734. return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
  12735. };
  12736. area.context = function(_) {
  12737. return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
  12738. };
  12739. return area;
  12740. }
  12741. function descending$1(a, b) {
  12742. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  12743. }
  12744. function identity$8(d) {
  12745. return d;
  12746. }
  12747. function pie() {
  12748. var value = identity$8,
  12749. sortValues = descending$1,
  12750. sort = null,
  12751. startAngle = constant$b(0),
  12752. endAngle = constant$b(tau$4),
  12753. padAngle = constant$b(0);
  12754. function pie(data) {
  12755. var i,
  12756. n = data.length,
  12757. j,
  12758. k,
  12759. sum = 0,
  12760. index = new Array(n),
  12761. arcs = new Array(n),
  12762. a0 = +startAngle.apply(this, arguments),
  12763. da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
  12764. a1,
  12765. p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
  12766. pa = p * (da < 0 ? -1 : 1),
  12767. v;
  12768. for (i = 0; i < n; ++i) {
  12769. if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
  12770. sum += v;
  12771. }
  12772. }
  12773. // Optionally sort the arcs by previously-computed values or by data.
  12774. if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
  12775. else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
  12776. // Compute the arcs! They are stored in the original data's order.
  12777. for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
  12778. j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
  12779. data: data[j],
  12780. index: i,
  12781. value: v,
  12782. startAngle: a0,
  12783. endAngle: a1,
  12784. padAngle: p
  12785. };
  12786. }
  12787. return arcs;
  12788. }
  12789. pie.value = function(_) {
  12790. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), pie) : value;
  12791. };
  12792. pie.sortValues = function(_) {
  12793. return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
  12794. };
  12795. pie.sort = function(_) {
  12796. return arguments.length ? (sort = _, sortValues = null, pie) : sort;
  12797. };
  12798. pie.startAngle = function(_) {
  12799. return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : startAngle;
  12800. };
  12801. pie.endAngle = function(_) {
  12802. return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : endAngle;
  12803. };
  12804. pie.padAngle = function(_) {
  12805. return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : padAngle;
  12806. };
  12807. return pie;
  12808. }
  12809. var curveRadialLinear = curveRadial(curveLinear);
  12810. function Radial(curve) {
  12811. this._curve = curve;
  12812. }
  12813. Radial.prototype = {
  12814. areaStart: function() {
  12815. this._curve.areaStart();
  12816. },
  12817. areaEnd: function() {
  12818. this._curve.areaEnd();
  12819. },
  12820. lineStart: function() {
  12821. this._curve.lineStart();
  12822. },
  12823. lineEnd: function() {
  12824. this._curve.lineEnd();
  12825. },
  12826. point: function(a, r) {
  12827. this._curve.point(r * Math.sin(a), r * -Math.cos(a));
  12828. }
  12829. };
  12830. function curveRadial(curve) {
  12831. function radial(context) {
  12832. return new Radial(curve(context));
  12833. }
  12834. radial._curve = curve;
  12835. return radial;
  12836. }
  12837. function lineRadial(l) {
  12838. var c = l.curve;
  12839. l.angle = l.x, delete l.x;
  12840. l.radius = l.y, delete l.y;
  12841. l.curve = function(_) {
  12842. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12843. };
  12844. return l;
  12845. }
  12846. function lineRadial$1() {
  12847. return lineRadial(line().curve(curveRadialLinear));
  12848. }
  12849. function areaRadial() {
  12850. var a = area$3().curve(curveRadialLinear),
  12851. c = a.curve,
  12852. x0 = a.lineX0,
  12853. x1 = a.lineX1,
  12854. y0 = a.lineY0,
  12855. y1 = a.lineY1;
  12856. a.angle = a.x, delete a.x;
  12857. a.startAngle = a.x0, delete a.x0;
  12858. a.endAngle = a.x1, delete a.x1;
  12859. a.radius = a.y, delete a.y;
  12860. a.innerRadius = a.y0, delete a.y0;
  12861. a.outerRadius = a.y1, delete a.y1;
  12862. a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
  12863. a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
  12864. a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
  12865. a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
  12866. a.curve = function(_) {
  12867. return arguments.length ? c(curveRadial(_)) : c()._curve;
  12868. };
  12869. return a;
  12870. }
  12871. function pointRadial(x, y) {
  12872. return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
  12873. }
  12874. var slice$6 = Array.prototype.slice;
  12875. function linkSource(d) {
  12876. return d.source;
  12877. }
  12878. function linkTarget(d) {
  12879. return d.target;
  12880. }
  12881. function link$2(curve) {
  12882. var source = linkSource,
  12883. target = linkTarget,
  12884. x = x$3,
  12885. y = y$3,
  12886. context = null;
  12887. function link() {
  12888. var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
  12889. if (!context) context = buffer = path();
  12890. curve(context, +x.apply(this, (argv[0] = s, argv)), +y.apply(this, argv), +x.apply(this, (argv[0] = t, argv)), +y.apply(this, argv));
  12891. if (buffer) return context = null, buffer + "" || null;
  12892. }
  12893. link.source = function(_) {
  12894. return arguments.length ? (source = _, link) : source;
  12895. };
  12896. link.target = function(_) {
  12897. return arguments.length ? (target = _, link) : target;
  12898. };
  12899. link.x = function(_) {
  12900. return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), link) : x;
  12901. };
  12902. link.y = function(_) {
  12903. return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), link) : y;
  12904. };
  12905. link.context = function(_) {
  12906. return arguments.length ? ((context = _ == null ? null : _), link) : context;
  12907. };
  12908. return link;
  12909. }
  12910. function curveHorizontal(context, x0, y0, x1, y1) {
  12911. context.moveTo(x0, y0);
  12912. context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
  12913. }
  12914. function curveVertical(context, x0, y0, x1, y1) {
  12915. context.moveTo(x0, y0);
  12916. context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
  12917. }
  12918. function curveRadial$1(context, x0, y0, x1, y1) {
  12919. var p0 = pointRadial(x0, y0),
  12920. p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
  12921. p2 = pointRadial(x1, y0),
  12922. p3 = pointRadial(x1, y1);
  12923. context.moveTo(p0[0], p0[1]);
  12924. context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
  12925. }
  12926. function linkHorizontal() {
  12927. return link$2(curveHorizontal);
  12928. }
  12929. function linkVertical() {
  12930. return link$2(curveVertical);
  12931. }
  12932. function linkRadial() {
  12933. var l = link$2(curveRadial$1);
  12934. l.angle = l.x, delete l.x;
  12935. l.radius = l.y, delete l.y;
  12936. return l;
  12937. }
  12938. var circle$2 = {
  12939. draw: function(context, size) {
  12940. var r = Math.sqrt(size / pi$4);
  12941. context.moveTo(r, 0);
  12942. context.arc(0, 0, r, 0, tau$4);
  12943. }
  12944. };
  12945. var cross$2 = {
  12946. draw: function(context, size) {
  12947. var r = Math.sqrt(size / 5) / 2;
  12948. context.moveTo(-3 * r, -r);
  12949. context.lineTo(-r, -r);
  12950. context.lineTo(-r, -3 * r);
  12951. context.lineTo(r, -3 * r);
  12952. context.lineTo(r, -r);
  12953. context.lineTo(3 * r, -r);
  12954. context.lineTo(3 * r, r);
  12955. context.lineTo(r, r);
  12956. context.lineTo(r, 3 * r);
  12957. context.lineTo(-r, 3 * r);
  12958. context.lineTo(-r, r);
  12959. context.lineTo(-3 * r, r);
  12960. context.closePath();
  12961. }
  12962. };
  12963. var tan30 = Math.sqrt(1 / 3),
  12964. tan30_2 = tan30 * 2;
  12965. var diamond = {
  12966. draw: function(context, size) {
  12967. var y = Math.sqrt(size / tan30_2),
  12968. x = y * tan30;
  12969. context.moveTo(0, -y);
  12970. context.lineTo(x, 0);
  12971. context.lineTo(0, y);
  12972. context.lineTo(-x, 0);
  12973. context.closePath();
  12974. }
  12975. };
  12976. var ka = 0.89081309152928522810,
  12977. kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
  12978. kx = Math.sin(tau$4 / 10) * kr,
  12979. ky = -Math.cos(tau$4 / 10) * kr;
  12980. var star = {
  12981. draw: function(context, size) {
  12982. var r = Math.sqrt(size * ka),
  12983. x = kx * r,
  12984. y = ky * r;
  12985. context.moveTo(0, -r);
  12986. context.lineTo(x, y);
  12987. for (var i = 1; i < 5; ++i) {
  12988. var a = tau$4 * i / 5,
  12989. c = Math.cos(a),
  12990. s = Math.sin(a);
  12991. context.lineTo(s * r, -c * r);
  12992. context.lineTo(c * x - s * y, s * x + c * y);
  12993. }
  12994. context.closePath();
  12995. }
  12996. };
  12997. var square = {
  12998. draw: function(context, size) {
  12999. var w = Math.sqrt(size),
  13000. x = -w / 2;
  13001. context.rect(x, x, w, w);
  13002. }
  13003. };
  13004. var sqrt3 = Math.sqrt(3);
  13005. var triangle = {
  13006. draw: function(context, size) {
  13007. var y = -Math.sqrt(size / (sqrt3 * 3));
  13008. context.moveTo(0, y * 2);
  13009. context.lineTo(-sqrt3 * y, -y);
  13010. context.lineTo(sqrt3 * y, -y);
  13011. context.closePath();
  13012. }
  13013. };
  13014. var c$2 = -0.5,
  13015. s = Math.sqrt(3) / 2,
  13016. k = 1 / Math.sqrt(12),
  13017. a = (k / 2 + 1) * 3;
  13018. var wye = {
  13019. draw: function(context, size) {
  13020. var r = Math.sqrt(size / a),
  13021. x0 = r / 2,
  13022. y0 = r * k,
  13023. x1 = x0,
  13024. y1 = r * k + r,
  13025. x2 = -x1,
  13026. y2 = y1;
  13027. context.moveTo(x0, y0);
  13028. context.lineTo(x1, y1);
  13029. context.lineTo(x2, y2);
  13030. context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
  13031. context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
  13032. context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
  13033. context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
  13034. context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
  13035. context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
  13036. context.closePath();
  13037. }
  13038. };
  13039. var symbols = [
  13040. circle$2,
  13041. cross$2,
  13042. diamond,
  13043. square,
  13044. star,
  13045. triangle,
  13046. wye
  13047. ];
  13048. function symbol() {
  13049. var type = constant$b(circle$2),
  13050. size = constant$b(64),
  13051. context = null;
  13052. function symbol() {
  13053. var buffer;
  13054. if (!context) context = buffer = path();
  13055. type.apply(this, arguments).draw(context, +size.apply(this, arguments));
  13056. if (buffer) return context = null, buffer + "" || null;
  13057. }
  13058. symbol.type = function(_) {
  13059. return arguments.length ? (type = typeof _ === "function" ? _ : constant$b(_), symbol) : type;
  13060. };
  13061. symbol.size = function(_) {
  13062. return arguments.length ? (size = typeof _ === "function" ? _ : constant$b(+_), symbol) : size;
  13063. };
  13064. symbol.context = function(_) {
  13065. return arguments.length ? (context = _ == null ? null : _, symbol) : context;
  13066. };
  13067. return symbol;
  13068. }
  13069. function noop$3() {}
  13070. function point$2(that, x, y) {
  13071. that._context.bezierCurveTo(
  13072. (2 * that._x0 + that._x1) / 3,
  13073. (2 * that._y0 + that._y1) / 3,
  13074. (that._x0 + 2 * that._x1) / 3,
  13075. (that._y0 + 2 * that._y1) / 3,
  13076. (that._x0 + 4 * that._x1 + x) / 6,
  13077. (that._y0 + 4 * that._y1 + y) / 6
  13078. );
  13079. }
  13080. function Basis(context) {
  13081. this._context = context;
  13082. }
  13083. Basis.prototype = {
  13084. areaStart: function() {
  13085. this._line = 0;
  13086. },
  13087. areaEnd: function() {
  13088. this._line = NaN;
  13089. },
  13090. lineStart: function() {
  13091. this._x0 = this._x1 =
  13092. this._y0 = this._y1 = NaN;
  13093. this._point = 0;
  13094. },
  13095. lineEnd: function() {
  13096. switch (this._point) {
  13097. case 3: point$2(this, this._x1, this._y1); // proceed
  13098. case 2: this._context.lineTo(this._x1, this._y1); break;
  13099. }
  13100. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13101. this._line = 1 - this._line;
  13102. },
  13103. point: function(x, y) {
  13104. x = +x, y = +y;
  13105. switch (this._point) {
  13106. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13107. case 1: this._point = 2; break;
  13108. case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
  13109. default: point$2(this, x, y); break;
  13110. }
  13111. this._x0 = this._x1, this._x1 = x;
  13112. this._y0 = this._y1, this._y1 = y;
  13113. }
  13114. };
  13115. function basis$2(context) {
  13116. return new Basis(context);
  13117. }
  13118. function BasisClosed(context) {
  13119. this._context = context;
  13120. }
  13121. BasisClosed.prototype = {
  13122. areaStart: noop$3,
  13123. areaEnd: noop$3,
  13124. lineStart: function() {
  13125. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
  13126. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
  13127. this._point = 0;
  13128. },
  13129. lineEnd: function() {
  13130. switch (this._point) {
  13131. case 1: {
  13132. this._context.moveTo(this._x2, this._y2);
  13133. this._context.closePath();
  13134. break;
  13135. }
  13136. case 2: {
  13137. this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
  13138. this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
  13139. this._context.closePath();
  13140. break;
  13141. }
  13142. case 3: {
  13143. this.point(this._x2, this._y2);
  13144. this.point(this._x3, this._y3);
  13145. this.point(this._x4, this._y4);
  13146. break;
  13147. }
  13148. }
  13149. },
  13150. point: function(x, y) {
  13151. x = +x, y = +y;
  13152. switch (this._point) {
  13153. case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
  13154. case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
  13155. 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;
  13156. default: point$2(this, x, y); break;
  13157. }
  13158. this._x0 = this._x1, this._x1 = x;
  13159. this._y0 = this._y1, this._y1 = y;
  13160. }
  13161. };
  13162. function basisClosed$1(context) {
  13163. return new BasisClosed(context);
  13164. }
  13165. function BasisOpen(context) {
  13166. this._context = context;
  13167. }
  13168. BasisOpen.prototype = {
  13169. areaStart: function() {
  13170. this._line = 0;
  13171. },
  13172. areaEnd: function() {
  13173. this._line = NaN;
  13174. },
  13175. lineStart: function() {
  13176. this._x0 = this._x1 =
  13177. this._y0 = this._y1 = NaN;
  13178. this._point = 0;
  13179. },
  13180. lineEnd: function() {
  13181. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13182. this._line = 1 - this._line;
  13183. },
  13184. point: function(x, y) {
  13185. x = +x, y = +y;
  13186. switch (this._point) {
  13187. case 0: this._point = 1; break;
  13188. case 1: this._point = 2; break;
  13189. 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;
  13190. case 3: this._point = 4; // proceed
  13191. default: point$2(this, x, y); break;
  13192. }
  13193. this._x0 = this._x1, this._x1 = x;
  13194. this._y0 = this._y1, this._y1 = y;
  13195. }
  13196. };
  13197. function basisOpen(context) {
  13198. return new BasisOpen(context);
  13199. }
  13200. function Bundle(context, beta) {
  13201. this._basis = new Basis(context);
  13202. this._beta = beta;
  13203. }
  13204. Bundle.prototype = {
  13205. lineStart: function() {
  13206. this._x = [];
  13207. this._y = [];
  13208. this._basis.lineStart();
  13209. },
  13210. lineEnd: function() {
  13211. var x = this._x,
  13212. y = this._y,
  13213. j = x.length - 1;
  13214. if (j > 0) {
  13215. var x0 = x[0],
  13216. y0 = y[0],
  13217. dx = x[j] - x0,
  13218. dy = y[j] - y0,
  13219. i = -1,
  13220. t;
  13221. while (++i <= j) {
  13222. t = i / j;
  13223. this._basis.point(
  13224. this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
  13225. this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
  13226. );
  13227. }
  13228. }
  13229. this._x = this._y = null;
  13230. this._basis.lineEnd();
  13231. },
  13232. point: function(x, y) {
  13233. this._x.push(+x);
  13234. this._y.push(+y);
  13235. }
  13236. };
  13237. var bundle = (function custom(beta) {
  13238. function bundle(context) {
  13239. return beta === 1 ? new Basis(context) : new Bundle(context, beta);
  13240. }
  13241. bundle.beta = function(beta) {
  13242. return custom(+beta);
  13243. };
  13244. return bundle;
  13245. })(0.85);
  13246. function point$3(that, x, y) {
  13247. that._context.bezierCurveTo(
  13248. that._x1 + that._k * (that._x2 - that._x0),
  13249. that._y1 + that._k * (that._y2 - that._y0),
  13250. that._x2 + that._k * (that._x1 - x),
  13251. that._y2 + that._k * (that._y1 - y),
  13252. that._x2,
  13253. that._y2
  13254. );
  13255. }
  13256. function Cardinal(context, tension) {
  13257. this._context = context;
  13258. this._k = (1 - tension) / 6;
  13259. }
  13260. Cardinal.prototype = {
  13261. areaStart: function() {
  13262. this._line = 0;
  13263. },
  13264. areaEnd: function() {
  13265. this._line = NaN;
  13266. },
  13267. lineStart: function() {
  13268. this._x0 = this._x1 = this._x2 =
  13269. this._y0 = this._y1 = this._y2 = NaN;
  13270. this._point = 0;
  13271. },
  13272. lineEnd: function() {
  13273. switch (this._point) {
  13274. case 2: this._context.lineTo(this._x2, this._y2); break;
  13275. case 3: point$3(this, this._x1, this._y1); break;
  13276. }
  13277. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13278. this._line = 1 - this._line;
  13279. },
  13280. point: function(x, y) {
  13281. x = +x, y = +y;
  13282. switch (this._point) {
  13283. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13284. case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
  13285. case 2: this._point = 3; // proceed
  13286. default: point$3(this, x, y); break;
  13287. }
  13288. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13289. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13290. }
  13291. };
  13292. var cardinal = (function custom(tension) {
  13293. function cardinal(context) {
  13294. return new Cardinal(context, tension);
  13295. }
  13296. cardinal.tension = function(tension) {
  13297. return custom(+tension);
  13298. };
  13299. return cardinal;
  13300. })(0);
  13301. function CardinalClosed(context, tension) {
  13302. this._context = context;
  13303. this._k = (1 - tension) / 6;
  13304. }
  13305. CardinalClosed.prototype = {
  13306. areaStart: noop$3,
  13307. areaEnd: noop$3,
  13308. lineStart: function() {
  13309. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13310. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13311. this._point = 0;
  13312. },
  13313. lineEnd: function() {
  13314. switch (this._point) {
  13315. case 1: {
  13316. this._context.moveTo(this._x3, this._y3);
  13317. this._context.closePath();
  13318. break;
  13319. }
  13320. case 2: {
  13321. this._context.lineTo(this._x3, this._y3);
  13322. this._context.closePath();
  13323. break;
  13324. }
  13325. case 3: {
  13326. this.point(this._x3, this._y3);
  13327. this.point(this._x4, this._y4);
  13328. this.point(this._x5, this._y5);
  13329. break;
  13330. }
  13331. }
  13332. },
  13333. point: function(x, y) {
  13334. x = +x, y = +y;
  13335. switch (this._point) {
  13336. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13337. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13338. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13339. default: point$3(this, x, y); break;
  13340. }
  13341. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13342. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13343. }
  13344. };
  13345. var cardinalClosed = (function custom(tension) {
  13346. function cardinal(context) {
  13347. return new CardinalClosed(context, tension);
  13348. }
  13349. cardinal.tension = function(tension) {
  13350. return custom(+tension);
  13351. };
  13352. return cardinal;
  13353. })(0);
  13354. function CardinalOpen(context, tension) {
  13355. this._context = context;
  13356. this._k = (1 - tension) / 6;
  13357. }
  13358. CardinalOpen.prototype = {
  13359. areaStart: function() {
  13360. this._line = 0;
  13361. },
  13362. areaEnd: function() {
  13363. this._line = NaN;
  13364. },
  13365. lineStart: function() {
  13366. this._x0 = this._x1 = this._x2 =
  13367. this._y0 = this._y1 = this._y2 = NaN;
  13368. this._point = 0;
  13369. },
  13370. lineEnd: function() {
  13371. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13372. this._line = 1 - this._line;
  13373. },
  13374. point: function(x, y) {
  13375. x = +x, y = +y;
  13376. switch (this._point) {
  13377. case 0: this._point = 1; break;
  13378. case 1: this._point = 2; break;
  13379. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13380. case 3: this._point = 4; // proceed
  13381. default: point$3(this, x, y); break;
  13382. }
  13383. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13384. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13385. }
  13386. };
  13387. var cardinalOpen = (function custom(tension) {
  13388. function cardinal(context) {
  13389. return new CardinalOpen(context, tension);
  13390. }
  13391. cardinal.tension = function(tension) {
  13392. return custom(+tension);
  13393. };
  13394. return cardinal;
  13395. })(0);
  13396. function point$4(that, x, y) {
  13397. var x1 = that._x1,
  13398. y1 = that._y1,
  13399. x2 = that._x2,
  13400. y2 = that._y2;
  13401. if (that._l01_a > epsilon$3) {
  13402. var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
  13403. n = 3 * that._l01_a * (that._l01_a + that._l12_a);
  13404. x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
  13405. y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
  13406. }
  13407. if (that._l23_a > epsilon$3) {
  13408. var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
  13409. m = 3 * that._l23_a * (that._l23_a + that._l12_a);
  13410. x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
  13411. y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
  13412. }
  13413. that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
  13414. }
  13415. function CatmullRom(context, alpha) {
  13416. this._context = context;
  13417. this._alpha = alpha;
  13418. }
  13419. CatmullRom.prototype = {
  13420. areaStart: function() {
  13421. this._line = 0;
  13422. },
  13423. areaEnd: function() {
  13424. this._line = NaN;
  13425. },
  13426. lineStart: function() {
  13427. this._x0 = this._x1 = this._x2 =
  13428. this._y0 = this._y1 = this._y2 = NaN;
  13429. this._l01_a = this._l12_a = this._l23_a =
  13430. this._l01_2a = this._l12_2a = this._l23_2a =
  13431. this._point = 0;
  13432. },
  13433. lineEnd: function() {
  13434. switch (this._point) {
  13435. case 2: this._context.lineTo(this._x2, this._y2); break;
  13436. case 3: this.point(this._x2, this._y2); break;
  13437. }
  13438. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13439. this._line = 1 - this._line;
  13440. },
  13441. point: function(x, y) {
  13442. x = +x, y = +y;
  13443. if (this._point) {
  13444. var x23 = this._x2 - x,
  13445. y23 = this._y2 - y;
  13446. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13447. }
  13448. switch (this._point) {
  13449. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13450. case 1: this._point = 2; break;
  13451. case 2: this._point = 3; // proceed
  13452. default: point$4(this, x, y); break;
  13453. }
  13454. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13455. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13456. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13457. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13458. }
  13459. };
  13460. var catmullRom = (function custom(alpha) {
  13461. function catmullRom(context) {
  13462. return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
  13463. }
  13464. catmullRom.alpha = function(alpha) {
  13465. return custom(+alpha);
  13466. };
  13467. return catmullRom;
  13468. })(0.5);
  13469. function CatmullRomClosed(context, alpha) {
  13470. this._context = context;
  13471. this._alpha = alpha;
  13472. }
  13473. CatmullRomClosed.prototype = {
  13474. areaStart: noop$3,
  13475. areaEnd: noop$3,
  13476. lineStart: function() {
  13477. this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
  13478. this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
  13479. this._l01_a = this._l12_a = this._l23_a =
  13480. this._l01_2a = this._l12_2a = this._l23_2a =
  13481. this._point = 0;
  13482. },
  13483. lineEnd: function() {
  13484. switch (this._point) {
  13485. case 1: {
  13486. this._context.moveTo(this._x3, this._y3);
  13487. this._context.closePath();
  13488. break;
  13489. }
  13490. case 2: {
  13491. this._context.lineTo(this._x3, this._y3);
  13492. this._context.closePath();
  13493. break;
  13494. }
  13495. case 3: {
  13496. this.point(this._x3, this._y3);
  13497. this.point(this._x4, this._y4);
  13498. this.point(this._x5, this._y5);
  13499. break;
  13500. }
  13501. }
  13502. },
  13503. point: function(x, y) {
  13504. x = +x, y = +y;
  13505. if (this._point) {
  13506. var x23 = this._x2 - x,
  13507. y23 = this._y2 - y;
  13508. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13509. }
  13510. switch (this._point) {
  13511. case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
  13512. case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
  13513. case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
  13514. default: point$4(this, x, y); break;
  13515. }
  13516. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13517. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13518. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13519. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13520. }
  13521. };
  13522. var catmullRomClosed = (function custom(alpha) {
  13523. function catmullRom(context) {
  13524. return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
  13525. }
  13526. catmullRom.alpha = function(alpha) {
  13527. return custom(+alpha);
  13528. };
  13529. return catmullRom;
  13530. })(0.5);
  13531. function CatmullRomOpen(context, alpha) {
  13532. this._context = context;
  13533. this._alpha = alpha;
  13534. }
  13535. CatmullRomOpen.prototype = {
  13536. areaStart: function() {
  13537. this._line = 0;
  13538. },
  13539. areaEnd: function() {
  13540. this._line = NaN;
  13541. },
  13542. lineStart: function() {
  13543. this._x0 = this._x1 = this._x2 =
  13544. this._y0 = this._y1 = this._y2 = NaN;
  13545. this._l01_a = this._l12_a = this._l23_a =
  13546. this._l01_2a = this._l12_2a = this._l23_2a =
  13547. this._point = 0;
  13548. },
  13549. lineEnd: function() {
  13550. if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
  13551. this._line = 1 - this._line;
  13552. },
  13553. point: function(x, y) {
  13554. x = +x, y = +y;
  13555. if (this._point) {
  13556. var x23 = this._x2 - x,
  13557. y23 = this._y2 - y;
  13558. this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
  13559. }
  13560. switch (this._point) {
  13561. case 0: this._point = 1; break;
  13562. case 1: this._point = 2; break;
  13563. case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
  13564. case 3: this._point = 4; // proceed
  13565. default: point$4(this, x, y); break;
  13566. }
  13567. this._l01_a = this._l12_a, this._l12_a = this._l23_a;
  13568. this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
  13569. this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
  13570. this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
  13571. }
  13572. };
  13573. var catmullRomOpen = (function custom(alpha) {
  13574. function catmullRom(context) {
  13575. return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
  13576. }
  13577. catmullRom.alpha = function(alpha) {
  13578. return custom(+alpha);
  13579. };
  13580. return catmullRom;
  13581. })(0.5);
  13582. function LinearClosed(context) {
  13583. this._context = context;
  13584. }
  13585. LinearClosed.prototype = {
  13586. areaStart: noop$3,
  13587. areaEnd: noop$3,
  13588. lineStart: function() {
  13589. this._point = 0;
  13590. },
  13591. lineEnd: function() {
  13592. if (this._point) this._context.closePath();
  13593. },
  13594. point: function(x, y) {
  13595. x = +x, y = +y;
  13596. if (this._point) this._context.lineTo(x, y);
  13597. else this._point = 1, this._context.moveTo(x, y);
  13598. }
  13599. };
  13600. function linearClosed(context) {
  13601. return new LinearClosed(context);
  13602. }
  13603. function sign$1(x) {
  13604. return x < 0 ? -1 : 1;
  13605. }
  13606. // Calculate the slopes of the tangents (Hermite-type interpolation) based on
  13607. // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
  13608. // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
  13609. // NOV(II), P. 443, 1990.
  13610. function slope3(that, x2, y2) {
  13611. var h0 = that._x1 - that._x0,
  13612. h1 = x2 - that._x1,
  13613. s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
  13614. s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
  13615. p = (s0 * h1 + s1 * h0) / (h0 + h1);
  13616. return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
  13617. }
  13618. // Calculate a one-sided slope.
  13619. function slope2(that, t) {
  13620. var h = that._x1 - that._x0;
  13621. return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
  13622. }
  13623. // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
  13624. // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
  13625. // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
  13626. function point$5(that, t0, t1) {
  13627. var x0 = that._x0,
  13628. y0 = that._y0,
  13629. x1 = that._x1,
  13630. y1 = that._y1,
  13631. dx = (x1 - x0) / 3;
  13632. that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
  13633. }
  13634. function MonotoneX(context) {
  13635. this._context = context;
  13636. }
  13637. MonotoneX.prototype = {
  13638. areaStart: function() {
  13639. this._line = 0;
  13640. },
  13641. areaEnd: function() {
  13642. this._line = NaN;
  13643. },
  13644. lineStart: function() {
  13645. this._x0 = this._x1 =
  13646. this._y0 = this._y1 =
  13647. this._t0 = NaN;
  13648. this._point = 0;
  13649. },
  13650. lineEnd: function() {
  13651. switch (this._point) {
  13652. case 2: this._context.lineTo(this._x1, this._y1); break;
  13653. case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
  13654. }
  13655. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13656. this._line = 1 - this._line;
  13657. },
  13658. point: function(x, y) {
  13659. var t1 = NaN;
  13660. x = +x, y = +y;
  13661. if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
  13662. switch (this._point) {
  13663. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13664. case 1: this._point = 2; break;
  13665. case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
  13666. default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
  13667. }
  13668. this._x0 = this._x1, this._x1 = x;
  13669. this._y0 = this._y1, this._y1 = y;
  13670. this._t0 = t1;
  13671. }
  13672. };
  13673. function MonotoneY(context) {
  13674. this._context = new ReflectContext(context);
  13675. }
  13676. (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
  13677. MonotoneX.prototype.point.call(this, y, x);
  13678. };
  13679. function ReflectContext(context) {
  13680. this._context = context;
  13681. }
  13682. ReflectContext.prototype = {
  13683. moveTo: function(x, y) { this._context.moveTo(y, x); },
  13684. closePath: function() { this._context.closePath(); },
  13685. lineTo: function(x, y) { this._context.lineTo(y, x); },
  13686. bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
  13687. };
  13688. function monotoneX(context) {
  13689. return new MonotoneX(context);
  13690. }
  13691. function monotoneY(context) {
  13692. return new MonotoneY(context);
  13693. }
  13694. function Natural(context) {
  13695. this._context = context;
  13696. }
  13697. Natural.prototype = {
  13698. areaStart: function() {
  13699. this._line = 0;
  13700. },
  13701. areaEnd: function() {
  13702. this._line = NaN;
  13703. },
  13704. lineStart: function() {
  13705. this._x = [];
  13706. this._y = [];
  13707. },
  13708. lineEnd: function() {
  13709. var x = this._x,
  13710. y = this._y,
  13711. n = x.length;
  13712. if (n) {
  13713. this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
  13714. if (n === 2) {
  13715. this._context.lineTo(x[1], y[1]);
  13716. } else {
  13717. var px = controlPoints(x),
  13718. py = controlPoints(y);
  13719. for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
  13720. this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
  13721. }
  13722. }
  13723. }
  13724. if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
  13725. this._line = 1 - this._line;
  13726. this._x = this._y = null;
  13727. },
  13728. point: function(x, y) {
  13729. this._x.push(+x);
  13730. this._y.push(+y);
  13731. }
  13732. };
  13733. // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
  13734. function controlPoints(x) {
  13735. var i,
  13736. n = x.length - 1,
  13737. m,
  13738. a = new Array(n),
  13739. b = new Array(n),
  13740. r = new Array(n);
  13741. a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
  13742. for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
  13743. a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
  13744. for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
  13745. a[n - 1] = r[n - 1] / b[n - 1];
  13746. for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
  13747. b[n - 1] = (x[n] + a[n - 1]) / 2;
  13748. for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
  13749. return [a, b];
  13750. }
  13751. function natural(context) {
  13752. return new Natural(context);
  13753. }
  13754. function Step(context, t) {
  13755. this._context = context;
  13756. this._t = t;
  13757. }
  13758. Step.prototype = {
  13759. areaStart: function() {
  13760. this._line = 0;
  13761. },
  13762. areaEnd: function() {
  13763. this._line = NaN;
  13764. },
  13765. lineStart: function() {
  13766. this._x = this._y = NaN;
  13767. this._point = 0;
  13768. },
  13769. lineEnd: function() {
  13770. if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
  13771. if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
  13772. if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
  13773. },
  13774. point: function(x, y) {
  13775. x = +x, y = +y;
  13776. switch (this._point) {
  13777. case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
  13778. case 1: this._point = 2; // proceed
  13779. default: {
  13780. if (this._t <= 0) {
  13781. this._context.lineTo(this._x, y);
  13782. this._context.lineTo(x, y);
  13783. } else {
  13784. var x1 = this._x * (1 - this._t) + x * this._t;
  13785. this._context.lineTo(x1, this._y);
  13786. this._context.lineTo(x1, y);
  13787. }
  13788. break;
  13789. }
  13790. }
  13791. this._x = x, this._y = y;
  13792. }
  13793. };
  13794. function step(context) {
  13795. return new Step(context, 0.5);
  13796. }
  13797. function stepBefore(context) {
  13798. return new Step(context, 0);
  13799. }
  13800. function stepAfter(context) {
  13801. return new Step(context, 1);
  13802. }
  13803. function none$1(series, order) {
  13804. if (!((n = series.length) > 1)) return;
  13805. for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
  13806. s0 = s1, s1 = series[order[i]];
  13807. for (j = 0; j < m; ++j) {
  13808. s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
  13809. }
  13810. }
  13811. }
  13812. function none$2(series) {
  13813. var n = series.length, o = new Array(n);
  13814. while (--n >= 0) o[n] = n;
  13815. return o;
  13816. }
  13817. function stackValue(d, key) {
  13818. return d[key];
  13819. }
  13820. function stack() {
  13821. var keys = constant$b([]),
  13822. order = none$2,
  13823. offset = none$1,
  13824. value = stackValue;
  13825. function stack(data) {
  13826. var kz = keys.apply(this, arguments),
  13827. i,
  13828. m = data.length,
  13829. n = kz.length,
  13830. sz = new Array(n),
  13831. oz;
  13832. for (i = 0; i < n; ++i) {
  13833. for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
  13834. si[j] = sij = [0, +value(data[j], ki, j, data)];
  13835. sij.data = data[j];
  13836. }
  13837. si.key = ki;
  13838. }
  13839. for (i = 0, oz = order(sz); i < n; ++i) {
  13840. sz[oz[i]].index = i;
  13841. }
  13842. offset(sz, oz);
  13843. return sz;
  13844. }
  13845. stack.keys = function(_) {
  13846. return arguments.length ? (keys = typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : keys;
  13847. };
  13848. stack.value = function(_) {
  13849. return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), stack) : value;
  13850. };
  13851. stack.order = function(_) {
  13852. return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : order;
  13853. };
  13854. stack.offset = function(_) {
  13855. return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
  13856. };
  13857. return stack;
  13858. }
  13859. function expand(series, order) {
  13860. if (!((n = series.length) > 0)) return;
  13861. for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
  13862. for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
  13863. if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
  13864. }
  13865. none$1(series, order);
  13866. }
  13867. function diverging$1(series, order) {
  13868. if (!((n = series.length) > 0)) return;
  13869. for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
  13870. for (yp = yn = 0, i = 0; i < n; ++i) {
  13871. if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
  13872. d[0] = yp, d[1] = yp += dy;
  13873. } else if (dy < 0) {
  13874. d[1] = yn, d[0] = yn += dy;
  13875. } else {
  13876. d[0] = yp;
  13877. }
  13878. }
  13879. }
  13880. }
  13881. function silhouette(series, order) {
  13882. if (!((n = series.length) > 0)) return;
  13883. for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
  13884. for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
  13885. s0[j][1] += s0[j][0] = -y / 2;
  13886. }
  13887. none$1(series, order);
  13888. }
  13889. function wiggle(series, order) {
  13890. if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
  13891. for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
  13892. for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
  13893. var si = series[order[i]],
  13894. sij0 = si[j][1] || 0,
  13895. sij1 = si[j - 1][1] || 0,
  13896. s3 = (sij0 - sij1) / 2;
  13897. for (var k = 0; k < i; ++k) {
  13898. var sk = series[order[k]],
  13899. skj0 = sk[j][1] || 0,
  13900. skj1 = sk[j - 1][1] || 0;
  13901. s3 += skj0 - skj1;
  13902. }
  13903. s1 += sij0, s2 += s3 * sij0;
  13904. }
  13905. s0[j - 1][1] += s0[j - 1][0] = y;
  13906. if (s1) y -= s2 / s1;
  13907. }
  13908. s0[j - 1][1] += s0[j - 1][0] = y;
  13909. none$1(series, order);
  13910. }
  13911. function appearance(series) {
  13912. var peaks = series.map(peak);
  13913. return none$2(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
  13914. }
  13915. function peak(series) {
  13916. var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
  13917. while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
  13918. return j;
  13919. }
  13920. function ascending$3(series) {
  13921. var sums = series.map(sum$2);
  13922. return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
  13923. }
  13924. function sum$2(series) {
  13925. var s = 0, i = -1, n = series.length, v;
  13926. while (++i < n) if (v = +series[i][1]) s += v;
  13927. return s;
  13928. }
  13929. function descending$2(series) {
  13930. return ascending$3(series).reverse();
  13931. }
  13932. function insideOut(series) {
  13933. var n = series.length,
  13934. i,
  13935. j,
  13936. sums = series.map(sum$2),
  13937. order = appearance(series),
  13938. top = 0,
  13939. bottom = 0,
  13940. tops = [],
  13941. bottoms = [];
  13942. for (i = 0; i < n; ++i) {
  13943. j = order[i];
  13944. if (top < bottom) {
  13945. top += sums[j];
  13946. tops.push(j);
  13947. } else {
  13948. bottom += sums[j];
  13949. bottoms.push(j);
  13950. }
  13951. }
  13952. return bottoms.reverse().concat(tops);
  13953. }
  13954. function reverse(series) {
  13955. return none$2(series).reverse();
  13956. }
  13957. function constant$c(x) {
  13958. return function() {
  13959. return x;
  13960. };
  13961. }
  13962. function x$4(d) {
  13963. return d[0];
  13964. }
  13965. function y$4(d) {
  13966. return d[1];
  13967. }
  13968. function RedBlackTree() {
  13969. this._ = null; // root node
  13970. }
  13971. function RedBlackNode(node) {
  13972. node.U = // parent node
  13973. node.C = // color - true for red, false for black
  13974. node.L = // left node
  13975. node.R = // right node
  13976. node.P = // previous node
  13977. node.N = null; // next node
  13978. }
  13979. RedBlackTree.prototype = {
  13980. constructor: RedBlackTree,
  13981. insert: function(after, node) {
  13982. var parent, grandpa, uncle;
  13983. if (after) {
  13984. node.P = after;
  13985. node.N = after.N;
  13986. if (after.N) after.N.P = node;
  13987. after.N = node;
  13988. if (after.R) {
  13989. after = after.R;
  13990. while (after.L) after = after.L;
  13991. after.L = node;
  13992. } else {
  13993. after.R = node;
  13994. }
  13995. parent = after;
  13996. } else if (this._) {
  13997. after = RedBlackFirst(this._);
  13998. node.P = null;
  13999. node.N = after;
  14000. after.P = after.L = node;
  14001. parent = after;
  14002. } else {
  14003. node.P = node.N = null;
  14004. this._ = node;
  14005. parent = null;
  14006. }
  14007. node.L = node.R = null;
  14008. node.U = parent;
  14009. node.C = true;
  14010. after = node;
  14011. while (parent && parent.C) {
  14012. grandpa = parent.U;
  14013. if (parent === grandpa.L) {
  14014. uncle = grandpa.R;
  14015. if (uncle && uncle.C) {
  14016. parent.C = uncle.C = false;
  14017. grandpa.C = true;
  14018. after = grandpa;
  14019. } else {
  14020. if (after === parent.R) {
  14021. RedBlackRotateLeft(this, parent);
  14022. after = parent;
  14023. parent = after.U;
  14024. }
  14025. parent.C = false;
  14026. grandpa.C = true;
  14027. RedBlackRotateRight(this, grandpa);
  14028. }
  14029. } else {
  14030. uncle = grandpa.L;
  14031. if (uncle && uncle.C) {
  14032. parent.C = uncle.C = false;
  14033. grandpa.C = true;
  14034. after = grandpa;
  14035. } else {
  14036. if (after === parent.L) {
  14037. RedBlackRotateRight(this, parent);
  14038. after = parent;
  14039. parent = after.U;
  14040. }
  14041. parent.C = false;
  14042. grandpa.C = true;
  14043. RedBlackRotateLeft(this, grandpa);
  14044. }
  14045. }
  14046. parent = after.U;
  14047. }
  14048. this._.C = false;
  14049. },
  14050. remove: function(node) {
  14051. if (node.N) node.N.P = node.P;
  14052. if (node.P) node.P.N = node.N;
  14053. node.N = node.P = null;
  14054. var parent = node.U,
  14055. sibling,
  14056. left = node.L,
  14057. right = node.R,
  14058. next,
  14059. red;
  14060. if (!left) next = right;
  14061. else if (!right) next = left;
  14062. else next = RedBlackFirst(right);
  14063. if (parent) {
  14064. if (parent.L === node) parent.L = next;
  14065. else parent.R = next;
  14066. } else {
  14067. this._ = next;
  14068. }
  14069. if (left && right) {
  14070. red = next.C;
  14071. next.C = node.C;
  14072. next.L = left;
  14073. left.U = next;
  14074. if (next !== right) {
  14075. parent = next.U;
  14076. next.U = node.U;
  14077. node = next.R;
  14078. parent.L = node;
  14079. next.R = right;
  14080. right.U = next;
  14081. } else {
  14082. next.U = parent;
  14083. parent = next;
  14084. node = next.R;
  14085. }
  14086. } else {
  14087. red = node.C;
  14088. node = next;
  14089. }
  14090. if (node) node.U = parent;
  14091. if (red) return;
  14092. if (node && node.C) { node.C = false; return; }
  14093. do {
  14094. if (node === this._) break;
  14095. if (node === parent.L) {
  14096. sibling = parent.R;
  14097. if (sibling.C) {
  14098. sibling.C = false;
  14099. parent.C = true;
  14100. RedBlackRotateLeft(this, parent);
  14101. sibling = parent.R;
  14102. }
  14103. if ((sibling.L && sibling.L.C)
  14104. || (sibling.R && sibling.R.C)) {
  14105. if (!sibling.R || !sibling.R.C) {
  14106. sibling.L.C = false;
  14107. sibling.C = true;
  14108. RedBlackRotateRight(this, sibling);
  14109. sibling = parent.R;
  14110. }
  14111. sibling.C = parent.C;
  14112. parent.C = sibling.R.C = false;
  14113. RedBlackRotateLeft(this, parent);
  14114. node = this._;
  14115. break;
  14116. }
  14117. } else {
  14118. sibling = parent.L;
  14119. if (sibling.C) {
  14120. sibling.C = false;
  14121. parent.C = true;
  14122. RedBlackRotateRight(this, parent);
  14123. sibling = parent.L;
  14124. }
  14125. if ((sibling.L && sibling.L.C)
  14126. || (sibling.R && sibling.R.C)) {
  14127. if (!sibling.L || !sibling.L.C) {
  14128. sibling.R.C = false;
  14129. sibling.C = true;
  14130. RedBlackRotateLeft(this, sibling);
  14131. sibling = parent.L;
  14132. }
  14133. sibling.C = parent.C;
  14134. parent.C = sibling.L.C = false;
  14135. RedBlackRotateRight(this, parent);
  14136. node = this._;
  14137. break;
  14138. }
  14139. }
  14140. sibling.C = true;
  14141. node = parent;
  14142. parent = parent.U;
  14143. } while (!node.C);
  14144. if (node) node.C = false;
  14145. }
  14146. };
  14147. function RedBlackRotateLeft(tree, node) {
  14148. var p = node,
  14149. q = node.R,
  14150. parent = p.U;
  14151. if (parent) {
  14152. if (parent.L === p) parent.L = q;
  14153. else parent.R = q;
  14154. } else {
  14155. tree._ = q;
  14156. }
  14157. q.U = parent;
  14158. p.U = q;
  14159. p.R = q.L;
  14160. if (p.R) p.R.U = p;
  14161. q.L = p;
  14162. }
  14163. function RedBlackRotateRight(tree, node) {
  14164. var p = node,
  14165. q = node.L,
  14166. parent = p.U;
  14167. if (parent) {
  14168. if (parent.L === p) parent.L = q;
  14169. else parent.R = q;
  14170. } else {
  14171. tree._ = q;
  14172. }
  14173. q.U = parent;
  14174. p.U = q;
  14175. p.L = q.R;
  14176. if (p.L) p.L.U = p;
  14177. q.R = p;
  14178. }
  14179. function RedBlackFirst(node) {
  14180. while (node.L) node = node.L;
  14181. return node;
  14182. }
  14183. function createEdge(left, right, v0, v1) {
  14184. var edge = [null, null],
  14185. index = edges.push(edge) - 1;
  14186. edge.left = left;
  14187. edge.right = right;
  14188. if (v0) setEdgeEnd(edge, left, right, v0);
  14189. if (v1) setEdgeEnd(edge, right, left, v1);
  14190. cells[left.index].halfedges.push(index);
  14191. cells[right.index].halfedges.push(index);
  14192. return edge;
  14193. }
  14194. function createBorderEdge(left, v0, v1) {
  14195. var edge = [v0, v1];
  14196. edge.left = left;
  14197. return edge;
  14198. }
  14199. function setEdgeEnd(edge, left, right, vertex) {
  14200. if (!edge[0] && !edge[1]) {
  14201. edge[0] = vertex;
  14202. edge.left = left;
  14203. edge.right = right;
  14204. } else if (edge.left === right) {
  14205. edge[1] = vertex;
  14206. } else {
  14207. edge[0] = vertex;
  14208. }
  14209. }
  14210. // Liang–Barsky line clipping.
  14211. function clipEdge(edge, x0, y0, x1, y1) {
  14212. var a = edge[0],
  14213. b = edge[1],
  14214. ax = a[0],
  14215. ay = a[1],
  14216. bx = b[0],
  14217. by = b[1],
  14218. t0 = 0,
  14219. t1 = 1,
  14220. dx = bx - ax,
  14221. dy = by - ay,
  14222. r;
  14223. r = x0 - ax;
  14224. if (!dx && r > 0) return;
  14225. r /= dx;
  14226. if (dx < 0) {
  14227. if (r < t0) return;
  14228. if (r < t1) t1 = r;
  14229. } else if (dx > 0) {
  14230. if (r > t1) return;
  14231. if (r > t0) t0 = r;
  14232. }
  14233. r = x1 - ax;
  14234. if (!dx && r < 0) return;
  14235. r /= dx;
  14236. if (dx < 0) {
  14237. if (r > t1) return;
  14238. if (r > t0) t0 = r;
  14239. } else if (dx > 0) {
  14240. if (r < t0) return;
  14241. if (r < t1) t1 = r;
  14242. }
  14243. r = y0 - ay;
  14244. if (!dy && r > 0) return;
  14245. r /= dy;
  14246. if (dy < 0) {
  14247. if (r < t0) return;
  14248. if (r < t1) t1 = r;
  14249. } else if (dy > 0) {
  14250. if (r > t1) return;
  14251. if (r > t0) t0 = r;
  14252. }
  14253. r = y1 - ay;
  14254. if (!dy && r < 0) return;
  14255. r /= dy;
  14256. if (dy < 0) {
  14257. if (r > t1) return;
  14258. if (r > t0) t0 = r;
  14259. } else if (dy > 0) {
  14260. if (r < t0) return;
  14261. if (r < t1) t1 = r;
  14262. }
  14263. if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
  14264. if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
  14265. if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
  14266. return true;
  14267. }
  14268. function connectEdge(edge, x0, y0, x1, y1) {
  14269. var v1 = edge[1];
  14270. if (v1) return true;
  14271. var v0 = edge[0],
  14272. left = edge.left,
  14273. right = edge.right,
  14274. lx = left[0],
  14275. ly = left[1],
  14276. rx = right[0],
  14277. ry = right[1],
  14278. fx = (lx + rx) / 2,
  14279. fy = (ly + ry) / 2,
  14280. fm,
  14281. fb;
  14282. if (ry === ly) {
  14283. if (fx < x0 || fx >= x1) return;
  14284. if (lx > rx) {
  14285. if (!v0) v0 = [fx, y0];
  14286. else if (v0[1] >= y1) return;
  14287. v1 = [fx, y1];
  14288. } else {
  14289. if (!v0) v0 = [fx, y1];
  14290. else if (v0[1] < y0) return;
  14291. v1 = [fx, y0];
  14292. }
  14293. } else {
  14294. fm = (lx - rx) / (ry - ly);
  14295. fb = fy - fm * fx;
  14296. if (fm < -1 || fm > 1) {
  14297. if (lx > rx) {
  14298. if (!v0) v0 = [(y0 - fb) / fm, y0];
  14299. else if (v0[1] >= y1) return;
  14300. v1 = [(y1 - fb) / fm, y1];
  14301. } else {
  14302. if (!v0) v0 = [(y1 - fb) / fm, y1];
  14303. else if (v0[1] < y0) return;
  14304. v1 = [(y0 - fb) / fm, y0];
  14305. }
  14306. } else {
  14307. if (ly < ry) {
  14308. if (!v0) v0 = [x0, fm * x0 + fb];
  14309. else if (v0[0] >= x1) return;
  14310. v1 = [x1, fm * x1 + fb];
  14311. } else {
  14312. if (!v0) v0 = [x1, fm * x1 + fb];
  14313. else if (v0[0] < x0) return;
  14314. v1 = [x0, fm * x0 + fb];
  14315. }
  14316. }
  14317. }
  14318. edge[0] = v0;
  14319. edge[1] = v1;
  14320. return true;
  14321. }
  14322. function clipEdges(x0, y0, x1, y1) {
  14323. var i = edges.length,
  14324. edge;
  14325. while (i--) {
  14326. if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
  14327. || !clipEdge(edge, x0, y0, x1, y1)
  14328. || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
  14329. || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
  14330. delete edges[i];
  14331. }
  14332. }
  14333. }
  14334. function createCell(site) {
  14335. return cells[site.index] = {
  14336. site: site,
  14337. halfedges: []
  14338. };
  14339. }
  14340. function cellHalfedgeAngle(cell, edge) {
  14341. var site = cell.site,
  14342. va = edge.left,
  14343. vb = edge.right;
  14344. if (site === vb) vb = va, va = site;
  14345. if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
  14346. if (site === va) va = edge[1], vb = edge[0];
  14347. else va = edge[0], vb = edge[1];
  14348. return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
  14349. }
  14350. function cellHalfedgeStart(cell, edge) {
  14351. return edge[+(edge.left !== cell.site)];
  14352. }
  14353. function cellHalfedgeEnd(cell, edge) {
  14354. return edge[+(edge.left === cell.site)];
  14355. }
  14356. function sortCellHalfedges() {
  14357. for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
  14358. if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
  14359. var index = new Array(m),
  14360. array = new Array(m);
  14361. for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
  14362. index.sort(function(i, j) { return array[j] - array[i]; });
  14363. for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
  14364. for (j = 0; j < m; ++j) halfedges[j] = array[j];
  14365. }
  14366. }
  14367. }
  14368. function clipCells(x0, y0, x1, y1) {
  14369. var nCells = cells.length,
  14370. iCell,
  14371. cell,
  14372. site,
  14373. iHalfedge,
  14374. halfedges,
  14375. nHalfedges,
  14376. start,
  14377. startX,
  14378. startY,
  14379. end,
  14380. endX,
  14381. endY,
  14382. cover = true;
  14383. for (iCell = 0; iCell < nCells; ++iCell) {
  14384. if (cell = cells[iCell]) {
  14385. site = cell.site;
  14386. halfedges = cell.halfedges;
  14387. iHalfedge = halfedges.length;
  14388. // Remove any dangling clipped edges.
  14389. while (iHalfedge--) {
  14390. if (!edges[halfedges[iHalfedge]]) {
  14391. halfedges.splice(iHalfedge, 1);
  14392. }
  14393. }
  14394. // Insert any border edges as necessary.
  14395. iHalfedge = 0, nHalfedges = halfedges.length;
  14396. while (iHalfedge < nHalfedges) {
  14397. end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
  14398. start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
  14399. if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
  14400. halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
  14401. Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
  14402. : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
  14403. : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
  14404. : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
  14405. : null)) - 1);
  14406. ++nHalfedges;
  14407. }
  14408. }
  14409. if (nHalfedges) cover = false;
  14410. }
  14411. }
  14412. // If there weren’t any edges, have the closest site cover the extent.
  14413. // It doesn’t matter which corner of the extent we measure!
  14414. if (cover) {
  14415. var dx, dy, d2, dc = Infinity;
  14416. for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
  14417. if (cell = cells[iCell]) {
  14418. site = cell.site;
  14419. dx = site[0] - x0;
  14420. dy = site[1] - y0;
  14421. d2 = dx * dx + dy * dy;
  14422. if (d2 < dc) dc = d2, cover = cell;
  14423. }
  14424. }
  14425. if (cover) {
  14426. var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
  14427. cover.halfedges.push(
  14428. edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
  14429. edges.push(createBorderEdge(site, v01, v11)) - 1,
  14430. edges.push(createBorderEdge(site, v11, v10)) - 1,
  14431. edges.push(createBorderEdge(site, v10, v00)) - 1
  14432. );
  14433. }
  14434. }
  14435. // Lastly delete any cells with no edges; these were entirely clipped.
  14436. for (iCell = 0; iCell < nCells; ++iCell) {
  14437. if (cell = cells[iCell]) {
  14438. if (!cell.halfedges.length) {
  14439. delete cells[iCell];
  14440. }
  14441. }
  14442. }
  14443. }
  14444. var circlePool = [];
  14445. var firstCircle;
  14446. function Circle() {
  14447. RedBlackNode(this);
  14448. this.x =
  14449. this.y =
  14450. this.arc =
  14451. this.site =
  14452. this.cy = null;
  14453. }
  14454. function attachCircle(arc) {
  14455. var lArc = arc.P,
  14456. rArc = arc.N;
  14457. if (!lArc || !rArc) return;
  14458. var lSite = lArc.site,
  14459. cSite = arc.site,
  14460. rSite = rArc.site;
  14461. if (lSite === rSite) return;
  14462. var bx = cSite[0],
  14463. by = cSite[1],
  14464. ax = lSite[0] - bx,
  14465. ay = lSite[1] - by,
  14466. cx = rSite[0] - bx,
  14467. cy = rSite[1] - by;
  14468. var d = 2 * (ax * cy - ay * cx);
  14469. if (d >= -epsilon2$2) return;
  14470. var ha = ax * ax + ay * ay,
  14471. hc = cx * cx + cy * cy,
  14472. x = (cy * ha - ay * hc) / d,
  14473. y = (ax * hc - cx * ha) / d;
  14474. var circle = circlePool.pop() || new Circle;
  14475. circle.arc = arc;
  14476. circle.site = cSite;
  14477. circle.x = x + bx;
  14478. circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
  14479. arc.circle = circle;
  14480. var before = null,
  14481. node = circles._;
  14482. while (node) {
  14483. if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
  14484. if (node.L) node = node.L;
  14485. else { before = node.P; break; }
  14486. } else {
  14487. if (node.R) node = node.R;
  14488. else { before = node; break; }
  14489. }
  14490. }
  14491. circles.insert(before, circle);
  14492. if (!before) firstCircle = circle;
  14493. }
  14494. function detachCircle(arc) {
  14495. var circle = arc.circle;
  14496. if (circle) {
  14497. if (!circle.P) firstCircle = circle.N;
  14498. circles.remove(circle);
  14499. circlePool.push(circle);
  14500. RedBlackNode(circle);
  14501. arc.circle = null;
  14502. }
  14503. }
  14504. var beachPool = [];
  14505. function Beach() {
  14506. RedBlackNode(this);
  14507. this.edge =
  14508. this.site =
  14509. this.circle = null;
  14510. }
  14511. function createBeach(site) {
  14512. var beach = beachPool.pop() || new Beach;
  14513. beach.site = site;
  14514. return beach;
  14515. }
  14516. function detachBeach(beach) {
  14517. detachCircle(beach);
  14518. beaches.remove(beach);
  14519. beachPool.push(beach);
  14520. RedBlackNode(beach);
  14521. }
  14522. function removeBeach(beach) {
  14523. var circle = beach.circle,
  14524. x = circle.x,
  14525. y = circle.cy,
  14526. vertex = [x, y],
  14527. previous = beach.P,
  14528. next = beach.N,
  14529. disappearing = [beach];
  14530. detachBeach(beach);
  14531. var lArc = previous;
  14532. while (lArc.circle
  14533. && Math.abs(x - lArc.circle.x) < epsilon$4
  14534. && Math.abs(y - lArc.circle.cy) < epsilon$4) {
  14535. previous = lArc.P;
  14536. disappearing.unshift(lArc);
  14537. detachBeach(lArc);
  14538. lArc = previous;
  14539. }
  14540. disappearing.unshift(lArc);
  14541. detachCircle(lArc);
  14542. var rArc = next;
  14543. while (rArc.circle
  14544. && Math.abs(x - rArc.circle.x) < epsilon$4
  14545. && Math.abs(y - rArc.circle.cy) < epsilon$4) {
  14546. next = rArc.N;
  14547. disappearing.push(rArc);
  14548. detachBeach(rArc);
  14549. rArc = next;
  14550. }
  14551. disappearing.push(rArc);
  14552. detachCircle(rArc);
  14553. var nArcs = disappearing.length,
  14554. iArc;
  14555. for (iArc = 1; iArc < nArcs; ++iArc) {
  14556. rArc = disappearing[iArc];
  14557. lArc = disappearing[iArc - 1];
  14558. setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  14559. }
  14560. lArc = disappearing[0];
  14561. rArc = disappearing[nArcs - 1];
  14562. rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
  14563. attachCircle(lArc);
  14564. attachCircle(rArc);
  14565. }
  14566. function addBeach(site) {
  14567. var x = site[0],
  14568. directrix = site[1],
  14569. lArc,
  14570. rArc,
  14571. dxl,
  14572. dxr,
  14573. node = beaches._;
  14574. while (node) {
  14575. dxl = leftBreakPoint(node, directrix) - x;
  14576. if (dxl > epsilon$4) node = node.L; else {
  14577. dxr = x - rightBreakPoint(node, directrix);
  14578. if (dxr > epsilon$4) {
  14579. if (!node.R) {
  14580. lArc = node;
  14581. break;
  14582. }
  14583. node = node.R;
  14584. } else {
  14585. if (dxl > -epsilon$4) {
  14586. lArc = node.P;
  14587. rArc = node;
  14588. } else if (dxr > -epsilon$4) {
  14589. lArc = node;
  14590. rArc = node.N;
  14591. } else {
  14592. lArc = rArc = node;
  14593. }
  14594. break;
  14595. }
  14596. }
  14597. }
  14598. createCell(site);
  14599. var newArc = createBeach(site);
  14600. beaches.insert(lArc, newArc);
  14601. if (!lArc && !rArc) return;
  14602. if (lArc === rArc) {
  14603. detachCircle(lArc);
  14604. rArc = createBeach(lArc.site);
  14605. beaches.insert(newArc, rArc);
  14606. newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
  14607. attachCircle(lArc);
  14608. attachCircle(rArc);
  14609. return;
  14610. }
  14611. if (!rArc) { // && lArc
  14612. newArc.edge = createEdge(lArc.site, newArc.site);
  14613. return;
  14614. }
  14615. // else lArc !== rArc
  14616. detachCircle(lArc);
  14617. detachCircle(rArc);
  14618. var lSite = lArc.site,
  14619. ax = lSite[0],
  14620. ay = lSite[1],
  14621. bx = site[0] - ax,
  14622. by = site[1] - ay,
  14623. rSite = rArc.site,
  14624. cx = rSite[0] - ax,
  14625. cy = rSite[1] - ay,
  14626. d = 2 * (bx * cy - by * cx),
  14627. hb = bx * bx + by * by,
  14628. hc = cx * cx + cy * cy,
  14629. vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
  14630. setEdgeEnd(rArc.edge, lSite, rSite, vertex);
  14631. newArc.edge = createEdge(lSite, site, null, vertex);
  14632. rArc.edge = createEdge(site, rSite, null, vertex);
  14633. attachCircle(lArc);
  14634. attachCircle(rArc);
  14635. }
  14636. function leftBreakPoint(arc, directrix) {
  14637. var site = arc.site,
  14638. rfocx = site[0],
  14639. rfocy = site[1],
  14640. pby2 = rfocy - directrix;
  14641. if (!pby2) return rfocx;
  14642. var lArc = arc.P;
  14643. if (!lArc) return -Infinity;
  14644. site = lArc.site;
  14645. var lfocx = site[0],
  14646. lfocy = site[1],
  14647. plby2 = lfocy - directrix;
  14648. if (!plby2) return lfocx;
  14649. var hl = lfocx - rfocx,
  14650. aby2 = 1 / pby2 - 1 / plby2,
  14651. b = hl / plby2;
  14652. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  14653. return (rfocx + lfocx) / 2;
  14654. }
  14655. function rightBreakPoint(arc, directrix) {
  14656. var rArc = arc.N;
  14657. if (rArc) return leftBreakPoint(rArc, directrix);
  14658. var site = arc.site;
  14659. return site[1] === directrix ? site[0] : Infinity;
  14660. }
  14661. var epsilon$4 = 1e-6;
  14662. var epsilon2$2 = 1e-12;
  14663. var beaches;
  14664. var cells;
  14665. var circles;
  14666. var edges;
  14667. function triangleArea(a, b, c) {
  14668. return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
  14669. }
  14670. function lexicographic(a, b) {
  14671. return b[1] - a[1]
  14672. || b[0] - a[0];
  14673. }
  14674. function Diagram(sites, extent) {
  14675. var site = sites.sort(lexicographic).pop(),
  14676. x,
  14677. y,
  14678. circle;
  14679. edges = [];
  14680. cells = new Array(sites.length);
  14681. beaches = new RedBlackTree;
  14682. circles = new RedBlackTree;
  14683. while (true) {
  14684. circle = firstCircle;
  14685. if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
  14686. if (site[0] !== x || site[1] !== y) {
  14687. addBeach(site);
  14688. x = site[0], y = site[1];
  14689. }
  14690. site = sites.pop();
  14691. } else if (circle) {
  14692. removeBeach(circle.arc);
  14693. } else {
  14694. break;
  14695. }
  14696. }
  14697. sortCellHalfedges();
  14698. if (extent) {
  14699. var x0 = +extent[0][0],
  14700. y0 = +extent[0][1],
  14701. x1 = +extent[1][0],
  14702. y1 = +extent[1][1];
  14703. clipEdges(x0, y0, x1, y1);
  14704. clipCells(x0, y0, x1, y1);
  14705. }
  14706. this.edges = edges;
  14707. this.cells = cells;
  14708. beaches =
  14709. circles =
  14710. edges =
  14711. cells = null;
  14712. }
  14713. Diagram.prototype = {
  14714. constructor: Diagram,
  14715. polygons: function() {
  14716. var edges = this.edges;
  14717. return this.cells.map(function(cell) {
  14718. var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
  14719. polygon.data = cell.site.data;
  14720. return polygon;
  14721. });
  14722. },
  14723. triangles: function() {
  14724. var triangles = [],
  14725. edges = this.edges;
  14726. this.cells.forEach(function(cell, i) {
  14727. if (!(m = (halfedges = cell.halfedges).length)) return;
  14728. var site = cell.site,
  14729. halfedges,
  14730. j = -1,
  14731. m,
  14732. s0,
  14733. e1 = edges[halfedges[m - 1]],
  14734. s1 = e1.left === site ? e1.right : e1.left;
  14735. while (++j < m) {
  14736. s0 = s1;
  14737. e1 = edges[halfedges[j]];
  14738. s1 = e1.left === site ? e1.right : e1.left;
  14739. if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
  14740. triangles.push([site.data, s0.data, s1.data]);
  14741. }
  14742. }
  14743. });
  14744. return triangles;
  14745. },
  14746. links: function() {
  14747. return this.edges.filter(function(edge) {
  14748. return edge.right;
  14749. }).map(function(edge) {
  14750. return {
  14751. source: edge.left.data,
  14752. target: edge.right.data
  14753. };
  14754. });
  14755. },
  14756. find: function(x, y, radius) {
  14757. var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
  14758. // Use the previously-found cell, or start with an arbitrary one.
  14759. while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
  14760. var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
  14761. // Traverse the half-edges to find a closer cell, if any.
  14762. do {
  14763. cell = that.cells[i0 = i1], i1 = null;
  14764. cell.halfedges.forEach(function(e) {
  14765. var edge = that.edges[e], v = edge.left;
  14766. if ((v === cell.site || !v) && !(v = edge.right)) return;
  14767. var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
  14768. if (v2 < d2) d2 = v2, i1 = v.index;
  14769. });
  14770. } while (i1 !== null);
  14771. that._found = i0;
  14772. return radius == null || d2 <= radius * radius ? cell.site : null;
  14773. }
  14774. };
  14775. function voronoi() {
  14776. var x = x$4,
  14777. y = y$4,
  14778. extent = null;
  14779. function voronoi(data) {
  14780. return new Diagram(data.map(function(d, i) {
  14781. var s = [Math.round(x(d, i, data) / epsilon$4) * epsilon$4, Math.round(y(d, i, data) / epsilon$4) * epsilon$4];
  14782. s.index = i;
  14783. s.data = d;
  14784. return s;
  14785. }), extent);
  14786. }
  14787. voronoi.polygons = function(data) {
  14788. return voronoi(data).polygons();
  14789. };
  14790. voronoi.links = function(data) {
  14791. return voronoi(data).links();
  14792. };
  14793. voronoi.triangles = function(data) {
  14794. return voronoi(data).triangles();
  14795. };
  14796. voronoi.x = function(_) {
  14797. return arguments.length ? (x = typeof _ === "function" ? _ : constant$c(+_), voronoi) : x;
  14798. };
  14799. voronoi.y = function(_) {
  14800. return arguments.length ? (y = typeof _ === "function" ? _ : constant$c(+_), voronoi) : y;
  14801. };
  14802. voronoi.extent = function(_) {
  14803. 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]]];
  14804. };
  14805. voronoi.size = function(_) {
  14806. return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
  14807. };
  14808. return voronoi;
  14809. }
  14810. function constant$d(x) {
  14811. return function() {
  14812. return x;
  14813. };
  14814. }
  14815. function ZoomEvent(target, type, transform) {
  14816. this.target = target;
  14817. this.type = type;
  14818. this.transform = transform;
  14819. }
  14820. function Transform(k, x, y) {
  14821. this.k = k;
  14822. this.x = x;
  14823. this.y = y;
  14824. }
  14825. Transform.prototype = {
  14826. constructor: Transform,
  14827. scale: function(k) {
  14828. return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
  14829. },
  14830. translate: function(x, y) {
  14831. return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
  14832. },
  14833. apply: function(point) {
  14834. return [point[0] * this.k + this.x, point[1] * this.k + this.y];
  14835. },
  14836. applyX: function(x) {
  14837. return x * this.k + this.x;
  14838. },
  14839. applyY: function(y) {
  14840. return y * this.k + this.y;
  14841. },
  14842. invert: function(location) {
  14843. return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
  14844. },
  14845. invertX: function(x) {
  14846. return (x - this.x) / this.k;
  14847. },
  14848. invertY: function(y) {
  14849. return (y - this.y) / this.k;
  14850. },
  14851. rescaleX: function(x) {
  14852. return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
  14853. },
  14854. rescaleY: function(y) {
  14855. return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
  14856. },
  14857. toString: function() {
  14858. return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
  14859. }
  14860. };
  14861. var identity$9 = new Transform(1, 0, 0);
  14862. transform$1.prototype = Transform.prototype;
  14863. function transform$1(node) {
  14864. while (!node.__zoom) if (!(node = node.parentNode)) return identity$9;
  14865. return node.__zoom;
  14866. }
  14867. function nopropagation$2() {
  14868. exports.event.stopImmediatePropagation();
  14869. }
  14870. function noevent$2() {
  14871. exports.event.preventDefault();
  14872. exports.event.stopImmediatePropagation();
  14873. }
  14874. // Ignore right-click, since that should open the context menu.
  14875. function defaultFilter$2() {
  14876. return !exports.event.ctrlKey && !exports.event.button;
  14877. }
  14878. function defaultExtent$1() {
  14879. var e = this;
  14880. if (e instanceof SVGElement) {
  14881. e = e.ownerSVGElement || e;
  14882. if (e.hasAttribute("viewBox")) {
  14883. e = e.viewBox.baseVal;
  14884. return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
  14885. }
  14886. return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
  14887. }
  14888. return [[0, 0], [e.clientWidth, e.clientHeight]];
  14889. }
  14890. function defaultTransform() {
  14891. return this.__zoom || identity$9;
  14892. }
  14893. function defaultWheelDelta() {
  14894. return -exports.event.deltaY * (exports.event.deltaMode === 1 ? 0.05 : exports.event.deltaMode ? 1 : 0.002);
  14895. }
  14896. function defaultTouchable$2() {
  14897. return navigator.maxTouchPoints || ("ontouchstart" in this);
  14898. }
  14899. function defaultConstrain(transform, extent, translateExtent) {
  14900. var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
  14901. dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
  14902. dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
  14903. dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
  14904. return transform.translate(
  14905. dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
  14906. dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
  14907. );
  14908. }
  14909. function zoom() {
  14910. var filter = defaultFilter$2,
  14911. extent = defaultExtent$1,
  14912. constrain = defaultConstrain,
  14913. wheelDelta = defaultWheelDelta,
  14914. touchable = defaultTouchable$2,
  14915. scaleExtent = [0, Infinity],
  14916. translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
  14917. duration = 250,
  14918. interpolate = interpolateZoom,
  14919. listeners = dispatch("start", "zoom", "end"),
  14920. touchstarting,
  14921. touchending,
  14922. touchDelay = 500,
  14923. wheelDelay = 150,
  14924. clickDistance2 = 0;
  14925. function zoom(selection) {
  14926. selection
  14927. .property("__zoom", defaultTransform)
  14928. .on("wheel.zoom", wheeled)
  14929. .on("mousedown.zoom", mousedowned)
  14930. .on("dblclick.zoom", dblclicked)
  14931. .filter(touchable)
  14932. .on("touchstart.zoom", touchstarted)
  14933. .on("touchmove.zoom", touchmoved)
  14934. .on("touchend.zoom touchcancel.zoom", touchended)
  14935. .style("touch-action", "none")
  14936. .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
  14937. }
  14938. zoom.transform = function(collection, transform, point) {
  14939. var selection = collection.selection ? collection.selection() : collection;
  14940. selection.property("__zoom", defaultTransform);
  14941. if (collection !== selection) {
  14942. schedule(collection, transform, point);
  14943. } else {
  14944. selection.interrupt().each(function() {
  14945. gesture(this, arguments)
  14946. .start()
  14947. .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
  14948. .end();
  14949. });
  14950. }
  14951. };
  14952. zoom.scaleBy = function(selection, k, p) {
  14953. zoom.scaleTo(selection, function() {
  14954. var k0 = this.__zoom.k,
  14955. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14956. return k0 * k1;
  14957. }, p);
  14958. };
  14959. zoom.scaleTo = function(selection, k, p) {
  14960. zoom.transform(selection, function() {
  14961. var e = extent.apply(this, arguments),
  14962. t0 = this.__zoom,
  14963. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
  14964. p1 = t0.invert(p0),
  14965. k1 = typeof k === "function" ? k.apply(this, arguments) : k;
  14966. return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
  14967. }, p);
  14968. };
  14969. zoom.translateBy = function(selection, x, y) {
  14970. zoom.transform(selection, function() {
  14971. return constrain(this.__zoom.translate(
  14972. typeof x === "function" ? x.apply(this, arguments) : x,
  14973. typeof y === "function" ? y.apply(this, arguments) : y
  14974. ), extent.apply(this, arguments), translateExtent);
  14975. });
  14976. };
  14977. zoom.translateTo = function(selection, x, y, p) {
  14978. zoom.transform(selection, function() {
  14979. var e = extent.apply(this, arguments),
  14980. t = this.__zoom,
  14981. p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
  14982. return constrain(identity$9.translate(p0[0], p0[1]).scale(t.k).translate(
  14983. typeof x === "function" ? -x.apply(this, arguments) : -x,
  14984. typeof y === "function" ? -y.apply(this, arguments) : -y
  14985. ), e, translateExtent);
  14986. }, p);
  14987. };
  14988. function scale(transform, k) {
  14989. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
  14990. return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
  14991. }
  14992. function translate(transform, p0, p1) {
  14993. var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
  14994. return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
  14995. }
  14996. function centroid(extent) {
  14997. return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
  14998. }
  14999. function schedule(transition, transform, point) {
  15000. transition
  15001. .on("start.zoom", function() { gesture(this, arguments).start(); })
  15002. .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
  15003. .tween("zoom", function() {
  15004. var that = this,
  15005. args = arguments,
  15006. g = gesture(that, args),
  15007. e = extent.apply(that, args),
  15008. p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
  15009. w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
  15010. a = that.__zoom,
  15011. b = typeof transform === "function" ? transform.apply(that, args) : transform,
  15012. i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
  15013. return function(t) {
  15014. if (t === 1) t = b; // Avoid rounding error on end.
  15015. else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
  15016. g.zoom(null, t);
  15017. };
  15018. });
  15019. }
  15020. function gesture(that, args, clean) {
  15021. return (!clean && that.__zooming) || new Gesture(that, args);
  15022. }
  15023. function Gesture(that, args) {
  15024. this.that = that;
  15025. this.args = args;
  15026. this.active = 0;
  15027. this.extent = extent.apply(that, args);
  15028. this.taps = 0;
  15029. }
  15030. Gesture.prototype = {
  15031. start: function() {
  15032. if (++this.active === 1) {
  15033. this.that.__zooming = this;
  15034. this.emit("start");
  15035. }
  15036. return this;
  15037. },
  15038. zoom: function(key, transform) {
  15039. if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
  15040. if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
  15041. if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
  15042. this.that.__zoom = transform;
  15043. this.emit("zoom");
  15044. return this;
  15045. },
  15046. end: function() {
  15047. if (--this.active === 0) {
  15048. delete this.that.__zooming;
  15049. this.emit("end");
  15050. }
  15051. return this;
  15052. },
  15053. emit: function(type) {
  15054. customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
  15055. }
  15056. };
  15057. function wheeled() {
  15058. if (!filter.apply(this, arguments)) return;
  15059. var g = gesture(this, arguments),
  15060. t = this.__zoom,
  15061. k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
  15062. p = mouse(this);
  15063. // If the mouse is in the same location as before, reuse it.
  15064. // If there were recent wheel events, reset the wheel idle timeout.
  15065. if (g.wheel) {
  15066. if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
  15067. g.mouse[1] = t.invert(g.mouse[0] = p);
  15068. }
  15069. clearTimeout(g.wheel);
  15070. }
  15071. // If this wheel event won’t trigger a transform change, ignore it.
  15072. else if (t.k === k) return;
  15073. // Otherwise, capture the mouse point and location at the start.
  15074. else {
  15075. g.mouse = [p, t.invert(p)];
  15076. interrupt(this);
  15077. g.start();
  15078. }
  15079. noevent$2();
  15080. g.wheel = setTimeout(wheelidled, wheelDelay);
  15081. g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
  15082. function wheelidled() {
  15083. g.wheel = null;
  15084. g.end();
  15085. }
  15086. }
  15087. function mousedowned() {
  15088. if (touchending || !filter.apply(this, arguments)) return;
  15089. var g = gesture(this, arguments, true),
  15090. v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
  15091. p = mouse(this),
  15092. x0 = exports.event.clientX,
  15093. y0 = exports.event.clientY;
  15094. dragDisable(exports.event.view);
  15095. nopropagation$2();
  15096. g.mouse = [p, this.__zoom.invert(p)];
  15097. interrupt(this);
  15098. g.start();
  15099. function mousemoved() {
  15100. noevent$2();
  15101. if (!g.moved) {
  15102. var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
  15103. g.moved = dx * dx + dy * dy > clickDistance2;
  15104. }
  15105. g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
  15106. }
  15107. function mouseupped() {
  15108. v.on("mousemove.zoom mouseup.zoom", null);
  15109. yesdrag(exports.event.view, g.moved);
  15110. noevent$2();
  15111. g.end();
  15112. }
  15113. }
  15114. function dblclicked() {
  15115. if (!filter.apply(this, arguments)) return;
  15116. var t0 = this.__zoom,
  15117. p0 = mouse(this),
  15118. p1 = t0.invert(p0),
  15119. k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
  15120. t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
  15121. noevent$2();
  15122. if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
  15123. else select(this).call(zoom.transform, t1);
  15124. }
  15125. function touchstarted() {
  15126. if (!filter.apply(this, arguments)) return;
  15127. var touches = exports.event.touches,
  15128. n = touches.length,
  15129. g = gesture(this, arguments, exports.event.changedTouches.length === n),
  15130. started, i, t, p;
  15131. nopropagation$2();
  15132. for (i = 0; i < n; ++i) {
  15133. t = touches[i], p = touch(this, touches, t.identifier);
  15134. p = [p, this.__zoom.invert(p), t.identifier];
  15135. if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
  15136. else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
  15137. }
  15138. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  15139. if (started) {
  15140. if (g.taps < 2) touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
  15141. interrupt(this);
  15142. g.start();
  15143. }
  15144. }
  15145. function touchmoved() {
  15146. if (!this.__zooming) return;
  15147. var g = gesture(this, arguments),
  15148. touches = exports.event.changedTouches,
  15149. n = touches.length, i, t, p, l;
  15150. noevent$2();
  15151. if (touchstarting) touchstarting = clearTimeout(touchstarting);
  15152. g.taps = 0;
  15153. for (i = 0; i < n; ++i) {
  15154. t = touches[i], p = touch(this, touches, t.identifier);
  15155. if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
  15156. else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
  15157. }
  15158. t = g.that.__zoom;
  15159. if (g.touch1) {
  15160. var p0 = g.touch0[0], l0 = g.touch0[1],
  15161. p1 = g.touch1[0], l1 = g.touch1[1],
  15162. dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
  15163. dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
  15164. t = scale(t, Math.sqrt(dp / dl));
  15165. p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
  15166. l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
  15167. }
  15168. else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
  15169. else return;
  15170. g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
  15171. }
  15172. function touchended() {
  15173. if (!this.__zooming) return;
  15174. var g = gesture(this, arguments),
  15175. touches = exports.event.changedTouches,
  15176. n = touches.length, i, t;
  15177. nopropagation$2();
  15178. if (touchending) clearTimeout(touchending);
  15179. touchending = setTimeout(function() { touchending = null; }, touchDelay);
  15180. for (i = 0; i < n; ++i) {
  15181. t = touches[i];
  15182. if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
  15183. else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
  15184. }
  15185. if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
  15186. if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
  15187. else {
  15188. g.end();
  15189. // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
  15190. if (g.taps === 2) {
  15191. var p = select(this).on("dblclick.zoom");
  15192. if (p) p.apply(this, arguments);
  15193. }
  15194. }
  15195. }
  15196. zoom.wheelDelta = function(_) {
  15197. return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$d(+_), zoom) : wheelDelta;
  15198. };
  15199. zoom.filter = function(_) {
  15200. return arguments.length ? (filter = typeof _ === "function" ? _ : constant$d(!!_), zoom) : filter;
  15201. };
  15202. zoom.touchable = function(_) {
  15203. return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$d(!!_), zoom) : touchable;
  15204. };
  15205. zoom.extent = function(_) {
  15206. return arguments.length ? (extent = typeof _ === "function" ? _ : constant$d([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
  15207. };
  15208. zoom.scaleExtent = function(_) {
  15209. return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
  15210. };
  15211. zoom.translateExtent = function(_) {
  15212. return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
  15213. };
  15214. zoom.constrain = function(_) {
  15215. return arguments.length ? (constrain = _, zoom) : constrain;
  15216. };
  15217. zoom.duration = function(_) {
  15218. return arguments.length ? (duration = +_, zoom) : duration;
  15219. };
  15220. zoom.interpolate = function(_) {
  15221. return arguments.length ? (interpolate = _, zoom) : interpolate;
  15222. };
  15223. zoom.on = function() {
  15224. var value = listeners.on.apply(listeners, arguments);
  15225. return value === listeners ? zoom : value;
  15226. };
  15227. zoom.clickDistance = function(_) {
  15228. return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
  15229. };
  15230. return zoom;
  15231. }
  15232. exports.FormatSpecifier = FormatSpecifier;
  15233. exports.active = active;
  15234. exports.arc = arc;
  15235. exports.area = area$3;
  15236. exports.areaRadial = areaRadial;
  15237. exports.ascending = ascending;
  15238. exports.autoType = autoType;
  15239. exports.axisBottom = axisBottom;
  15240. exports.axisLeft = axisLeft;
  15241. exports.axisRight = axisRight;
  15242. exports.axisTop = axisTop;
  15243. exports.bisect = bisectRight;
  15244. exports.bisectLeft = bisectLeft;
  15245. exports.bisectRight = bisectRight;
  15246. exports.bisector = bisector;
  15247. exports.blob = blob;
  15248. exports.brush = brush;
  15249. exports.brushSelection = brushSelection;
  15250. exports.brushX = brushX;
  15251. exports.brushY = brushY;
  15252. exports.buffer = buffer;
  15253. exports.chord = chord;
  15254. exports.clientPoint = point;
  15255. exports.cluster = cluster;
  15256. exports.color = color;
  15257. exports.contourDensity = density;
  15258. exports.contours = contours;
  15259. exports.create = create;
  15260. exports.creator = creator;
  15261. exports.cross = cross;
  15262. exports.csv = csv$1;
  15263. exports.csvFormat = csvFormat;
  15264. exports.csvFormatBody = csvFormatBody;
  15265. exports.csvFormatRows = csvFormatRows;
  15266. exports.csvParse = csvParse;
  15267. exports.csvParseRows = csvParseRows;
  15268. exports.cubehelix = cubehelix;
  15269. exports.curveBasis = basis$2;
  15270. exports.curveBasisClosed = basisClosed$1;
  15271. exports.curveBasisOpen = basisOpen;
  15272. exports.curveBundle = bundle;
  15273. exports.curveCardinal = cardinal;
  15274. exports.curveCardinalClosed = cardinalClosed;
  15275. exports.curveCardinalOpen = cardinalOpen;
  15276. exports.curveCatmullRom = catmullRom;
  15277. exports.curveCatmullRomClosed = catmullRomClosed;
  15278. exports.curveCatmullRomOpen = catmullRomOpen;
  15279. exports.curveLinear = curveLinear;
  15280. exports.curveLinearClosed = linearClosed;
  15281. exports.curveMonotoneX = monotoneX;
  15282. exports.curveMonotoneY = monotoneY;
  15283. exports.curveNatural = natural;
  15284. exports.curveStep = step;
  15285. exports.curveStepAfter = stepAfter;
  15286. exports.curveStepBefore = stepBefore;
  15287. exports.customEvent = customEvent;
  15288. exports.descending = descending;
  15289. exports.deviation = deviation;
  15290. exports.dispatch = dispatch;
  15291. exports.drag = drag;
  15292. exports.dragDisable = dragDisable;
  15293. exports.dragEnable = yesdrag;
  15294. exports.dsv = dsv;
  15295. exports.dsvFormat = dsvFormat;
  15296. exports.easeBack = backInOut;
  15297. exports.easeBackIn = backIn;
  15298. exports.easeBackInOut = backInOut;
  15299. exports.easeBackOut = backOut;
  15300. exports.easeBounce = bounceOut;
  15301. exports.easeBounceIn = bounceIn;
  15302. exports.easeBounceInOut = bounceInOut;
  15303. exports.easeBounceOut = bounceOut;
  15304. exports.easeCircle = circleInOut;
  15305. exports.easeCircleIn = circleIn;
  15306. exports.easeCircleInOut = circleInOut;
  15307. exports.easeCircleOut = circleOut;
  15308. exports.easeCubic = cubicInOut;
  15309. exports.easeCubicIn = cubicIn;
  15310. exports.easeCubicInOut = cubicInOut;
  15311. exports.easeCubicOut = cubicOut;
  15312. exports.easeElastic = elasticOut;
  15313. exports.easeElasticIn = elasticIn;
  15314. exports.easeElasticInOut = elasticInOut;
  15315. exports.easeElasticOut = elasticOut;
  15316. exports.easeExp = expInOut;
  15317. exports.easeExpIn = expIn;
  15318. exports.easeExpInOut = expInOut;
  15319. exports.easeExpOut = expOut;
  15320. exports.easeLinear = linear$1;
  15321. exports.easePoly = polyInOut;
  15322. exports.easePolyIn = polyIn;
  15323. exports.easePolyInOut = polyInOut;
  15324. exports.easePolyOut = polyOut;
  15325. exports.easeQuad = quadInOut;
  15326. exports.easeQuadIn = quadIn;
  15327. exports.easeQuadInOut = quadInOut;
  15328. exports.easeQuadOut = quadOut;
  15329. exports.easeSin = sinInOut;
  15330. exports.easeSinIn = sinIn;
  15331. exports.easeSinInOut = sinInOut;
  15332. exports.easeSinOut = sinOut;
  15333. exports.entries = entries;
  15334. exports.extent = extent;
  15335. exports.forceCenter = center$1;
  15336. exports.forceCollide = collide;
  15337. exports.forceLink = link;
  15338. exports.forceManyBody = manyBody;
  15339. exports.forceRadial = radial;
  15340. exports.forceSimulation = simulation;
  15341. exports.forceX = x$2;
  15342. exports.forceY = y$2;
  15343. exports.formatDefaultLocale = defaultLocale;
  15344. exports.formatLocale = formatLocale;
  15345. exports.formatSpecifier = formatSpecifier;
  15346. exports.geoAlbers = albers;
  15347. exports.geoAlbersUsa = albersUsa;
  15348. exports.geoArea = area$1;
  15349. exports.geoAzimuthalEqualArea = azimuthalEqualArea;
  15350. exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
  15351. exports.geoAzimuthalEquidistant = azimuthalEquidistant;
  15352. exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
  15353. exports.geoBounds = bounds;
  15354. exports.geoCentroid = centroid;
  15355. exports.geoCircle = circle;
  15356. exports.geoClipAntimeridian = clipAntimeridian;
  15357. exports.geoClipCircle = clipCircle;
  15358. exports.geoClipExtent = extent$1;
  15359. exports.geoClipRectangle = clipRectangle;
  15360. exports.geoConicConformal = conicConformal;
  15361. exports.geoConicConformalRaw = conicConformalRaw;
  15362. exports.geoConicEqualArea = conicEqualArea;
  15363. exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
  15364. exports.geoConicEquidistant = conicEquidistant;
  15365. exports.geoConicEquidistantRaw = conicEquidistantRaw;
  15366. exports.geoContains = contains$1;
  15367. exports.geoDistance = distance;
  15368. exports.geoEqualEarth = equalEarth;
  15369. exports.geoEqualEarthRaw = equalEarthRaw;
  15370. exports.geoEquirectangular = equirectangular;
  15371. exports.geoEquirectangularRaw = equirectangularRaw;
  15372. exports.geoGnomonic = gnomonic;
  15373. exports.geoGnomonicRaw = gnomonicRaw;
  15374. exports.geoGraticule = graticule;
  15375. exports.geoGraticule10 = graticule10;
  15376. exports.geoIdentity = identity$5;
  15377. exports.geoInterpolate = interpolate$1;
  15378. exports.geoLength = length$1;
  15379. exports.geoMercator = mercator;
  15380. exports.geoMercatorRaw = mercatorRaw;
  15381. exports.geoNaturalEarth1 = naturalEarth1;
  15382. exports.geoNaturalEarth1Raw = naturalEarth1Raw;
  15383. exports.geoOrthographic = orthographic;
  15384. exports.geoOrthographicRaw = orthographicRaw;
  15385. exports.geoPath = index$1;
  15386. exports.geoProjection = projection;
  15387. exports.geoProjectionMutator = projectionMutator;
  15388. exports.geoRotation = rotation;
  15389. exports.geoStereographic = stereographic;
  15390. exports.geoStereographicRaw = stereographicRaw;
  15391. exports.geoStream = geoStream;
  15392. exports.geoTransform = transform;
  15393. exports.geoTransverseMercator = transverseMercator;
  15394. exports.geoTransverseMercatorRaw = transverseMercatorRaw;
  15395. exports.gray = gray;
  15396. exports.hcl = hcl;
  15397. exports.hierarchy = hierarchy;
  15398. exports.histogram = histogram;
  15399. exports.hsl = hsl;
  15400. exports.html = html;
  15401. exports.image = image;
  15402. exports.interpolate = interpolateValue;
  15403. exports.interpolateArray = array$1;
  15404. exports.interpolateBasis = basis$1;
  15405. exports.interpolateBasisClosed = basisClosed;
  15406. exports.interpolateBlues = Blues;
  15407. exports.interpolateBrBG = BrBG;
  15408. exports.interpolateBuGn = BuGn;
  15409. exports.interpolateBuPu = BuPu;
  15410. exports.interpolateCividis = cividis;
  15411. exports.interpolateCool = cool;
  15412. exports.interpolateCubehelix = cubehelix$2;
  15413. exports.interpolateCubehelixDefault = cubehelix$3;
  15414. exports.interpolateCubehelixLong = cubehelixLong;
  15415. exports.interpolateDate = date;
  15416. exports.interpolateDiscrete = discrete;
  15417. exports.interpolateGnBu = GnBu;
  15418. exports.interpolateGreens = Greens;
  15419. exports.interpolateGreys = Greys;
  15420. exports.interpolateHcl = hcl$2;
  15421. exports.interpolateHclLong = hclLong;
  15422. exports.interpolateHsl = hsl$2;
  15423. exports.interpolateHslLong = hslLong;
  15424. exports.interpolateHue = hue$1;
  15425. exports.interpolateInferno = inferno;
  15426. exports.interpolateLab = lab$1;
  15427. exports.interpolateMagma = magma;
  15428. exports.interpolateNumber = interpolateNumber;
  15429. exports.interpolateObject = object;
  15430. exports.interpolateOrRd = OrRd;
  15431. exports.interpolateOranges = Oranges;
  15432. exports.interpolatePRGn = PRGn;
  15433. exports.interpolatePiYG = PiYG;
  15434. exports.interpolatePlasma = plasma;
  15435. exports.interpolatePuBu = PuBu;
  15436. exports.interpolatePuBuGn = PuBuGn;
  15437. exports.interpolatePuOr = PuOr;
  15438. exports.interpolatePuRd = PuRd;
  15439. exports.interpolatePurples = Purples;
  15440. exports.interpolateRainbow = rainbow;
  15441. exports.interpolateRdBu = RdBu;
  15442. exports.interpolateRdGy = RdGy;
  15443. exports.interpolateRdPu = RdPu;
  15444. exports.interpolateRdYlBu = RdYlBu;
  15445. exports.interpolateRdYlGn = RdYlGn;
  15446. exports.interpolateReds = Reds;
  15447. exports.interpolateRgb = interpolateRgb;
  15448. exports.interpolateRgbBasis = rgbBasis;
  15449. exports.interpolateRgbBasisClosed = rgbBasisClosed;
  15450. exports.interpolateRound = interpolateRound;
  15451. exports.interpolateSinebow = sinebow;
  15452. exports.interpolateSpectral = Spectral;
  15453. exports.interpolateString = interpolateString;
  15454. exports.interpolateTransformCss = interpolateTransformCss;
  15455. exports.interpolateTransformSvg = interpolateTransformSvg;
  15456. exports.interpolateTurbo = turbo;
  15457. exports.interpolateViridis = viridis;
  15458. exports.interpolateWarm = warm;
  15459. exports.interpolateYlGn = YlGn;
  15460. exports.interpolateYlGnBu = YlGnBu;
  15461. exports.interpolateYlOrBr = YlOrBr;
  15462. exports.interpolateYlOrRd = YlOrRd;
  15463. exports.interpolateZoom = interpolateZoom;
  15464. exports.interrupt = interrupt;
  15465. exports.interval = interval$1;
  15466. exports.isoFormat = formatIso;
  15467. exports.isoParse = parseIso;
  15468. exports.json = json;
  15469. exports.keys = keys;
  15470. exports.lab = lab;
  15471. exports.lch = lch;
  15472. exports.line = line;
  15473. exports.lineRadial = lineRadial$1;
  15474. exports.linkHorizontal = linkHorizontal;
  15475. exports.linkRadial = linkRadial;
  15476. exports.linkVertical = linkVertical;
  15477. exports.local = local;
  15478. exports.map = map$1;
  15479. exports.matcher = matcher;
  15480. exports.max = max;
  15481. exports.mean = mean;
  15482. exports.median = median;
  15483. exports.merge = merge;
  15484. exports.min = min;
  15485. exports.mouse = mouse;
  15486. exports.namespace = namespace;
  15487. exports.namespaces = namespaces;
  15488. exports.nest = nest;
  15489. exports.now = now;
  15490. exports.pack = index$2;
  15491. exports.packEnclose = enclose;
  15492. exports.packSiblings = siblings;
  15493. exports.pairs = pairs;
  15494. exports.partition = partition;
  15495. exports.path = path;
  15496. exports.permute = permute;
  15497. exports.pie = pie;
  15498. exports.piecewise = piecewise;
  15499. exports.pointRadial = pointRadial;
  15500. exports.polygonArea = area$2;
  15501. exports.polygonCentroid = centroid$1;
  15502. exports.polygonContains = contains$2;
  15503. exports.polygonHull = hull;
  15504. exports.polygonLength = length$2;
  15505. exports.precisionFixed = precisionFixed;
  15506. exports.precisionPrefix = precisionPrefix;
  15507. exports.precisionRound = precisionRound;
  15508. exports.quadtree = quadtree;
  15509. exports.quantile = threshold;
  15510. exports.quantize = quantize;
  15511. exports.radialArea = areaRadial;
  15512. exports.radialLine = lineRadial$1;
  15513. exports.randomBates = bates;
  15514. exports.randomExponential = exponential$1;
  15515. exports.randomIrwinHall = irwinHall;
  15516. exports.randomLogNormal = logNormal;
  15517. exports.randomNormal = normal;
  15518. exports.randomUniform = uniform;
  15519. exports.range = sequence;
  15520. exports.rgb = rgb;
  15521. exports.ribbon = ribbon;
  15522. exports.scaleBand = band;
  15523. exports.scaleDiverging = diverging;
  15524. exports.scaleDivergingLog = divergingLog;
  15525. exports.scaleDivergingPow = divergingPow;
  15526. exports.scaleDivergingSqrt = divergingSqrt;
  15527. exports.scaleDivergingSymlog = divergingSymlog;
  15528. exports.scaleIdentity = identity$7;
  15529. exports.scaleImplicit = implicit;
  15530. exports.scaleLinear = linear$2;
  15531. exports.scaleLog = log$1;
  15532. exports.scaleOrdinal = ordinal;
  15533. exports.scalePoint = point$1;
  15534. exports.scalePow = pow$1;
  15535. exports.scaleQuantile = quantile;
  15536. exports.scaleQuantize = quantize$1;
  15537. exports.scaleSequential = sequential;
  15538. exports.scaleSequentialLog = sequentialLog;
  15539. exports.scaleSequentialPow = sequentialPow;
  15540. exports.scaleSequentialQuantile = sequentialQuantile;
  15541. exports.scaleSequentialSqrt = sequentialSqrt;
  15542. exports.scaleSequentialSymlog = sequentialSymlog;
  15543. exports.scaleSqrt = sqrt$1;
  15544. exports.scaleSymlog = symlog;
  15545. exports.scaleThreshold = threshold$1;
  15546. exports.scaleTime = time;
  15547. exports.scaleUtc = utcTime;
  15548. exports.scan = scan;
  15549. exports.schemeAccent = Accent;
  15550. exports.schemeBlues = scheme$l;
  15551. exports.schemeBrBG = scheme;
  15552. exports.schemeBuGn = scheme$9;
  15553. exports.schemeBuPu = scheme$a;
  15554. exports.schemeCategory10 = category10;
  15555. exports.schemeDark2 = Dark2;
  15556. exports.schemeGnBu = scheme$b;
  15557. exports.schemeGreens = scheme$m;
  15558. exports.schemeGreys = scheme$n;
  15559. exports.schemeOrRd = scheme$c;
  15560. exports.schemeOranges = scheme$q;
  15561. exports.schemePRGn = scheme$1;
  15562. exports.schemePaired = Paired;
  15563. exports.schemePastel1 = Pastel1;
  15564. exports.schemePastel2 = Pastel2;
  15565. exports.schemePiYG = scheme$2;
  15566. exports.schemePuBu = scheme$e;
  15567. exports.schemePuBuGn = scheme$d;
  15568. exports.schemePuOr = scheme$3;
  15569. exports.schemePuRd = scheme$f;
  15570. exports.schemePurples = scheme$o;
  15571. exports.schemeRdBu = scheme$4;
  15572. exports.schemeRdGy = scheme$5;
  15573. exports.schemeRdPu = scheme$g;
  15574. exports.schemeRdYlBu = scheme$6;
  15575. exports.schemeRdYlGn = scheme$7;
  15576. exports.schemeReds = scheme$p;
  15577. exports.schemeSet1 = Set1;
  15578. exports.schemeSet2 = Set2;
  15579. exports.schemeSet3 = Set3;
  15580. exports.schemeSpectral = scheme$8;
  15581. exports.schemeTableau10 = Tableau10;
  15582. exports.schemeYlGn = scheme$i;
  15583. exports.schemeYlGnBu = scheme$h;
  15584. exports.schemeYlOrBr = scheme$j;
  15585. exports.schemeYlOrRd = scheme$k;
  15586. exports.select = select;
  15587. exports.selectAll = selectAll;
  15588. exports.selection = selection;
  15589. exports.selector = selector;
  15590. exports.selectorAll = selectorAll;
  15591. exports.set = set$2;
  15592. exports.shuffle = shuffle;
  15593. exports.stack = stack;
  15594. exports.stackOffsetDiverging = diverging$1;
  15595. exports.stackOffsetExpand = expand;
  15596. exports.stackOffsetNone = none$1;
  15597. exports.stackOffsetSilhouette = silhouette;
  15598. exports.stackOffsetWiggle = wiggle;
  15599. exports.stackOrderAppearance = appearance;
  15600. exports.stackOrderAscending = ascending$3;
  15601. exports.stackOrderDescending = descending$2;
  15602. exports.stackOrderInsideOut = insideOut;
  15603. exports.stackOrderNone = none$2;
  15604. exports.stackOrderReverse = reverse;
  15605. exports.stratify = stratify;
  15606. exports.style = styleValue;
  15607. exports.sum = sum;
  15608. exports.svg = svg;
  15609. exports.symbol = symbol;
  15610. exports.symbolCircle = circle$2;
  15611. exports.symbolCross = cross$2;
  15612. exports.symbolDiamond = diamond;
  15613. exports.symbolSquare = square;
  15614. exports.symbolStar = star;
  15615. exports.symbolTriangle = triangle;
  15616. exports.symbolWye = wye;
  15617. exports.symbols = symbols;
  15618. exports.text = text;
  15619. exports.thresholdFreedmanDiaconis = freedmanDiaconis;
  15620. exports.thresholdScott = scott;
  15621. exports.thresholdSturges = thresholdSturges;
  15622. exports.tickFormat = tickFormat;
  15623. exports.tickIncrement = tickIncrement;
  15624. exports.tickStep = tickStep;
  15625. exports.ticks = ticks;
  15626. exports.timeDay = day;
  15627. exports.timeDays = days;
  15628. exports.timeFormatDefaultLocale = defaultLocale$1;
  15629. exports.timeFormatLocale = formatLocale$1;
  15630. exports.timeFriday = friday;
  15631. exports.timeFridays = fridays;
  15632. exports.timeHour = hour;
  15633. exports.timeHours = hours;
  15634. exports.timeInterval = newInterval;
  15635. exports.timeMillisecond = millisecond;
  15636. exports.timeMilliseconds = milliseconds;
  15637. exports.timeMinute = minute;
  15638. exports.timeMinutes = minutes;
  15639. exports.timeMonday = monday;
  15640. exports.timeMondays = mondays;
  15641. exports.timeMonth = month;
  15642. exports.timeMonths = months;
  15643. exports.timeSaturday = saturday;
  15644. exports.timeSaturdays = saturdays;
  15645. exports.timeSecond = second;
  15646. exports.timeSeconds = seconds;
  15647. exports.timeSunday = sunday;
  15648. exports.timeSundays = sundays;
  15649. exports.timeThursday = thursday;
  15650. exports.timeThursdays = thursdays;
  15651. exports.timeTuesday = tuesday;
  15652. exports.timeTuesdays = tuesdays;
  15653. exports.timeWednesday = wednesday;
  15654. exports.timeWednesdays = wednesdays;
  15655. exports.timeWeek = sunday;
  15656. exports.timeWeeks = sundays;
  15657. exports.timeYear = year;
  15658. exports.timeYears = years;
  15659. exports.timeout = timeout$1;
  15660. exports.timer = timer;
  15661. exports.timerFlush = timerFlush;
  15662. exports.touch = touch;
  15663. exports.touches = touches;
  15664. exports.transition = transition;
  15665. exports.transpose = transpose;
  15666. exports.tree = tree;
  15667. exports.treemap = index$3;
  15668. exports.treemapBinary = binary;
  15669. exports.treemapDice = treemapDice;
  15670. exports.treemapResquarify = resquarify;
  15671. exports.treemapSlice = treemapSlice;
  15672. exports.treemapSliceDice = sliceDice;
  15673. exports.treemapSquarify = squarify;
  15674. exports.tsv = tsv$1;
  15675. exports.tsvFormat = tsvFormat;
  15676. exports.tsvFormatBody = tsvFormatBody;
  15677. exports.tsvFormatRows = tsvFormatRows;
  15678. exports.tsvParse = tsvParse;
  15679. exports.tsvParseRows = tsvParseRows;
  15680. exports.utcDay = utcDay;
  15681. exports.utcDays = utcDays;
  15682. exports.utcFriday = utcFriday;
  15683. exports.utcFridays = utcFridays;
  15684. exports.utcHour = utcHour;
  15685. exports.utcHours = utcHours;
  15686. exports.utcMillisecond = millisecond;
  15687. exports.utcMilliseconds = milliseconds;
  15688. exports.utcMinute = utcMinute;
  15689. exports.utcMinutes = utcMinutes;
  15690. exports.utcMonday = utcMonday;
  15691. exports.utcMondays = utcMondays;
  15692. exports.utcMonth = utcMonth;
  15693. exports.utcMonths = utcMonths;
  15694. exports.utcSaturday = utcSaturday;
  15695. exports.utcSaturdays = utcSaturdays;
  15696. exports.utcSecond = second;
  15697. exports.utcSeconds = seconds;
  15698. exports.utcSunday = utcSunday;
  15699. exports.utcSundays = utcSundays;
  15700. exports.utcThursday = utcThursday;
  15701. exports.utcThursdays = utcThursdays;
  15702. exports.utcTuesday = utcTuesday;
  15703. exports.utcTuesdays = utcTuesdays;
  15704. exports.utcWednesday = utcWednesday;
  15705. exports.utcWednesdays = utcWednesdays;
  15706. exports.utcWeek = utcSunday;
  15707. exports.utcWeeks = utcSundays;
  15708. exports.utcYear = utcYear;
  15709. exports.utcYears = utcYears;
  15710. exports.values = values;
  15711. exports.variance = variance;
  15712. exports.version = version;
  15713. exports.voronoi = voronoi;
  15714. exports.window = defaultView;
  15715. exports.xml = xml;
  15716. exports.zip = zip;
  15717. exports.zoom = zoom;
  15718. exports.zoomIdentity = identity$9;
  15719. exports.zoomTransform = transform$1;
  15720. Object.defineProperty(exports, '__esModule', { value: true });
  15721. }));